Tomáš Pecka | 5123e00 | 2020-06-05 15:29:21 +0200 | [diff] [blame] | 1 | project(velia LANGUAGES CXX) |
Tomáš Pecka | a06d74d | 2020-06-14 18:18:13 +0200 | [diff] [blame] | 2 | cmake_minimum_required(VERSION 3.15) |
Tomáš Pecka | 5123e00 | 2020-06-05 15:29:21 +0200 | [diff] [blame] | 3 | |
| 4 | # Build options |
| 5 | set(CMAKE_CXX_STANDARD 17) |
| 6 | set(CMAKE_CXX_STANDARD_REQUIRED ON) |
| 7 | |
| 8 | set(CMAKE_CXX_FLAGS_DEBUG "-Werror ${CMAKE_CXX_FLAGS_DEBUG}") |
| 9 | set(CMAKE_CXX_FLAGS "-Wall -Wextra -pedantic -Woverloaded-virtual ${CMAKE_CXX_FLAGS}") |
| 10 | if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") |
| 11 | set(CMAKE_CXX_FLAGS "-Wsuggest-override ${CMAKE_CXX_FLAGS}") |
| 12 | endif() |
| 13 | |
Tomáš Pecka | 5d4cf2a | 2020-07-13 13:19:41 +0200 | [diff] [blame^] | 14 | if(CMAKE_CXX_FLAGS MATCHES "-stdlib=libc\\+\\+" AND CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 9.0) |
| 15 | set(STD_FILESYSTEM_LIBRARY c++fs) |
| 16 | elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 9.1) |
| 17 | set(STD_FILESYSTEM_LIBRARY stdc++fs) |
| 18 | endif() |
| 19 | |
| 20 | |
Tomáš Pecka | 5123e00 | 2020-06-05 15:29:21 +0200 | [diff] [blame] | 21 | add_custom_target(velia-version-cmake-ide |
| 22 | cmake/ProjectGitVersion.cmake |
| 23 | cmake/ProjectGitVersionRunner.cmake |
| 24 | ) |
| 25 | include(cmake/ProjectGitVersion.cmake) |
| 26 | prepare_git_version(VELIA_VERSION "0.0") |
| 27 | |
| 28 | find_package(Doxygen) |
| 29 | option(WITH_DOCS "Create and install internal documentation (needs Doxygen)" ${DOXYGEN_FOUND}) |
| 30 | |
Tomáš Pecka | 74b885f | 2020-06-06 20:02:41 +0200 | [diff] [blame] | 31 | find_package(Boost REQUIRED) |
Tomáš Pecka | 5123e00 | 2020-06-05 15:29:21 +0200 | [diff] [blame] | 32 | find_package(spdlog REQUIRED) |
Tomáš Pecka | 0a2e890 | 2020-06-09 21:11:20 +0200 | [diff] [blame] | 33 | find_package(sdbus-c++ REQUIRED) |
Tomáš Pecka | 5123e00 | 2020-06-05 15:29:21 +0200 | [diff] [blame] | 34 | |
| 35 | include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/) |
| 36 | |
Tomáš Pecka | c927d66 | 2020-07-13 11:16:16 +0200 | [diff] [blame] | 37 | include(GNUInstallDirs) |
| 38 | |
Tomáš Pecka | 5123e00 | 2020-06-05 15:29:21 +0200 | [diff] [blame] | 39 | # Targets |
Tomáš Pecka | bd82886 | 2020-06-15 15:53:35 +0200 | [diff] [blame] | 40 | add_library(velia-utils STATIC |
Tomáš Pecka | 5123e00 | 2020-06-05 15:29:21 +0200 | [diff] [blame] | 41 | src/utils/log-init.h |
| 42 | src/utils/log-init.cpp |
| 43 | ) |
Tomáš Pecka | bd82886 | 2020-06-15 15:53:35 +0200 | [diff] [blame] | 44 | target_link_libraries(velia-utils PUBLIC spdlog::spdlog) |
Tomáš Pecka | 5123e00 | 2020-06-05 15:29:21 +0200 | [diff] [blame] | 45 | |
Tomáš Pecka | 74b885f | 2020-06-06 20:02:41 +0200 | [diff] [blame] | 46 | add_library(velia-state-manager STATIC |
| 47 | src/inputs/AbstractInput.cpp |
Tomáš Pecka | 0a2e890 | 2020-06-09 21:11:20 +0200 | [diff] [blame] | 48 | src/inputs/DbusSemaphoreInput.cpp |
Tomáš Pecka | ccd80c3 | 2020-06-22 14:44:32 +0200 | [diff] [blame] | 49 | src/inputs/DbusSystemdInput.cpp |
Tomáš Pecka | 74b885f | 2020-06-06 20:02:41 +0200 | [diff] [blame] | 50 | src/manager/AbstractManager.cpp |
| 51 | src/manager/StateManager.cpp |
Tomáš Pecka | efd8843 | 2020-06-17 15:31:39 +0200 | [diff] [blame] | 52 | src/outputs/LedSysfsDriver.cpp |
Tomáš Pecka | ddf04a3 | 2020-06-17 15:32:01 +0200 | [diff] [blame] | 53 | src/outputs/callables.cpp |
Tomáš Pecka | 74b885f | 2020-06-06 20:02:41 +0200 | [diff] [blame] | 54 | src/State.cpp |
| 55 | ) |
Tomáš Pecka | 5d4cf2a | 2020-07-13 13:19:41 +0200 | [diff] [blame^] | 56 | target_link_libraries(velia-state-manager PUBLIC velia-utils Boost::boost SDBusCpp::sdbus-c++ ${STD_FILESYSTEM_LIBRARY}) |
Tomáš Pecka | 74b885f | 2020-06-06 20:02:41 +0200 | [diff] [blame] | 57 | |
Tomáš Pecka | bd82886 | 2020-06-15 15:53:35 +0200 | [diff] [blame] | 58 | add_executable(veliad |
Tomáš Pecka | 5123e00 | 2020-06-05 15:29:21 +0200 | [diff] [blame] | 59 | src/main.cpp |
| 60 | ) |
| 61 | |
Tomáš Pecka | bd82886 | 2020-06-15 15:53:35 +0200 | [diff] [blame] | 62 | target_link_libraries(veliad PUBLIC velia-utils) |
| 63 | add_dependencies(veliad target-VELIA_VERSION) |
Tomáš Pecka | 5123e00 | 2020-06-05 15:29:21 +0200 | [diff] [blame] | 64 | |
| 65 | # Testing |
Tomáš Pecka | a06d74d | 2020-06-14 18:18:13 +0200 | [diff] [blame] | 66 | include(CTest) |
Tomáš Pecka | 5123e00 | 2020-06-05 15:29:21 +0200 | [diff] [blame] | 67 | if(BUILD_TESTING) |
Tomáš Pecka | 5123e00 | 2020-06-05 15:29:21 +0200 | [diff] [blame] | 68 | find_package(trompeloeil 33 REQUIRED) |
| 69 | find_package(doctest 2.3.1 REQUIRED) |
| 70 | |
Tomáš Pecka | efd8843 | 2020-06-17 15:31:39 +0200 | [diff] [blame] | 71 | configure_file(${CMAKE_CURRENT_SOURCE_DIR}/tests/configure.cmake.h.in ${CMAKE_CURRENT_BINARY_DIR}/tests/configure.cmake.h) |
| 72 | |
Tomáš Pecka | 5123e00 | 2020-06-05 15:29:21 +0200 | [diff] [blame] | 73 | add_library(DoctestIntegration STATIC |
| 74 | tests/doctest_integration.cpp |
| 75 | tests/trompeloeil_doctest.h |
Tomáš Pecka | 0a2e890 | 2020-06-09 21:11:20 +0200 | [diff] [blame] | 76 | tests/wait-a-bit-longer.cpp |
Tomáš Pecka | 5123e00 | 2020-06-05 15:29:21 +0200 | [diff] [blame] | 77 | ) |
| 78 | target_include_directories(DoctestIntegration PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/tests/ ${CMAKE_CURRENT_SOURCE_DIR}/src/) |
| 79 | target_link_libraries(DoctestIntegration doctest::doctest trompeloeil spdlog::spdlog) |
| 80 | target_compile_definitions(DoctestIntegration PUBLIC DOCTEST_CONFIG_SUPER_FAST_ASSERTS) |
| 81 | |
Tomáš Pecka | 0a2e890 | 2020-06-09 21:11:20 +0200 | [diff] [blame] | 82 | add_library(DbusTesting STATIC |
| 83 | tests/dbus-helpers/dbus_semaphore_server.cpp |
Tomáš Pecka | ccd80c3 | 2020-06-22 14:44:32 +0200 | [diff] [blame] | 84 | tests/dbus-helpers/dbus_systemd_server.cpp |
Tomáš Pecka | 0a2e890 | 2020-06-09 21:11:20 +0200 | [diff] [blame] | 85 | ) |
| 86 | target_link_libraries(DbusTesting PUBLIC SDBusCpp::sdbus-c++) |
| 87 | |
Tomáš Pecka | 5123e00 | 2020-06-05 15:29:21 +0200 | [diff] [blame] | 88 | function(velia_test name) |
| 89 | add_executable(test_${name} tests/${name}.cpp) |
| 90 | target_link_libraries(test_${name} DoctestIntegration ${ARGN}) |
| 91 | target_include_directories(test_${name} PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) |
| 92 | |
| 93 | if(NOT CMAKE_CROSSCOMPILING) |
| 94 | add_test(test_${name} test_${name}) |
| 95 | endif() |
| 96 | |
| 97 | endfunction() |
Tomáš Pecka | 74b885f | 2020-06-06 20:02:41 +0200 | [diff] [blame] | 98 | velia_test(state-manager velia-state-manager) |
Tomáš Pecka | 0a2e890 | 2020-06-09 21:11:20 +0200 | [diff] [blame] | 99 | velia_test(input-semaphore velia-state-manager DbusTesting) |
Tomáš Pecka | ccd80c3 | 2020-06-22 14:44:32 +0200 | [diff] [blame] | 100 | velia_test(input-systemd velia-state-manager DbusTesting) |
Tomáš Pecka | efd8843 | 2020-06-17 15:31:39 +0200 | [diff] [blame] | 101 | velia_test(output-led velia-state-manager) |
Tomáš Pecka | 5123e00 | 2020-06-05 15:29:21 +0200 | [diff] [blame] | 102 | endif() |
| 103 | |
Tomáš Pecka | c927d66 | 2020-07-13 11:16:16 +0200 | [diff] [blame] | 104 | install(TARGETS |
| 105 | veliad |
| 106 | RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}/) |
| 107 | |
Tomáš Pecka | 5123e00 | 2020-06-05 15:29:21 +0200 | [diff] [blame] | 108 | if(WITH_DOCS) |
| 109 | set(doxyfile_in ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in) |
| 110 | set(doxyfile ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile) |
| 111 | configure_file(${doxyfile_in} ${doxyfile} @ONLY) |
| 112 | add_custom_target(doc |
| 113 | COMMAND ${DOXYGEN_EXECUTABLE} ${doxyfile} |
| 114 | WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} |
| 115 | COMMENT "Generating API documentation with Doxygen" |
| 116 | VERBATIM |
| 117 | SOURCES ${doxyfile_in} |
| 118 | ) |
Tomáš Pecka | a06d74d | 2020-06-14 18:18:13 +0200 | [diff] [blame] | 119 | endif() |