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 | |
Václav Kubernát | de0e4e6 | 2021-02-08 17:46:14 +0100 | [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) |
Václav Kubernát | babbab9 | 2021-01-27 09:25:05 +0100 | [diff] [blame] | 36 | find_package(fmt) |
Tomáš Pecka | a433681 | 2020-07-24 15:32:58 +0200 | [diff] [blame] | 37 | |
| 38 | pkg_check_modules(SYSTEMD REQUIRED IMPORTED_TARGET libsystemd) |
Tomáš Pecka | 1f42cfe | 2020-10-21 18:38:27 +0200 | [diff] [blame] | 39 | if(${SYSTEMD_VERSION} VERSION_EQUAL 245) |
| 40 | 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.") |
| 41 | endif() |
Tomáš Pecka | 5123e00 | 2020-06-05 15:29:21 +0200 | [diff] [blame] | 42 | |
Jan Kundrát | 9b8bb73 | 2021-01-27 15:39:12 +0100 | [diff] [blame] | 43 | pkg_check_modules(SYSREPO REQUIRED sysrepo-cpp>=1.4.103 IMPORTED_TARGET sysrepo) |
| 44 | pkg_check_modules(LIBYANG REQUIRED libyang-cpp>=1.0.215 IMPORTED_TARGET libyang) |
Tomáš Pecka | 98ad18d | 2020-11-13 15:39:55 +0100 | [diff] [blame] | 45 | |
Tomáš Pecka | c927d66 | 2020-07-13 11:16:16 +0200 | [diff] [blame] | 46 | include(GNUInstallDirs) |
| 47 | |
Tomáš Pecka | 261c886 | 2020-11-05 11:23:08 +0100 | [diff] [blame] | 48 | include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/) |
| 49 | |
Tomáš Pecka | 73a13cc | 2020-11-17 11:12:19 +0100 | [diff] [blame] | 50 | set(YANG_SRCS |
Tomáš Pecka | 9a02c3f | 2021-01-21 15:27:22 +0100 | [diff] [blame] | 51 | yang/czechlight-system@2021-01-13.yang |
Tomáš Pecka | 73a13cc | 2020-11-17 11:12:19 +0100 | [diff] [blame] | 52 | yang/iana-hardware@2018-03-13.yang |
Tomáš Pecka | 73a13cc | 2020-11-17 11:12:19 +0100 | [diff] [blame] | 53 | yang/ietf-hardware@2018-03-13.yang |
Tomáš Pecka | f98ce03 | 2021-01-14 13:35:00 +0100 | [diff] [blame] | 54 | yang/iana-crypt-hash@2014-08-06.yang |
| 55 | yang/ietf-inet-types@2013-07-15.yang |
| 56 | yang/ietf-netconf-acm@2018-02-14.yang |
| 57 | yang/ietf-system@2014-08-06.yang |
| 58 | yang/ietf-yang-types@2013-07-15.yang |
Tomáš Pecka | 435ca2a | 2021-01-27 10:53:48 +0100 | [diff] [blame] | 59 | yang/ietf-ethertypes@2019-03-04.yang |
| 60 | yang/ietf-interfaces@2018-02-20.yang |
| 61 | yang/ietf-packet-fields@2019-03-04.yang |
Václav Kubernát | 637fe80 | 2021-01-22 02:43:18 +0100 | [diff] [blame] | 62 | yang/ietf-access-control-list@2019-03-04.yang |
Václav Kubernát | 457d1ad | 2021-01-22 02:43:18 +0100 | [diff] [blame] | 63 | yang/czechlight-firewall@2021-01-25.yang |
Tomáš Pecka | 73a13cc | 2020-11-17 11:12:19 +0100 | [diff] [blame] | 64 | ) |
| 65 | |
Tomáš Pecka | 5123e00 | 2020-06-05 15:29:21 +0200 | [diff] [blame] | 66 | # Targets |
Tomáš Pecka | 261c886 | 2020-11-05 11:23:08 +0100 | [diff] [blame] | 67 | # - utils |
Tomáš Pecka | bd82886 | 2020-06-15 15:53:35 +0200 | [diff] [blame] | 68 | add_library(velia-utils STATIC |
Tomáš Pecka | a193c03 | 2020-06-22 17:33:31 +0200 | [diff] [blame] | 69 | src/utils/exceptions.cpp |
Tomáš Pecka | 261c886 | 2020-11-05 11:23:08 +0100 | [diff] [blame] | 70 | src/utils/exceptions.h |
Václav Kubernát | 6d9357e | 2021-01-28 15:38:24 +0100 | [diff] [blame] | 71 | src/utils/exec.cpp |
| 72 | src/utils/exec.h |
Tomáš Pecka | 491f4f2 | 2020-11-05 15:44:00 +0100 | [diff] [blame] | 73 | src/utils/io.cpp |
| 74 | src/utils/io.h |
Tomáš Pecka | a433681 | 2020-07-24 15:32:58 +0200 | [diff] [blame] | 75 | src/utils/journal.cpp |
Tomáš Pecka | 261c886 | 2020-11-05 11:23:08 +0100 | [diff] [blame] | 76 | src/utils/journal.h |
Václav Kubernát | cbdc98a | 2021-01-28 13:24:37 +0100 | [diff] [blame] | 77 | src/utils/libyang.cpp |
| 78 | src/utils/libyang.h |
Tomáš Pecka | 261c886 | 2020-11-05 11:23:08 +0100 | [diff] [blame] | 79 | src/utils/log.h |
| 80 | src/utils/log-fwd.h |
Tomáš Pecka | 5123e00 | 2020-06-05 15:29:21 +0200 | [diff] [blame] | 81 | src/utils/log-init.cpp |
Tomáš Pecka | 261c886 | 2020-11-05 11:23:08 +0100 | [diff] [blame] | 82 | src/utils/log-init.h |
Tomáš Pecka | ba2dc31 | 2021-01-23 22:29:11 +0100 | [diff] [blame] | 83 | src/utils/sysrepo.cpp |
| 84 | src/utils/sysrepo.h |
Tomáš Pecka | 339bc67 | 2020-11-11 15:59:03 +0100 | [diff] [blame] | 85 | src/utils/time.cpp |
| 86 | src/utils/time.h |
Tomáš Pecka | d033707 | 2021-01-25 19:57:00 +0100 | [diff] [blame] | 87 | src/utils/waitUntilSignalled.cpp |
| 88 | src/utils/waitUntilSignalled.h |
Tomáš Pecka | 5123e00 | 2020-06-05 15:29:21 +0200 | [diff] [blame] | 89 | ) |
Václav Kubernát | babbab9 | 2021-01-27 09:25:05 +0100 | [diff] [blame] | 90 | target_link_libraries(velia-utils PUBLIC spdlog::spdlog PRIVATE PkgConfig::SYSTEMD PkgConfig::SYSREPO fmt::fmt) |
Tomáš Pecka | a433681 | 2020-07-24 15:32:58 +0200 | [diff] [blame] | 91 | |
Tomáš Pecka | 261c886 | 2020-11-05 11:23:08 +0100 | [diff] [blame] | 92 | # - health |
| 93 | add_library(velia-health STATIC |
| 94 | src/health/inputs/AbstractInput.cpp |
| 95 | src/health/inputs/DbusSemaphoreInput.cpp |
| 96 | src/health/inputs/DbusSystemdInput.cpp |
| 97 | src/health/manager/AbstractManager.cpp |
| 98 | src/health/manager/StateManager.cpp |
| 99 | src/health/outputs/LedSysfsDriver.cpp |
| 100 | src/health/outputs/callables.cpp |
| 101 | src/health/State.cpp |
Tomáš Pecka | 74b885f | 2020-06-06 20:02:41 +0200 | [diff] [blame] | 102 | ) |
Tomáš Pecka | 261c886 | 2020-11-05 11:23:08 +0100 | [diff] [blame] | 103 | target_link_libraries(velia-health |
| 104 | PUBLIC |
| 105 | velia-utils |
| 106 | Boost::boost |
| 107 | SDBusCpp::sdbus-c++ |
| 108 | ${STD_FILESYSTEM_LIBRARY} |
| 109 | ) |
Tomáš Pecka | 74b885f | 2020-06-06 20:02:41 +0200 | [diff] [blame] | 110 | |
Tomáš Pecka | 491f4f2 | 2020-11-05 15:44:00 +0100 | [diff] [blame] | 111 | # - ietf-hardware |
| 112 | add_library(velia-ietf-hardware STATIC |
| 113 | src/ietf-hardware/sysfs/EMMC.cpp |
| 114 | src/ietf-hardware/sysfs/EMMC.h |
Tomáš Pecka | 9b1c967 | 2020-11-11 15:24:06 +0100 | [diff] [blame] | 115 | src/ietf-hardware/sysfs/HWMon.cpp |
| 116 | src/ietf-hardware/sysfs/HWMon.h |
Tomáš Pecka | 339bc67 | 2020-11-11 15:59:03 +0100 | [diff] [blame] | 117 | src/ietf-hardware/IETFHardware.cpp |
| 118 | src/ietf-hardware/IETFHardware.h |
Tomáš Pecka | 491f4f2 | 2020-11-05 15:44:00 +0100 | [diff] [blame] | 119 | ) |
| 120 | target_link_libraries(velia-ietf-hardware |
| 121 | PUBLIC |
| 122 | velia-utils |
| 123 | ${STD_FILESYSTEM_LIBRARY} |
Tomáš Pecka | 9b1c967 | 2020-11-11 15:24:06 +0100 | [diff] [blame] | 124 | Boost::boost |
Tomáš Pecka | 491f4f2 | 2020-11-05 15:44:00 +0100 | [diff] [blame] | 125 | ) |
Tomáš Pecka | 491f4f2 | 2020-11-05 15:44:00 +0100 | [diff] [blame] | 126 | |
Tomáš Pecka | 98ad18d | 2020-11-13 15:39:55 +0100 | [diff] [blame] | 127 | add_library(velia-ietf-hardware-sysrepo STATIC |
Tomáš Pecka | 98ad18d | 2020-11-13 15:39:55 +0100 | [diff] [blame] | 128 | src/ietf-hardware/sysrepo/Sysrepo.cpp |
| 129 | src/ietf-hardware/sysrepo/Sysrepo.h |
| 130 | ) |
| 131 | target_link_libraries(velia-ietf-hardware-sysrepo |
| 132 | PUBLIC |
| 133 | velia-utils |
| 134 | PkgConfig::SYSREPO |
| 135 | PkgConfig::LIBYANG |
| 136 | ) |
Tomáš Pecka | 5123e00 | 2020-06-05 15:29:21 +0200 | [diff] [blame] | 137 | |
Václav Kubernát | 6d9357e | 2021-01-28 15:38:24 +0100 | [diff] [blame] | 138 | set(NOBODY_UID 65534 CACHE STRING "UID which refers to 'nobody'. Used for dropping root privileges.") |
| 139 | set(NOBODY_GID 65534 CACHE STRING "GID which refers to 'nobody'. Used for dropping root privileges.") |
| 140 | |
Václav Kubernát | de0e4e6 | 2021-02-08 17:46:14 +0100 | [diff] [blame] | 141 | if(NOT NFT_EXECUTABLE) |
| 142 | find_program(NFT_EXECUTABLE nft) |
| 143 | endif() |
Václav Kubernát | babbab9 | 2021-01-27 09:25:05 +0100 | [diff] [blame] | 144 | if(NOT SSH_KEYGEN_EXECUTABLE) |
| 145 | find_program(SSH_KEYGEN_EXECUTABLE ssh-keygen) |
| 146 | endif() |
| 147 | if(NOT CHPASSWD_EXECUTABLE) |
| 148 | find_program(CHPASSWD_EXECUTABLE chpasswd) |
| 149 | endif() |
Tomáš Pecka | 879a603 | 2021-02-03 17:21:48 +0100 | [diff] [blame^] | 150 | if(NOT SYSTEMCTL_EXECUTABLE) |
| 151 | find_program(SYSTEMCTL_EXECUTABLE systemctl) |
| 152 | endif() |
Václav Kubernát | babbab9 | 2021-01-27 09:25:05 +0100 | [diff] [blame] | 153 | |
| 154 | set(VELIA_AUTHORIZED_KEYS_FORMAT "{HOME}/.ssh/authorized_keys" CACHE STRING "pattern for determining path to users' SSH authorized_keys file. Must at least one of '{USER}' or '{HOME}' which will get replaced by the name of the user and the home directory of the user respectively.") |
| 155 | if(NOT VELIA_AUTHORIZED_KEYS_FORMAT) |
| 156 | message(FATAL_ERROR "VELIA_AUTHORIZED_KEYS_FORMAT not set.") |
| 157 | endif() |
| 158 | |
| 159 | if(NOT VELIA_AUTHORIZED_KEYS_FORMAT MATCHES "{USER}" AND NOT VELIA_AUTHORIZED_KEYS_FORMAT MATCHES "{HOME}") |
| 160 | message(FATAL_ERROR "Wrong format string given for VELIA_AUTHORIZED_KEYS_FORMAT: at least one of {USER} or {HOME} expected.") |
| 161 | endif() |
| 162 | |
| 163 | set(VELIA_REAL_ETC_PASSWD "/etc/passwd" CACHE STRING "Path to passwd file") |
| 164 | if(NOT VELIA_REAL_ETC_PASSWD) |
| 165 | message(FATAL_ERROR "VELIA_REAL_ETC_PASSWD not set") |
| 166 | endif() |
| 167 | |
| 168 | set(VELIA_REAL_ETC_SHADOW "/etc/shadow" CACHE STRING "Path to shadow file") |
| 169 | if(NOT VELIA_REAL_ETC_SHADOW) |
| 170 | message(FATAL_ERROR "VELIA_REAL_ETC_SHADOW not set") |
| 171 | endif() |
| 172 | |
| 173 | set(VELIA_BACKUP_ETC_SHADOW "/etc/shadow" CACHE STRING "Path to where /etc/shadow gets copied to upon each change") |
| 174 | if(NOT VELIA_BACKUP_ETC_SHADOW) |
| 175 | message(FATAL_ERROR "VELIA_BACKUP_ETC_SHADOW not set") |
| 176 | endif() |
Václav Kubernát | de0e4e6 | 2021-02-08 17:46:14 +0100 | [diff] [blame] | 177 | |
Václav Kubernát | 6d9357e | 2021-01-28 15:38:24 +0100 | [diff] [blame] | 178 | configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/system/system_vars.h.in ${CMAKE_CURRENT_BINARY_DIR}/system_vars.h @ONLY) |
| 179 | include_directories(${CMAKE_CURRENT_BINARY_DIR}) |
| 180 | |
Tomáš Pecka | 292bc9c | 2021-01-11 22:03:11 +0100 | [diff] [blame] | 181 | # - ietf-system |
| 182 | add_library(velia-system STATIC |
Tomáš Pecka | 991e4d5 | 2021-01-11 10:03:14 +0100 | [diff] [blame] | 183 | src/system/RAUC.cpp |
| 184 | src/system/RAUC.h |
Tomáš Pecka | 594a676 | 2021-01-29 11:06:08 +0100 | [diff] [blame] | 185 | src/system/Firmware.cpp |
| 186 | src/system/Firmware.h |
Tomáš Pecka | f976c5b | 2021-01-23 21:19:52 +0100 | [diff] [blame] | 187 | src/system/IETFSystem.cpp |
| 188 | src/system/IETFSystem.h |
Václav Kubernát | babbab9 | 2021-01-27 09:25:05 +0100 | [diff] [blame] | 189 | src/system/Authentication.cpp |
| 190 | src/system/Authentication.h |
Tomáš Pecka | 292bc9c | 2021-01-11 22:03:11 +0100 | [diff] [blame] | 191 | ) |
| 192 | target_link_libraries(velia-system |
| 193 | PUBLIC |
| 194 | velia-utils |
| 195 | PkgConfig::SYSREPO |
| 196 | PkgConfig::LIBYANG |
Václav Kubernát | 6dd52c8 | 2021-01-21 08:38:42 +0100 | [diff] [blame] | 197 | SDBusCpp::sdbus-c++ |
Tomáš Pecka | 292bc9c | 2021-01-11 22:03:11 +0100 | [diff] [blame] | 198 | ) |
| 199 | |
Václav Kubernát | d386aba | 2021-01-19 10:03:28 +0100 | [diff] [blame] | 200 | # - firewall |
| 201 | add_library(velia-firewall STATIC |
| 202 | src/firewall/Firewall.cpp |
| 203 | ) |
| 204 | target_link_libraries(velia-firewall |
| 205 | PUBLIC |
| 206 | velia-utils |
| 207 | PkgConfig::SYSREPO |
| 208 | PRIVATE |
| 209 | PkgConfig::LIBYANG |
| 210 | ) |
| 211 | |
| 212 | |
Tomáš Pecka | 625b7a1 | 2021-01-23 20:55:51 +0100 | [diff] [blame] | 213 | # - daemons |
Tomáš Pecka | cd19e62 | 2021-01-27 09:18:11 +0100 | [diff] [blame] | 214 | add_executable(veliad-health |
| 215 | src/main-health.cpp |
Tomáš Pecka | 139e361 | 2021-01-25 19:49:00 +0100 | [diff] [blame] | 216 | src/health/Factory.cpp |
| 217 | src/health/Factory.h |
| 218 | ) |
Tomáš Pecka | cd19e62 | 2021-01-27 09:18:11 +0100 | [diff] [blame] | 219 | target_link_libraries(veliad-health |
Tomáš Pecka | aae9fe3 | 2021-01-25 19:57:22 +0100 | [diff] [blame] | 220 | PUBLIC |
Tomáš Pecka | d03044f | 2020-11-12 14:33:10 +0100 | [diff] [blame] | 221 | velia-health |
Tomáš Pecka | d03044f | 2020-11-12 14:33:10 +0100 | [diff] [blame] | 222 | docopt |
Tomáš Pecka | aae9fe3 | 2021-01-25 19:57:22 +0100 | [diff] [blame] | 223 | ) |
Tomáš Pecka | cd19e62 | 2021-01-27 09:18:11 +0100 | [diff] [blame] | 224 | add_dependencies(veliad-health target-VELIA_VERSION) |
| 225 | target_include_directories(veliad-health PUBLIC ${CMAKE_BINARY_DIR}) |
Tomáš Pecka | d03044f | 2020-11-12 14:33:10 +0100 | [diff] [blame] | 226 | |
Tomáš Pecka | 625b7a1 | 2021-01-23 20:55:51 +0100 | [diff] [blame] | 227 | add_executable(veliad-system |
| 228 | src/main-system.cpp |
| 229 | ) |
| 230 | target_link_libraries(veliad-system |
| 231 | PUBLIC |
| 232 | velia-system |
| 233 | docopt |
| 234 | ) |
| 235 | add_dependencies(veliad-system target-VELIA_VERSION) |
| 236 | target_include_directories(veliad-system PUBLIC ${CMAKE_BINARY_DIR}) |
| 237 | |
Václav Kubernát | d386aba | 2021-01-19 10:03:28 +0100 | [diff] [blame] | 238 | add_executable(veliad-firewall |
| 239 | src/main-firewall.cpp |
| 240 | ) |
| 241 | target_link_libraries(veliad-firewall |
| 242 | PUBLIC |
| 243 | velia-firewall |
| 244 | velia-utils |
Václav Kubernát | d386aba | 2021-01-19 10:03:28 +0100 | [diff] [blame] | 245 | docopt |
| 246 | ) |
| 247 | add_dependencies(veliad-firewall target-VELIA_VERSION) |
| 248 | target_include_directories(veliad-firewall PUBLIC ${CMAKE_BINARY_DIR}) |
| 249 | |
Tomáš Pecka | aae9fe3 | 2021-01-25 19:57:22 +0100 | [diff] [blame] | 250 | add_executable(veliad-hardware |
| 251 | src/main-hardware.cpp |
| 252 | src/ietf-hardware/Factory.cpp |
| 253 | src/ietf-hardware/Factory.h |
| 254 | ) |
| 255 | target_link_libraries(veliad-hardware |
| 256 | PUBLIC |
| 257 | velia-ietf-hardware |
| 258 | velia-ietf-hardware-sysrepo |
| 259 | docopt |
| 260 | ) |
| 261 | add_dependencies(veliad-hardware target-VELIA_VERSION) |
| 262 | target_include_directories(veliad-hardware PUBLIC ${CMAKE_BINARY_DIR}) |
| 263 | |
Tomáš Pecka | 5123e00 | 2020-06-05 15:29:21 +0200 | [diff] [blame] | 264 | # Testing |
Tomáš Pecka | a06d74d | 2020-06-14 18:18:13 +0200 | [diff] [blame] | 265 | include(CTest) |
Tomáš Pecka | 5123e00 | 2020-06-05 15:29:21 +0200 | [diff] [blame] | 266 | if(BUILD_TESTING) |
Tomáš Pecka | 5123e00 | 2020-06-05 15:29:21 +0200 | [diff] [blame] | 267 | find_package(trompeloeil 33 REQUIRED) |
| 268 | find_package(doctest 2.3.1 REQUIRED) |
| 269 | |
Tomáš Pecka | efd8843 | 2020-06-17 15:31:39 +0200 | [diff] [blame] | 270 | configure_file(${CMAKE_CURRENT_SOURCE_DIR}/tests/configure.cmake.h.in ${CMAKE_CURRENT_BINARY_DIR}/tests/configure.cmake.h) |
| 271 | |
Tomáš Pecka | 5123e00 | 2020-06-05 15:29:21 +0200 | [diff] [blame] | 272 | add_library(DoctestIntegration STATIC |
Tomáš Pecka | 261c886 | 2020-11-05 11:23:08 +0100 | [diff] [blame] | 273 | tests/doctest_integration.cpp |
| 274 | tests/trompeloeil_doctest.h |
| 275 | tests/wait-a-bit-longer.cpp |
| 276 | ) |
Tomáš Pecka | 5123e00 | 2020-06-05 15:29:21 +0200 | [diff] [blame] | 277 | target_link_libraries(DoctestIntegration doctest::doctest trompeloeil spdlog::spdlog) |
Tomáš Pecka | 261c886 | 2020-11-05 11:23:08 +0100 | [diff] [blame] | 278 | target_include_directories(DoctestIntegration PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/tests/) |
Tomáš Pecka | 5123e00 | 2020-06-05 15:29:21 +0200 | [diff] [blame] | 279 | target_compile_definitions(DoctestIntegration PUBLIC DOCTEST_CONFIG_SUPER_FAST_ASSERTS) |
| 280 | |
Tomáš Pecka | a18702d | 2021-01-25 18:07:23 +0100 | [diff] [blame] | 281 | add_library(SysrepoTesting STATIC |
| 282 | tests/mock/sysrepo/events.cpp |
| 283 | tests/mock/sysrepo/events.h |
| 284 | ) |
| 285 | target_link_libraries(SysrepoTesting DoctestIntegration PkgConfig::SYSREPO) |
| 286 | |
Tomáš Pecka | 0a2e890 | 2020-06-09 21:11:20 +0200 | [diff] [blame] | 287 | add_library(DbusTesting STATIC |
Tomáš Pecka | 991e4d5 | 2021-01-11 10:03:14 +0100 | [diff] [blame] | 288 | tests/dbus-helpers/dbus_rauc_server.cpp |
| 289 | tests/dbus-helpers/dbus_rauc_server.h |
Tomáš Pecka | 0a2e890 | 2020-06-09 21:11:20 +0200 | [diff] [blame] | 290 | tests/dbus-helpers/dbus_semaphore_server.cpp |
Tomáš Pecka | 261c886 | 2020-11-05 11:23:08 +0100 | [diff] [blame] | 291 | tests/dbus-helpers/dbus_semaphore_server.h |
Tomáš Pecka | ccd80c3 | 2020-06-22 14:44:32 +0200 | [diff] [blame] | 292 | tests/dbus-helpers/dbus_systemd_server.cpp |
Tomáš Pecka | 261c886 | 2020-11-05 11:23:08 +0100 | [diff] [blame] | 293 | tests/dbus-helpers/dbus_systemd_server.h |
| 294 | ) |
| 295 | target_link_libraries(DbusTesting |
| 296 | PUBLIC |
| 297 | velia-utils |
| 298 | SDBusCpp::sdbus-c++ |
| 299 | ) |
Tomáš Pecka | 0a2e890 | 2020-06-09 21:11:20 +0200 | [diff] [blame] | 300 | |
Tomáš Pecka | 9b1c967 | 2020-11-11 15:24:06 +0100 | [diff] [blame] | 301 | add_library(FsTestUtils STATIC |
| 302 | tests/fs-helpers/FileInjector.cpp |
| 303 | tests/fs-helpers/FileInjector.h |
| 304 | tests/fs-helpers/utils.cpp |
| 305 | tests/fs-helpers/utils.h |
| 306 | ) |
| 307 | target_link_libraries(FsTestUtils |
| 308 | PUBLIC |
| 309 | ${STD_FILESYSTEM_LIBRARY} |
| 310 | ) |
| 311 | |
Tomáš Pecka | 5123e00 | 2020-06-05 15:29:21 +0200 | [diff] [blame] | 312 | function(velia_test name) |
Tomáš Pecka | 261c886 | 2020-11-05 11:23:08 +0100 | [diff] [blame] | 313 | add_executable(test-${name} ${CMAKE_SOURCE_DIR}/tests/${name}.cpp) |
| 314 | target_link_libraries(test-${name} DoctestIntegration ${ARGN}) |
| 315 | target_include_directories(test-${name} |
| 316 | PUBLIC |
| 317 | ${CMAKE_CURRENT_SOURCE_DIR} |
| 318 | PRIVATE |
| 319 | ${CMAKE_BINARY_DIR} |
| 320 | ) |
Tomáš Pecka | 5123e00 | 2020-06-05 15:29:21 +0200 | [diff] [blame] | 321 | |
| 322 | if(NOT CMAKE_CROSSCOMPILING) |
Tomáš Pecka | 261c886 | 2020-11-05 11:23:08 +0100 | [diff] [blame] | 323 | add_test(test-${name} test-${name}) |
Tomáš Pecka | 5123e00 | 2020-06-05 15:29:21 +0200 | [diff] [blame] | 324 | endif() |
Tomáš Pecka | 5123e00 | 2020-06-05 15:29:21 +0200 | [diff] [blame] | 325 | endfunction() |
Tomáš Pecka | 5123e00 | 2020-06-05 15:29:21 +0200 | [diff] [blame] | 326 | |
Tomáš Pecka | 98ad18d | 2020-11-13 15:39:55 +0100 | [diff] [blame] | 327 | find_program(SYSREPOCTL sysrepoctl) |
| 328 | find_program(SYSREPOCFG sysrepocfg) |
| 329 | |
| 330 | set(sysrepo_previous_fixture_name UNDEFINED) |
| 331 | function(sysrepo_fixture_env name) |
| 332 | set(test_name_init sysrepo:prep:${name}) |
| 333 | set(test_name_cleanup sysrepo:clean:${name}) |
| 334 | set(fixture_name sysrepo:env:${name}) |
| 335 | |
| 336 | add_test(NAME ${test_name_init} COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/tests/sysrepoctl-manage-module.sh ${SYSREPOCTL} ${SYSREPOCFG} prepare ${ARGN}) |
| 337 | set_tests_properties(${test_name_init} PROPERTIES FIXTURES_SETUP ${fixture_name} RESOURCE_LOCK sysrepo) |
| 338 | add_test(NAME ${test_name_cleanup} COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/tests/sysrepoctl-manage-module.sh ${SYSREPOCTL} ${SYSREPOCFG} uninstall ${ARGN}) |
| 339 | set_tests_properties(${test_name_cleanup} PROPERTIES FIXTURES_CLEANUP ${fixture_name} RESOURCE_LOCK sysrepo) |
| 340 | |
| 341 | if (sysrepo_previous_fixture_name) |
| 342 | set_tests_properties(${test_name_init} PROPERTIES DEPENDS sysrepo:clean:${sysrepo_previous_fixture_name}) |
| 343 | endif () |
| 344 | |
| 345 | set(sysrepo_previous_fixture_name ${name} PARENT_SCOPE) |
| 346 | endfunction() |
| 347 | |
Tomáš Pecka | 261c886 | 2020-11-05 11:23:08 +0100 | [diff] [blame] | 348 | velia_test(health_state-manager velia-health) |
| 349 | velia_test(health_input-semaphore velia-health DbusTesting) |
| 350 | velia_test(health_input-systemd velia-health DbusTesting) |
| 351 | velia_test(health_output-led velia-health) |
Tomáš Pecka | 491f4f2 | 2020-11-05 15:44:00 +0100 | [diff] [blame] | 352 | |
Tomáš Pecka | 991e4d5 | 2021-01-11 10:03:14 +0100 | [diff] [blame] | 353 | velia_test(system_rauc velia-system DbusTesting) |
Tomáš Pecka | cb7a5f8 | 2021-01-20 15:12:00 +0100 | [diff] [blame] | 354 | set_tests_properties( |
| 355 | test-system_rauc |
| 356 | PROPERTIES RESOURCE_LOCK dbus-rauc |
| 357 | ) |
Tomáš Pecka | 991e4d5 | 2021-01-11 10:03:14 +0100 | [diff] [blame] | 358 | |
Tomáš Pecka | 9b1c967 | 2020-11-11 15:24:06 +0100 | [diff] [blame] | 359 | velia_test(hardware_emmc velia-ietf-hardware FsTestUtils) |
| 360 | velia_test(hardware_hwmon velia-ietf-hardware FsTestUtils) |
Tomáš Pecka | 83b62e1 | 2020-12-16 14:50:49 +0100 | [diff] [blame] | 361 | |
Tomáš Pecka | 292bc9c | 2021-01-11 22:03:11 +0100 | [diff] [blame] | 362 | sysrepo_fixture_env(sysrepo-ietf-system YANG ${CMAKE_CURRENT_SOURCE_DIR}/yang/ietf-system@2014-08-06.yang) |
Tomáš Pecka | f976c5b | 2021-01-23 21:19:52 +0100 | [diff] [blame] | 363 | velia_test(sysrepo_system-ietfsystem velia-system DbusTesting) |
Tomáš Pecka | 292bc9c | 2021-01-11 22:03:11 +0100 | [diff] [blame] | 364 | set_tests_properties( |
Tomáš Pecka | f976c5b | 2021-01-23 21:19:52 +0100 | [diff] [blame] | 365 | test-sysrepo_system-ietfsystem |
Tomáš Pecka | 292bc9c | 2021-01-11 22:03:11 +0100 | [diff] [blame] | 366 | PROPERTIES FIXTURES_REQUIRED sysrepo:env:sysrepo-ietf-system |
| 367 | RESOURCE_LOCK sysrepo |
Tomáš Pecka | cb7a5f8 | 2021-01-20 15:12:00 +0100 | [diff] [blame] | 368 | ) |
| 369 | |
| 370 | sysrepo_fixture_env(sysrepo-czechlight-system YANG ${CMAKE_CURRENT_SOURCE_DIR}/yang/czechlight-system@2021-01-13.yang) |
Tomáš Pecka | 594a676 | 2021-01-29 11:06:08 +0100 | [diff] [blame] | 371 | velia_test(sysrepo_system-firmware velia-system DbusTesting) |
| 372 | target_link_libraries(test-sysrepo_system-firmware SysrepoTesting) |
Tomáš Pecka | cb7a5f8 | 2021-01-20 15:12:00 +0100 | [diff] [blame] | 373 | set_tests_properties( |
Tomáš Pecka | 594a676 | 2021-01-29 11:06:08 +0100 | [diff] [blame] | 374 | test-sysrepo_system-firmware |
Tomáš Pecka | cb7a5f8 | 2021-01-20 15:12:00 +0100 | [diff] [blame] | 375 | PROPERTIES FIXTURES_REQUIRED sysrepo:env:sysrepo-czechlight-system |
| 376 | RESOURCE_LOCK "sysrepo;dbus-rauc" |
Tomáš Pecka | 292bc9c | 2021-01-11 22:03:11 +0100 | [diff] [blame] | 377 | ) |
| 378 | |
Václav Kubernát | babbab9 | 2021-01-27 09:25:05 +0100 | [diff] [blame] | 379 | velia_test(sysrepo_authentication velia-system FsTestUtils) |
| 380 | |
| 381 | set_tests_properties( |
| 382 | test-sysrepo_authentication |
| 383 | PROPERTIES FIXTURES_REQUIRED sysrepo:env:sysrepo-czechlight-system |
| 384 | RESOURCE_LOCK sysrepo |
| 385 | ) |
| 386 | |
Tomáš Pecka | 83b62e1 | 2020-12-16 14:50:49 +0100 | [diff] [blame] | 387 | sysrepo_fixture_env(sysrepo-ietf-hardware YANG ${CMAKE_CURRENT_SOURCE_DIR}/yang/iana-hardware@2018-03-13.yang YANG ${CMAKE_CURRENT_SOURCE_DIR}/yang/ietf-hardware@2018-03-13.yang FEATURE hardware-sensor) |
Tomáš Pecka | 98ad18d | 2020-11-13 15:39:55 +0100 | [diff] [blame] | 388 | velia_test(hardware_ietf-hardware velia-ietf-hardware velia-ietf-hardware-sysrepo) |
Tomáš Pecka | 98ad18d | 2020-11-13 15:39:55 +0100 | [diff] [blame] | 389 | set_tests_properties( |
| 390 | test-hardware_ietf-hardware |
Tomáš Pecka | 83b62e1 | 2020-12-16 14:50:49 +0100 | [diff] [blame] | 391 | PROPERTIES FIXTURES_REQUIRED sysrepo:env:sysrepo-ietf-hardware |
Tomáš Pecka | 55f64f8 | 2020-12-10 19:03:30 +0100 | [diff] [blame] | 392 | RESOURCE_LOCK sysrepo |
| 393 | ) |
| 394 | |
| 395 | velia_test(sysrepo_two-daemons velia-ietf-hardware-sysrepo) |
Tomáš Pecka | 83b62e1 | 2020-12-16 14:50:49 +0100 | [diff] [blame] | 396 | # ctest dance for sysrepo_two-daemons: compile daemon, create a fixture for test, add the test into the fixture |
Tomáš Pecka | 55f64f8 | 2020-12-10 19:03:30 +0100 | [diff] [blame] | 397 | add_executable(test-sysrepo_test_merge-daemon ${CMAKE_SOURCE_DIR}/tests/sysrepo_two-daemons_daemon.cpp) |
| 398 | target_link_libraries(test-sysrepo_test_merge-daemon PkgConfig::SYSREPO PkgConfig::LIBYANG) |
| 399 | |
| 400 | add_test(NAME sysrepo_test_merge-start COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/tests/sysrepo_two-daemons_control.sh start) |
| 401 | add_test(NAME sysrepo_test_merge-stop COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/tests/sysrepo_two-daemons_control.sh stop) |
| 402 | set_tests_properties(sysrepo_test_merge-start PROPERTIES FIXTURES_SETUP sysrepo:two-daemons RESOURCE_LOCK sysrepo) |
| 403 | set_tests_properties(sysrepo_test_merge-stop PROPERTIES FIXTURES_CLEANUP sysrepo:two-daemons RESOURCE_LOCK sysrepo) |
Tomáš Pecka | 55f64f8 | 2020-12-10 19:03:30 +0100 | [diff] [blame] | 404 | |
| 405 | set_tests_properties( |
| 406 | test-sysrepo_two-daemons |
| 407 | PROPERTIES |
| 408 | FIXTURES_REQUIRED "sysrepo:two-daemons;sysrepo:env:sysrepo-ietf-hardware" |
Tomáš Pecka | 98ad18d | 2020-11-13 15:39:55 +0100 | [diff] [blame] | 409 | RESOURCE_LOCK sysrepo |
| 410 | ) |
Tomáš Pecka | 83b62e1 | 2020-12-16 14:50:49 +0100 | [diff] [blame] | 411 | # ensure we run two-daemons merge test and ietf-hardware test sequentially and don't cleanup before everything ends |
| 412 | set_tests_properties(sysrepo_test_merge-start PROPERTIES DEPENDS test-hardware_ietf-hardware) |
| 413 | set_tests_properties(sysrepo:clean:sysrepo-ietf-hardware PROPERTIES DEPENDS sysrepo_test_merge-stop) |
| 414 | |
Tomáš Pecka | 73a13cc | 2020-11-17 11:12:19 +0100 | [diff] [blame] | 415 | |
| 416 | find_program(YANGLINT_PATH yanglint) |
| 417 | if (NOT YANGLINT_PATH) |
| 418 | message(FATAL_ERROR "Cannot find libyang's yanglint") |
| 419 | endif() |
| 420 | foreach(yang_file ${YANG_SRCS}) |
| 421 | add_test(NAME yang-tree:${yang_file} COMMAND ${YANGLINT_PATH} -f tree ${CMAKE_CURRENT_SOURCE_DIR}/${yang_file}) |
| 422 | endforeach() |
Václav Kubernát | d386aba | 2021-01-19 10:03:28 +0100 | [diff] [blame] | 423 | |
| 424 | sysrepo_fixture_env(sysrepo-firewall |
| 425 | # Installing czechlight-firewall automatically installs ietf-access-control-list as implemented (not just |
| 426 | # imported) but I still need to install it myself to enable the features. |
| 427 | YANG ${CMAKE_CURRENT_SOURCE_DIR}/yang/ietf-access-control-list@2019-03-04.yang |
| 428 | FEATURE eth |
| 429 | FEATURE match-on-eth |
| 430 | FEATURE match-on-ipv4 |
| 431 | FEATURE ipv4 |
| 432 | FEATURE match-on-ipv6 |
| 433 | FEATURE ipv6 |
| 434 | FEATURE mixed-eth-ipv4-ipv6 |
| 435 | YANG ${CMAKE_CURRENT_SOURCE_DIR}/yang/czechlight-firewall@2021-01-25.yang |
| 436 | ) |
| 437 | |
| 438 | velia_test(sysrepo-firewall velia-firewall) |
| 439 | set_tests_properties( |
| 440 | test-sysrepo-firewall |
| 441 | PROPERTIES FIXTURES_REQUIRED sysrepo:env:sysrepo-firewall |
| 442 | RESOURCE_LOCK sysrepo |
| 443 | ) |
Tomáš Pecka | 261c886 | 2020-11-05 11:23:08 +0100 | [diff] [blame] | 444 | endif() |
Tomáš Pecka | c927d66 | 2020-07-13 11:16:16 +0200 | [diff] [blame] | 445 | |
Tomáš Pecka | 5123e00 | 2020-06-05 15:29:21 +0200 | [diff] [blame] | 446 | if(WITH_DOCS) |
| 447 | set(doxyfile_in ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in) |
| 448 | set(doxyfile ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile) |
| 449 | configure_file(${doxyfile_in} ${doxyfile} @ONLY) |
| 450 | add_custom_target(doc |
| 451 | COMMAND ${DOXYGEN_EXECUTABLE} ${doxyfile} |
| 452 | WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} |
| 453 | COMMENT "Generating API documentation with Doxygen" |
| 454 | VERBATIM |
| 455 | SOURCES ${doxyfile_in} |
| 456 | ) |
Tomáš Pecka | a06d74d | 2020-06-14 18:18:13 +0200 | [diff] [blame] | 457 | endif() |
Tomáš Pecka | 261c886 | 2020-11-05 11:23:08 +0100 | [diff] [blame] | 458 | |
Tomáš Pecka | 73a13cc | 2020-11-17 11:12:19 +0100 | [diff] [blame] | 459 | set(YANG_DIR ${CMAKE_INSTALL_PREFIX}/share/velia/yang) |
| 460 | install(FILES ${YANG_SRCS} DESTINATION ${YANG_DIR}) |
Tomáš Pecka | cd19e62 | 2021-01-27 09:18:11 +0100 | [diff] [blame] | 461 | install(TARGETS veliad-health RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}/) |
Tomáš Pecka | 625b7a1 | 2021-01-23 20:55:51 +0100 | [diff] [blame] | 462 | install(TARGETS veliad-system RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}/) |
Tomáš Pecka | aae9fe3 | 2021-01-25 19:57:22 +0100 | [diff] [blame] | 463 | install(TARGETS veliad-hardware RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}/) |
Tomáš Pecka | fb14b18 | 2021-01-27 10:54:00 +0100 | [diff] [blame] | 464 | install(TARGETS veliad-firewall RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}/) |