blob: 23f8387d1a83e4ed1f023e540b1f7428cf854eb6 [file] [log] [blame]
Tomáš Pecka5123e002020-06-05 15:29:21 +02001project(velia LANGUAGES CXX)
Tomáš Pecka9fa5f6a2021-04-13 11:36:11 +02002cmake_minimum_required(VERSION 3.19)
3cmake_policy(SET CMP0109 NEW)
Tomáš Pecka5123e002020-06-05 15:29:21 +02004
5# Build options
Václav Kubernátb332d982021-04-16 01:40:11 +02006set(CMAKE_CXX_STANDARD 20)
Tomáš Pecka5123e002020-06-05 15:29:21 +02007set(CMAKE_CXX_STANDARD_REQUIRED ON)
8
9set(CMAKE_CXX_FLAGS_DEBUG "-Werror ${CMAKE_CXX_FLAGS_DEBUG}")
Václav Kubernátd4b8a692021-04-16 01:21:44 +020010set(CMAKE_CXX_FLAGS "-Wall -Wextra -pedantic -Woverloaded-virtual -Wimplicit-fallthrough ${CMAKE_CXX_FLAGS}")
Tomáš Pecka5123e002020-06-05 15:29:21 +020011if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
12 set(CMAKE_CXX_FLAGS "-Wsuggest-override ${CMAKE_CXX_FLAGS}")
13endif()
14
Tomáš Pecka5d4cf2a2020-07-13 13:19:41 +020015if(CMAKE_CXX_FLAGS MATCHES "-stdlib=libc\\+\\+" AND CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 9.0)
16 set(STD_FILESYSTEM_LIBRARY c++fs)
17elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 9.1)
18 set(STD_FILESYSTEM_LIBRARY stdc++fs)
19endif()
20
21
Tomáš Pecka5123e002020-06-05 15:29:21 +020022add_custom_target(velia-version-cmake-ide
23 cmake/ProjectGitVersion.cmake
24 cmake/ProjectGitVersionRunner.cmake
25 )
26include(cmake/ProjectGitVersion.cmake)
27prepare_git_version(VELIA_VERSION "0.0")
28
29find_package(Doxygen)
30option(WITH_DOCS "Create and install internal documentation (needs Doxygen)" ${DOXYGEN_FOUND})
31
Václav Kubernátde0e4e62021-02-08 17:46:14 +010032find_package(Boost REQUIRED)
Tomáš Pecka5123e002020-06-05 15:29:21 +020033find_package(spdlog REQUIRED)
Tomáš Pecka6a266d82021-11-19 11:35:39 +010034find_package(sdbus-c++ "1.0.0" REQUIRED)
Tomáš Peckaa4336812020-07-24 15:32:58 +020035find_package(PkgConfig)
Václav Kubernátbabbab92021-01-27 09:25:05 +010036find_package(fmt)
Jan Kundrátfee3bea2022-02-15 20:36:08 +010037find_package(nlohmann_json REQUIRED)
Jan Kundrát9e8752a2023-02-02 20:55:39 +010038pkg_check_modules(DOCOPT REQUIRED IMPORTED_TARGET docopt)
Tomáš Peckaa4336812020-07-24 15:32:58 +020039
40pkg_check_modules(SYSTEMD REQUIRED IMPORTED_TARGET libsystemd)
Tomáš Pecka1f42cfe2020-10-21 18:38:27 +020041if(${SYSTEMD_VERSION} VERSION_EQUAL 245)
42 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.")
43endif()
Tomáš Pecka070f60d2021-10-13 21:48:14 +020044#TODO: Check patch 20333 active
Tomáš Pecka5123e002020-06-05 15:29:21 +020045
Jan Kundrátb3e99982022-03-18 17:38:20 +010046pkg_check_modules(SYSREPO REQUIRED sysrepo-cpp>=1.1.0 IMPORTED_TARGET sysrepo)
47pkg_check_modules(LIBYANG REQUIRED libyang-cpp>=1.1.0 IMPORTED_TARGET libyang)
Tomáš Pecka2d578c82021-02-23 19:01:35 +010048pkg_check_modules(LIBNL REQUIRED IMPORTED_TARGET libnl-route-3.0)
Tomáš Pecka98ad18d2020-11-13 15:39:55 +010049
Tomáš Peckac927d662020-07-13 11:16:16 +020050include(GNUInstallDirs)
51
Tomáš Pecka261c8862020-11-05 11:23:08 +010052include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/)
53
Tomáš Pecka73a13cc2020-11-17 11:12:19 +010054set(YANG_SRCS
Jan Kundrát7a30cf42022-07-12 22:24:09 +020055 yang/czechlight-system@2022-07-08.yang
Tomáš Pecka73a13cc2020-11-17 11:12:19 +010056 yang/iana-hardware@2018-03-13.yang
Tomáš Pecka73a13cc2020-11-17 11:12:19 +010057 yang/ietf-hardware@2018-03-13.yang
Tomáš Peckaf98ce032021-01-14 13:35:00 +010058 yang/iana-crypt-hash@2014-08-06.yang
59 yang/ietf-inet-types@2013-07-15.yang
60 yang/ietf-netconf-acm@2018-02-14.yang
61 yang/ietf-system@2014-08-06.yang
62 yang/ietf-yang-types@2013-07-15.yang
Tomáš Pecka435ca2a2021-01-27 10:53:48 +010063 yang/ietf-ethertypes@2019-03-04.yang
64 yang/ietf-interfaces@2018-02-20.yang
65 yang/ietf-packet-fields@2019-03-04.yang
Václav Kubernát637fe802021-01-22 02:43:18 +010066 yang/ietf-access-control-list@2019-03-04.yang
Václav Kubernát457d1ad2021-01-22 02:43:18 +010067 yang/czechlight-firewall@2021-01-25.yang
Tomáš Peckadac27d42021-02-22 13:20:05 +010068 yang/czechlight-network@2021-02-22.yang
69 yang/iana-if-type@2017-01-19.yang
70 yang/ietf-ip@2018-02-22.yang
Tomáš Pecka2a4ea7b2021-03-30 17:01:37 +020071 yang/ietf-routing@2018-03-13.yang
72 yang/ietf-ipv4-unicast-routing@2018-03-13.yang
73 yang/ietf-ipv6-unicast-routing@2018-03-13.yang
Tomáš Pecka7acf3922021-08-10 11:16:57 +020074 yang/czechlight-lldp@2020-11-04.yang
75 yang/iana-afn-safi@2013-07-04.yang
Tomáš Pecka73a13cc2020-11-17 11:12:19 +010076 )
77
Tomáš Pecka59a148f2023-01-16 19:14:15 +010078# temporary until our CI switches to fmt>=9
79add_compile_definitions(FMT_DEPRECATED_OSTREAM)
80
Tomáš Pecka5123e002020-06-05 15:29:21 +020081# Targets
Tomáš Pecka261c8862020-11-05 11:23:08 +010082# - utils
Tomáš Peckabd828862020-06-15 15:53:35 +020083add_library(velia-utils STATIC
Tomáš Peckaa193c032020-06-22 17:33:31 +020084 src/utils/exceptions.cpp
Tomáš Pecka261c8862020-11-05 11:23:08 +010085 src/utils/exceptions.h
Václav Kubernát6d9357e2021-01-28 15:38:24 +010086 src/utils/exec.cpp
87 src/utils/exec.h
Tomáš Pecka491f4f22020-11-05 15:44:00 +010088 src/utils/io.cpp
89 src/utils/io.h
Tomáš Peckaa4336812020-07-24 15:32:58 +020090 src/utils/journal.cpp
Tomáš Pecka261c8862020-11-05 11:23:08 +010091 src/utils/journal.h
Václav Kubernátcbdc98a2021-01-28 13:24:37 +010092 src/utils/libyang.cpp
93 src/utils/libyang.h
Tomáš Pecka261c8862020-11-05 11:23:08 +010094 src/utils/log.h
Václav Kubernát6018f082021-02-11 01:32:18 +010095 src/utils/log.cpp
Tomáš Pecka261c8862020-11-05 11:23:08 +010096 src/utils/log-fwd.h
Tomáš Pecka5123e002020-06-05 15:29:21 +020097 src/utils/log-init.cpp
Tomáš Pecka261c8862020-11-05 11:23:08 +010098 src/utils/log-init.h
Tomáš Peckaba2dc312021-01-23 22:29:11 +010099 src/utils/sysrepo.cpp
100 src/utils/sysrepo.h
Tomáš Pecka339bc672020-11-11 15:59:03 +0100101 src/utils/time.cpp
102 src/utils/time.h
Tomáš Peckad0337072021-01-25 19:57:00 +0100103 src/utils/waitUntilSignalled.cpp
104 src/utils/waitUntilSignalled.h
Tomáš Pecka5123e002020-06-05 15:29:21 +0200105 )
Jan Kundrát9e8752a2023-02-02 20:55:39 +0100106target_link_libraries(velia-utils PUBLIC spdlog::spdlog PRIVATE PkgConfig::SYSTEMD PkgConfig::SYSREPO fmt::fmt PkgConfig::DOCOPT)
Tomáš Peckaa4336812020-07-24 15:32:58 +0200107
Tomáš Pecka261c8862020-11-05 11:23:08 +0100108# - health
109add_library(velia-health STATIC
110 src/health/inputs/AbstractInput.cpp
111 src/health/inputs/DbusSemaphoreInput.cpp
112 src/health/inputs/DbusSystemdInput.cpp
113 src/health/manager/AbstractManager.cpp
114 src/health/manager/StateManager.cpp
115 src/health/outputs/LedSysfsDriver.cpp
116 src/health/outputs/callables.cpp
117 src/health/State.cpp
Tomáš Pecka74b885f2020-06-06 20:02:41 +0200118 )
Tomáš Pecka261c8862020-11-05 11:23:08 +0100119target_link_libraries(velia-health
120 PUBLIC
121 velia-utils
122 Boost::boost
123 SDBusCpp::sdbus-c++
124 ${STD_FILESYSTEM_LIBRARY}
125 )
Tomáš Pecka74b885f2020-06-06 20:02:41 +0200126
Tomáš Pecka491f4f22020-11-05 15:44:00 +0100127# - ietf-hardware
128add_library(velia-ietf-hardware STATIC
129 src/ietf-hardware/sysfs/EMMC.cpp
130 src/ietf-hardware/sysfs/EMMC.h
Tomáš Pecka9b1c9672020-11-11 15:24:06 +0100131 src/ietf-hardware/sysfs/HWMon.cpp
132 src/ietf-hardware/sysfs/HWMon.h
Tomáš Pecka339bc672020-11-11 15:59:03 +0100133 src/ietf-hardware/IETFHardware.cpp
134 src/ietf-hardware/IETFHardware.h
Václav Kubernát97e5ea12021-03-24 00:36:57 +0100135 src/ietf-hardware/FspYhPsu.cpp
136 src/ietf-hardware/FspYhPsu.h
Tomáš Pecka491f4f22020-11-05 15:44:00 +0100137 )
138target_link_libraries(velia-ietf-hardware
139 PUBLIC
140 velia-utils
141 ${STD_FILESYSTEM_LIBRARY}
Tomáš Pecka9b1c9672020-11-11 15:24:06 +0100142 Boost::boost
Tomáš Pecka491f4f22020-11-05 15:44:00 +0100143 )
Tomáš Pecka491f4f22020-11-05 15:44:00 +0100144
Tomáš Pecka98ad18d2020-11-13 15:39:55 +0100145add_library(velia-ietf-hardware-sysrepo STATIC
Tomáš Pecka98ad18d2020-11-13 15:39:55 +0100146 src/ietf-hardware/sysrepo/Sysrepo.cpp
147 src/ietf-hardware/sysrepo/Sysrepo.h
148 )
149target_link_libraries(velia-ietf-hardware-sysrepo
150 PUBLIC
151 velia-utils
152 PkgConfig::SYSREPO
153 PkgConfig::LIBYANG
154 )
Tomáš Pecka5123e002020-06-05 15:29:21 +0200155
Václav Kubernát6d9357e2021-01-28 15:38:24 +0100156set(NOBODY_UID 65534 CACHE STRING "UID which refers to 'nobody'. Used for dropping root privileges.")
157set(NOBODY_GID 65534 CACHE STRING "GID which refers to 'nobody'. Used for dropping root privileges.")
158
Václav Kubernátde0e4e62021-02-08 17:46:14 +0100159if(NOT NFT_EXECUTABLE)
160 find_program(NFT_EXECUTABLE nft)
161endif()
Václav Kubernátbabbab92021-01-27 09:25:05 +0100162if(NOT SSH_KEYGEN_EXECUTABLE)
163 find_program(SSH_KEYGEN_EXECUTABLE ssh-keygen)
164endif()
165if(NOT CHPASSWD_EXECUTABLE)
166 find_program(CHPASSWD_EXECUTABLE chpasswd)
167endif()
Tomáš Pecka879a6032021-02-03 17:21:48 +0100168if(NOT SYSTEMCTL_EXECUTABLE)
169 find_program(SYSTEMCTL_EXECUTABLE systemctl)
170endif()
Tomáš Pecka5c19e722021-02-15 20:41:29 +0100171if(NOT NETWORKCTL_EXECUTABLE)
172 find_program(NETWORKCTL_EXECUTABLE networkctl)
173endif()
Václav Kubernát566c9402021-02-10 08:33:54 +0100174if(NOT HOSTNAMECTL_EXECUTABLE)
175 find_program(HOSTNAMECTL_EXECUTABLE hostnamectl)
176endif()
Václav Kubernátbabbab92021-01-27 09:25:05 +0100177
178set(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.")
179if(NOT VELIA_AUTHORIZED_KEYS_FORMAT)
180 message(FATAL_ERROR "VELIA_AUTHORIZED_KEYS_FORMAT not set.")
181endif()
182
183if(NOT VELIA_AUTHORIZED_KEYS_FORMAT MATCHES "{USER}" AND NOT VELIA_AUTHORIZED_KEYS_FORMAT MATCHES "{HOME}")
184 message(FATAL_ERROR "Wrong format string given for VELIA_AUTHORIZED_KEYS_FORMAT: at least one of {USER} or {HOME} expected.")
185endif()
186
187set(VELIA_REAL_ETC_PASSWD "/etc/passwd" CACHE STRING "Path to passwd file")
188if(NOT VELIA_REAL_ETC_PASSWD)
189 message(FATAL_ERROR "VELIA_REAL_ETC_PASSWD not set")
190endif()
191
192set(VELIA_REAL_ETC_SHADOW "/etc/shadow" CACHE STRING "Path to shadow file")
193if(NOT VELIA_REAL_ETC_SHADOW)
194 message(FATAL_ERROR "VELIA_REAL_ETC_SHADOW not set")
195endif()
196
197set(VELIA_BACKUP_ETC_SHADOW "/etc/shadow" CACHE STRING "Path to where /etc/shadow gets copied to upon each change")
198if(NOT VELIA_BACKUP_ETC_SHADOW)
199 message(FATAL_ERROR "VELIA_BACKUP_ETC_SHADOW not set")
200endif()
Václav Kubernátde0e4e62021-02-08 17:46:14 +0100201
Václav Kubernát566c9402021-02-10 08:33:54 +0100202set(VELIA_BACKUP_ETC_HOSTNAME "/etc/hostname" CACHE STRING "Path to hostname file")
203if(NOT VELIA_BACKUP_ETC_HOSTNAME )
204 message(FATAL_ERROR "VELIA_BACKUP_ETC_HOSTNAME not set")
205endif()
206
Václav Kubernát6d9357e2021-01-28 15:38:24 +0100207configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/system/system_vars.h.in ${CMAKE_CURRENT_BINARY_DIR}/system_vars.h @ONLY)
208include_directories(${CMAKE_CURRENT_BINARY_DIR})
209
Tomáš Pecka292bc9c2021-01-11 22:03:11 +0100210# - ietf-system
211add_library(velia-system STATIC
Tomáš Pecka991e4d52021-01-11 10:03:14 +0100212 src/system/RAUC.cpp
213 src/system/RAUC.h
Tomáš Pecka594a6762021-01-29 11:06:08 +0100214 src/system/Firmware.cpp
215 src/system/Firmware.h
Tomáš Peckaf976c5b2021-01-23 21:19:52 +0100216 src/system/IETFSystem.cpp
217 src/system/IETFSystem.h
Václav Kubernátbabbab92021-01-27 09:25:05 +0100218 src/system/Authentication.cpp
219 src/system/Authentication.h
Tomáš Pecka2d578c82021-02-23 19:01:35 +0100220 src/system/Rtnetlink.cpp
221 src/system/Rtnetlink.h
Tomáš Peckaf10b9302021-02-23 19:02:02 +0100222 src/system/IETFInterfaces.cpp
223 src/system/IETFInterfaces.h
Tomáš Pecka39bbb512021-05-23 22:07:22 +0200224 src/system/IETFInterfacesConfig.cpp
225 src/system/IETFInterfacesConfig.h
Tomáš Peckaaf7b7042021-04-20 20:14:13 +0200226 src/system/LED.cpp
227 src/system/LED.h
Tomáš Pecka7acf3922021-08-10 11:16:57 +0200228 src/system/LLDP.cpp
229 src/system/LLDP.h
230 src/system/LLDPCallback.cpp
231 src/system/LLDPCallback.h
Tomáš Pecka292bc9c2021-01-11 22:03:11 +0100232 )
233target_link_libraries(velia-system
234 PUBLIC
235 velia-utils
236 PkgConfig::SYSREPO
237 PkgConfig::LIBYANG
Tomáš Pecka2d578c82021-02-23 19:01:35 +0100238 PkgConfig::LIBNL
Václav Kubernát6dd52c82021-01-21 08:38:42 +0100239 SDBusCpp::sdbus-c++
Jan Kundrátfee3bea2022-02-15 20:36:08 +0100240 nlohmann_json::nlohmann_json
Tomáš Pecka292bc9c2021-01-11 22:03:11 +0100241 )
242
Václav Kubernátd386aba2021-01-19 10:03:28 +0100243# - firewall
244add_library(velia-firewall STATIC
245 src/firewall/Firewall.cpp
246 )
247target_link_libraries(velia-firewall
248 PUBLIC
249 velia-utils
250 PkgConfig::SYSREPO
251 PRIVATE
252 PkgConfig::LIBYANG
253 )
254
255
Tomáš Pecka625b7a12021-01-23 20:55:51 +0100256# - daemons
Tomáš Peckacd19e622021-01-27 09:18:11 +0100257add_executable(veliad-health
258 src/main-health.cpp
Tomáš Pecka139e3612021-01-25 19:49:00 +0100259 src/health/Factory.cpp
260 src/health/Factory.h
261 )
Tomáš Peckacd19e622021-01-27 09:18:11 +0100262target_link_libraries(veliad-health
Tomáš Peckaaae9fe32021-01-25 19:57:22 +0100263 PUBLIC
Tomáš Peckad03044f2020-11-12 14:33:10 +0100264 velia-health
Jan Kundrát9e8752a2023-02-02 20:55:39 +0100265 PkgConfig::DOCOPT
Tomáš Peckaaae9fe32021-01-25 19:57:22 +0100266 )
Tomáš Peckacd19e622021-01-27 09:18:11 +0100267add_dependencies(veliad-health target-VELIA_VERSION)
268target_include_directories(veliad-health PUBLIC ${CMAKE_BINARY_DIR})
Tomáš Peckad03044f2020-11-12 14:33:10 +0100269
Tomáš Pecka625b7a12021-01-23 20:55:51 +0100270add_executable(veliad-system
271 src/main-system.cpp
272 )
273target_link_libraries(veliad-system
274 PUBLIC
275 velia-system
Jan Kundrát9e8752a2023-02-02 20:55:39 +0100276 PkgConfig::DOCOPT
Tomáš Pecka625b7a12021-01-23 20:55:51 +0100277 )
278add_dependencies(veliad-system target-VELIA_VERSION)
279target_include_directories(veliad-system PUBLIC ${CMAKE_BINARY_DIR})
280
Václav Kubernátd386aba2021-01-19 10:03:28 +0100281add_executable(veliad-firewall
282 src/main-firewall.cpp
283 )
284target_link_libraries(veliad-firewall
285 PUBLIC
286 velia-firewall
287 velia-utils
Jan Kundrát9e8752a2023-02-02 20:55:39 +0100288 PkgConfig::DOCOPT
Václav Kubernátd386aba2021-01-19 10:03:28 +0100289 )
290add_dependencies(veliad-firewall target-VELIA_VERSION)
291target_include_directories(veliad-firewall PUBLIC ${CMAKE_BINARY_DIR})
292
Tomáš Peckaaae9fe32021-01-25 19:57:22 +0100293add_executable(veliad-hardware
294 src/main-hardware.cpp
295 src/ietf-hardware/Factory.cpp
296 src/ietf-hardware/Factory.h
297 )
298target_link_libraries(veliad-hardware
299 PUBLIC
300 velia-ietf-hardware
301 velia-ietf-hardware-sysrepo
Jan Kundrát9e8752a2023-02-02 20:55:39 +0100302 PkgConfig::DOCOPT
Tomáš Peckaaae9fe32021-01-25 19:57:22 +0100303 )
304add_dependencies(veliad-hardware target-VELIA_VERSION)
305target_include_directories(veliad-hardware PUBLIC ${CMAKE_BINARY_DIR})
306
Tomáš Pecka5123e002020-06-05 15:29:21 +0200307# Testing
Tomáš Peckaa06d74d2020-06-14 18:18:13 +0200308include(CTest)
Tomáš Pecka5123e002020-06-05 15:29:21 +0200309if(BUILD_TESTING)
Tomáš Pecka5123e002020-06-05 15:29:21 +0200310 find_package(trompeloeil 33 REQUIRED)
311 find_package(doctest 2.3.1 REQUIRED)
312
Tomáš Pecka9fa5f6a2021-04-13 11:36:11 +0200313 option(TEST_NETWORK_WITH_SUDO "Include ietf-routing and ietf-interfaces tests that require root privileges" "OFF")
314
Tomáš Peckaefd88432020-06-17 15:31:39 +0200315 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/tests/configure.cmake.h.in ${CMAKE_CURRENT_BINARY_DIR}/tests/configure.cmake.h)
316
Tomáš Pecka5123e002020-06-05 15:29:21 +0200317 add_library(DoctestIntegration STATIC
Tomáš Pecka261c8862020-11-05 11:23:08 +0100318 tests/doctest_integration.cpp
319 tests/trompeloeil_doctest.h
320 tests/wait-a-bit-longer.cpp
321 )
Václav Kubernát7efd6d52021-11-09 01:31:11 +0100322 target_link_libraries(DoctestIntegration doctest::doctest spdlog::spdlog)
Tomáš Pecka261c8862020-11-05 11:23:08 +0100323 target_include_directories(DoctestIntegration PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/tests/)
Tomáš Pecka5123e002020-06-05 15:29:21 +0200324 target_compile_definitions(DoctestIntegration PUBLIC DOCTEST_CONFIG_SUPER_FAST_ASSERTS)
325
Tomáš Peckaa18702d2021-01-25 18:07:23 +0100326 add_library(SysrepoTesting STATIC
327 tests/mock/sysrepo/events.cpp
328 tests/mock/sysrepo/events.h
329 )
330 target_link_libraries(SysrepoTesting DoctestIntegration PkgConfig::SYSREPO)
331
Tomáš Pecka0a2e8902020-06-09 21:11:20 +0200332 add_library(DbusTesting STATIC
Tomáš Pecka991e4d52021-01-11 10:03:14 +0100333 tests/dbus-helpers/dbus_rauc_server.cpp
334 tests/dbus-helpers/dbus_rauc_server.h
Tomáš Pecka79344c82021-09-16 18:25:59 +0200335 tests/dbus-helpers/dbus_resolve1_server.cpp
336 tests/dbus-helpers/dbus_resolve1_server.h
Tomáš Pecka0a2e8902020-06-09 21:11:20 +0200337 tests/dbus-helpers/dbus_semaphore_server.cpp
Tomáš Pecka261c8862020-11-05 11:23:08 +0100338 tests/dbus-helpers/dbus_semaphore_server.h
Tomáš Peckaccd80c32020-06-22 14:44:32 +0200339 tests/dbus-helpers/dbus_systemd_server.cpp
Tomáš Pecka261c8862020-11-05 11:23:08 +0100340 tests/dbus-helpers/dbus_systemd_server.h
341 )
342 target_link_libraries(DbusTesting
343 PUBLIC
344 velia-utils
345 SDBusCpp::sdbus-c++
346 )
Tomáš Pecka0a2e8902020-06-09 21:11:20 +0200347
Tomáš Pecka9b1c9672020-11-11 15:24:06 +0100348 add_library(FsTestUtils STATIC
349 tests/fs-helpers/FileInjector.cpp
350 tests/fs-helpers/FileInjector.h
351 tests/fs-helpers/utils.cpp
352 tests/fs-helpers/utils.h
353 )
354 target_link_libraries(FsTestUtils
355 PUBLIC
356 ${STD_FILESYSTEM_LIBRARY}
357 )
358
Václav Kubernát5a745d22021-11-12 12:09:57 +0100359 find_program(SYSREPOCTL sysrepoctl)
360 find_program(SYSREPOCFG sysrepocfg)
361
Tomáš Pecka5123e002020-06-05 15:29:21 +0200362 function(velia_test name)
Tomáš Pecka261c8862020-11-05 11:23:08 +0100363 add_executable(test-${name} ${CMAKE_SOURCE_DIR}/tests/${name}.cpp)
Václav Kubernát6677c222021-11-12 11:46:45 +0100364 target_link_libraries(test-${name} DoctestIntegration)
Tomáš Pecka261c8862020-11-05 11:23:08 +0100365 target_include_directories(test-${name}
366 PUBLIC
367 ${CMAKE_CURRENT_SOURCE_DIR}
368 PRIVATE
369 ${CMAKE_BINARY_DIR}
370 )
Tomáš Pecka5123e002020-06-05 15:29:21 +0200371
372 if(NOT CMAKE_CROSSCOMPILING)
Tomáš Pecka261c8862020-11-05 11:23:08 +0100373 add_test(test-${name} test-${name})
Tomáš Pecka5123e002020-06-05 15:29:21 +0200374 endif()
Tomáš Pecka5123e002020-06-05 15:29:21 +0200375
Tomáš Pecka98ad18d2020-11-13 15:39:55 +0100376 set(test_name_init sysrepo:prep:${name})
377 set(test_name_cleanup sysrepo:clean:${name})
378 set(fixture_name sysrepo:env:${name})
379
Václav Kubernát5a745d22021-11-12 12:09:57 +0100380 # How to do this:
381 # Check ARGN for name of fixture
382 # then take the args for manage module from variable "fixture{fixture_name}"
383 # and then add set env vars for sysrepo
384 # set them ALSO for the init/cleanup tests
385 if(ARGC GREATER 1)
386 set(wanted_fixture ${ARGV1})
387 add_test(NAME ${test_name_init} COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/tests/sysrepoctl-manage-module.sh ${SYSREPOCTL} ${SYSREPOCFG} prepare ${${wanted_fixture}})
388 set_tests_properties(${test_name_init} PROPERTIES FIXTURES_SETUP ${fixture_name})
389 add_test(NAME ${test_name_cleanup} COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/tests/sysrepoctl-manage-module.sh ${SYSREPOCTL} ${SYSREPOCFG} uninstall ${${wanted_fixture}})
390 set_tests_properties(${test_name_cleanup} PROPERTIES FIXTURES_CLEANUP ${fixture_name})
Tomáš Pecka98ad18d2020-11-13 15:39:55 +0100391
Václav Kubernát5a745d22021-11-12 12:09:57 +0100392 set_tests_properties(test-${name} PROPERTIES FIXTURES_REQUIRED ${fixture_name})
393 set_property(TEST test-${name} ${test_name_init} ${test_name_cleanup} APPEND PROPERTY ENVIRONMENT
394 "SYSREPO_REPOSITORY_PATH=${CMAKE_CURRENT_BINARY_DIR}/test_repositories/test_${name}"
395 "SYSREPO_SHM_PREFIX=velia_test_${name}"
396 )
Tomáš Pecka98ad18d2020-11-13 15:39:55 +0100397
Václav Kubernát5a745d22021-11-12 12:09:57 +0100398 endif()
399
Tomáš Pecka98ad18d2020-11-13 15:39:55 +0100400 endfunction()
401
Tomáš Pecka0f85ab62023-02-02 14:53:14 +0100402 find_program(YANGLINT_PATH yanglint)
403 if (NOT YANGLINT_PATH)
404 message(FATAL_ERROR "Cannot find libyang's yanglint")
405 endif()
406 foreach(yang_file ${YANG_SRCS})
407 add_test(NAME yang-tree:${yang_file} COMMAND ${YANGLINT_PATH} -f tree ${CMAKE_CURRENT_SOURCE_DIR}/${yang_file})
408 endforeach()
409
Václav Kubernát6677c222021-11-12 11:46:45 +0100410 velia_test(health_state-manager)
411 target_link_libraries(test-health_state-manager velia-health)
412 velia_test(health_input-semaphore)
413 target_link_libraries(test-health_input-semaphore velia-health DbusTesting)
414 velia_test(health_input-systemd)
415 target_link_libraries(test-health_input-systemd velia-health DbusTesting)
416 velia_test(health_output-led)
417 target_link_libraries(test-health_output-led velia-health)
Tomáš Pecka491f4f22020-11-05 15:44:00 +0100418
Václav Kubernát6677c222021-11-12 11:46:45 +0100419 velia_test(system_rauc)
420 target_link_libraries(test-system_rauc velia-system DbusTesting)
Tomáš Peckacb7a5f82021-01-20 15:12:00 +0100421 set_tests_properties(
422 test-system_rauc
423 PROPERTIES RESOURCE_LOCK dbus-rauc
424 )
Tomáš Pecka991e4d52021-01-11 10:03:14 +0100425
Václav Kubernát6677c222021-11-12 11:46:45 +0100426 velia_test(system_lldp)
427 target_link_libraries(test-system_lldp velia-system DbusTesting)
Tomáš Pecka7acf3922021-08-10 11:16:57 +0200428
Václav Kubernát5a745d22021-11-12 12:09:57 +0100429 set(fixture_sysrepo-czechlight-lldp YANG ${CMAKE_CURRENT_SOURCE_DIR}/yang/czechlight-lldp@2020-11-04.yang)
430 velia_test(sysrepo_system-lldp fixture_sysrepo-czechlight-lldp)
Václav Kubernát6677c222021-11-12 11:46:45 +0100431 target_link_libraries(test-sysrepo_system-lldp velia-system DbusTesting)
Tomáš Pecka7acf3922021-08-10 11:16:57 +0200432
Václav Kubernát6677c222021-11-12 11:46:45 +0100433 velia_test(hardware_emmc)
434 target_link_libraries(test-hardware_emmc velia-ietf-hardware FsTestUtils)
435 velia_test(hardware_hwmon)
436 target_link_libraries(test-hardware_hwmon velia-ietf-hardware FsTestUtils)
Tomáš Pecka83b62e12020-12-16 14:50:49 +0100437
Václav Kubernát5a745d22021-11-12 12:09:57 +0100438 set(fixture_sysrepo-ietf-system YANG ${CMAKE_CURRENT_SOURCE_DIR}/yang/ietf-system@2014-08-06.yang)
439 velia_test(sysrepo_system-ietfsystem fixture_sysrepo-ietf-system)
Václav Kubernát6677c222021-11-12 11:46:45 +0100440 target_link_libraries(test-sysrepo_system-ietfsystem velia-system DbusTesting)
Tomáš Peckacb7a5f82021-01-20 15:12:00 +0100441
Jan Kundrát7a30cf42022-07-12 22:24:09 +0200442 set(fixture_sysrepo-czechlight-system YANG ${CMAKE_CURRENT_SOURCE_DIR}/yang/czechlight-system@2022-07-08.yang)
Václav Kubernát5a745d22021-11-12 12:09:57 +0100443 velia_test(sysrepo_system-firmware fixture_sysrepo-czechlight-system)
Václav Kubernát6677c222021-11-12 11:46:45 +0100444 target_link_libraries(test-sysrepo_system-firmware velia-system DbusTesting SysrepoTesting)
Tomáš Peckacb7a5f82021-01-20 15:12:00 +0100445 set_tests_properties(
Tomáš Pecka594a6762021-01-29 11:06:08 +0100446 test-sysrepo_system-firmware
Václav Kubernát5a745d22021-11-12 12:09:57 +0100447 PROPERTIES RESOURCE_LOCK dbus-rauc
Tomáš Pecka292bc9c2021-01-11 22:03:11 +0100448 )
449
Václav Kubernát5a745d22021-11-12 12:09:57 +0100450 velia_test(sysrepo_authentication fixture_sysrepo-czechlight-system)
Václav Kubernát6677c222021-11-12 11:46:45 +0100451 target_link_libraries(test-sysrepo_authentication velia-system FsTestUtils)
Václav Kubernátbabbab92021-01-27 09:25:05 +0100452
Václav Kubernát5a745d22021-11-12 12:09:57 +0100453 velia_test(sysrepo_system-leds fixture_sysrepo-czechlight-system)
Václav Kubernát6677c222021-11-12 11:46:45 +0100454 target_link_libraries(test-sysrepo_system-leds velia-system FsTestUtils)
Tomáš Peckaaf7b7042021-04-20 20:14:13 +0200455
Václav Kubernát5a745d22021-11-12 12:09:57 +0100456 set(fixture_sysrepo-czechlight-network
Tomáš Peckaf10b9302021-02-23 19:02:02 +0100457 YANG ${CMAKE_CURRENT_SOURCE_DIR}/yang/iana-if-type@2017-01-19.yang
458 YANG ${CMAKE_CURRENT_SOURCE_DIR}/yang/ietf-interfaces@2018-02-20.yang
459 YANG ${CMAKE_CURRENT_SOURCE_DIR}/yang/ietf-ip@2018-02-22.yang
Tomáš Pecka2a4ea7b2021-03-30 17:01:37 +0200460 YANG ${CMAKE_CURRENT_SOURCE_DIR}/yang/ietf-routing@2018-03-13.yang
461 YANG ${CMAKE_CURRENT_SOURCE_DIR}/yang/ietf-ipv4-unicast-routing@2018-03-13.yang
462 YANG ${CMAKE_CURRENT_SOURCE_DIR}/yang/ietf-ipv6-unicast-routing@2018-03-13.yang
Tomáš Peckaf10b9302021-02-23 19:02:02 +0100463 YANG ${CMAKE_CURRENT_SOURCE_DIR}/yang/czechlight-network@2021-02-22.yang)
Tomáš Pecka9fa5f6a2021-04-13 11:36:11 +0200464
Václav Kubernát5a745d22021-11-12 12:09:57 +0100465 velia_test(sysrepo_system-ietfinterfaces fixture_sysrepo-czechlight-network)
Václav Kubernát6677c222021-11-12 11:46:45 +0100466 target_link_libraries(test-sysrepo_system-ietfinterfaces velia-system)
Tomáš Peckaf10b9302021-02-23 19:02:02 +0100467
Tomáš Pecka9fa5f6a2021-04-13 11:36:11 +0200468 if(TEST_NETWORK_WITH_SUDO)
469 find_program(SUDO_EXECUTABLE sudo REQUIRED)
470 find_program(IPROUTE2_EXECUTABLE ip REQUIRED)
471 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/tests/test_vars.h.in ${CMAKE_CURRENT_BINARY_DIR}/test_vars.h @ONLY)
472
473 add_test(NAME network-czechlight0-prepare COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/tests/sysrepo_system-ietfinterfaces-sudo.sh ${SUDO_EXECUTABLE})
474 add_test(NAME network-czechlight0-cleanup COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/tests/sysrepo_system-ietfinterfaces-sudo.sh ${SUDO_EXECUTABLE})
475 set_tests_properties(network-czechlight0-prepare PROPERTIES FIXTURES_SETUP network-czechlight0)
476 set_tests_properties(network-czechlight0-cleanup PROPERTIES FIXTURES_CLEANUP network-czechlight0)
477
Václav Kubernát5a745d22021-11-12 12:09:57 +0100478 velia_test(sysrepo_system-ietfinterfaces-sudo fixture_sysrepo-czechlight-network)
Václav Kubernát6677c222021-11-12 11:46:45 +0100479 target_link_libraries(test-sysrepo_system-ietfinterfaces-sudo velia-system)
Václav Kubernát5a745d22021-11-12 12:09:57 +0100480 set_property(TEST test-sysrepo_system-ietfinterfaces-sudo APPEND PROPERTY FIXTURES_REQUIRED network-czechlight0)
Tomáš Pecka9fa5f6a2021-04-13 11:36:11 +0200481 endif()
482
Václav Kubernát5a745d22021-11-12 12:09:57 +0100483 set(fixture_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)
484 velia_test(hardware_ietf-hardware fixture_sysrepo-ietf-hardware)
Václav Kubernát6677c222021-11-12 11:46:45 +0100485 target_link_libraries(test-hardware_ietf-hardware velia-ietf-hardware velia-ietf-hardware-sysrepo FsTestUtils)
Tomáš Pecka55f64f82020-12-10 19:03:30 +0100486
Václav Kubernát5a745d22021-11-12 12:09:57 +0100487 velia_test(sysrepo_two-daemons fixture_sysrepo-ietf-hardware)
Václav Kubernát6677c222021-11-12 11:46:45 +0100488 target_link_libraries(test-sysrepo_two-daemons velia-ietf-hardware-sysrepo)
Tomáš Pecka83b62e12020-12-16 14:50:49 +0100489 # ctest dance for sysrepo_two-daemons: compile daemon, create a fixture for test, add the test into the fixture
Tomáš Pecka55f64f82020-12-10 19:03:30 +0100490 add_executable(test-sysrepo_test_merge-daemon ${CMAKE_SOURCE_DIR}/tests/sysrepo_two-daemons_daemon.cpp)
491 target_link_libraries(test-sysrepo_test_merge-daemon PkgConfig::SYSREPO PkgConfig::LIBYANG)
492
493 add_test(NAME sysrepo_test_merge-start COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/tests/sysrepo_two-daemons_control.sh start)
494 add_test(NAME sysrepo_test_merge-stop COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/tests/sysrepo_two-daemons_control.sh stop)
Václav Kubernát5a745d22021-11-12 12:09:57 +0100495 set_tests_properties(sysrepo_test_merge-start PROPERTIES FIXTURES_SETUP sysrepo:two-daemons)
496 set_tests_properties(sysrepo_test_merge-stop PROPERTIES FIXTURES_CLEANUP sysrepo:two-daemons)
497 set_property(TEST sysrepo_test_merge-start sysrepo_test_merge-stop APPEND PROPERTY ENVIRONMENT
498 "SYSREPO_REPOSITORY_PATH=${CMAKE_CURRENT_BINARY_DIR}/test_repositories/test_sysrepo_two-daemons"
499 "SYSREPO_SHM_PREFIX=velia_test_sysrepo_two-daemons"
500 )
Tomáš Pecka55f64f82020-12-10 19:03:30 +0100501
Václav Kubernát5a745d22021-11-12 12:09:57 +0100502 set_property(TEST test-sysrepo_two-daemons APPEND PROPERTY FIXTURES_REQUIRED sysrepo:two-daemons)
503
Tomáš Pecka83b62e12020-12-16 14:50:49 +0100504 # ensure we run two-daemons merge test and ietf-hardware test sequentially and don't cleanup before everything ends
505 set_tests_properties(sysrepo_test_merge-start PROPERTIES DEPENDS test-hardware_ietf-hardware)
Václav Kubernát5a745d22021-11-12 12:09:57 +0100506 set_tests_properties(sysrepo:clean:sysrepo_two-daemons PROPERTIES DEPENDS sysrepo_test_merge-stop)
Tomáš Pecka83b62e12020-12-16 14:50:49 +0100507
Václav Kubernát5a745d22021-11-12 12:09:57 +0100508 set(fixture_sysrepo-firewall
Václav Kubernátd386aba2021-01-19 10:03:28 +0100509 # Installing czechlight-firewall automatically installs ietf-access-control-list as implemented (not just
510 # imported) but I still need to install it myself to enable the features.
511 YANG ${CMAKE_CURRENT_SOURCE_DIR}/yang/ietf-access-control-list@2019-03-04.yang
Václav Kubernátd386aba2021-01-19 10:03:28 +0100512 FEATURE match-on-eth
Václav Kubernát2b073632021-11-25 15:39:42 +0100513 FEATURE eth
Václav Kubernátd386aba2021-01-19 10:03:28 +0100514 FEATURE match-on-ipv4
515 FEATURE ipv4
516 FEATURE match-on-ipv6
517 FEATURE ipv6
518 FEATURE mixed-eth-ipv4-ipv6
519 YANG ${CMAKE_CURRENT_SOURCE_DIR}/yang/czechlight-firewall@2021-01-25.yang
520 )
521
Václav Kubernát5a745d22021-11-12 12:09:57 +0100522 velia_test(sysrepo-firewall fixture_sysrepo-firewall)
Václav Kubernát6677c222021-11-12 11:46:45 +0100523 target_link_libraries(test-sysrepo-firewall velia-firewall)
Tomáš Pecka261c8862020-11-05 11:23:08 +0100524endif()
Tomáš Peckac927d662020-07-13 11:16:16 +0200525
Tomáš Pecka5123e002020-06-05 15:29:21 +0200526if(WITH_DOCS)
527 set(doxyfile_in ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in)
528 set(doxyfile ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile)
529 configure_file(${doxyfile_in} ${doxyfile} @ONLY)
530 add_custom_target(doc
531 COMMAND ${DOXYGEN_EXECUTABLE} ${doxyfile}
532 WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
533 COMMENT "Generating API documentation with Doxygen"
534 VERBATIM
535 SOURCES ${doxyfile_in}
536 )
Tomáš Peckaa06d74d2020-06-14 18:18:13 +0200537endif()
Tomáš Pecka261c8862020-11-05 11:23:08 +0100538
Tomáš Pecka73a13cc2020-11-17 11:12:19 +0100539set(YANG_DIR ${CMAKE_INSTALL_PREFIX}/share/velia/yang)
540install(FILES ${YANG_SRCS} DESTINATION ${YANG_DIR})
Tomáš Peckaeb317722021-04-13 21:33:20 +0200541install(FILES ${CMAKE_SOURCE_DIR}/yang/ietf-ipv6-router-advertisements@2018-03-13.yang DESTINATION ${YANG_DIR})
Tomáš Peckacd19e622021-01-27 09:18:11 +0100542install(TARGETS veliad-health RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}/)
Tomáš Pecka625b7a12021-01-23 20:55:51 +0100543install(TARGETS veliad-system RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}/)
Tomáš Peckaaae9fe32021-01-25 19:57:22 +0100544install(TARGETS veliad-hardware RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}/)
Tomáš Peckafb14b182021-01-27 10:54:00 +0100545install(TARGETS veliad-firewall RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}/)