blob: 19dcfa4601a18480b7b5e91e73a41342cae60422 [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áš Peckaa193c032020-06-22 17:33:31 +020033find_package(docopt REQUIRED)
Tomáš Pecka5123e002020-06-05 15:29:21 +020034find_package(spdlog REQUIRED)
Tomáš Pecka6a266d82021-11-19 11:35:39 +010035find_package(sdbus-c++ "1.0.0" REQUIRED)
Tomáš Peckaa4336812020-07-24 15:32:58 +020036find_package(PkgConfig)
Václav Kubernátbabbab92021-01-27 09:25:05 +010037find_package(fmt)
Jan Kundrátfee3bea2022-02-15 20:36:08 +010038find_package(nlohmann_json REQUIRED)
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át5681a502021-10-01 01:38:22 +020046pkg_check_modules(SYSREPO REQUIRED sysrepo-cpp>=1.4.148 IMPORTED_TARGET sysrepo)
47pkg_check_modules(LIBYANG REQUIRED libyang-cpp>=1.0.248 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
Tomáš Pecka9a02c3f2021-01-21 15:27:22 +010055 yang/czechlight-system@2021-01-13.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áš Pecka5123e002020-06-05 15:29:21 +020078# Targets
Tomáš Pecka261c8862020-11-05 11:23:08 +010079# - utils
Tomáš Peckabd828862020-06-15 15:53:35 +020080add_library(velia-utils STATIC
Tomáš Peckaa193c032020-06-22 17:33:31 +020081 src/utils/exceptions.cpp
Tomáš Pecka261c8862020-11-05 11:23:08 +010082 src/utils/exceptions.h
Václav Kubernát6d9357e2021-01-28 15:38:24 +010083 src/utils/exec.cpp
84 src/utils/exec.h
Tomáš Pecka491f4f22020-11-05 15:44:00 +010085 src/utils/io.cpp
86 src/utils/io.h
Tomáš Peckaa4336812020-07-24 15:32:58 +020087 src/utils/journal.cpp
Tomáš Pecka261c8862020-11-05 11:23:08 +010088 src/utils/journal.h
Václav Kubernátcbdc98a2021-01-28 13:24:37 +010089 src/utils/libyang.cpp
90 src/utils/libyang.h
Tomáš Pecka261c8862020-11-05 11:23:08 +010091 src/utils/log.h
Václav Kubernát6018f082021-02-11 01:32:18 +010092 src/utils/log.cpp
Tomáš Pecka261c8862020-11-05 11:23:08 +010093 src/utils/log-fwd.h
Tomáš Pecka5123e002020-06-05 15:29:21 +020094 src/utils/log-init.cpp
Tomáš Pecka261c8862020-11-05 11:23:08 +010095 src/utils/log-init.h
Tomáš Peckaba2dc312021-01-23 22:29:11 +010096 src/utils/sysrepo.cpp
97 src/utils/sysrepo.h
Tomáš Pecka339bc672020-11-11 15:59:03 +010098 src/utils/time.cpp
99 src/utils/time.h
Tomáš Peckad0337072021-01-25 19:57:00 +0100100 src/utils/waitUntilSignalled.cpp
101 src/utils/waitUntilSignalled.h
Tomáš Pecka5123e002020-06-05 15:29:21 +0200102 )
Václav Kubernát6018f082021-02-11 01:32:18 +0100103target_link_libraries(velia-utils PUBLIC spdlog::spdlog PRIVATE PkgConfig::SYSTEMD PkgConfig::SYSREPO fmt::fmt docopt)
Tomáš Peckaa4336812020-07-24 15:32:58 +0200104
Tomáš Pecka261c8862020-11-05 11:23:08 +0100105# - health
106add_library(velia-health STATIC
107 src/health/inputs/AbstractInput.cpp
108 src/health/inputs/DbusSemaphoreInput.cpp
109 src/health/inputs/DbusSystemdInput.cpp
110 src/health/manager/AbstractManager.cpp
111 src/health/manager/StateManager.cpp
112 src/health/outputs/LedSysfsDriver.cpp
113 src/health/outputs/callables.cpp
114 src/health/State.cpp
Tomáš Pecka74b885f2020-06-06 20:02:41 +0200115 )
Tomáš Pecka261c8862020-11-05 11:23:08 +0100116target_link_libraries(velia-health
117 PUBLIC
118 velia-utils
119 Boost::boost
120 SDBusCpp::sdbus-c++
121 ${STD_FILESYSTEM_LIBRARY}
122 )
Tomáš Pecka74b885f2020-06-06 20:02:41 +0200123
Tomáš Pecka491f4f22020-11-05 15:44:00 +0100124# - ietf-hardware
125add_library(velia-ietf-hardware STATIC
126 src/ietf-hardware/sysfs/EMMC.cpp
127 src/ietf-hardware/sysfs/EMMC.h
Tomáš Pecka9b1c9672020-11-11 15:24:06 +0100128 src/ietf-hardware/sysfs/HWMon.cpp
129 src/ietf-hardware/sysfs/HWMon.h
Tomáš Pecka339bc672020-11-11 15:59:03 +0100130 src/ietf-hardware/IETFHardware.cpp
131 src/ietf-hardware/IETFHardware.h
Václav Kubernát97e5ea12021-03-24 00:36:57 +0100132 src/ietf-hardware/FspYhPsu.cpp
133 src/ietf-hardware/FspYhPsu.h
Tomáš Pecka491f4f22020-11-05 15:44:00 +0100134 )
135target_link_libraries(velia-ietf-hardware
136 PUBLIC
137 velia-utils
138 ${STD_FILESYSTEM_LIBRARY}
Tomáš Pecka9b1c9672020-11-11 15:24:06 +0100139 Boost::boost
Tomáš Pecka491f4f22020-11-05 15:44:00 +0100140 )
Tomáš Pecka491f4f22020-11-05 15:44:00 +0100141
Tomáš Pecka98ad18d2020-11-13 15:39:55 +0100142add_library(velia-ietf-hardware-sysrepo STATIC
Tomáš Pecka98ad18d2020-11-13 15:39:55 +0100143 src/ietf-hardware/sysrepo/Sysrepo.cpp
144 src/ietf-hardware/sysrepo/Sysrepo.h
145 )
146target_link_libraries(velia-ietf-hardware-sysrepo
147 PUBLIC
148 velia-utils
149 PkgConfig::SYSREPO
150 PkgConfig::LIBYANG
151 )
Tomáš Pecka5123e002020-06-05 15:29:21 +0200152
Václav Kubernát6d9357e2021-01-28 15:38:24 +0100153set(NOBODY_UID 65534 CACHE STRING "UID which refers to 'nobody'. Used for dropping root privileges.")
154set(NOBODY_GID 65534 CACHE STRING "GID which refers to 'nobody'. Used for dropping root privileges.")
155
Václav Kubernátde0e4e62021-02-08 17:46:14 +0100156if(NOT NFT_EXECUTABLE)
157 find_program(NFT_EXECUTABLE nft)
158endif()
Václav Kubernátbabbab92021-01-27 09:25:05 +0100159if(NOT SSH_KEYGEN_EXECUTABLE)
160 find_program(SSH_KEYGEN_EXECUTABLE ssh-keygen)
161endif()
162if(NOT CHPASSWD_EXECUTABLE)
163 find_program(CHPASSWD_EXECUTABLE chpasswd)
164endif()
Tomáš Pecka879a6032021-02-03 17:21:48 +0100165if(NOT SYSTEMCTL_EXECUTABLE)
166 find_program(SYSTEMCTL_EXECUTABLE systemctl)
167endif()
Tomáš Pecka5c19e722021-02-15 20:41:29 +0100168if(NOT NETWORKCTL_EXECUTABLE)
169 find_program(NETWORKCTL_EXECUTABLE networkctl)
170endif()
Václav Kubernát566c9402021-02-10 08:33:54 +0100171if(NOT HOSTNAMECTL_EXECUTABLE)
172 find_program(HOSTNAMECTL_EXECUTABLE hostnamectl)
173endif()
Václav Kubernátbabbab92021-01-27 09:25:05 +0100174
175set(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.")
176if(NOT VELIA_AUTHORIZED_KEYS_FORMAT)
177 message(FATAL_ERROR "VELIA_AUTHORIZED_KEYS_FORMAT not set.")
178endif()
179
180if(NOT VELIA_AUTHORIZED_KEYS_FORMAT MATCHES "{USER}" AND NOT VELIA_AUTHORIZED_KEYS_FORMAT MATCHES "{HOME}")
181 message(FATAL_ERROR "Wrong format string given for VELIA_AUTHORIZED_KEYS_FORMAT: at least one of {USER} or {HOME} expected.")
182endif()
183
184set(VELIA_REAL_ETC_PASSWD "/etc/passwd" CACHE STRING "Path to passwd file")
185if(NOT VELIA_REAL_ETC_PASSWD)
186 message(FATAL_ERROR "VELIA_REAL_ETC_PASSWD not set")
187endif()
188
189set(VELIA_REAL_ETC_SHADOW "/etc/shadow" CACHE STRING "Path to shadow file")
190if(NOT VELIA_REAL_ETC_SHADOW)
191 message(FATAL_ERROR "VELIA_REAL_ETC_SHADOW not set")
192endif()
193
194set(VELIA_BACKUP_ETC_SHADOW "/etc/shadow" CACHE STRING "Path to where /etc/shadow gets copied to upon each change")
195if(NOT VELIA_BACKUP_ETC_SHADOW)
196 message(FATAL_ERROR "VELIA_BACKUP_ETC_SHADOW not set")
197endif()
Václav Kubernátde0e4e62021-02-08 17:46:14 +0100198
Václav Kubernát566c9402021-02-10 08:33:54 +0100199set(VELIA_BACKUP_ETC_HOSTNAME "/etc/hostname" CACHE STRING "Path to hostname file")
200if(NOT VELIA_BACKUP_ETC_HOSTNAME )
201 message(FATAL_ERROR "VELIA_BACKUP_ETC_HOSTNAME not set")
202endif()
203
Václav Kubernát6d9357e2021-01-28 15:38:24 +0100204configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/system/system_vars.h.in ${CMAKE_CURRENT_BINARY_DIR}/system_vars.h @ONLY)
205include_directories(${CMAKE_CURRENT_BINARY_DIR})
206
Tomáš Pecka292bc9c2021-01-11 22:03:11 +0100207# - ietf-system
208add_library(velia-system STATIC
Tomáš Pecka991e4d52021-01-11 10:03:14 +0100209 src/system/RAUC.cpp
210 src/system/RAUC.h
Tomáš Pecka594a6762021-01-29 11:06:08 +0100211 src/system/Firmware.cpp
212 src/system/Firmware.h
Tomáš Peckaf976c5b2021-01-23 21:19:52 +0100213 src/system/IETFSystem.cpp
214 src/system/IETFSystem.h
Václav Kubernátbabbab92021-01-27 09:25:05 +0100215 src/system/Authentication.cpp
216 src/system/Authentication.h
Tomáš Pecka2d578c82021-02-23 19:01:35 +0100217 src/system/Rtnetlink.cpp
218 src/system/Rtnetlink.h
Tomáš Peckaf10b9302021-02-23 19:02:02 +0100219 src/system/IETFInterfaces.cpp
220 src/system/IETFInterfaces.h
Tomáš Pecka39bbb512021-05-23 22:07:22 +0200221 src/system/IETFInterfacesConfig.cpp
222 src/system/IETFInterfacesConfig.h
Tomáš Peckaaf7b7042021-04-20 20:14:13 +0200223 src/system/LED.cpp
224 src/system/LED.h
Tomáš Pecka7acf3922021-08-10 11:16:57 +0200225 src/system/LLDP.cpp
226 src/system/LLDP.h
227 src/system/LLDPCallback.cpp
228 src/system/LLDPCallback.h
Tomáš Pecka292bc9c2021-01-11 22:03:11 +0100229 )
230target_link_libraries(velia-system
231 PUBLIC
232 velia-utils
233 PkgConfig::SYSREPO
234 PkgConfig::LIBYANG
Tomáš Pecka2d578c82021-02-23 19:01:35 +0100235 PkgConfig::LIBNL
Václav Kubernát6dd52c82021-01-21 08:38:42 +0100236 SDBusCpp::sdbus-c++
Jan Kundrátfee3bea2022-02-15 20:36:08 +0100237 nlohmann_json::nlohmann_json
Tomáš Pecka292bc9c2021-01-11 22:03:11 +0100238 )
239
Václav Kubernátd386aba2021-01-19 10:03:28 +0100240# - firewall
241add_library(velia-firewall STATIC
242 src/firewall/Firewall.cpp
243 )
244target_link_libraries(velia-firewall
245 PUBLIC
246 velia-utils
247 PkgConfig::SYSREPO
248 PRIVATE
249 PkgConfig::LIBYANG
250 )
251
252
Tomáš Pecka625b7a12021-01-23 20:55:51 +0100253# - daemons
Tomáš Peckacd19e622021-01-27 09:18:11 +0100254add_executable(veliad-health
255 src/main-health.cpp
Tomáš Pecka139e3612021-01-25 19:49:00 +0100256 src/health/Factory.cpp
257 src/health/Factory.h
258 )
Tomáš Peckacd19e622021-01-27 09:18:11 +0100259target_link_libraries(veliad-health
Tomáš Peckaaae9fe32021-01-25 19:57:22 +0100260 PUBLIC
Tomáš Peckad03044f2020-11-12 14:33:10 +0100261 velia-health
Tomáš Peckad03044f2020-11-12 14:33:10 +0100262 docopt
Tomáš Peckaaae9fe32021-01-25 19:57:22 +0100263 )
Tomáš Peckacd19e622021-01-27 09:18:11 +0100264add_dependencies(veliad-health target-VELIA_VERSION)
265target_include_directories(veliad-health PUBLIC ${CMAKE_BINARY_DIR})
Tomáš Peckad03044f2020-11-12 14:33:10 +0100266
Tomáš Pecka625b7a12021-01-23 20:55:51 +0100267add_executable(veliad-system
268 src/main-system.cpp
269 )
270target_link_libraries(veliad-system
271 PUBLIC
272 velia-system
273 docopt
274 )
275add_dependencies(veliad-system target-VELIA_VERSION)
276target_include_directories(veliad-system PUBLIC ${CMAKE_BINARY_DIR})
277
Václav Kubernátd386aba2021-01-19 10:03:28 +0100278add_executable(veliad-firewall
279 src/main-firewall.cpp
280 )
281target_link_libraries(veliad-firewall
282 PUBLIC
283 velia-firewall
284 velia-utils
Václav Kubernátd386aba2021-01-19 10:03:28 +0100285 docopt
286 )
287add_dependencies(veliad-firewall target-VELIA_VERSION)
288target_include_directories(veliad-firewall PUBLIC ${CMAKE_BINARY_DIR})
289
Tomáš Peckaaae9fe32021-01-25 19:57:22 +0100290add_executable(veliad-hardware
291 src/main-hardware.cpp
292 src/ietf-hardware/Factory.cpp
293 src/ietf-hardware/Factory.h
294 )
295target_link_libraries(veliad-hardware
296 PUBLIC
297 velia-ietf-hardware
298 velia-ietf-hardware-sysrepo
299 docopt
300 )
301add_dependencies(veliad-hardware target-VELIA_VERSION)
302target_include_directories(veliad-hardware PUBLIC ${CMAKE_BINARY_DIR})
303
Tomáš Pecka5123e002020-06-05 15:29:21 +0200304# Testing
Tomáš Peckaa06d74d2020-06-14 18:18:13 +0200305include(CTest)
Tomáš Pecka5123e002020-06-05 15:29:21 +0200306if(BUILD_TESTING)
Tomáš Pecka5123e002020-06-05 15:29:21 +0200307 find_package(trompeloeil 33 REQUIRED)
308 find_package(doctest 2.3.1 REQUIRED)
309
Tomáš Pecka9fa5f6a2021-04-13 11:36:11 +0200310 option(TEST_NETWORK_WITH_SUDO "Include ietf-routing and ietf-interfaces tests that require root privileges" "OFF")
311
Tomáš Peckaefd88432020-06-17 15:31:39 +0200312 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/tests/configure.cmake.h.in ${CMAKE_CURRENT_BINARY_DIR}/tests/configure.cmake.h)
313
Tomáš Pecka5123e002020-06-05 15:29:21 +0200314 add_library(DoctestIntegration STATIC
Tomáš Pecka261c8862020-11-05 11:23:08 +0100315 tests/doctest_integration.cpp
316 tests/trompeloeil_doctest.h
317 tests/wait-a-bit-longer.cpp
318 )
Tomáš Pecka5123e002020-06-05 15:29:21 +0200319 target_link_libraries(DoctestIntegration doctest::doctest trompeloeil spdlog::spdlog)
Tomáš Pecka261c8862020-11-05 11:23:08 +0100320 target_include_directories(DoctestIntegration PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/tests/)
Tomáš Pecka5123e002020-06-05 15:29:21 +0200321 target_compile_definitions(DoctestIntegration PUBLIC DOCTEST_CONFIG_SUPER_FAST_ASSERTS)
322
Tomáš Peckaa18702d2021-01-25 18:07:23 +0100323 add_library(SysrepoTesting STATIC
324 tests/mock/sysrepo/events.cpp
325 tests/mock/sysrepo/events.h
326 )
327 target_link_libraries(SysrepoTesting DoctestIntegration PkgConfig::SYSREPO)
328
Tomáš Pecka0a2e8902020-06-09 21:11:20 +0200329 add_library(DbusTesting STATIC
Tomáš Pecka991e4d52021-01-11 10:03:14 +0100330 tests/dbus-helpers/dbus_rauc_server.cpp
331 tests/dbus-helpers/dbus_rauc_server.h
Tomáš Pecka79344c82021-09-16 18:25:59 +0200332 tests/dbus-helpers/dbus_resolve1_server.cpp
333 tests/dbus-helpers/dbus_resolve1_server.h
Tomáš Pecka0a2e8902020-06-09 21:11:20 +0200334 tests/dbus-helpers/dbus_semaphore_server.cpp
Tomáš Pecka261c8862020-11-05 11:23:08 +0100335 tests/dbus-helpers/dbus_semaphore_server.h
Tomáš Peckaccd80c32020-06-22 14:44:32 +0200336 tests/dbus-helpers/dbus_systemd_server.cpp
Tomáš Pecka261c8862020-11-05 11:23:08 +0100337 tests/dbus-helpers/dbus_systemd_server.h
338 )
339 target_link_libraries(DbusTesting
340 PUBLIC
341 velia-utils
342 SDBusCpp::sdbus-c++
343 )
Tomáš Pecka0a2e8902020-06-09 21:11:20 +0200344
Tomáš Pecka9b1c9672020-11-11 15:24:06 +0100345 add_library(FsTestUtils STATIC
346 tests/fs-helpers/FileInjector.cpp
347 tests/fs-helpers/FileInjector.h
348 tests/fs-helpers/utils.cpp
349 tests/fs-helpers/utils.h
350 )
351 target_link_libraries(FsTestUtils
352 PUBLIC
353 ${STD_FILESYSTEM_LIBRARY}
354 )
355
Václav Kubernát5a745d22021-11-12 12:09:57 +0100356 find_program(SYSREPOCTL sysrepoctl)
357 find_program(SYSREPOCFG sysrepocfg)
358
Tomáš Pecka5123e002020-06-05 15:29:21 +0200359 function(velia_test name)
Tomáš Pecka261c8862020-11-05 11:23:08 +0100360 add_executable(test-${name} ${CMAKE_SOURCE_DIR}/tests/${name}.cpp)
Václav Kubernát6677c222021-11-12 11:46:45 +0100361 target_link_libraries(test-${name} DoctestIntegration)
Tomáš Pecka261c8862020-11-05 11:23:08 +0100362 target_include_directories(test-${name}
363 PUBLIC
364 ${CMAKE_CURRENT_SOURCE_DIR}
365 PRIVATE
366 ${CMAKE_BINARY_DIR}
367 )
Tomáš Pecka5123e002020-06-05 15:29:21 +0200368
369 if(NOT CMAKE_CROSSCOMPILING)
Tomáš Pecka261c8862020-11-05 11:23:08 +0100370 add_test(test-${name} test-${name})
Tomáš Pecka5123e002020-06-05 15:29:21 +0200371 endif()
Tomáš Pecka5123e002020-06-05 15:29:21 +0200372
Tomáš Pecka98ad18d2020-11-13 15:39:55 +0100373 set(test_name_init sysrepo:prep:${name})
374 set(test_name_cleanup sysrepo:clean:${name})
375 set(fixture_name sysrepo:env:${name})
376
Václav Kubernát5a745d22021-11-12 12:09:57 +0100377 # How to do this:
378 # Check ARGN for name of fixture
379 # then take the args for manage module from variable "fixture{fixture_name}"
380 # and then add set env vars for sysrepo
381 # set them ALSO for the init/cleanup tests
382 if(ARGC GREATER 1)
383 set(wanted_fixture ${ARGV1})
384 add_test(NAME ${test_name_init} COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/tests/sysrepoctl-manage-module.sh ${SYSREPOCTL} ${SYSREPOCFG} prepare ${${wanted_fixture}})
385 set_tests_properties(${test_name_init} PROPERTIES FIXTURES_SETUP ${fixture_name})
386 add_test(NAME ${test_name_cleanup} COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/tests/sysrepoctl-manage-module.sh ${SYSREPOCTL} ${SYSREPOCFG} uninstall ${${wanted_fixture}})
387 set_tests_properties(${test_name_cleanup} PROPERTIES FIXTURES_CLEANUP ${fixture_name})
Tomáš Pecka98ad18d2020-11-13 15:39:55 +0100388
Václav Kubernát5a745d22021-11-12 12:09:57 +0100389 set_tests_properties(test-${name} PROPERTIES FIXTURES_REQUIRED ${fixture_name})
390 set_property(TEST test-${name} ${test_name_init} ${test_name_cleanup} APPEND PROPERTY ENVIRONMENT
391 "SYSREPO_REPOSITORY_PATH=${CMAKE_CURRENT_BINARY_DIR}/test_repositories/test_${name}"
392 "SYSREPO_SHM_PREFIX=velia_test_${name}"
393 )
Tomáš Pecka98ad18d2020-11-13 15:39:55 +0100394
Václav Kubernát5a745d22021-11-12 12:09:57 +0100395 endif()
396
Tomáš Pecka98ad18d2020-11-13 15:39:55 +0100397 endfunction()
398
Václav Kubernát6677c222021-11-12 11:46:45 +0100399 velia_test(health_state-manager)
400 target_link_libraries(test-health_state-manager velia-health)
401 velia_test(health_input-semaphore)
402 target_link_libraries(test-health_input-semaphore velia-health DbusTesting)
403 velia_test(health_input-systemd)
404 target_link_libraries(test-health_input-systemd velia-health DbusTesting)
405 velia_test(health_output-led)
406 target_link_libraries(test-health_output-led velia-health)
Tomáš Pecka491f4f22020-11-05 15:44:00 +0100407
Václav Kubernát6677c222021-11-12 11:46:45 +0100408 velia_test(system_rauc)
409 target_link_libraries(test-system_rauc velia-system DbusTesting)
Tomáš Peckacb7a5f82021-01-20 15:12:00 +0100410 set_tests_properties(
411 test-system_rauc
412 PROPERTIES RESOURCE_LOCK dbus-rauc
413 )
Tomáš Pecka991e4d52021-01-11 10:03:14 +0100414
Václav Kubernát6677c222021-11-12 11:46:45 +0100415 velia_test(system_lldp)
416 target_link_libraries(test-system_lldp velia-system DbusTesting)
Tomáš Pecka7acf3922021-08-10 11:16:57 +0200417
Václav Kubernát5a745d22021-11-12 12:09:57 +0100418 set(fixture_sysrepo-czechlight-lldp YANG ${CMAKE_CURRENT_SOURCE_DIR}/yang/czechlight-lldp@2020-11-04.yang)
419 velia_test(sysrepo_system-lldp fixture_sysrepo-czechlight-lldp)
Václav Kubernát6677c222021-11-12 11:46:45 +0100420 target_link_libraries(test-sysrepo_system-lldp velia-system DbusTesting)
Tomáš Pecka7acf3922021-08-10 11:16:57 +0200421
Václav Kubernát6677c222021-11-12 11:46:45 +0100422 velia_test(hardware_emmc)
423 target_link_libraries(test-hardware_emmc velia-ietf-hardware FsTestUtils)
424 velia_test(hardware_hwmon)
425 target_link_libraries(test-hardware_hwmon velia-ietf-hardware FsTestUtils)
Tomáš Pecka83b62e12020-12-16 14:50:49 +0100426
Václav Kubernát5a745d22021-11-12 12:09:57 +0100427 set(fixture_sysrepo-ietf-system YANG ${CMAKE_CURRENT_SOURCE_DIR}/yang/ietf-system@2014-08-06.yang)
428 velia_test(sysrepo_system-ietfsystem fixture_sysrepo-ietf-system)
Václav Kubernát6677c222021-11-12 11:46:45 +0100429 target_link_libraries(test-sysrepo_system-ietfsystem velia-system DbusTesting)
Tomáš Peckacb7a5f82021-01-20 15:12:00 +0100430
Václav Kubernát5a745d22021-11-12 12:09:57 +0100431 set(fixture_sysrepo-czechlight-system YANG ${CMAKE_CURRENT_SOURCE_DIR}/yang/czechlight-system@2021-01-13.yang)
432 velia_test(sysrepo_system-firmware fixture_sysrepo-czechlight-system)
Václav Kubernát6677c222021-11-12 11:46:45 +0100433 target_link_libraries(test-sysrepo_system-firmware velia-system DbusTesting SysrepoTesting)
Tomáš Peckacb7a5f82021-01-20 15:12:00 +0100434 set_tests_properties(
Tomáš Pecka594a6762021-01-29 11:06:08 +0100435 test-sysrepo_system-firmware
Václav Kubernát5a745d22021-11-12 12:09:57 +0100436 PROPERTIES RESOURCE_LOCK dbus-rauc
Tomáš Pecka292bc9c2021-01-11 22:03:11 +0100437 )
438
Václav Kubernát5a745d22021-11-12 12:09:57 +0100439 velia_test(sysrepo_authentication fixture_sysrepo-czechlight-system)
Václav Kubernát6677c222021-11-12 11:46:45 +0100440 target_link_libraries(test-sysrepo_authentication velia-system FsTestUtils)
Václav Kubernátbabbab92021-01-27 09:25:05 +0100441
Václav Kubernát5a745d22021-11-12 12:09:57 +0100442 velia_test(sysrepo_system-leds fixture_sysrepo-czechlight-system)
Václav Kubernát6677c222021-11-12 11:46:45 +0100443 target_link_libraries(test-sysrepo_system-leds velia-system FsTestUtils)
Tomáš Peckaaf7b7042021-04-20 20:14:13 +0200444
Václav Kubernát5a745d22021-11-12 12:09:57 +0100445 set(fixture_sysrepo-czechlight-network
Tomáš Peckaf10b9302021-02-23 19:02:02 +0100446 YANG ${CMAKE_CURRENT_SOURCE_DIR}/yang/iana-if-type@2017-01-19.yang
447 YANG ${CMAKE_CURRENT_SOURCE_DIR}/yang/ietf-interfaces@2018-02-20.yang
448 YANG ${CMAKE_CURRENT_SOURCE_DIR}/yang/ietf-ip@2018-02-22.yang
Tomáš Pecka2a4ea7b2021-03-30 17:01:37 +0200449 YANG ${CMAKE_CURRENT_SOURCE_DIR}/yang/ietf-routing@2018-03-13.yang
450 YANG ${CMAKE_CURRENT_SOURCE_DIR}/yang/ietf-ipv4-unicast-routing@2018-03-13.yang
451 YANG ${CMAKE_CURRENT_SOURCE_DIR}/yang/ietf-ipv6-unicast-routing@2018-03-13.yang
Tomáš Peckaf10b9302021-02-23 19:02:02 +0100452 YANG ${CMAKE_CURRENT_SOURCE_DIR}/yang/czechlight-network@2021-02-22.yang)
Tomáš Pecka9fa5f6a2021-04-13 11:36:11 +0200453
Václav Kubernát5a745d22021-11-12 12:09:57 +0100454 velia_test(sysrepo_system-ietfinterfaces fixture_sysrepo-czechlight-network)
Václav Kubernát6677c222021-11-12 11:46:45 +0100455 target_link_libraries(test-sysrepo_system-ietfinterfaces velia-system)
Tomáš Peckaf10b9302021-02-23 19:02:02 +0100456
Tomáš Pecka9fa5f6a2021-04-13 11:36:11 +0200457 if(TEST_NETWORK_WITH_SUDO)
458 find_program(SUDO_EXECUTABLE sudo REQUIRED)
459 find_program(IPROUTE2_EXECUTABLE ip REQUIRED)
460 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/tests/test_vars.h.in ${CMAKE_CURRENT_BINARY_DIR}/test_vars.h @ONLY)
461
462 add_test(NAME network-czechlight0-prepare COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/tests/sysrepo_system-ietfinterfaces-sudo.sh ${SUDO_EXECUTABLE})
463 add_test(NAME network-czechlight0-cleanup COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/tests/sysrepo_system-ietfinterfaces-sudo.sh ${SUDO_EXECUTABLE})
464 set_tests_properties(network-czechlight0-prepare PROPERTIES FIXTURES_SETUP network-czechlight0)
465 set_tests_properties(network-czechlight0-cleanup PROPERTIES FIXTURES_CLEANUP network-czechlight0)
466
Václav Kubernát5a745d22021-11-12 12:09:57 +0100467 velia_test(sysrepo_system-ietfinterfaces-sudo fixture_sysrepo-czechlight-network)
Václav Kubernát6677c222021-11-12 11:46:45 +0100468 target_link_libraries(test-sysrepo_system-ietfinterfaces-sudo velia-system)
Václav Kubernát5a745d22021-11-12 12:09:57 +0100469 set_property(TEST test-sysrepo_system-ietfinterfaces-sudo APPEND PROPERTY FIXTURES_REQUIRED network-czechlight0)
Tomáš Pecka9fa5f6a2021-04-13 11:36:11 +0200470 endif()
471
Václav Kubernát5a745d22021-11-12 12:09:57 +0100472 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)
473 velia_test(hardware_ietf-hardware fixture_sysrepo-ietf-hardware)
Václav Kubernát6677c222021-11-12 11:46:45 +0100474 target_link_libraries(test-hardware_ietf-hardware velia-ietf-hardware velia-ietf-hardware-sysrepo FsTestUtils)
Tomáš Pecka55f64f82020-12-10 19:03:30 +0100475
Václav Kubernát5a745d22021-11-12 12:09:57 +0100476 velia_test(sysrepo_two-daemons fixture_sysrepo-ietf-hardware)
Václav Kubernát6677c222021-11-12 11:46:45 +0100477 target_link_libraries(test-sysrepo_two-daemons velia-ietf-hardware-sysrepo)
Tomáš Pecka83b62e12020-12-16 14:50:49 +0100478 # 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 +0100479 add_executable(test-sysrepo_test_merge-daemon ${CMAKE_SOURCE_DIR}/tests/sysrepo_two-daemons_daemon.cpp)
480 target_link_libraries(test-sysrepo_test_merge-daemon PkgConfig::SYSREPO PkgConfig::LIBYANG)
481
482 add_test(NAME sysrepo_test_merge-start COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/tests/sysrepo_two-daemons_control.sh start)
483 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 +0100484 set_tests_properties(sysrepo_test_merge-start PROPERTIES FIXTURES_SETUP sysrepo:two-daemons)
485 set_tests_properties(sysrepo_test_merge-stop PROPERTIES FIXTURES_CLEANUP sysrepo:two-daemons)
486 set_property(TEST sysrepo_test_merge-start sysrepo_test_merge-stop APPEND PROPERTY ENVIRONMENT
487 "SYSREPO_REPOSITORY_PATH=${CMAKE_CURRENT_BINARY_DIR}/test_repositories/test_sysrepo_two-daemons"
488 "SYSREPO_SHM_PREFIX=velia_test_sysrepo_two-daemons"
489 )
Tomáš Pecka55f64f82020-12-10 19:03:30 +0100490
Václav Kubernát5a745d22021-11-12 12:09:57 +0100491 set_property(TEST test-sysrepo_two-daemons APPEND PROPERTY FIXTURES_REQUIRED sysrepo:two-daemons)
492
Tomáš Pecka83b62e12020-12-16 14:50:49 +0100493 # ensure we run two-daemons merge test and ietf-hardware test sequentially and don't cleanup before everything ends
494 set_tests_properties(sysrepo_test_merge-start PROPERTIES DEPENDS test-hardware_ietf-hardware)
Václav Kubernát5a745d22021-11-12 12:09:57 +0100495 set_tests_properties(sysrepo:clean:sysrepo_two-daemons PROPERTIES DEPENDS sysrepo_test_merge-stop)
Tomáš Pecka83b62e12020-12-16 14:50:49 +0100496
Tomáš Pecka73a13cc2020-11-17 11:12:19 +0100497
498 find_program(YANGLINT_PATH yanglint)
499 if (NOT YANGLINT_PATH)
500 message(FATAL_ERROR "Cannot find libyang's yanglint")
501 endif()
502 foreach(yang_file ${YANG_SRCS})
503 add_test(NAME yang-tree:${yang_file} COMMAND ${YANGLINT_PATH} -f tree ${CMAKE_CURRENT_SOURCE_DIR}/${yang_file})
504 endforeach()
Václav Kubernátd386aba2021-01-19 10:03:28 +0100505
Václav Kubernát5a745d22021-11-12 12:09:57 +0100506 set(fixture_sysrepo-firewall
Václav Kubernátd386aba2021-01-19 10:03:28 +0100507 # Installing czechlight-firewall automatically installs ietf-access-control-list as implemented (not just
508 # imported) but I still need to install it myself to enable the features.
509 YANG ${CMAKE_CURRENT_SOURCE_DIR}/yang/ietf-access-control-list@2019-03-04.yang
Václav Kubernátd386aba2021-01-19 10:03:28 +0100510 FEATURE match-on-eth
Václav Kubernát2b073632021-11-25 15:39:42 +0100511 FEATURE eth
Václav Kubernátd386aba2021-01-19 10:03:28 +0100512 FEATURE match-on-ipv4
513 FEATURE ipv4
514 FEATURE match-on-ipv6
515 FEATURE ipv6
516 FEATURE mixed-eth-ipv4-ipv6
517 YANG ${CMAKE_CURRENT_SOURCE_DIR}/yang/czechlight-firewall@2021-01-25.yang
518 )
519
Václav Kubernát5a745d22021-11-12 12:09:57 +0100520 velia_test(sysrepo-firewall fixture_sysrepo-firewall)
Václav Kubernát6677c222021-11-12 11:46:45 +0100521 target_link_libraries(test-sysrepo-firewall velia-firewall)
Tomáš Pecka261c8862020-11-05 11:23:08 +0100522endif()
Tomáš Peckac927d662020-07-13 11:16:16 +0200523
Tomáš Pecka5123e002020-06-05 15:29:21 +0200524if(WITH_DOCS)
525 set(doxyfile_in ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in)
526 set(doxyfile ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile)
527 configure_file(${doxyfile_in} ${doxyfile} @ONLY)
528 add_custom_target(doc
529 COMMAND ${DOXYGEN_EXECUTABLE} ${doxyfile}
530 WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
531 COMMENT "Generating API documentation with Doxygen"
532 VERBATIM
533 SOURCES ${doxyfile_in}
534 )
Tomáš Peckaa06d74d2020-06-14 18:18:13 +0200535endif()
Tomáš Pecka261c8862020-11-05 11:23:08 +0100536
Tomáš Pecka73a13cc2020-11-17 11:12:19 +0100537set(YANG_DIR ${CMAKE_INSTALL_PREFIX}/share/velia/yang)
538install(FILES ${YANG_SRCS} DESTINATION ${YANG_DIR})
Tomáš Peckaeb317722021-04-13 21:33:20 +0200539install(FILES ${CMAKE_SOURCE_DIR}/yang/ietf-ipv6-router-advertisements@2018-03-13.yang DESTINATION ${YANG_DIR})
Tomáš Peckacd19e622021-01-27 09:18:11 +0100540install(TARGETS veliad-health RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}/)
Tomáš Pecka625b7a12021-01-23 20:55:51 +0100541install(TARGETS veliad-system RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}/)
Tomáš Peckaaae9fe32021-01-25 19:57:22 +0100542install(TARGETS veliad-hardware RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}/)
Tomáš Peckafb14b182021-01-27 10:54:00 +0100543install(TARGETS veliad-firewall RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}/)