blob: c0c9a68ab614b835d622bc8cadbb87cb8f200c2f [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
Václav Kubernátb332d982021-04-16 01:40:11 +02005set(CMAKE_CXX_STANDARD 20)
Tomáš Pecka5123e002020-06-05 15:29:21 +02006set(CMAKE_CXX_STANDARD_REQUIRED ON)
7
8set(CMAKE_CXX_FLAGS_DEBUG "-Werror ${CMAKE_CXX_FLAGS_DEBUG}")
Václav Kubernátd4b8a692021-04-16 01:21:44 +02009set(CMAKE_CXX_FLAGS "-Wall -Wextra -pedantic -Woverloaded-virtual -Wimplicit-fallthrough ${CMAKE_CXX_FLAGS}")
Tomáš Pecka5123e002020-06-05 15:29:21 +020010if("${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
Tomáš Pecka0b291da2021-06-02 18:08:18 +020043pkg_check_modules(SYSREPO REQUIRED sysrepo-cpp>=1.4.140 IMPORTED_TARGET sysrepo)
44pkg_check_modules(LIBYANG REQUIRED libyang-cpp>=1.0.241 IMPORTED_TARGET libyang)
Tomáš Pecka2d578c82021-02-23 19:01:35 +010045pkg_check_modules(LIBNL REQUIRED IMPORTED_TARGET libnl-route-3.0)
Tomáš Pecka98ad18d2020-11-13 15:39:55 +010046
Tomáš Peckac927d662020-07-13 11:16:16 +020047include(GNUInstallDirs)
48
Tomáš Pecka261c8862020-11-05 11:23:08 +010049include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/)
50
Tomáš Pecka73a13cc2020-11-17 11:12:19 +010051set(YANG_SRCS
Tomáš Pecka9a02c3f2021-01-21 15:27:22 +010052 yang/czechlight-system@2021-01-13.yang
Tomáš Pecka73a13cc2020-11-17 11:12:19 +010053 yang/iana-hardware@2018-03-13.yang
Tomáš Pecka73a13cc2020-11-17 11:12:19 +010054 yang/ietf-hardware@2018-03-13.yang
Tomáš Peckaf98ce032021-01-14 13:35:00 +010055 yang/iana-crypt-hash@2014-08-06.yang
56 yang/ietf-inet-types@2013-07-15.yang
57 yang/ietf-netconf-acm@2018-02-14.yang
58 yang/ietf-system@2014-08-06.yang
59 yang/ietf-yang-types@2013-07-15.yang
Tomáš Pecka435ca2a2021-01-27 10:53:48 +010060 yang/ietf-ethertypes@2019-03-04.yang
61 yang/ietf-interfaces@2018-02-20.yang
62 yang/ietf-packet-fields@2019-03-04.yang
Václav Kubernát637fe802021-01-22 02:43:18 +010063 yang/ietf-access-control-list@2019-03-04.yang
Václav Kubernát457d1ad2021-01-22 02:43:18 +010064 yang/czechlight-firewall@2021-01-25.yang
Tomáš Peckadac27d42021-02-22 13:20:05 +010065 yang/czechlight-network@2021-02-22.yang
66 yang/iana-if-type@2017-01-19.yang
67 yang/ietf-ip@2018-02-22.yang
Tomáš Pecka2a4ea7b2021-03-30 17:01:37 +020068 yang/ietf-routing@2018-03-13.yang
69 yang/ietf-ipv4-unicast-routing@2018-03-13.yang
70 yang/ietf-ipv6-unicast-routing@2018-03-13.yang
Tomáš Pecka73a13cc2020-11-17 11:12:19 +010071 )
72
Tomáš Pecka5123e002020-06-05 15:29:21 +020073# Targets
Tomáš Pecka261c8862020-11-05 11:23:08 +010074# - utils
Tomáš Peckabd828862020-06-15 15:53:35 +020075add_library(velia-utils STATIC
Tomáš Peckaa193c032020-06-22 17:33:31 +020076 src/utils/exceptions.cpp
Tomáš Pecka261c8862020-11-05 11:23:08 +010077 src/utils/exceptions.h
Václav Kubernát6d9357e2021-01-28 15:38:24 +010078 src/utils/exec.cpp
79 src/utils/exec.h
Tomáš Pecka491f4f22020-11-05 15:44:00 +010080 src/utils/io.cpp
81 src/utils/io.h
Tomáš Peckaa4336812020-07-24 15:32:58 +020082 src/utils/journal.cpp
Tomáš Pecka261c8862020-11-05 11:23:08 +010083 src/utils/journal.h
Václav Kubernátcbdc98a2021-01-28 13:24:37 +010084 src/utils/libyang.cpp
85 src/utils/libyang.h
Tomáš Pecka261c8862020-11-05 11:23:08 +010086 src/utils/log.h
Václav Kubernát6018f082021-02-11 01:32:18 +010087 src/utils/log.cpp
Tomáš Pecka261c8862020-11-05 11:23:08 +010088 src/utils/log-fwd.h
Tomáš Pecka5123e002020-06-05 15:29:21 +020089 src/utils/log-init.cpp
Tomáš Pecka261c8862020-11-05 11:23:08 +010090 src/utils/log-init.h
Tomáš Peckaba2dc312021-01-23 22:29:11 +010091 src/utils/sysrepo.cpp
92 src/utils/sysrepo.h
Tomáš Pecka339bc672020-11-11 15:59:03 +010093 src/utils/time.cpp
94 src/utils/time.h
Tomáš Peckad0337072021-01-25 19:57:00 +010095 src/utils/waitUntilSignalled.cpp
96 src/utils/waitUntilSignalled.h
Tomáš Pecka5123e002020-06-05 15:29:21 +020097 )
Václav Kubernát6018f082021-02-11 01:32:18 +010098target_link_libraries(velia-utils PUBLIC spdlog::spdlog PRIVATE PkgConfig::SYSTEMD PkgConfig::SYSREPO fmt::fmt docopt)
Tomáš Peckaa4336812020-07-24 15:32:58 +020099
Tomáš Pecka261c8862020-11-05 11:23:08 +0100100# - health
101add_library(velia-health STATIC
102 src/health/inputs/AbstractInput.cpp
103 src/health/inputs/DbusSemaphoreInput.cpp
104 src/health/inputs/DbusSystemdInput.cpp
105 src/health/manager/AbstractManager.cpp
106 src/health/manager/StateManager.cpp
107 src/health/outputs/LedSysfsDriver.cpp
108 src/health/outputs/callables.cpp
109 src/health/State.cpp
Tomáš Pecka74b885f2020-06-06 20:02:41 +0200110 )
Tomáš Pecka261c8862020-11-05 11:23:08 +0100111target_link_libraries(velia-health
112 PUBLIC
113 velia-utils
114 Boost::boost
115 SDBusCpp::sdbus-c++
116 ${STD_FILESYSTEM_LIBRARY}
117 )
Tomáš Pecka74b885f2020-06-06 20:02:41 +0200118
Tomáš Pecka491f4f22020-11-05 15:44:00 +0100119# - ietf-hardware
120add_library(velia-ietf-hardware STATIC
121 src/ietf-hardware/sysfs/EMMC.cpp
122 src/ietf-hardware/sysfs/EMMC.h
Tomáš Pecka9b1c9672020-11-11 15:24:06 +0100123 src/ietf-hardware/sysfs/HWMon.cpp
124 src/ietf-hardware/sysfs/HWMon.h
Tomáš Pecka339bc672020-11-11 15:59:03 +0100125 src/ietf-hardware/IETFHardware.cpp
126 src/ietf-hardware/IETFHardware.h
Václav Kubernát97e5ea12021-03-24 00:36:57 +0100127 src/ietf-hardware/FspYhPsu.cpp
128 src/ietf-hardware/FspYhPsu.h
Tomáš Pecka491f4f22020-11-05 15:44:00 +0100129 )
130target_link_libraries(velia-ietf-hardware
131 PUBLIC
132 velia-utils
133 ${STD_FILESYSTEM_LIBRARY}
Tomáš Pecka9b1c9672020-11-11 15:24:06 +0100134 Boost::boost
Tomáš Pecka491f4f22020-11-05 15:44:00 +0100135 )
Tomáš Pecka491f4f22020-11-05 15:44:00 +0100136
Tomáš Pecka98ad18d2020-11-13 15:39:55 +0100137add_library(velia-ietf-hardware-sysrepo STATIC
Tomáš Pecka98ad18d2020-11-13 15:39:55 +0100138 src/ietf-hardware/sysrepo/Sysrepo.cpp
139 src/ietf-hardware/sysrepo/Sysrepo.h
140 )
141target_link_libraries(velia-ietf-hardware-sysrepo
142 PUBLIC
143 velia-utils
144 PkgConfig::SYSREPO
145 PkgConfig::LIBYANG
146 )
Tomáš Pecka5123e002020-06-05 15:29:21 +0200147
Václav Kubernát6d9357e2021-01-28 15:38:24 +0100148set(NOBODY_UID 65534 CACHE STRING "UID which refers to 'nobody'. Used for dropping root privileges.")
149set(NOBODY_GID 65534 CACHE STRING "GID which refers to 'nobody'. Used for dropping root privileges.")
150
Václav Kubernátde0e4e62021-02-08 17:46:14 +0100151if(NOT NFT_EXECUTABLE)
152 find_program(NFT_EXECUTABLE nft)
153endif()
Václav Kubernátbabbab92021-01-27 09:25:05 +0100154if(NOT SSH_KEYGEN_EXECUTABLE)
155 find_program(SSH_KEYGEN_EXECUTABLE ssh-keygen)
156endif()
157if(NOT CHPASSWD_EXECUTABLE)
158 find_program(CHPASSWD_EXECUTABLE chpasswd)
159endif()
Tomáš Pecka879a6032021-02-03 17:21:48 +0100160if(NOT SYSTEMCTL_EXECUTABLE)
161 find_program(SYSTEMCTL_EXECUTABLE systemctl)
162endif()
Tomáš Pecka5c19e722021-02-15 20:41:29 +0100163if(NOT NETWORKCTL_EXECUTABLE)
164 find_program(NETWORKCTL_EXECUTABLE networkctl)
165endif()
Václav Kubernát566c9402021-02-10 08:33:54 +0100166if(NOT HOSTNAMECTL_EXECUTABLE)
167 find_program(HOSTNAMECTL_EXECUTABLE hostnamectl)
168endif()
Václav Kubernátbabbab92021-01-27 09:25:05 +0100169
170set(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.")
171if(NOT VELIA_AUTHORIZED_KEYS_FORMAT)
172 message(FATAL_ERROR "VELIA_AUTHORIZED_KEYS_FORMAT not set.")
173endif()
174
175if(NOT VELIA_AUTHORIZED_KEYS_FORMAT MATCHES "{USER}" AND NOT VELIA_AUTHORIZED_KEYS_FORMAT MATCHES "{HOME}")
176 message(FATAL_ERROR "Wrong format string given for VELIA_AUTHORIZED_KEYS_FORMAT: at least one of {USER} or {HOME} expected.")
177endif()
178
179set(VELIA_REAL_ETC_PASSWD "/etc/passwd" CACHE STRING "Path to passwd file")
180if(NOT VELIA_REAL_ETC_PASSWD)
181 message(FATAL_ERROR "VELIA_REAL_ETC_PASSWD not set")
182endif()
183
184set(VELIA_REAL_ETC_SHADOW "/etc/shadow" CACHE STRING "Path to shadow file")
185if(NOT VELIA_REAL_ETC_SHADOW)
186 message(FATAL_ERROR "VELIA_REAL_ETC_SHADOW not set")
187endif()
188
189set(VELIA_BACKUP_ETC_SHADOW "/etc/shadow" CACHE STRING "Path to where /etc/shadow gets copied to upon each change")
190if(NOT VELIA_BACKUP_ETC_SHADOW)
191 message(FATAL_ERROR "VELIA_BACKUP_ETC_SHADOW not set")
192endif()
Václav Kubernátde0e4e62021-02-08 17:46:14 +0100193
Václav Kubernát566c9402021-02-10 08:33:54 +0100194set(VELIA_BACKUP_ETC_HOSTNAME "/etc/hostname" CACHE STRING "Path to hostname file")
195if(NOT VELIA_BACKUP_ETC_HOSTNAME )
196 message(FATAL_ERROR "VELIA_BACKUP_ETC_HOSTNAME not set")
197endif()
198
Václav Kubernát6d9357e2021-01-28 15:38:24 +0100199configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/system/system_vars.h.in ${CMAKE_CURRENT_BINARY_DIR}/system_vars.h @ONLY)
200include_directories(${CMAKE_CURRENT_BINARY_DIR})
201
Tomáš Pecka292bc9c2021-01-11 22:03:11 +0100202# - ietf-system
203add_library(velia-system STATIC
Tomáš Pecka991e4d52021-01-11 10:03:14 +0100204 src/system/RAUC.cpp
205 src/system/RAUC.h
Tomáš Pecka594a6762021-01-29 11:06:08 +0100206 src/system/Firmware.cpp
207 src/system/Firmware.h
Tomáš Peckaf976c5b2021-01-23 21:19:52 +0100208 src/system/IETFSystem.cpp
209 src/system/IETFSystem.h
Václav Kubernátbabbab92021-01-27 09:25:05 +0100210 src/system/Authentication.cpp
211 src/system/Authentication.h
Tomáš Pecka5c19e722021-02-15 20:41:29 +0100212 src/system/Network.cpp
213 src/system/Network.h
Tomáš Pecka2d578c82021-02-23 19:01:35 +0100214 src/system/Rtnetlink.cpp
215 src/system/Rtnetlink.h
Tomáš Peckaf10b9302021-02-23 19:02:02 +0100216 src/system/IETFInterfaces.cpp
217 src/system/IETFInterfaces.h
Tomáš Peckaaf7b7042021-04-20 20:14:13 +0200218 src/system/LED.cpp
219 src/system/LED.h
Tomáš Pecka292bc9c2021-01-11 22:03:11 +0100220 )
221target_link_libraries(velia-system
222 PUBLIC
223 velia-utils
224 PkgConfig::SYSREPO
225 PkgConfig::LIBYANG
Tomáš Pecka2d578c82021-02-23 19:01:35 +0100226 PkgConfig::LIBNL
Václav Kubernát6dd52c82021-01-21 08:38:42 +0100227 SDBusCpp::sdbus-c++
Tomáš Pecka292bc9c2021-01-11 22:03:11 +0100228 )
229
Václav Kubernátd386aba2021-01-19 10:03:28 +0100230# - firewall
231add_library(velia-firewall STATIC
232 src/firewall/Firewall.cpp
233 )
234target_link_libraries(velia-firewall
235 PUBLIC
236 velia-utils
237 PkgConfig::SYSREPO
238 PRIVATE
239 PkgConfig::LIBYANG
240 )
241
242
Tomáš Pecka625b7a12021-01-23 20:55:51 +0100243# - daemons
Tomáš Peckacd19e622021-01-27 09:18:11 +0100244add_executable(veliad-health
245 src/main-health.cpp
Tomáš Pecka139e3612021-01-25 19:49:00 +0100246 src/health/Factory.cpp
247 src/health/Factory.h
248 )
Tomáš Peckacd19e622021-01-27 09:18:11 +0100249target_link_libraries(veliad-health
Tomáš Peckaaae9fe32021-01-25 19:57:22 +0100250 PUBLIC
Tomáš Peckad03044f2020-11-12 14:33:10 +0100251 velia-health
Tomáš Peckad03044f2020-11-12 14:33:10 +0100252 docopt
Tomáš Peckaaae9fe32021-01-25 19:57:22 +0100253 )
Tomáš Peckacd19e622021-01-27 09:18:11 +0100254add_dependencies(veliad-health target-VELIA_VERSION)
255target_include_directories(veliad-health PUBLIC ${CMAKE_BINARY_DIR})
Tomáš Peckad03044f2020-11-12 14:33:10 +0100256
Tomáš Pecka625b7a12021-01-23 20:55:51 +0100257add_executable(veliad-system
258 src/main-system.cpp
259 )
260target_link_libraries(veliad-system
261 PUBLIC
262 velia-system
263 docopt
264 )
265add_dependencies(veliad-system target-VELIA_VERSION)
266target_include_directories(veliad-system PUBLIC ${CMAKE_BINARY_DIR})
267
Václav Kubernátd386aba2021-01-19 10:03:28 +0100268add_executable(veliad-firewall
269 src/main-firewall.cpp
270 )
271target_link_libraries(veliad-firewall
272 PUBLIC
273 velia-firewall
274 velia-utils
Václav Kubernátd386aba2021-01-19 10:03:28 +0100275 docopt
276 )
277add_dependencies(veliad-firewall target-VELIA_VERSION)
278target_include_directories(veliad-firewall PUBLIC ${CMAKE_BINARY_DIR})
279
Tomáš Peckaaae9fe32021-01-25 19:57:22 +0100280add_executable(veliad-hardware
281 src/main-hardware.cpp
282 src/ietf-hardware/Factory.cpp
283 src/ietf-hardware/Factory.h
284 )
285target_link_libraries(veliad-hardware
286 PUBLIC
287 velia-ietf-hardware
288 velia-ietf-hardware-sysrepo
289 docopt
290 )
291add_dependencies(veliad-hardware target-VELIA_VERSION)
292target_include_directories(veliad-hardware PUBLIC ${CMAKE_BINARY_DIR})
293
Tomáš Pecka5123e002020-06-05 15:29:21 +0200294# Testing
Tomáš Peckaa06d74d2020-06-14 18:18:13 +0200295include(CTest)
Tomáš Pecka5123e002020-06-05 15:29:21 +0200296if(BUILD_TESTING)
Tomáš Pecka5123e002020-06-05 15:29:21 +0200297 find_package(trompeloeil 33 REQUIRED)
298 find_package(doctest 2.3.1 REQUIRED)
299
Tomáš Peckaefd88432020-06-17 15:31:39 +0200300 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/tests/configure.cmake.h.in ${CMAKE_CURRENT_BINARY_DIR}/tests/configure.cmake.h)
301
Tomáš Pecka5123e002020-06-05 15:29:21 +0200302 add_library(DoctestIntegration STATIC
Tomáš Pecka261c8862020-11-05 11:23:08 +0100303 tests/doctest_integration.cpp
304 tests/trompeloeil_doctest.h
305 tests/wait-a-bit-longer.cpp
306 )
Tomáš Pecka5123e002020-06-05 15:29:21 +0200307 target_link_libraries(DoctestIntegration doctest::doctest trompeloeil spdlog::spdlog)
Tomáš Pecka261c8862020-11-05 11:23:08 +0100308 target_include_directories(DoctestIntegration PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/tests/)
Tomáš Pecka5123e002020-06-05 15:29:21 +0200309 target_compile_definitions(DoctestIntegration PUBLIC DOCTEST_CONFIG_SUPER_FAST_ASSERTS)
310
Tomáš Peckaa18702d2021-01-25 18:07:23 +0100311 add_library(SysrepoTesting STATIC
312 tests/mock/sysrepo/events.cpp
313 tests/mock/sysrepo/events.h
314 )
315 target_link_libraries(SysrepoTesting DoctestIntegration PkgConfig::SYSREPO)
316
Tomáš Pecka0a2e8902020-06-09 21:11:20 +0200317 add_library(DbusTesting STATIC
Tomáš Pecka991e4d52021-01-11 10:03:14 +0100318 tests/dbus-helpers/dbus_rauc_server.cpp
319 tests/dbus-helpers/dbus_rauc_server.h
Tomáš Pecka0a2e8902020-06-09 21:11:20 +0200320 tests/dbus-helpers/dbus_semaphore_server.cpp
Tomáš Pecka261c8862020-11-05 11:23:08 +0100321 tests/dbus-helpers/dbus_semaphore_server.h
Tomáš Peckaccd80c32020-06-22 14:44:32 +0200322 tests/dbus-helpers/dbus_systemd_server.cpp
Tomáš Pecka261c8862020-11-05 11:23:08 +0100323 tests/dbus-helpers/dbus_systemd_server.h
324 )
325 target_link_libraries(DbusTesting
326 PUBLIC
327 velia-utils
328 SDBusCpp::sdbus-c++
329 )
Tomáš Pecka0a2e8902020-06-09 21:11:20 +0200330
Tomáš Pecka9b1c9672020-11-11 15:24:06 +0100331 add_library(FsTestUtils STATIC
332 tests/fs-helpers/FileInjector.cpp
333 tests/fs-helpers/FileInjector.h
334 tests/fs-helpers/utils.cpp
335 tests/fs-helpers/utils.h
336 )
337 target_link_libraries(FsTestUtils
338 PUBLIC
339 ${STD_FILESYSTEM_LIBRARY}
340 )
341
Tomáš Pecka5123e002020-06-05 15:29:21 +0200342 function(velia_test name)
Tomáš Pecka261c8862020-11-05 11:23:08 +0100343 add_executable(test-${name} ${CMAKE_SOURCE_DIR}/tests/${name}.cpp)
344 target_link_libraries(test-${name} DoctestIntegration ${ARGN})
345 target_include_directories(test-${name}
346 PUBLIC
347 ${CMAKE_CURRENT_SOURCE_DIR}
348 PRIVATE
349 ${CMAKE_BINARY_DIR}
350 )
Tomáš Pecka5123e002020-06-05 15:29:21 +0200351
352 if(NOT CMAKE_CROSSCOMPILING)
Tomáš Pecka261c8862020-11-05 11:23:08 +0100353 add_test(test-${name} test-${name})
Tomáš Pecka5123e002020-06-05 15:29:21 +0200354 endif()
Tomáš Pecka5123e002020-06-05 15:29:21 +0200355 endfunction()
Tomáš Pecka5123e002020-06-05 15:29:21 +0200356
Tomáš Pecka98ad18d2020-11-13 15:39:55 +0100357 find_program(SYSREPOCTL sysrepoctl)
358 find_program(SYSREPOCFG sysrepocfg)
359
360 set(sysrepo_previous_fixture_name UNDEFINED)
361 function(sysrepo_fixture_env name)
362 set(test_name_init sysrepo:prep:${name})
363 set(test_name_cleanup sysrepo:clean:${name})
364 set(fixture_name sysrepo:env:${name})
365
366 add_test(NAME ${test_name_init} COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/tests/sysrepoctl-manage-module.sh ${SYSREPOCTL} ${SYSREPOCFG} prepare ${ARGN})
367 set_tests_properties(${test_name_init} PROPERTIES FIXTURES_SETUP ${fixture_name} RESOURCE_LOCK sysrepo)
368 add_test(NAME ${test_name_cleanup} COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/tests/sysrepoctl-manage-module.sh ${SYSREPOCTL} ${SYSREPOCFG} uninstall ${ARGN})
369 set_tests_properties(${test_name_cleanup} PROPERTIES FIXTURES_CLEANUP ${fixture_name} RESOURCE_LOCK sysrepo)
370
371 if (sysrepo_previous_fixture_name)
372 set_tests_properties(${test_name_init} PROPERTIES DEPENDS sysrepo:clean:${sysrepo_previous_fixture_name})
373 endif ()
374
375 set(sysrepo_previous_fixture_name ${name} PARENT_SCOPE)
376 endfunction()
377
Tomáš Pecka261c8862020-11-05 11:23:08 +0100378 velia_test(health_state-manager velia-health)
379 velia_test(health_input-semaphore velia-health DbusTesting)
380 velia_test(health_input-systemd velia-health DbusTesting)
381 velia_test(health_output-led velia-health)
Tomáš Pecka491f4f22020-11-05 15:44:00 +0100382
Tomáš Pecka991e4d52021-01-11 10:03:14 +0100383 velia_test(system_rauc velia-system DbusTesting)
Tomáš Peckacb7a5f82021-01-20 15:12:00 +0100384 set_tests_properties(
385 test-system_rauc
386 PROPERTIES RESOURCE_LOCK dbus-rauc
387 )
Tomáš Pecka991e4d52021-01-11 10:03:14 +0100388
Tomáš Pecka9b1c9672020-11-11 15:24:06 +0100389 velia_test(hardware_emmc velia-ietf-hardware FsTestUtils)
390 velia_test(hardware_hwmon velia-ietf-hardware FsTestUtils)
Tomáš Pecka83b62e12020-12-16 14:50:49 +0100391
Tomáš Pecka292bc9c2021-01-11 22:03:11 +0100392 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 +0100393 velia_test(sysrepo_system-ietfsystem velia-system DbusTesting)
Tomáš Pecka292bc9c2021-01-11 22:03:11 +0100394 set_tests_properties(
Tomáš Peckaf976c5b2021-01-23 21:19:52 +0100395 test-sysrepo_system-ietfsystem
Tomáš Pecka292bc9c2021-01-11 22:03:11 +0100396 PROPERTIES FIXTURES_REQUIRED sysrepo:env:sysrepo-ietf-system
397 RESOURCE_LOCK sysrepo
Tomáš Peckacb7a5f82021-01-20 15:12:00 +0100398)
399
400 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 +0100401 velia_test(sysrepo_system-firmware velia-system DbusTesting)
402 target_link_libraries(test-sysrepo_system-firmware SysrepoTesting)
Tomáš Peckacb7a5f82021-01-20 15:12:00 +0100403 set_tests_properties(
Tomáš Pecka594a6762021-01-29 11:06:08 +0100404 test-sysrepo_system-firmware
Tomáš Peckacb7a5f82021-01-20 15:12:00 +0100405 PROPERTIES FIXTURES_REQUIRED sysrepo:env:sysrepo-czechlight-system
406 RESOURCE_LOCK "sysrepo;dbus-rauc"
Tomáš Pecka292bc9c2021-01-11 22:03:11 +0100407 )
408
Václav Kubernátbabbab92021-01-27 09:25:05 +0100409 velia_test(sysrepo_authentication velia-system FsTestUtils)
410
411 set_tests_properties(
412 test-sysrepo_authentication
413 PROPERTIES FIXTURES_REQUIRED sysrepo:env:sysrepo-czechlight-system
414 RESOURCE_LOCK sysrepo
415 )
416
Tomáš Pecka5be83e42021-04-21 17:26:40 +0200417 velia_test(sysrepo_system-leds velia-system FsTestUtils)
Tomáš Peckaaf7b7042021-04-20 20:14:13 +0200418 set_tests_properties(
419 test-sysrepo_system-leds
420 PROPERTIES FIXTURES_REQUIRED sysrepo:env:sysrepo-czechlight-system
421 RESOURCE_LOCK sysrepo
422 )
423
Tomáš Pecka5c19e722021-02-15 20:41:29 +0100424 velia_test(sysrepo_system-network velia-system)
425 target_link_libraries(test-sysrepo_system-network FsTestUtils)
426 set_tests_properties(
427 test-sysrepo_system-network
428 PROPERTIES FIXTURES_REQUIRED sysrepo:env:sysrepo-czechlight-system
429 RESOURCE_LOCK sysrepo
430 )
431
Tomáš Peckaf10b9302021-02-23 19:02:02 +0100432 sysrepo_fixture_env(sysrepo-czechlight-network
433 YANG ${CMAKE_CURRENT_SOURCE_DIR}/yang/iana-if-type@2017-01-19.yang
434 YANG ${CMAKE_CURRENT_SOURCE_DIR}/yang/ietf-interfaces@2018-02-20.yang
435 YANG ${CMAKE_CURRENT_SOURCE_DIR}/yang/ietf-ip@2018-02-22.yang
Tomáš Pecka2a4ea7b2021-03-30 17:01:37 +0200436 YANG ${CMAKE_CURRENT_SOURCE_DIR}/yang/ietf-routing@2018-03-13.yang
437 YANG ${CMAKE_CURRENT_SOURCE_DIR}/yang/ietf-ipv4-unicast-routing@2018-03-13.yang
438 YANG ${CMAKE_CURRENT_SOURCE_DIR}/yang/ietf-ipv6-unicast-routing@2018-03-13.yang
Tomáš Peckaf10b9302021-02-23 19:02:02 +0100439 YANG ${CMAKE_CURRENT_SOURCE_DIR}/yang/czechlight-network@2021-02-22.yang)
440 velia_test(sysrepo_system-ietfinterfaces velia-system)
441 set_tests_properties(
442 test-sysrepo_system-ietfinterfaces
443 PROPERTIES FIXTURES_REQUIRED sysrepo:env:sysrepo-czechlight-network
444 RESOURCE_LOCK sysrepo
445 )
446
Tomáš Pecka83b62e12020-12-16 14:50:49 +0100447 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)
Václav Kubernát97e5ea12021-03-24 00:36:57 +0100448 velia_test(hardware_ietf-hardware velia-ietf-hardware velia-ietf-hardware-sysrepo FsTestUtils)
Tomáš Pecka98ad18d2020-11-13 15:39:55 +0100449 set_tests_properties(
450 test-hardware_ietf-hardware
Tomáš Pecka83b62e12020-12-16 14:50:49 +0100451 PROPERTIES FIXTURES_REQUIRED sysrepo:env:sysrepo-ietf-hardware
Tomáš Pecka55f64f82020-12-10 19:03:30 +0100452 RESOURCE_LOCK sysrepo
453 )
454
455 velia_test(sysrepo_two-daemons velia-ietf-hardware-sysrepo)
Tomáš Pecka83b62e12020-12-16 14:50:49 +0100456 # 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 +0100457 add_executable(test-sysrepo_test_merge-daemon ${CMAKE_SOURCE_DIR}/tests/sysrepo_two-daemons_daemon.cpp)
458 target_link_libraries(test-sysrepo_test_merge-daemon PkgConfig::SYSREPO PkgConfig::LIBYANG)
459
460 add_test(NAME sysrepo_test_merge-start COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/tests/sysrepo_two-daemons_control.sh start)
461 add_test(NAME sysrepo_test_merge-stop COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/tests/sysrepo_two-daemons_control.sh stop)
462 set_tests_properties(sysrepo_test_merge-start PROPERTIES FIXTURES_SETUP sysrepo:two-daemons RESOURCE_LOCK sysrepo)
463 set_tests_properties(sysrepo_test_merge-stop PROPERTIES FIXTURES_CLEANUP sysrepo:two-daemons RESOURCE_LOCK sysrepo)
Tomáš Pecka55f64f82020-12-10 19:03:30 +0100464
465 set_tests_properties(
466 test-sysrepo_two-daemons
467 PROPERTIES
468 FIXTURES_REQUIRED "sysrepo:two-daemons;sysrepo:env:sysrepo-ietf-hardware"
Tomáš Pecka98ad18d2020-11-13 15:39:55 +0100469 RESOURCE_LOCK sysrepo
470 )
Tomáš Pecka83b62e12020-12-16 14:50:49 +0100471 # ensure we run two-daemons merge test and ietf-hardware test sequentially and don't cleanup before everything ends
472 set_tests_properties(sysrepo_test_merge-start PROPERTIES DEPENDS test-hardware_ietf-hardware)
473 set_tests_properties(sysrepo:clean:sysrepo-ietf-hardware PROPERTIES DEPENDS sysrepo_test_merge-stop)
474
Tomáš Pecka73a13cc2020-11-17 11:12:19 +0100475
476 find_program(YANGLINT_PATH yanglint)
477 if (NOT YANGLINT_PATH)
478 message(FATAL_ERROR "Cannot find libyang's yanglint")
479 endif()
480 foreach(yang_file ${YANG_SRCS})
481 add_test(NAME yang-tree:${yang_file} COMMAND ${YANGLINT_PATH} -f tree ${CMAKE_CURRENT_SOURCE_DIR}/${yang_file})
482 endforeach()
Václav Kubernátd386aba2021-01-19 10:03:28 +0100483
484 sysrepo_fixture_env(sysrepo-firewall
485 # Installing czechlight-firewall automatically installs ietf-access-control-list as implemented (not just
486 # imported) but I still need to install it myself to enable the features.
487 YANG ${CMAKE_CURRENT_SOURCE_DIR}/yang/ietf-access-control-list@2019-03-04.yang
488 FEATURE eth
489 FEATURE match-on-eth
490 FEATURE match-on-ipv4
491 FEATURE ipv4
492 FEATURE match-on-ipv6
493 FEATURE ipv6
494 FEATURE mixed-eth-ipv4-ipv6
495 YANG ${CMAKE_CURRENT_SOURCE_DIR}/yang/czechlight-firewall@2021-01-25.yang
496 )
497
498 velia_test(sysrepo-firewall velia-firewall)
499 set_tests_properties(
500 test-sysrepo-firewall
501 PROPERTIES FIXTURES_REQUIRED sysrepo:env:sysrepo-firewall
502 RESOURCE_LOCK sysrepo
503 )
Tomáš Pecka261c8862020-11-05 11:23:08 +0100504endif()
Tomáš Peckac927d662020-07-13 11:16:16 +0200505
Tomáš Pecka5123e002020-06-05 15:29:21 +0200506if(WITH_DOCS)
507 set(doxyfile_in ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in)
508 set(doxyfile ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile)
509 configure_file(${doxyfile_in} ${doxyfile} @ONLY)
510 add_custom_target(doc
511 COMMAND ${DOXYGEN_EXECUTABLE} ${doxyfile}
512 WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
513 COMMENT "Generating API documentation with Doxygen"
514 VERBATIM
515 SOURCES ${doxyfile_in}
516 )
Tomáš Peckaa06d74d2020-06-14 18:18:13 +0200517endif()
Tomáš Pecka261c8862020-11-05 11:23:08 +0100518
Tomáš Pecka73a13cc2020-11-17 11:12:19 +0100519set(YANG_DIR ${CMAKE_INSTALL_PREFIX}/share/velia/yang)
520install(FILES ${YANG_SRCS} DESTINATION ${YANG_DIR})
Tomáš Peckaeb317722021-04-13 21:33:20 +0200521install(FILES ${CMAKE_SOURCE_DIR}/yang/ietf-ipv6-router-advertisements@2018-03-13.yang DESTINATION ${YANG_DIR})
Tomáš Peckacd19e622021-01-27 09:18:11 +0100522install(TARGETS veliad-health RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}/)
Tomáš Pecka625b7a12021-01-23 20:55:51 +0100523install(TARGETS veliad-system RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}/)
Tomáš Peckaaae9fe32021-01-25 19:57:22 +0100524install(TARGETS veliad-hardware RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}/)
Tomáš Peckafb14b182021-01-27 10:54:00 +0100525install(TARGETS veliad-firewall RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}/)