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 | a193c03 | 2020-06-22 17:33:31 +0200 | [diff] [blame] | 32 | find_package(docopt REQUIRED) |
Tomáš Pecka | 5123e00 | 2020-06-05 15:29:21 +0200 | [diff] [blame] | 33 | find_package(spdlog REQUIRED) |
Tomáš Pecka | 0a2e890 | 2020-06-09 21:11:20 +0200 | [diff] [blame] | 34 | find_package(sdbus-c++ REQUIRED) |
Tomáš Pecka | a433681 | 2020-07-24 15:32:58 +0200 | [diff] [blame] | 35 | find_package(PkgConfig) |
| 36 | |
| 37 | pkg_check_modules(SYSTEMD REQUIRED IMPORTED_TARGET libsystemd) |
Tomáš Pecka | 1f42cfe | 2020-10-21 18:38:27 +0200 | [diff] [blame] | 38 | if(${SYSTEMD_VERSION} VERSION_EQUAL 245) |
| 39 | message(FATAL_ERROR "Systemd 245 has a bug affecting DBus method calls using sdbus-c++. Please see https://github.com/Kistler-Group/sdbus-cpp/issues/106.") |
| 40 | endif() |
Tomáš Pecka | 5123e00 | 2020-06-05 15:29:21 +0200 | [diff] [blame] | 41 | |
Tomáš Pecka | 98ad18d | 2020-11-13 15:39:55 +0100 | [diff] [blame^] | 42 | pkg_check_modules(SYSREPO REQUIRED sysrepo-cpp>=1.4.79 IMPORTED_TARGET sysrepo) |
| 43 | pkg_check_modules(LIBYANG REQUIRED libyang-cpp>=1.0.190 IMPORTED_TARGET libyang) |
| 44 | |
Tomáš Pecka | c927d66 | 2020-07-13 11:16:16 +0200 | [diff] [blame] | 45 | include(GNUInstallDirs) |
| 46 | |
Tomáš Pecka | 261c886 | 2020-11-05 11:23:08 +0100 | [diff] [blame] | 47 | include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/) |
| 48 | |
Tomáš Pecka | 73a13cc | 2020-11-17 11:12:19 +0100 | [diff] [blame] | 49 | set(YANG_SRCS |
| 50 | yang/iana-hardware@2018-03-13.yang |
| 51 | yang/ietf-hardware-state@2018-03-13.yang |
| 52 | yang/ietf-hardware@2018-03-13.yang |
| 53 | ) |
| 54 | |
Tomáš Pecka | 5123e00 | 2020-06-05 15:29:21 +0200 | [diff] [blame] | 55 | # Targets |
Tomáš Pecka | 261c886 | 2020-11-05 11:23:08 +0100 | [diff] [blame] | 56 | # - utils |
Tomáš Pecka | bd82886 | 2020-06-15 15:53:35 +0200 | [diff] [blame] | 57 | add_library(velia-utils STATIC |
Tomáš Pecka | a193c03 | 2020-06-22 17:33:31 +0200 | [diff] [blame] | 58 | src/utils/exceptions.cpp |
Tomáš Pecka | 261c886 | 2020-11-05 11:23:08 +0100 | [diff] [blame] | 59 | src/utils/exceptions.h |
Tomáš Pecka | 491f4f2 | 2020-11-05 15:44:00 +0100 | [diff] [blame] | 60 | src/utils/io.cpp |
| 61 | src/utils/io.h |
Tomáš Pecka | a433681 | 2020-07-24 15:32:58 +0200 | [diff] [blame] | 62 | src/utils/journal.cpp |
Tomáš Pecka | 261c886 | 2020-11-05 11:23:08 +0100 | [diff] [blame] | 63 | src/utils/journal.h |
| 64 | src/utils/log.h |
| 65 | src/utils/log-fwd.h |
Tomáš Pecka | 5123e00 | 2020-06-05 15:29:21 +0200 | [diff] [blame] | 66 | src/utils/log-init.cpp |
Tomáš Pecka | 261c886 | 2020-11-05 11:23:08 +0100 | [diff] [blame] | 67 | src/utils/log-init.h |
Tomáš Pecka | 339bc67 | 2020-11-11 15:59:03 +0100 | [diff] [blame] | 68 | src/utils/time.cpp |
| 69 | src/utils/time.h |
Tomáš Pecka | 5123e00 | 2020-06-05 15:29:21 +0200 | [diff] [blame] | 70 | ) |
Tomáš Pecka | 261c886 | 2020-11-05 11:23:08 +0100 | [diff] [blame] | 71 | target_link_libraries(velia-utils PUBLIC spdlog::spdlog PRIVATE PkgConfig::SYSTEMD) |
Tomáš Pecka | a433681 | 2020-07-24 15:32:58 +0200 | [diff] [blame] | 72 | |
Tomáš Pecka | 261c886 | 2020-11-05 11:23:08 +0100 | [diff] [blame] | 73 | # - health |
| 74 | add_library(velia-health STATIC |
| 75 | src/health/inputs/AbstractInput.cpp |
| 76 | src/health/inputs/DbusSemaphoreInput.cpp |
| 77 | src/health/inputs/DbusSystemdInput.cpp |
| 78 | src/health/manager/AbstractManager.cpp |
| 79 | src/health/manager/StateManager.cpp |
| 80 | src/health/outputs/LedSysfsDriver.cpp |
| 81 | src/health/outputs/callables.cpp |
| 82 | src/health/State.cpp |
Tomáš Pecka | 74b885f | 2020-06-06 20:02:41 +0200 | [diff] [blame] | 83 | ) |
Tomáš Pecka | 261c886 | 2020-11-05 11:23:08 +0100 | [diff] [blame] | 84 | target_link_libraries(velia-health |
| 85 | PUBLIC |
| 86 | velia-utils |
| 87 | Boost::boost |
| 88 | SDBusCpp::sdbus-c++ |
| 89 | ${STD_FILESYSTEM_LIBRARY} |
| 90 | ) |
Tomáš Pecka | 74b885f | 2020-06-06 20:02:41 +0200 | [diff] [blame] | 91 | |
Tomáš Pecka | bd82886 | 2020-06-15 15:53:35 +0200 | [diff] [blame] | 92 | add_executable(veliad |
Tomáš Pecka | 5123e00 | 2020-06-05 15:29:21 +0200 | [diff] [blame] | 93 | src/main.cpp |
| 94 | ) |
Tomáš Pecka | 261c886 | 2020-11-05 11:23:08 +0100 | [diff] [blame] | 95 | target_link_libraries(veliad |
| 96 | PUBLIC |
| 97 | velia-health |
| 98 | docopt |
| 99 | ) |
Tomáš Pecka | bd82886 | 2020-06-15 15:53:35 +0200 | [diff] [blame] | 100 | add_dependencies(veliad target-VELIA_VERSION) |
Tomáš Pecka | 261c886 | 2020-11-05 11:23:08 +0100 | [diff] [blame] | 101 | target_include_directories(veliad PUBLIC ${CMAKE_BINARY_DIR}) |
| 102 | |
Tomáš Pecka | 491f4f2 | 2020-11-05 15:44:00 +0100 | [diff] [blame] | 103 | # - ietf-hardware |
| 104 | add_library(velia-ietf-hardware STATIC |
| 105 | src/ietf-hardware/sysfs/EMMC.cpp |
| 106 | src/ietf-hardware/sysfs/EMMC.h |
Tomáš Pecka | 9b1c967 | 2020-11-11 15:24:06 +0100 | [diff] [blame] | 107 | src/ietf-hardware/sysfs/HWMon.cpp |
| 108 | src/ietf-hardware/sysfs/HWMon.h |
Tomáš Pecka | 339bc67 | 2020-11-11 15:59:03 +0100 | [diff] [blame] | 109 | src/ietf-hardware/IETFHardware.cpp |
| 110 | src/ietf-hardware/IETFHardware.h |
Tomáš Pecka | 491f4f2 | 2020-11-05 15:44:00 +0100 | [diff] [blame] | 111 | ) |
| 112 | target_link_libraries(velia-ietf-hardware |
| 113 | PUBLIC |
| 114 | velia-utils |
| 115 | ${STD_FILESYSTEM_LIBRARY} |
Tomáš Pecka | 9b1c967 | 2020-11-11 15:24:06 +0100 | [diff] [blame] | 116 | Boost::boost |
Tomáš Pecka | 491f4f2 | 2020-11-05 15:44:00 +0100 | [diff] [blame] | 117 | ) |
| 118 | target_include_directories(velia-ietf-hardware PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src/velia-hardware) |
| 119 | |
Tomáš Pecka | 98ad18d | 2020-11-13 15:39:55 +0100 | [diff] [blame^] | 120 | add_library(velia-ietf-hardware-sysrepo STATIC |
| 121 | src/ietf-hardware/sysrepo/Logging.cpp |
| 122 | src/ietf-hardware/sysrepo/Logging.h |
| 123 | src/ietf-hardware/sysrepo/Sysrepo.cpp |
| 124 | src/ietf-hardware/sysrepo/Sysrepo.h |
| 125 | ) |
| 126 | target_link_libraries(velia-ietf-hardware-sysrepo |
| 127 | PUBLIC |
| 128 | velia-utils |
| 129 | PkgConfig::SYSREPO |
| 130 | PkgConfig::LIBYANG |
| 131 | ) |
| 132 | target_include_directories(velia-ietf-hardware PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src/velia-hardware) |
Tomáš Pecka | 5123e00 | 2020-06-05 15:29:21 +0200 | [diff] [blame] | 133 | |
| 134 | # Testing |
Tomáš Pecka | a06d74d | 2020-06-14 18:18:13 +0200 | [diff] [blame] | 135 | include(CTest) |
Tomáš Pecka | 5123e00 | 2020-06-05 15:29:21 +0200 | [diff] [blame] | 136 | if(BUILD_TESTING) |
Tomáš Pecka | 5123e00 | 2020-06-05 15:29:21 +0200 | [diff] [blame] | 137 | find_package(trompeloeil 33 REQUIRED) |
| 138 | find_package(doctest 2.3.1 REQUIRED) |
| 139 | |
Tomáš Pecka | efd8843 | 2020-06-17 15:31:39 +0200 | [diff] [blame] | 140 | configure_file(${CMAKE_CURRENT_SOURCE_DIR}/tests/configure.cmake.h.in ${CMAKE_CURRENT_BINARY_DIR}/tests/configure.cmake.h) |
| 141 | |
Tomáš Pecka | 5123e00 | 2020-06-05 15:29:21 +0200 | [diff] [blame] | 142 | add_library(DoctestIntegration STATIC |
Tomáš Pecka | 261c886 | 2020-11-05 11:23:08 +0100 | [diff] [blame] | 143 | tests/doctest_integration.cpp |
| 144 | tests/trompeloeil_doctest.h |
| 145 | tests/wait-a-bit-longer.cpp |
| 146 | ) |
Tomáš Pecka | 5123e00 | 2020-06-05 15:29:21 +0200 | [diff] [blame] | 147 | target_link_libraries(DoctestIntegration doctest::doctest trompeloeil spdlog::spdlog) |
Tomáš Pecka | 261c886 | 2020-11-05 11:23:08 +0100 | [diff] [blame] | 148 | target_include_directories(DoctestIntegration PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/tests/) |
Tomáš Pecka | 5123e00 | 2020-06-05 15:29:21 +0200 | [diff] [blame] | 149 | target_compile_definitions(DoctestIntegration PUBLIC DOCTEST_CONFIG_SUPER_FAST_ASSERTS) |
| 150 | |
Tomáš Pecka | 0a2e890 | 2020-06-09 21:11:20 +0200 | [diff] [blame] | 151 | add_library(DbusTesting STATIC |
| 152 | tests/dbus-helpers/dbus_semaphore_server.cpp |
Tomáš Pecka | 261c886 | 2020-11-05 11:23:08 +0100 | [diff] [blame] | 153 | tests/dbus-helpers/dbus_semaphore_server.h |
Tomáš Pecka | ccd80c3 | 2020-06-22 14:44:32 +0200 | [diff] [blame] | 154 | tests/dbus-helpers/dbus_systemd_server.cpp |
Tomáš Pecka | 261c886 | 2020-11-05 11:23:08 +0100 | [diff] [blame] | 155 | tests/dbus-helpers/dbus_systemd_server.h |
| 156 | ) |
| 157 | target_link_libraries(DbusTesting |
| 158 | PUBLIC |
| 159 | velia-utils |
| 160 | SDBusCpp::sdbus-c++ |
| 161 | ) |
Tomáš Pecka | 0a2e890 | 2020-06-09 21:11:20 +0200 | [diff] [blame] | 162 | |
Tomáš Pecka | 9b1c967 | 2020-11-11 15:24:06 +0100 | [diff] [blame] | 163 | add_library(FsTestUtils STATIC |
| 164 | tests/fs-helpers/FileInjector.cpp |
| 165 | tests/fs-helpers/FileInjector.h |
| 166 | tests/fs-helpers/utils.cpp |
| 167 | tests/fs-helpers/utils.h |
| 168 | ) |
| 169 | target_link_libraries(FsTestUtils |
| 170 | PUBLIC |
| 171 | ${STD_FILESYSTEM_LIBRARY} |
| 172 | ) |
| 173 | |
Tomáš Pecka | 5123e00 | 2020-06-05 15:29:21 +0200 | [diff] [blame] | 174 | function(velia_test name) |
Tomáš Pecka | 261c886 | 2020-11-05 11:23:08 +0100 | [diff] [blame] | 175 | add_executable(test-${name} ${CMAKE_SOURCE_DIR}/tests/${name}.cpp) |
| 176 | target_link_libraries(test-${name} DoctestIntegration ${ARGN}) |
| 177 | target_include_directories(test-${name} |
| 178 | PUBLIC |
| 179 | ${CMAKE_CURRENT_SOURCE_DIR} |
| 180 | PRIVATE |
| 181 | ${CMAKE_BINARY_DIR} |
| 182 | ) |
Tomáš Pecka | 5123e00 | 2020-06-05 15:29:21 +0200 | [diff] [blame] | 183 | |
| 184 | if(NOT CMAKE_CROSSCOMPILING) |
Tomáš Pecka | 261c886 | 2020-11-05 11:23:08 +0100 | [diff] [blame] | 185 | add_test(test-${name} test-${name}) |
Tomáš Pecka | 5123e00 | 2020-06-05 15:29:21 +0200 | [diff] [blame] | 186 | endif() |
Tomáš Pecka | 5123e00 | 2020-06-05 15:29:21 +0200 | [diff] [blame] | 187 | endfunction() |
Tomáš Pecka | 5123e00 | 2020-06-05 15:29:21 +0200 | [diff] [blame] | 188 | |
Tomáš Pecka | 98ad18d | 2020-11-13 15:39:55 +0100 | [diff] [blame^] | 189 | find_program(SYSREPOCTL sysrepoctl) |
| 190 | find_program(SYSREPOCFG sysrepocfg) |
| 191 | |
| 192 | set(sysrepo_previous_fixture_name UNDEFINED) |
| 193 | function(sysrepo_fixture_env name) |
| 194 | set(test_name_init sysrepo:prep:${name}) |
| 195 | set(test_name_cleanup sysrepo:clean:${name}) |
| 196 | set(fixture_name sysrepo:env:${name}) |
| 197 | |
| 198 | add_test(NAME ${test_name_init} COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/tests/sysrepoctl-manage-module.sh ${SYSREPOCTL} ${SYSREPOCFG} prepare ${ARGN}) |
| 199 | set_tests_properties(${test_name_init} PROPERTIES FIXTURES_SETUP ${fixture_name} RESOURCE_LOCK sysrepo) |
| 200 | add_test(NAME ${test_name_cleanup} COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/tests/sysrepoctl-manage-module.sh ${SYSREPOCTL} ${SYSREPOCFG} uninstall ${ARGN}) |
| 201 | set_tests_properties(${test_name_cleanup} PROPERTIES FIXTURES_CLEANUP ${fixture_name} RESOURCE_LOCK sysrepo) |
| 202 | |
| 203 | if (sysrepo_previous_fixture_name) |
| 204 | set_tests_properties(${test_name_init} PROPERTIES DEPENDS sysrepo:clean:${sysrepo_previous_fixture_name}) |
| 205 | endif () |
| 206 | |
| 207 | set(sysrepo_previous_fixture_name ${name} PARENT_SCOPE) |
| 208 | endfunction() |
| 209 | |
| 210 | |
Tomáš Pecka | 261c886 | 2020-11-05 11:23:08 +0100 | [diff] [blame] | 211 | velia_test(health_state-manager velia-health) |
| 212 | velia_test(health_input-semaphore velia-health DbusTesting) |
| 213 | velia_test(health_input-systemd velia-health DbusTesting) |
| 214 | velia_test(health_output-led velia-health) |
Tomáš Pecka | 491f4f2 | 2020-11-05 15:44:00 +0100 | [diff] [blame] | 215 | |
Tomáš Pecka | 9b1c967 | 2020-11-11 15:24:06 +0100 | [diff] [blame] | 216 | velia_test(hardware_emmc velia-ietf-hardware FsTestUtils) |
| 217 | velia_test(hardware_hwmon velia-ietf-hardware FsTestUtils) |
Tomáš Pecka | 98ad18d | 2020-11-13 15:39:55 +0100 | [diff] [blame^] | 218 | velia_test(hardware_ietf-hardware velia-ietf-hardware velia-ietf-hardware-sysrepo) |
| 219 | sysrepo_fixture_env(sysrepo YANG ${CMAKE_CURRENT_SOURCE_DIR}/yang/iana-hardware@2018-03-13.yang YANG ${CMAKE_CURRENT_SOURCE_DIR}/yang/ietf-hardware-state@2018-03-13.yang FEATURE hardware-sensor) |
| 220 | set_tests_properties( |
| 221 | test-hardware_ietf-hardware |
| 222 | PROPERTIES FIXTURES_REQUIRED sysrepo:env:sysrepo |
| 223 | RESOURCE_LOCK sysrepo |
| 224 | ) |
Tomáš Pecka | 73a13cc | 2020-11-17 11:12:19 +0100 | [diff] [blame] | 225 | |
| 226 | find_program(YANGLINT_PATH yanglint) |
| 227 | if (NOT YANGLINT_PATH) |
| 228 | message(FATAL_ERROR "Cannot find libyang's yanglint") |
| 229 | endif() |
| 230 | foreach(yang_file ${YANG_SRCS}) |
| 231 | add_test(NAME yang-tree:${yang_file} COMMAND ${YANGLINT_PATH} -f tree ${CMAKE_CURRENT_SOURCE_DIR}/${yang_file}) |
| 232 | endforeach() |
Tomáš Pecka | 261c886 | 2020-11-05 11:23:08 +0100 | [diff] [blame] | 233 | endif() |
Tomáš Pecka | c927d66 | 2020-07-13 11:16:16 +0200 | [diff] [blame] | 234 | |
Tomáš Pecka | 5123e00 | 2020-06-05 15:29:21 +0200 | [diff] [blame] | 235 | if(WITH_DOCS) |
| 236 | set(doxyfile_in ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in) |
| 237 | set(doxyfile ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile) |
| 238 | configure_file(${doxyfile_in} ${doxyfile} @ONLY) |
| 239 | add_custom_target(doc |
| 240 | COMMAND ${DOXYGEN_EXECUTABLE} ${doxyfile} |
| 241 | WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} |
| 242 | COMMENT "Generating API documentation with Doxygen" |
| 243 | VERBATIM |
| 244 | SOURCES ${doxyfile_in} |
| 245 | ) |
Tomáš Pecka | a06d74d | 2020-06-14 18:18:13 +0200 | [diff] [blame] | 246 | endif() |
Tomáš Pecka | 261c886 | 2020-11-05 11:23:08 +0100 | [diff] [blame] | 247 | |
Tomáš Pecka | 73a13cc | 2020-11-17 11:12:19 +0100 | [diff] [blame] | 248 | set(YANG_DIR ${CMAKE_INSTALL_PREFIX}/share/velia/yang) |
| 249 | install(FILES ${YANG_SRCS} DESTINATION ${YANG_DIR}) |
Tomáš Pecka | 261c886 | 2020-11-05 11:23:08 +0100 | [diff] [blame] | 250 | install(TARGETS veliad RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}/) |