blob: 8b64dfe4097b63ada716f5a74fbd4ccd1148dd66 [file] [log] [blame]
Tomáš Pecka5123e002020-06-05 15:29:21 +02001project(velia LANGUAGES CXX)
Tomáš Peckaa06d74d2020-06-14 18:18:13 +02002cmake_minimum_required(VERSION 3.15)
Tomáš Pecka5123e002020-06-05 15:29:21 +02003
4# Build options
5set(CMAKE_CXX_STANDARD 17)
6set(CMAKE_CXX_STANDARD_REQUIRED ON)
7
8set(CMAKE_CXX_FLAGS_DEBUG "-Werror ${CMAKE_CXX_FLAGS_DEBUG}")
9set(CMAKE_CXX_FLAGS "-Wall -Wextra -pedantic -Woverloaded-virtual ${CMAKE_CXX_FLAGS}")
10if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
11 set(CMAKE_CXX_FLAGS "-Wsuggest-override ${CMAKE_CXX_FLAGS}")
12endif()
13
Tomáš Pecka5d4cf2a2020-07-13 13:19:41 +020014if(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)
16elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 9.1)
17 set(STD_FILESYSTEM_LIBRARY stdc++fs)
18endif()
19
20
Tomáš Pecka5123e002020-06-05 15:29:21 +020021add_custom_target(velia-version-cmake-ide
22 cmake/ProjectGitVersion.cmake
23 cmake/ProjectGitVersionRunner.cmake
24 )
25include(cmake/ProjectGitVersion.cmake)
26prepare_git_version(VELIA_VERSION "0.0")
27
28find_package(Doxygen)
29option(WITH_DOCS "Create and install internal documentation (needs Doxygen)" ${DOXYGEN_FOUND})
30
Václav Kubernátde0e4e62021-02-08 17:46:14 +010031find_package(Boost REQUIRED)
Tomáš Peckaa193c032020-06-22 17:33:31 +020032find_package(docopt REQUIRED)
Tomáš Pecka5123e002020-06-05 15:29:21 +020033find_package(spdlog REQUIRED)
Tomáš Pecka0a2e8902020-06-09 21:11:20 +020034find_package(sdbus-c++ REQUIRED)
Tomáš Peckaa4336812020-07-24 15:32:58 +020035find_package(PkgConfig)
Václav Kubernátbabbab92021-01-27 09:25:05 +010036find_package(fmt)
Tomáš Peckaa4336812020-07-24 15:32:58 +020037
38pkg_check_modules(SYSTEMD REQUIRED IMPORTED_TARGET libsystemd)
Tomáš Pecka1f42cfe2020-10-21 18:38:27 +020039if(${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.")
41endif()
Tomáš Pecka5123e002020-06-05 15:29:21 +020042
Jan Kundrát9b8bb732021-01-27 15:39:12 +010043pkg_check_modules(SYSREPO REQUIRED sysrepo-cpp>=1.4.103 IMPORTED_TARGET sysrepo)
44pkg_check_modules(LIBYANG REQUIRED libyang-cpp>=1.0.215 IMPORTED_TARGET libyang)
Tomáš Pecka98ad18d2020-11-13 15:39:55 +010045
Tomáš Peckac927d662020-07-13 11:16:16 +020046include(GNUInstallDirs)
47
Tomáš Pecka261c8862020-11-05 11:23:08 +010048include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/)
49
Tomáš Pecka73a13cc2020-11-17 11:12:19 +010050set(YANG_SRCS
Tomáš Pecka9a02c3f2021-01-21 15:27:22 +010051 yang/czechlight-system@2021-01-13.yang
Tomáš Pecka73a13cc2020-11-17 11:12:19 +010052 yang/iana-hardware@2018-03-13.yang
Tomáš Pecka73a13cc2020-11-17 11:12:19 +010053 yang/ietf-hardware@2018-03-13.yang
Tomáš Peckaf98ce032021-01-14 13:35:00 +010054 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áš Pecka435ca2a2021-01-27 10:53:48 +010059 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át637fe802021-01-22 02:43:18 +010062 yang/ietf-access-control-list@2019-03-04.yang
Václav Kubernát457d1ad2021-01-22 02:43:18 +010063 yang/czechlight-firewall@2021-01-25.yang
Tomáš Pecka73a13cc2020-11-17 11:12:19 +010064 )
65
Tomáš Pecka5123e002020-06-05 15:29:21 +020066# Targets
Tomáš Pecka261c8862020-11-05 11:23:08 +010067# - utils
Tomáš Peckabd828862020-06-15 15:53:35 +020068add_library(velia-utils STATIC
Tomáš Peckaa193c032020-06-22 17:33:31 +020069 src/utils/exceptions.cpp
Tomáš Pecka261c8862020-11-05 11:23:08 +010070 src/utils/exceptions.h
Václav Kubernát6d9357e2021-01-28 15:38:24 +010071 src/utils/exec.cpp
72 src/utils/exec.h
Tomáš Pecka491f4f22020-11-05 15:44:00 +010073 src/utils/io.cpp
74 src/utils/io.h
Tomáš Peckaa4336812020-07-24 15:32:58 +020075 src/utils/journal.cpp
Tomáš Pecka261c8862020-11-05 11:23:08 +010076 src/utils/journal.h
Václav Kubernátcbdc98a2021-01-28 13:24:37 +010077 src/utils/libyang.cpp
78 src/utils/libyang.h
Tomáš Pecka261c8862020-11-05 11:23:08 +010079 src/utils/log.h
Václav Kubernát6018f082021-02-11 01:32:18 +010080 src/utils/log.cpp
Tomáš Pecka261c8862020-11-05 11:23:08 +010081 src/utils/log-fwd.h
Tomáš Pecka5123e002020-06-05 15:29:21 +020082 src/utils/log-init.cpp
Tomáš Pecka261c8862020-11-05 11:23:08 +010083 src/utils/log-init.h
Tomáš Peckaba2dc312021-01-23 22:29:11 +010084 src/utils/sysrepo.cpp
85 src/utils/sysrepo.h
Tomáš Pecka339bc672020-11-11 15:59:03 +010086 src/utils/time.cpp
87 src/utils/time.h
Tomáš Peckad0337072021-01-25 19:57:00 +010088 src/utils/waitUntilSignalled.cpp
89 src/utils/waitUntilSignalled.h
Tomáš Pecka5123e002020-06-05 15:29:21 +020090 )
Václav Kubernát6018f082021-02-11 01:32:18 +010091target_link_libraries(velia-utils PUBLIC spdlog::spdlog PRIVATE PkgConfig::SYSTEMD PkgConfig::SYSREPO fmt::fmt docopt)
Tomáš Peckaa4336812020-07-24 15:32:58 +020092
Tomáš Pecka261c8862020-11-05 11:23:08 +010093# - health
94add_library(velia-health STATIC
95 src/health/inputs/AbstractInput.cpp
96 src/health/inputs/DbusSemaphoreInput.cpp
97 src/health/inputs/DbusSystemdInput.cpp
98 src/health/manager/AbstractManager.cpp
99 src/health/manager/StateManager.cpp
100 src/health/outputs/LedSysfsDriver.cpp
101 src/health/outputs/callables.cpp
102 src/health/State.cpp
Tomáš Pecka74b885f2020-06-06 20:02:41 +0200103 )
Tomáš Pecka261c8862020-11-05 11:23:08 +0100104target_link_libraries(velia-health
105 PUBLIC
106 velia-utils
107 Boost::boost
108 SDBusCpp::sdbus-c++
109 ${STD_FILESYSTEM_LIBRARY}
110 )
Tomáš Pecka74b885f2020-06-06 20:02:41 +0200111
Tomáš Pecka491f4f22020-11-05 15:44:00 +0100112# - ietf-hardware
113add_library(velia-ietf-hardware STATIC
114 src/ietf-hardware/sysfs/EMMC.cpp
115 src/ietf-hardware/sysfs/EMMC.h
Tomáš Pecka9b1c9672020-11-11 15:24:06 +0100116 src/ietf-hardware/sysfs/HWMon.cpp
117 src/ietf-hardware/sysfs/HWMon.h
Tomáš Pecka339bc672020-11-11 15:59:03 +0100118 src/ietf-hardware/IETFHardware.cpp
119 src/ietf-hardware/IETFHardware.h
Tomáš Pecka491f4f22020-11-05 15:44:00 +0100120 )
121target_link_libraries(velia-ietf-hardware
122 PUBLIC
123 velia-utils
124 ${STD_FILESYSTEM_LIBRARY}
Tomáš Pecka9b1c9672020-11-11 15:24:06 +0100125 Boost::boost
Tomáš Pecka491f4f22020-11-05 15:44:00 +0100126 )
Tomáš Pecka491f4f22020-11-05 15:44:00 +0100127
Tomáš Pecka98ad18d2020-11-13 15:39:55 +0100128add_library(velia-ietf-hardware-sysrepo STATIC
Tomáš Pecka98ad18d2020-11-13 15:39:55 +0100129 src/ietf-hardware/sysrepo/Sysrepo.cpp
130 src/ietf-hardware/sysrepo/Sysrepo.h
131 )
132target_link_libraries(velia-ietf-hardware-sysrepo
133 PUBLIC
134 velia-utils
135 PkgConfig::SYSREPO
136 PkgConfig::LIBYANG
137 )
Tomáš Pecka5123e002020-06-05 15:29:21 +0200138
Václav Kubernát6d9357e2021-01-28 15:38:24 +0100139set(NOBODY_UID 65534 CACHE STRING "UID which refers to 'nobody'. Used for dropping root privileges.")
140set(NOBODY_GID 65534 CACHE STRING "GID which refers to 'nobody'. Used for dropping root privileges.")
141
Václav Kubernátde0e4e62021-02-08 17:46:14 +0100142if(NOT NFT_EXECUTABLE)
143 find_program(NFT_EXECUTABLE nft)
144endif()
Václav Kubernátbabbab92021-01-27 09:25:05 +0100145if(NOT SSH_KEYGEN_EXECUTABLE)
146 find_program(SSH_KEYGEN_EXECUTABLE ssh-keygen)
147endif()
148if(NOT CHPASSWD_EXECUTABLE)
149 find_program(CHPASSWD_EXECUTABLE chpasswd)
150endif()
Tomáš Pecka879a6032021-02-03 17:21:48 +0100151if(NOT SYSTEMCTL_EXECUTABLE)
152 find_program(SYSTEMCTL_EXECUTABLE systemctl)
153endif()
Tomáš Pecka5c19e722021-02-15 20:41:29 +0100154if(NOT NETWORKCTL_EXECUTABLE)
155 find_program(NETWORKCTL_EXECUTABLE networkctl)
156endif()
Václav Kubernát566c9402021-02-10 08:33:54 +0100157if(NOT HOSTNAMECTL_EXECUTABLE)
158 find_program(HOSTNAMECTL_EXECUTABLE hostnamectl)
159endif()
Václav Kubernátbabbab92021-01-27 09:25:05 +0100160
161set(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.")
162if(NOT VELIA_AUTHORIZED_KEYS_FORMAT)
163 message(FATAL_ERROR "VELIA_AUTHORIZED_KEYS_FORMAT not set.")
164endif()
165
166if(NOT VELIA_AUTHORIZED_KEYS_FORMAT MATCHES "{USER}" AND NOT VELIA_AUTHORIZED_KEYS_FORMAT MATCHES "{HOME}")
167 message(FATAL_ERROR "Wrong format string given for VELIA_AUTHORIZED_KEYS_FORMAT: at least one of {USER} or {HOME} expected.")
168endif()
169
170set(VELIA_REAL_ETC_PASSWD "/etc/passwd" CACHE STRING "Path to passwd file")
171if(NOT VELIA_REAL_ETC_PASSWD)
172 message(FATAL_ERROR "VELIA_REAL_ETC_PASSWD not set")
173endif()
174
175set(VELIA_REAL_ETC_SHADOW "/etc/shadow" CACHE STRING "Path to shadow file")
176if(NOT VELIA_REAL_ETC_SHADOW)
177 message(FATAL_ERROR "VELIA_REAL_ETC_SHADOW not set")
178endif()
179
180set(VELIA_BACKUP_ETC_SHADOW "/etc/shadow" CACHE STRING "Path to where /etc/shadow gets copied to upon each change")
181if(NOT VELIA_BACKUP_ETC_SHADOW)
182 message(FATAL_ERROR "VELIA_BACKUP_ETC_SHADOW not set")
183endif()
Václav Kubernátde0e4e62021-02-08 17:46:14 +0100184
Václav Kubernát566c9402021-02-10 08:33:54 +0100185set(VELIA_BACKUP_ETC_HOSTNAME "/etc/hostname" CACHE STRING "Path to hostname file")
186if(NOT VELIA_BACKUP_ETC_HOSTNAME )
187 message(FATAL_ERROR "VELIA_BACKUP_ETC_HOSTNAME not set")
188endif()
189
Václav Kubernát6d9357e2021-01-28 15:38:24 +0100190configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/system/system_vars.h.in ${CMAKE_CURRENT_BINARY_DIR}/system_vars.h @ONLY)
191include_directories(${CMAKE_CURRENT_BINARY_DIR})
192
Tomáš Pecka292bc9c2021-01-11 22:03:11 +0100193# - ietf-system
194add_library(velia-system STATIC
Tomáš Pecka991e4d52021-01-11 10:03:14 +0100195 src/system/RAUC.cpp
196 src/system/RAUC.h
Tomáš Pecka594a6762021-01-29 11:06:08 +0100197 src/system/Firmware.cpp
198 src/system/Firmware.h
Tomáš Peckaf976c5b2021-01-23 21:19:52 +0100199 src/system/IETFSystem.cpp
200 src/system/IETFSystem.h
Václav Kubernátbabbab92021-01-27 09:25:05 +0100201 src/system/Authentication.cpp
202 src/system/Authentication.h
Tomáš Pecka5c19e722021-02-15 20:41:29 +0100203 src/system/Network.cpp
204 src/system/Network.h
Tomáš Pecka292bc9c2021-01-11 22:03:11 +0100205 )
206target_link_libraries(velia-system
207 PUBLIC
208 velia-utils
209 PkgConfig::SYSREPO
210 PkgConfig::LIBYANG
Václav Kubernát6dd52c82021-01-21 08:38:42 +0100211 SDBusCpp::sdbus-c++
Tomáš Pecka292bc9c2021-01-11 22:03:11 +0100212 )
213
Václav Kubernátd386aba2021-01-19 10:03:28 +0100214# - firewall
215add_library(velia-firewall STATIC
216 src/firewall/Firewall.cpp
217 )
218target_link_libraries(velia-firewall
219 PUBLIC
220 velia-utils
221 PkgConfig::SYSREPO
222 PRIVATE
223 PkgConfig::LIBYANG
224 )
225
226
Tomáš Pecka625b7a12021-01-23 20:55:51 +0100227# - daemons
Tomáš Peckacd19e622021-01-27 09:18:11 +0100228add_executable(veliad-health
229 src/main-health.cpp
Tomáš Pecka139e3612021-01-25 19:49:00 +0100230 src/health/Factory.cpp
231 src/health/Factory.h
232 )
Tomáš Peckacd19e622021-01-27 09:18:11 +0100233target_link_libraries(veliad-health
Tomáš Peckaaae9fe32021-01-25 19:57:22 +0100234 PUBLIC
Tomáš Peckad03044f2020-11-12 14:33:10 +0100235 velia-health
Tomáš Peckad03044f2020-11-12 14:33:10 +0100236 docopt
Tomáš Peckaaae9fe32021-01-25 19:57:22 +0100237 )
Tomáš Peckacd19e622021-01-27 09:18:11 +0100238add_dependencies(veliad-health target-VELIA_VERSION)
239target_include_directories(veliad-health PUBLIC ${CMAKE_BINARY_DIR})
Tomáš Peckad03044f2020-11-12 14:33:10 +0100240
Tomáš Pecka625b7a12021-01-23 20:55:51 +0100241add_executable(veliad-system
242 src/main-system.cpp
243 )
244target_link_libraries(veliad-system
245 PUBLIC
246 velia-system
247 docopt
248 )
249add_dependencies(veliad-system target-VELIA_VERSION)
250target_include_directories(veliad-system PUBLIC ${CMAKE_BINARY_DIR})
251
Václav Kubernátd386aba2021-01-19 10:03:28 +0100252add_executable(veliad-firewall
253 src/main-firewall.cpp
254 )
255target_link_libraries(veliad-firewall
256 PUBLIC
257 velia-firewall
258 velia-utils
Václav Kubernátd386aba2021-01-19 10:03:28 +0100259 docopt
260 )
261add_dependencies(veliad-firewall target-VELIA_VERSION)
262target_include_directories(veliad-firewall PUBLIC ${CMAKE_BINARY_DIR})
263
Tomáš Peckaaae9fe32021-01-25 19:57:22 +0100264add_executable(veliad-hardware
265 src/main-hardware.cpp
266 src/ietf-hardware/Factory.cpp
267 src/ietf-hardware/Factory.h
268 )
269target_link_libraries(veliad-hardware
270 PUBLIC
271 velia-ietf-hardware
272 velia-ietf-hardware-sysrepo
273 docopt
274 )
275add_dependencies(veliad-hardware target-VELIA_VERSION)
276target_include_directories(veliad-hardware PUBLIC ${CMAKE_BINARY_DIR})
277
Tomáš Pecka5123e002020-06-05 15:29:21 +0200278# Testing
Tomáš Peckaa06d74d2020-06-14 18:18:13 +0200279include(CTest)
Tomáš Pecka5123e002020-06-05 15:29:21 +0200280if(BUILD_TESTING)
Tomáš Pecka5123e002020-06-05 15:29:21 +0200281 find_package(trompeloeil 33 REQUIRED)
282 find_package(doctest 2.3.1 REQUIRED)
283
Tomáš Peckaefd88432020-06-17 15:31:39 +0200284 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/tests/configure.cmake.h.in ${CMAKE_CURRENT_BINARY_DIR}/tests/configure.cmake.h)
285
Tomáš Pecka5123e002020-06-05 15:29:21 +0200286 add_library(DoctestIntegration STATIC
Tomáš Pecka261c8862020-11-05 11:23:08 +0100287 tests/doctest_integration.cpp
288 tests/trompeloeil_doctest.h
289 tests/wait-a-bit-longer.cpp
290 )
Tomáš Pecka5123e002020-06-05 15:29:21 +0200291 target_link_libraries(DoctestIntegration doctest::doctest trompeloeil spdlog::spdlog)
Tomáš Pecka261c8862020-11-05 11:23:08 +0100292 target_include_directories(DoctestIntegration PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/tests/)
Tomáš Pecka5123e002020-06-05 15:29:21 +0200293 target_compile_definitions(DoctestIntegration PUBLIC DOCTEST_CONFIG_SUPER_FAST_ASSERTS)
294
Tomáš Peckaa18702d2021-01-25 18:07:23 +0100295 add_library(SysrepoTesting STATIC
296 tests/mock/sysrepo/events.cpp
297 tests/mock/sysrepo/events.h
298 )
299 target_link_libraries(SysrepoTesting DoctestIntegration PkgConfig::SYSREPO)
300
Tomáš Pecka0a2e8902020-06-09 21:11:20 +0200301 add_library(DbusTesting STATIC
Tomáš Pecka991e4d52021-01-11 10:03:14 +0100302 tests/dbus-helpers/dbus_rauc_server.cpp
303 tests/dbus-helpers/dbus_rauc_server.h
Tomáš Pecka0a2e8902020-06-09 21:11:20 +0200304 tests/dbus-helpers/dbus_semaphore_server.cpp
Tomáš Pecka261c8862020-11-05 11:23:08 +0100305 tests/dbus-helpers/dbus_semaphore_server.h
Tomáš Peckaccd80c32020-06-22 14:44:32 +0200306 tests/dbus-helpers/dbus_systemd_server.cpp
Tomáš Pecka261c8862020-11-05 11:23:08 +0100307 tests/dbus-helpers/dbus_systemd_server.h
308 )
309 target_link_libraries(DbusTesting
310 PUBLIC
311 velia-utils
312 SDBusCpp::sdbus-c++
313 )
Tomáš Pecka0a2e8902020-06-09 21:11:20 +0200314
Tomáš Pecka9b1c9672020-11-11 15:24:06 +0100315 add_library(FsTestUtils STATIC
316 tests/fs-helpers/FileInjector.cpp
317 tests/fs-helpers/FileInjector.h
318 tests/fs-helpers/utils.cpp
319 tests/fs-helpers/utils.h
320 )
321 target_link_libraries(FsTestUtils
322 PUBLIC
323 ${STD_FILESYSTEM_LIBRARY}
324 )
325
Tomáš Pecka5123e002020-06-05 15:29:21 +0200326 function(velia_test name)
Tomáš Pecka261c8862020-11-05 11:23:08 +0100327 add_executable(test-${name} ${CMAKE_SOURCE_DIR}/tests/${name}.cpp)
328 target_link_libraries(test-${name} DoctestIntegration ${ARGN})
329 target_include_directories(test-${name}
330 PUBLIC
331 ${CMAKE_CURRENT_SOURCE_DIR}
332 PRIVATE
333 ${CMAKE_BINARY_DIR}
334 )
Tomáš Pecka5123e002020-06-05 15:29:21 +0200335
336 if(NOT CMAKE_CROSSCOMPILING)
Tomáš Pecka261c8862020-11-05 11:23:08 +0100337 add_test(test-${name} test-${name})
Tomáš Pecka5123e002020-06-05 15:29:21 +0200338 endif()
Tomáš Pecka5123e002020-06-05 15:29:21 +0200339 endfunction()
Tomáš Pecka5123e002020-06-05 15:29:21 +0200340
Tomáš Pecka98ad18d2020-11-13 15:39:55 +0100341 find_program(SYSREPOCTL sysrepoctl)
342 find_program(SYSREPOCFG sysrepocfg)
343
344 set(sysrepo_previous_fixture_name UNDEFINED)
345 function(sysrepo_fixture_env name)
346 set(test_name_init sysrepo:prep:${name})
347 set(test_name_cleanup sysrepo:clean:${name})
348 set(fixture_name sysrepo:env:${name})
349
350 add_test(NAME ${test_name_init} COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/tests/sysrepoctl-manage-module.sh ${SYSREPOCTL} ${SYSREPOCFG} prepare ${ARGN})
351 set_tests_properties(${test_name_init} PROPERTIES FIXTURES_SETUP ${fixture_name} RESOURCE_LOCK sysrepo)
352 add_test(NAME ${test_name_cleanup} COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/tests/sysrepoctl-manage-module.sh ${SYSREPOCTL} ${SYSREPOCFG} uninstall ${ARGN})
353 set_tests_properties(${test_name_cleanup} PROPERTIES FIXTURES_CLEANUP ${fixture_name} RESOURCE_LOCK sysrepo)
354
355 if (sysrepo_previous_fixture_name)
356 set_tests_properties(${test_name_init} PROPERTIES DEPENDS sysrepo:clean:${sysrepo_previous_fixture_name})
357 endif ()
358
359 set(sysrepo_previous_fixture_name ${name} PARENT_SCOPE)
360 endfunction()
361
Tomáš Pecka261c8862020-11-05 11:23:08 +0100362 velia_test(health_state-manager velia-health)
363 velia_test(health_input-semaphore velia-health DbusTesting)
364 velia_test(health_input-systemd velia-health DbusTesting)
365 velia_test(health_output-led velia-health)
Tomáš Pecka491f4f22020-11-05 15:44:00 +0100366
Tomáš Pecka991e4d52021-01-11 10:03:14 +0100367 velia_test(system_rauc velia-system DbusTesting)
Tomáš Peckacb7a5f82021-01-20 15:12:00 +0100368 set_tests_properties(
369 test-system_rauc
370 PROPERTIES RESOURCE_LOCK dbus-rauc
371 )
Tomáš Pecka991e4d52021-01-11 10:03:14 +0100372
Tomáš Pecka9b1c9672020-11-11 15:24:06 +0100373 velia_test(hardware_emmc velia-ietf-hardware FsTestUtils)
374 velia_test(hardware_hwmon velia-ietf-hardware FsTestUtils)
Tomáš Pecka83b62e12020-12-16 14:50:49 +0100375
Tomáš Pecka292bc9c2021-01-11 22:03:11 +0100376 sysrepo_fixture_env(sysrepo-ietf-system YANG ${CMAKE_CURRENT_SOURCE_DIR}/yang/ietf-system@2014-08-06.yang)
Tomáš Peckaf976c5b2021-01-23 21:19:52 +0100377 velia_test(sysrepo_system-ietfsystem velia-system DbusTesting)
Tomáš Pecka292bc9c2021-01-11 22:03:11 +0100378 set_tests_properties(
Tomáš Peckaf976c5b2021-01-23 21:19:52 +0100379 test-sysrepo_system-ietfsystem
Tomáš Pecka292bc9c2021-01-11 22:03:11 +0100380 PROPERTIES FIXTURES_REQUIRED sysrepo:env:sysrepo-ietf-system
381 RESOURCE_LOCK sysrepo
Tomáš Peckacb7a5f82021-01-20 15:12:00 +0100382)
383
384 sysrepo_fixture_env(sysrepo-czechlight-system YANG ${CMAKE_CURRENT_SOURCE_DIR}/yang/czechlight-system@2021-01-13.yang)
Tomáš Pecka594a6762021-01-29 11:06:08 +0100385 velia_test(sysrepo_system-firmware velia-system DbusTesting)
386 target_link_libraries(test-sysrepo_system-firmware SysrepoTesting)
Tomáš Peckacb7a5f82021-01-20 15:12:00 +0100387 set_tests_properties(
Tomáš Pecka594a6762021-01-29 11:06:08 +0100388 test-sysrepo_system-firmware
Tomáš Peckacb7a5f82021-01-20 15:12:00 +0100389 PROPERTIES FIXTURES_REQUIRED sysrepo:env:sysrepo-czechlight-system
390 RESOURCE_LOCK "sysrepo;dbus-rauc"
Tomáš Pecka292bc9c2021-01-11 22:03:11 +0100391 )
392
Václav Kubernátbabbab92021-01-27 09:25:05 +0100393 velia_test(sysrepo_authentication velia-system FsTestUtils)
394
395 set_tests_properties(
396 test-sysrepo_authentication
397 PROPERTIES FIXTURES_REQUIRED sysrepo:env:sysrepo-czechlight-system
398 RESOURCE_LOCK sysrepo
399 )
400
Tomáš Pecka5c19e722021-02-15 20:41:29 +0100401 velia_test(sysrepo_system-network velia-system)
402 target_link_libraries(test-sysrepo_system-network FsTestUtils)
403 set_tests_properties(
404 test-sysrepo_system-network
405 PROPERTIES FIXTURES_REQUIRED sysrepo:env:sysrepo-czechlight-system
406 RESOURCE_LOCK sysrepo
407 )
408
Tomáš Pecka83b62e12020-12-16 14:50:49 +0100409 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áš Pecka98ad18d2020-11-13 15:39:55 +0100410 velia_test(hardware_ietf-hardware velia-ietf-hardware velia-ietf-hardware-sysrepo)
Tomáš Pecka98ad18d2020-11-13 15:39:55 +0100411 set_tests_properties(
412 test-hardware_ietf-hardware
Tomáš Pecka83b62e12020-12-16 14:50:49 +0100413 PROPERTIES FIXTURES_REQUIRED sysrepo:env:sysrepo-ietf-hardware
Tomáš Pecka55f64f82020-12-10 19:03:30 +0100414 RESOURCE_LOCK sysrepo
415 )
416
417 velia_test(sysrepo_two-daemons velia-ietf-hardware-sysrepo)
Tomáš Pecka83b62e12020-12-16 14:50:49 +0100418 # 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 +0100419 add_executable(test-sysrepo_test_merge-daemon ${CMAKE_SOURCE_DIR}/tests/sysrepo_two-daemons_daemon.cpp)
420 target_link_libraries(test-sysrepo_test_merge-daemon PkgConfig::SYSREPO PkgConfig::LIBYANG)
421
422 add_test(NAME sysrepo_test_merge-start COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/tests/sysrepo_two-daemons_control.sh start)
423 add_test(NAME sysrepo_test_merge-stop COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/tests/sysrepo_two-daemons_control.sh stop)
424 set_tests_properties(sysrepo_test_merge-start PROPERTIES FIXTURES_SETUP sysrepo:two-daemons RESOURCE_LOCK sysrepo)
425 set_tests_properties(sysrepo_test_merge-stop PROPERTIES FIXTURES_CLEANUP sysrepo:two-daemons RESOURCE_LOCK sysrepo)
Tomáš Pecka55f64f82020-12-10 19:03:30 +0100426
427 set_tests_properties(
428 test-sysrepo_two-daemons
429 PROPERTIES
430 FIXTURES_REQUIRED "sysrepo:two-daemons;sysrepo:env:sysrepo-ietf-hardware"
Tomáš Pecka98ad18d2020-11-13 15:39:55 +0100431 RESOURCE_LOCK sysrepo
432 )
Tomáš Pecka83b62e12020-12-16 14:50:49 +0100433 # ensure we run two-daemons merge test and ietf-hardware test sequentially and don't cleanup before everything ends
434 set_tests_properties(sysrepo_test_merge-start PROPERTIES DEPENDS test-hardware_ietf-hardware)
435 set_tests_properties(sysrepo:clean:sysrepo-ietf-hardware PROPERTIES DEPENDS sysrepo_test_merge-stop)
436
Tomáš Pecka73a13cc2020-11-17 11:12:19 +0100437
438 find_program(YANGLINT_PATH yanglint)
439 if (NOT YANGLINT_PATH)
440 message(FATAL_ERROR "Cannot find libyang's yanglint")
441 endif()
442 foreach(yang_file ${YANG_SRCS})
443 add_test(NAME yang-tree:${yang_file} COMMAND ${YANGLINT_PATH} -f tree ${CMAKE_CURRENT_SOURCE_DIR}/${yang_file})
444 endforeach()
Václav Kubernátd386aba2021-01-19 10:03:28 +0100445
446 sysrepo_fixture_env(sysrepo-firewall
447 # Installing czechlight-firewall automatically installs ietf-access-control-list as implemented (not just
448 # imported) but I still need to install it myself to enable the features.
449 YANG ${CMAKE_CURRENT_SOURCE_DIR}/yang/ietf-access-control-list@2019-03-04.yang
450 FEATURE eth
451 FEATURE match-on-eth
452 FEATURE match-on-ipv4
453 FEATURE ipv4
454 FEATURE match-on-ipv6
455 FEATURE ipv6
456 FEATURE mixed-eth-ipv4-ipv6
457 YANG ${CMAKE_CURRENT_SOURCE_DIR}/yang/czechlight-firewall@2021-01-25.yang
458 )
459
460 velia_test(sysrepo-firewall velia-firewall)
461 set_tests_properties(
462 test-sysrepo-firewall
463 PROPERTIES FIXTURES_REQUIRED sysrepo:env:sysrepo-firewall
464 RESOURCE_LOCK sysrepo
465 )
Tomáš Pecka261c8862020-11-05 11:23:08 +0100466endif()
Tomáš Peckac927d662020-07-13 11:16:16 +0200467
Tomáš Pecka5123e002020-06-05 15:29:21 +0200468if(WITH_DOCS)
469 set(doxyfile_in ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in)
470 set(doxyfile ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile)
471 configure_file(${doxyfile_in} ${doxyfile} @ONLY)
472 add_custom_target(doc
473 COMMAND ${DOXYGEN_EXECUTABLE} ${doxyfile}
474 WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
475 COMMENT "Generating API documentation with Doxygen"
476 VERBATIM
477 SOURCES ${doxyfile_in}
478 )
Tomáš Peckaa06d74d2020-06-14 18:18:13 +0200479endif()
Tomáš Pecka261c8862020-11-05 11:23:08 +0100480
Tomáš Pecka73a13cc2020-11-17 11:12:19 +0100481set(YANG_DIR ${CMAKE_INSTALL_PREFIX}/share/velia/yang)
482install(FILES ${YANG_SRCS} DESTINATION ${YANG_DIR})
Tomáš Peckacd19e622021-01-27 09:18:11 +0100483install(TARGETS veliad-health RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}/)
Tomáš Pecka625b7a12021-01-23 20:55:51 +0100484install(TARGETS veliad-system RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}/)
Tomáš Peckaaae9fe32021-01-25 19:57:22 +0100485install(TARGETS veliad-hardware RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}/)
Tomáš Peckafb14b182021-01-27 10:54:00 +0100486install(TARGETS veliad-firewall RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}/)