diff --git a/CMakeLists.txt b/CMakeLists.txt index 7a0c7d5..dd2647f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,11 +1,13 @@ cmake_minimum_required (VERSION 3.7) -project(controller) +project(controller + VERSION 0.1.0 + LANGUAGES C) -add_executable(controller main.c) +add_executable(controller src/main.c) option(WIRING_PI_DEBUG "Use WiringPi Debugging Tool (OFF)" OFF) -SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99 -Wpedantic -Werror -Wall -Wextra -lwiringPi -lwiringPiDev -luuid -llmdb -ffile-prefix-map=${CMAKE_SOURCE_DIR}/=/") +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99 -Wpedantic -Werror -Wall -Wextra -lwiringPi -lwiringPiDev -luuid -llmdb -ffile-prefix-map=${CMAKE_SOURCE_DIR}/src/=") set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -g -fprofile-arcs -ftest-coverage") @@ -14,34 +16,34 @@ if(WIRING_PI_DEBUG) add_definitions("-DWIRING_PI_DEBUG") endif(WIRING_PI_DEBUG) -aux_source_directory(vendor VENDOR_SRC) # vendor first to put their warnings on top -aux_source_directory(. SRC_DIR) -aux_source_directory(models MODELS_SRC) -aux_source_directory(helpers HELPERS_SRC) -aux_source_directory(handlers HANDLERS_SRC) -aux_source_directory(drivers DRIVERS_SRC) -aux_source_directory(runners RUNNERS_SRC) +aux_source_directory(src/ SRC_DIR) +aux_source_directory(src/models MODELS_SRC) +aux_source_directory(src/helpers HELPERS_SRC) +aux_source_directory(src/handlers HANDLERS_SRC) +aux_source_directory(src/drivers DRIVERS_SRC) +aux_source_directory(src/runners RUNNERS_SRC) configure_file("controller.ini" "controller.ini" COPYONLY) +configure_file("version.h.in" "version.h" @ONLY) -target_sources(controller PRIVATE ${VENDOR_SRC} ${SRC_DIR} ${MODELS_SRC} ${HELPERS_SRC} ${HANDLERS_SRC} ${DRIVERS_SRC} ${RUNNERS_SRC}) +target_sources(controller PRIVATE ${SRC_DIR} ${MODELS_SRC} ${HELPERS_SRC} ${HANDLERS_SRC} ${DRIVERS_SRC} ${RUNNERS_SRC}) target_include_directories(controller PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include) -target_include_directories(controller PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/vendor) +target_include_directories(controller PRIVATE ${CMAKE_BINARY_DIR}) add_custom_target(run COMMAND ./controller start DEPENDS controller - WORKING_DIRECTORY ${CMAKE_PROJECT_DIR} + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} ) add_custom_target(debug COMMAND valgrind ./controller start DEPENDS controller - WORKING_DIRECTORY ${CMAKE_PROJECT_DIR} + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} ) add_custom_target(debug-full COMMAND valgrind --leak-check=full --show-leak-kinds=all ./controller start DEPENDS controller - WORKING_DIRECTORY ${CMAKE_PROJECT_DIR} + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} ) add_custom_target(docs COMMAND doxygen diff --git a/vendor/argparse.h b/include/argparse.h similarity index 100% rename from vendor/argparse.h rename to include/argparse.h diff --git a/vendor/confini.h b/include/confini.h similarity index 100% rename from vendor/confini.h rename to include/confini.h diff --git a/vendor/mpack.h b/include/mpack.h similarity index 100% rename from vendor/mpack.h rename to include/mpack.h diff --git a/vendor/argparse.c b/src/argparse.c similarity index 100% rename from vendor/argparse.c rename to src/argparse.c diff --git a/vendor/confini.c b/src/confini.c similarity index 100% rename from vendor/confini.c rename to src/confini.c diff --git a/database.c b/src/database.c similarity index 100% rename from database.c rename to src/database.c diff --git a/drivers/gpio.c b/src/drivers/gpio.c similarity index 100% rename from drivers/gpio.c rename to src/drivers/gpio.c diff --git a/drivers/piface.c b/src/drivers/piface.c similarity index 100% rename from drivers/piface.c rename to src/drivers/piface.c diff --git a/handlers/command.c b/src/handlers/command.c similarity index 100% rename from handlers/command.c rename to src/handlers/command.c diff --git a/handlers/discovery.c b/src/handlers/discovery.c similarity index 100% rename from handlers/discovery.c rename to src/handlers/discovery.c diff --git a/handlers/loop.c b/src/handlers/loop.c similarity index 100% rename from handlers/loop.c rename to src/handlers/loop.c diff --git a/handlers/poll.c b/src/handlers/poll.c similarity index 100% rename from handlers/poll.c rename to src/handlers/poll.c diff --git a/helpers/bind_server.c b/src/helpers/bind_server.c similarity index 100% rename from helpers/bind_server.c rename to src/helpers/bind_server.c diff --git a/helpers/connect_server.c b/src/helpers/connect_server.c similarity index 100% rename from helpers/connect_server.c rename to src/helpers/connect_server.c diff --git a/helpers/get_port.c b/src/helpers/get_port.c similarity index 100% rename from helpers/get_port.c rename to src/helpers/get_port.c diff --git a/helpers/get_weekday.c b/src/helpers/get_weekday.c similarity index 100% rename from helpers/get_weekday.c rename to src/helpers/get_weekday.c diff --git a/helpers/load_config.c b/src/helpers/load_config.c similarity index 100% rename from helpers/load_config.c rename to src/helpers/load_config.c diff --git a/helpers/open_discovery_socket.c b/src/helpers/open_discovery_socket.c similarity index 100% rename from helpers/open_discovery_socket.c rename to src/helpers/open_discovery_socket.c diff --git a/helpers/parse_cli.c b/src/helpers/parse_cli.c similarity index 86% rename from helpers/parse_cli.c rename to src/helpers/parse_cli.c index f9fac01..2baba20 100644 --- a/helpers/parse_cli.c +++ b/src/helpers/parse_cli.c @@ -6,6 +6,7 @@ #include #include #include +#include static const char *const usage[] = { "controller [options] [[--] args]", @@ -20,12 +21,13 @@ static const char *const usage[] = { void helper_parse_cli(int argc, const char **argv, config_t *config) { + int version = 0; struct argparse_option options[] = { OPT_HELP(), OPT_GROUP("Basic options"), OPT_STRING('c', "config", &config->file, "path to config file", NULL, 0, OPT_NONEG), - + OPT_BOOLEAN('v', "version", &version, "print version", NULL, 0, OPT_NONEG), OPT_END(), }; @@ -38,6 +40,12 @@ helper_parse_cli(int argc, const char **argv, config_t *config) ); argc = argparse_parse(&argparse, argc, argv); + if(version) + { + printf("%s\n", EMGAUWA_CONTROLLER_VERSION); + exit(0); + } + if(argc == 1) { if(strcmp(argv[0], "start") == 0) diff --git a/logger.c b/src/logger.c similarity index 100% rename from logger.c rename to src/logger.c diff --git a/main.c b/src/main.c similarity index 100% rename from main.c rename to src/main.c diff --git a/models/controller.c b/src/models/controller.c similarity index 100% rename from models/controller.c rename to src/models/controller.c diff --git a/models/controller_load.c b/src/models/controller_load.c similarity index 100% rename from models/controller_load.c rename to src/models/controller_load.c diff --git a/models/controller_save.c b/src/models/controller_save.c similarity index 100% rename from models/controller_save.c rename to src/models/controller_save.c diff --git a/models/period.c b/src/models/period.c similarity index 100% rename from models/period.c rename to src/models/period.c diff --git a/models/relay.c b/src/models/relay.c similarity index 100% rename from models/relay.c rename to src/models/relay.c diff --git a/models/relay_load.c b/src/models/relay_load.c similarity index 100% rename from models/relay_load.c rename to src/models/relay_load.c diff --git a/models/relay_save.c b/src/models/relay_save.c similarity index 100% rename from models/relay_save.c rename to src/models/relay_save.c diff --git a/models/schedule.c b/src/models/schedule.c similarity index 100% rename from models/schedule.c rename to src/models/schedule.c diff --git a/models/schedule_load.c b/src/models/schedule_load.c similarity index 100% rename from models/schedule_load.c rename to src/models/schedule_load.c diff --git a/models/schedule_save.c b/src/models/schedule_save.c similarity index 100% rename from models/schedule_save.c rename to src/models/schedule_save.c diff --git a/vendor/mpack.c b/src/mpack.c similarity index 100% rename from vendor/mpack.c rename to src/mpack.c diff --git a/runners/test.c b/src/runners/test.c similarity index 100% rename from runners/test.c rename to src/runners/test.c diff --git a/toolchain-rpi.cmake b/toolchain-rpi.cmake deleted file mode 100644 index 21fe457..0000000 --- a/toolchain-rpi.cmake +++ /dev/null @@ -1,18 +0,0 @@ -set(CMAKE_C_COMPILER /usr/bin/arm-none-eabi-gcc) -set(CMAKE_C_COMPILER_WORKS 1) - -set(ARM-SYSROOT /usr/arm-none-eabi) - -set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -marm") -set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mfpu=vfp") -set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=armv6zk+fp") -set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mcpu=arm1176jzf-s") -set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mtune=arm1176jzf-s") -set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --sysroot=${ARM-SYSROOT}" CACHE INTERNAL "" FORCE) - -set(CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} --sysroot=${ARM-SYSROOT}" CACHE INTERNAL "" FORCE) - -set(CMAKE_FIND_ROOT_PATH ${ARM-SYSROOT}) -set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) -set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) -set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) diff --git a/version.h.in b/version.h.in new file mode 100644 index 0000000..252b6fb --- /dev/null +++ b/version.h.in @@ -0,0 +1 @@ +#define EMGAUWA_CONTROLLER_VERSION "@CMAKE_PROJECT_VERSION@"