core-legacy/CMakeLists.txt

91 lines
3 KiB
CMake

cmake_minimum_required (VERSION 3.7)
project(core
VERSION 0.3.5
LANGUAGES C)
add_executable(core src/main.c)
target_link_libraries(core -lsqlite3)
target_link_libraries(core -luuid)
set(CMAKE_C_FLAGS "$ENV{CFLAGS}")
set(CMAKE_C_FLAGS "-D'__FILENAME__=\"$(subst $(realpath ${CMAKE_SOURCE_DIR}/src/)/,,$(abspath $<))\"'")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3 -std=gnu99 -Wpedantic -Werror -Wall -Wextra")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -g -fprofile-arcs -ftest-coverage")
add_definitions("-DMG_ENABLE_EXTRA_ERRORS_DESC -DMG_ENABLE_MQTT_BROKER")
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/endpoints ENDPOINTS_SRC)
aux_source_directory(vendor VENDOR_SRC)
add_dependencies(core sql)
configure_file("version.h.in" "version.h" @ONLY)
target_sources(core PRIVATE ${SRC_DIR} ${HANDLERS_SRC} ${HELPERS_SRC} ${MODELS_SRC} ${ENDPOINTS_SRC} ${VENDOR_SRC})
target_include_directories(core PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include)
target_include_directories(core PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/vendor)
target_include_directories(core PRIVATE ${CMAKE_BINARY_DIR})
add_custom_target(sql
COMMAND ./compile_sql.sh
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
add_custom_target(run
COMMAND ${CMAKE_BINARY_DIR}/core start
DEPENDS core
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)
add_custom_target(test
COMMAND ./run_tests.sh ${CMAKE_BINARY_DIR}/core "--leak-check=full --show-leak-kinds=all --track-origins=yes"
DEPENDS core
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/tests
)
add_custom_target(docs
COMMAND doxygen
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)
IF(CMAKE_BUILD_TYPE MATCHES Debug)
message("debug mode")
add_custom_target(debug
COMMAND gdb ${CMAKE_BINARY_DIR}/core
DEPENDS core
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)
add_custom_target(valgrind
COMMAND valgrind -s ${CMAKE_BINARY_DIR}/core start
DEPENDS core
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)
add_custom_target(valgrind-leak
COMMAND valgrind --leak-check=full --show-leak-kinds=all ${CMAKE_BINARY_DIR}/core start
DEPENDS core
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)
add_custom_target(valgrind-callgrind
COMMAND valgrind --tool=callgrind ${CMAKE_BINARY_DIR}/core start
DEPENDS core
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)
add_custom_target(coverage
COMMAND gcovr -s --root ${CMAKE_SOURCE_DIR} -e ${CMAKE_SOURCE_DIR}/vendor --html-details ${CMAKE_BINARY_DIR}/coverage.html --html-title "Emgauwa Core Coverage" ${CMAKE_BINARY_DIR}/CMakeFiles/core.dir
DEPENDS test
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)
add_custom_target(test-callgrind
COMMAND ./run_tests.sh ${CMAKE_BINARY_DIR}/core "--tool=callgrind"
DEPENDS core
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/tests
)
ENDIF(CMAKE_BUILD_TYPE MATCHES Debug)