blob: af01252265a48c72a98dc9c38ff132a9191bd6f6 [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áš Pecka0a2e8902020-06-09 21:11:20 +020035find_package(sdbus-c++ REQUIRED)
Tomáš Peckaa4336812020-07-24 15:32:58 +020036find_package(PkgConfig)
Václav Kubernátbabbab92021-01-27 09:25:05 +010037find_package(fmt)
Tomáš Peckaa4336812020-07-24 15:32:58 +020038
39pkg_check_modules(SYSTEMD REQUIRED IMPORTED_TARGET libsystemd)
Tomáš Pecka1f42cfe2020-10-21 18:38:27 +020040if(${SYSTEMD_VERSION} VERSION_EQUAL 245)
41 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.")
42endif()
Tomáš Pecka5123e002020-06-05 15:29:21 +020043
Tomáš Pecka0b291da2021-06-02 18:08:18 +020044pkg_check_modules(SYSREPO REQUIRED sysrepo-cpp>=1.4.140 IMPORTED_TARGET sysrepo)
45pkg_check_modules(LIBYANG REQUIRED libyang-cpp>=1.0.241 IMPORTED_TARGET libyang)
Tomáš Pecka2d578c82021-02-23 19:01:35 +010046pkg_check_modules(LIBNL REQUIRED IMPORTED_TARGET libnl-route-3.0)
Tomáš Pecka98ad18d2020-11-13 15:39:55 +010047
Tomáš Peckac927d662020-07-13 11:16:16 +020048include(GNUInstallDirs)
49
Tomáš Pecka261c8862020-11-05 11:23:08 +010050include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/)
51
Tomáš Pecka73a13cc2020-11-17 11:12:19 +010052set(YANG_SRCS
Tomáš Pecka9a02c3f2021-01-21 15:27:22 +010053 yang/czechlight-system@2021-01-13.yang
Tomáš Pecka73a13cc2020-11-17 11:12:19 +010054 yang/iana-hardware@2018-03-13.yang
Tomáš Pecka73a13cc2020-11-17 11:12:19 +010055 yang/ietf-hardware@2018-03-13.yang
Tomáš Peckaf98ce032021-01-14 13:35:00 +010056 yang/iana-crypt-hash@2014-08-06.yang
57 yang/ietf-inet-types@2013-07-15.yang
58 yang/ietf-netconf-acm@2018-02-14.yang
59 yang/ietf-system@2014-08-06.yang
60 yang/ietf-yang-types@2013-07-15.yang
Tomáš Pecka435ca2a2021-01-27 10:53:48 +010061 yang/ietf-ethertypes@2019-03-04.yang
62 yang/ietf-interfaces@2018-02-20.yang
63 yang/ietf-packet-fields@2019-03-04.yang
Václav Kubernát637fe802021-01-22 02:43:18 +010064 yang/ietf-access-control-list@2019-03-04.yang
Václav Kubernát457d1ad2021-01-22 02:43:18 +010065 yang/czechlight-firewall@2021-01-25.yang
Tomáš Peckadac27d42021-02-22 13:20:05 +010066 yang/czechlight-network@2021-02-22.yang
67 yang/iana-if-type@2017-01-19.yang
68 yang/ietf-ip@2018-02-22.yang
Tomáš Pecka2a4ea7b2021-03-30 17:01:37 +020069 yang/ietf-routing@2018-03-13.yang
70 yang/ietf-ipv4-unicast-routing@2018-03-13.yang
71 yang/ietf-ipv6-unicast-routing@2018-03-13.yang
Tomáš Pecka73a13cc2020-11-17 11:12:19 +010072 )
73
Tomáš Pecka5123e002020-06-05 15:29:21 +020074# Targets
Tomáš Pecka261c8862020-11-05 11:23:08 +010075# - utils
Tomáš Peckabd828862020-06-15 15:53:35 +020076add_library(velia-utils STATIC
Tomáš Peckaa193c032020-06-22 17:33:31 +020077 src/utils/exceptions.cpp
Tomáš Pecka261c8862020-11-05 11:23:08 +010078 src/utils/exceptions.h
Václav Kubernát6d9357e2021-01-28 15:38:24 +010079 src/utils/exec.cpp
80 src/utils/exec.h
Tomáš Pecka491f4f22020-11-05 15:44:00 +010081 src/utils/io.cpp
82 src/utils/io.h
Tomáš Peckaa4336812020-07-24 15:32:58 +020083 src/utils/journal.cpp
Tomáš Pecka261c8862020-11-05 11:23:08 +010084 src/utils/journal.h
Václav Kubernátcbdc98a2021-01-28 13:24:37 +010085 src/utils/libyang.cpp
86 src/utils/libyang.h
Tomáš Pecka261c8862020-11-05 11:23:08 +010087 src/utils/log.h
Václav Kubernát6018f082021-02-11 01:32:18 +010088 src/utils/log.cpp
Tomáš Pecka261c8862020-11-05 11:23:08 +010089 src/utils/log-fwd.h
Tomáš Pecka5123e002020-06-05 15:29:21 +020090 src/utils/log-init.cpp
Tomáš Pecka261c8862020-11-05 11:23:08 +010091 src/utils/log-init.h
Tomáš Peckaba2dc312021-01-23 22:29:11 +010092 src/utils/sysrepo.cpp
93 src/utils/sysrepo.h
Tomáš Pecka339bc672020-11-11 15:59:03 +010094 src/utils/time.cpp
95 src/utils/time.h
Tomáš Peckad0337072021-01-25 19:57:00 +010096 src/utils/waitUntilSignalled.cpp
97 src/utils/waitUntilSignalled.h
Tomáš Pecka5123e002020-06-05 15:29:21 +020098 )
Václav Kubernát6018f082021-02-11 01:32:18 +010099target_link_libraries(velia-utils PUBLIC spdlog::spdlog PRIVATE PkgConfig::SYSTEMD PkgConfig::SYSREPO fmt::fmt docopt)
Tomáš Peckaa4336812020-07-24 15:32:58 +0200100
Tomáš Pecka261c8862020-11-05 11:23:08 +0100101# - health
102add_library(velia-health STATIC
103 src/health/inputs/AbstractInput.cpp
104 src/health/inputs/DbusSemaphoreInput.cpp
105 src/health/inputs/DbusSystemdInput.cpp
106 src/health/manager/AbstractManager.cpp
107 src/health/manager/StateManager.cpp
108 src/health/outputs/LedSysfsDriver.cpp
109 src/health/outputs/callables.cpp
110 src/health/State.cpp
Tomáš Pecka74b885f2020-06-06 20:02:41 +0200111 )
Tomáš Pecka261c8862020-11-05 11:23:08 +0100112target_link_libraries(velia-health
113 PUBLIC
114 velia-utils
115 Boost::boost
116 SDBusCpp::sdbus-c++
117 ${STD_FILESYSTEM_LIBRARY}
118 )
Tomáš Pecka74b885f2020-06-06 20:02:41 +0200119
Tomáš Pecka491f4f22020-11-05 15:44:00 +0100120# - ietf-hardware
121add_library(velia-ietf-hardware STATIC
122 src/ietf-hardware/sysfs/EMMC.cpp
123 src/ietf-hardware/sysfs/EMMC.h
Tomáš Pecka9b1c9672020-11-11 15:24:06 +0100124 src/ietf-hardware/sysfs/HWMon.cpp
125 src/ietf-hardware/sysfs/HWMon.h
Tomáš Pecka339bc672020-11-11 15:59:03 +0100126 src/ietf-hardware/IETFHardware.cpp
127 src/ietf-hardware/IETFHardware.h
Václav Kubernát97e5ea12021-03-24 00:36:57 +0100128 src/ietf-hardware/FspYhPsu.cpp
129 src/ietf-hardware/FspYhPsu.h
Tomáš Pecka491f4f22020-11-05 15:44:00 +0100130 )
131target_link_libraries(velia-ietf-hardware
132 PUBLIC
133 velia-utils
134 ${STD_FILESYSTEM_LIBRARY}
Tomáš Pecka9b1c9672020-11-11 15:24:06 +0100135 Boost::boost
Tomáš Pecka491f4f22020-11-05 15:44:00 +0100136 )
Tomáš Pecka491f4f22020-11-05 15:44:00 +0100137
Tomáš Pecka98ad18d2020-11-13 15:39:55 +0100138add_library(velia-ietf-hardware-sysrepo STATIC
Tomáš Pecka98ad18d2020-11-13 15:39:55 +0100139 src/ietf-hardware/sysrepo/Sysrepo.cpp
140 src/ietf-hardware/sysrepo/Sysrepo.h
141 )
142target_link_libraries(velia-ietf-hardware-sysrepo
143 PUBLIC
144 velia-utils
145 PkgConfig::SYSREPO
146 PkgConfig::LIBYANG
147 )
Tomáš Pecka5123e002020-06-05 15:29:21 +0200148
Václav Kubernát6d9357e2021-01-28 15:38:24 +0100149set(NOBODY_UID 65534 CACHE STRING "UID which refers to 'nobody'. Used for dropping root privileges.")
150set(NOBODY_GID 65534 CACHE STRING "GID which refers to 'nobody'. Used for dropping root privileges.")
151
Václav Kubernátde0e4e62021-02-08 17:46:14 +0100152if(NOT NFT_EXECUTABLE)
153 find_program(NFT_EXECUTABLE nft)
154endif()
Václav Kubernátbabbab92021-01-27 09:25:05 +0100155if(NOT SSH_KEYGEN_EXECUTABLE)
156 find_program(SSH_KEYGEN_EXECUTABLE ssh-keygen)
157endif()
158if(NOT CHPASSWD_EXECUTABLE)
159 find_program(CHPASSWD_EXECUTABLE chpasswd)
160endif()
Tomáš Pecka879a6032021-02-03 17:21:48 +0100161if(NOT SYSTEMCTL_EXECUTABLE)
162 find_program(SYSTEMCTL_EXECUTABLE systemctl)
163endif()
Tomáš Pecka5c19e722021-02-15 20:41:29 +0100164if(NOT NETWORKCTL_EXECUTABLE)
165 find_program(NETWORKCTL_EXECUTABLE networkctl)
166endif()
Václav Kubernát566c9402021-02-10 08:33:54 +0100167if(NOT HOSTNAMECTL_EXECUTABLE)
168 find_program(HOSTNAMECTL_EXECUTABLE hostnamectl)
169endif()
Václav Kubernátbabbab92021-01-27 09:25:05 +0100170
171set(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.")
172if(NOT VELIA_AUTHORIZED_KEYS_FORMAT)
173 message(FATAL_ERROR "VELIA_AUTHORIZED_KEYS_FORMAT not set.")
174endif()
175
176if(NOT VELIA_AUTHORIZED_KEYS_FORMAT MATCHES "{USER}" AND NOT VELIA_AUTHORIZED_KEYS_FORMAT MATCHES "{HOME}")
177 message(FATAL_ERROR "Wrong format string given for VELIA_AUTHORIZED_KEYS_FORMAT: at least one of {USER} or {HOME} expected.")
178endif()
179
180set(VELIA_REAL_ETC_PASSWD "/etc/passwd" CACHE STRING "Path to passwd file")
181if(NOT VELIA_REAL_ETC_PASSWD)
182 message(FATAL_ERROR "VELIA_REAL_ETC_PASSWD not set")
183endif()
184
185set(VELIA_REAL_ETC_SHADOW "/etc/shadow" CACHE STRING "Path to shadow file")
186if(NOT VELIA_REAL_ETC_SHADOW)
187 message(FATAL_ERROR "VELIA_REAL_ETC_SHADOW not set")
188endif()
189
190set(VELIA_BACKUP_ETC_SHADOW "/etc/shadow" CACHE STRING "Path to where /etc/shadow gets copied to upon each change")
191if(NOT VELIA_BACKUP_ETC_SHADOW)
192 message(FATAL_ERROR "VELIA_BACKUP_ETC_SHADOW not set")
193endif()
Václav Kubernátde0e4e62021-02-08 17:46:14 +0100194
Václav Kubernát566c9402021-02-10 08:33:54 +0100195set(VELIA_BACKUP_ETC_HOSTNAME "/etc/hostname" CACHE STRING "Path to hostname file")
196if(NOT VELIA_BACKUP_ETC_HOSTNAME )
197 message(FATAL_ERROR "VELIA_BACKUP_ETC_HOSTNAME not set")
198endif()
199
Václav Kubernát6d9357e2021-01-28 15:38:24 +0100200configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/system/system_vars.h.in ${CMAKE_CURRENT_BINARY_DIR}/system_vars.h @ONLY)
201include_directories(${CMAKE_CURRENT_BINARY_DIR})
202
Tomáš Pecka292bc9c2021-01-11 22:03:11 +0100203# - ietf-system
204add_library(velia-system STATIC
Tomáš Pecka991e4d52021-01-11 10:03:14 +0100205 src/system/RAUC.cpp
206 src/system/RAUC.h
Tomáš Pecka594a6762021-01-29 11:06:08 +0100207 src/system/Firmware.cpp
208 src/system/Firmware.h
Tomáš Peckaf976c5b2021-01-23 21:19:52 +0100209 src/system/IETFSystem.cpp
210 src/system/IETFSystem.h
Václav Kubernátbabbab92021-01-27 09:25:05 +0100211 src/system/Authentication.cpp
212 src/system/Authentication.h
Tomáš Pecka5c19e722021-02-15 20:41:29 +0100213 src/system/Network.cpp
214 src/system/Network.h
Tomáš Pecka2d578c82021-02-23 19:01:35 +0100215 src/system/Rtnetlink.cpp
216 src/system/Rtnetlink.h
Tomáš Peckaf10b9302021-02-23 19:02:02 +0100217 src/system/IETFInterfaces.cpp
218 src/system/IETFInterfaces.h
Tomáš Peckaaf7b7042021-04-20 20:14:13 +0200219 src/system/LED.cpp
220 src/system/LED.h
Tomáš Pecka292bc9c2021-01-11 22:03:11 +0100221 )
222target_link_libraries(velia-system
223 PUBLIC
224 velia-utils
225 PkgConfig::SYSREPO
226 PkgConfig::LIBYANG
Tomáš Pecka2d578c82021-02-23 19:01:35 +0100227 PkgConfig::LIBNL
Václav Kubernát6dd52c82021-01-21 08:38:42 +0100228 SDBusCpp::sdbus-c++
Tomáš Pecka292bc9c2021-01-11 22:03:11 +0100229 )
230
Václav Kubernátd386aba2021-01-19 10:03:28 +0100231# - firewall
232add_library(velia-firewall STATIC
233 src/firewall/Firewall.cpp
234 )
235target_link_libraries(velia-firewall
236 PUBLIC
237 velia-utils
238 PkgConfig::SYSREPO
239 PRIVATE
240 PkgConfig::LIBYANG
241 )
242
243
Tomáš Pecka625b7a12021-01-23 20:55:51 +0100244# - daemons
Tomáš Peckacd19e622021-01-27 09:18:11 +0100245add_executable(veliad-health
246 src/main-health.cpp
Tomáš Pecka139e3612021-01-25 19:49:00 +0100247 src/health/Factory.cpp
248 src/health/Factory.h
249 )
Tomáš Peckacd19e622021-01-27 09:18:11 +0100250target_link_libraries(veliad-health
Tomáš Peckaaae9fe32021-01-25 19:57:22 +0100251 PUBLIC
Tomáš Peckad03044f2020-11-12 14:33:10 +0100252 velia-health
Tomáš Peckad03044f2020-11-12 14:33:10 +0100253 docopt
Tomáš Peckaaae9fe32021-01-25 19:57:22 +0100254 )
Tomáš Peckacd19e622021-01-27 09:18:11 +0100255add_dependencies(veliad-health target-VELIA_VERSION)
256target_include_directories(veliad-health PUBLIC ${CMAKE_BINARY_DIR})
Tomáš Peckad03044f2020-11-12 14:33:10 +0100257
Tomáš Pecka625b7a12021-01-23 20:55:51 +0100258add_executable(veliad-system
259 src/main-system.cpp
260 )
261target_link_libraries(veliad-system
262 PUBLIC
263 velia-system
264 docopt
265 )
266add_dependencies(veliad-system target-VELIA_VERSION)
267target_include_directories(veliad-system PUBLIC ${CMAKE_BINARY_DIR})
268
Václav Kubernátd386aba2021-01-19 10:03:28 +0100269add_executable(veliad-firewall
270 src/main-firewall.cpp
271 )
272target_link_libraries(veliad-firewall
273 PUBLIC
274 velia-firewall
275 velia-utils
Václav Kubernátd386aba2021-01-19 10:03:28 +0100276 docopt
277 )
278add_dependencies(veliad-firewall target-VELIA_VERSION)
279target_include_directories(veliad-firewall PUBLIC ${CMAKE_BINARY_DIR})
280
Tomáš Peckaaae9fe32021-01-25 19:57:22 +0100281add_executable(veliad-hardware
282 src/main-hardware.cpp
283 src/ietf-hardware/Factory.cpp
284 src/ietf-hardware/Factory.h
285 )
286target_link_libraries(veliad-hardware
287 PUBLIC
288 velia-ietf-hardware
289 velia-ietf-hardware-sysrepo
290 docopt
291 )
292add_dependencies(veliad-hardware target-VELIA_VERSION)
293target_include_directories(veliad-hardware PUBLIC ${CMAKE_BINARY_DIR})
294
Tomáš Pecka5123e002020-06-05 15:29:21 +0200295# Testing
Tomáš Peckaa06d74d2020-06-14 18:18:13 +0200296include(CTest)
Tomáš Pecka5123e002020-06-05 15:29:21 +0200297if(BUILD_TESTING)
Tomáš Pecka5123e002020-06-05 15:29:21 +0200298 find_package(trompeloeil 33 REQUIRED)
299 find_package(doctest 2.3.1 REQUIRED)
300
Tomáš Pecka9fa5f6a2021-04-13 11:36:11 +0200301 option(TEST_NETWORK_WITH_SUDO "Include ietf-routing and ietf-interfaces tests that require root privileges" "OFF")
302
Tomáš Peckaefd88432020-06-17 15:31:39 +0200303 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/tests/configure.cmake.h.in ${CMAKE_CURRENT_BINARY_DIR}/tests/configure.cmake.h)
304
Tomáš Pecka5123e002020-06-05 15:29:21 +0200305 add_library(DoctestIntegration STATIC
Tomáš Pecka261c8862020-11-05 11:23:08 +0100306 tests/doctest_integration.cpp
307 tests/trompeloeil_doctest.h
308 tests/wait-a-bit-longer.cpp
309 )
Tomáš Pecka5123e002020-06-05 15:29:21 +0200310 target_link_libraries(DoctestIntegration doctest::doctest trompeloeil spdlog::spdlog)
Tomáš Pecka261c8862020-11-05 11:23:08 +0100311 target_include_directories(DoctestIntegration PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/tests/)
Tomáš Pecka5123e002020-06-05 15:29:21 +0200312 target_compile_definitions(DoctestIntegration PUBLIC DOCTEST_CONFIG_SUPER_FAST_ASSERTS)
313
Tomáš Peckaa18702d2021-01-25 18:07:23 +0100314 add_library(SysrepoTesting STATIC
315 tests/mock/sysrepo/events.cpp
316 tests/mock/sysrepo/events.h
317 )
318 target_link_libraries(SysrepoTesting DoctestIntegration PkgConfig::SYSREPO)
319
Tomáš Pecka0a2e8902020-06-09 21:11:20 +0200320 add_library(DbusTesting STATIC
Tomáš Pecka991e4d52021-01-11 10:03:14 +0100321 tests/dbus-helpers/dbus_rauc_server.cpp
322 tests/dbus-helpers/dbus_rauc_server.h
Tomáš Pecka0a2e8902020-06-09 21:11:20 +0200323 tests/dbus-helpers/dbus_semaphore_server.cpp
Tomáš Pecka261c8862020-11-05 11:23:08 +0100324 tests/dbus-helpers/dbus_semaphore_server.h
Tomáš Peckaccd80c32020-06-22 14:44:32 +0200325 tests/dbus-helpers/dbus_systemd_server.cpp
Tomáš Pecka261c8862020-11-05 11:23:08 +0100326 tests/dbus-helpers/dbus_systemd_server.h
327 )
328 target_link_libraries(DbusTesting
329 PUBLIC
330 velia-utils
331 SDBusCpp::sdbus-c++
332 )
Tomáš Pecka0a2e8902020-06-09 21:11:20 +0200333
Tomáš Pecka9b1c9672020-11-11 15:24:06 +0100334 add_library(FsTestUtils STATIC
335 tests/fs-helpers/FileInjector.cpp
336 tests/fs-helpers/FileInjector.h
337 tests/fs-helpers/utils.cpp
338 tests/fs-helpers/utils.h
339 )
340 target_link_libraries(FsTestUtils
341 PUBLIC
342 ${STD_FILESYSTEM_LIBRARY}
343 )
344
Tomáš Pecka5123e002020-06-05 15:29:21 +0200345 function(velia_test name)
Tomáš Pecka261c8862020-11-05 11:23:08 +0100346 add_executable(test-${name} ${CMAKE_SOURCE_DIR}/tests/${name}.cpp)
347 target_link_libraries(test-${name} DoctestIntegration ${ARGN})
348 target_include_directories(test-${name}
349 PUBLIC
350 ${CMAKE_CURRENT_SOURCE_DIR}
351 PRIVATE
352 ${CMAKE_BINARY_DIR}
353 )
Tomáš Pecka5123e002020-06-05 15:29:21 +0200354
355 if(NOT CMAKE_CROSSCOMPILING)
Tomáš Pecka261c8862020-11-05 11:23:08 +0100356 add_test(test-${name} test-${name})
Tomáš Pecka5123e002020-06-05 15:29:21 +0200357 endif()
Tomáš Pecka5123e002020-06-05 15:29:21 +0200358 endfunction()
Tomáš Pecka5123e002020-06-05 15:29:21 +0200359
Tomáš Pecka98ad18d2020-11-13 15:39:55 +0100360 find_program(SYSREPOCTL sysrepoctl)
361 find_program(SYSREPOCFG sysrepocfg)
362
363 set(sysrepo_previous_fixture_name UNDEFINED)
364 function(sysrepo_fixture_env name)
365 set(test_name_init sysrepo:prep:${name})
366 set(test_name_cleanup sysrepo:clean:${name})
367 set(fixture_name sysrepo:env:${name})
368
369 add_test(NAME ${test_name_init} COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/tests/sysrepoctl-manage-module.sh ${SYSREPOCTL} ${SYSREPOCFG} prepare ${ARGN})
370 set_tests_properties(${test_name_init} PROPERTIES FIXTURES_SETUP ${fixture_name} RESOURCE_LOCK sysrepo)
371 add_test(NAME ${test_name_cleanup} COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/tests/sysrepoctl-manage-module.sh ${SYSREPOCTL} ${SYSREPOCFG} uninstall ${ARGN})
372 set_tests_properties(${test_name_cleanup} PROPERTIES FIXTURES_CLEANUP ${fixture_name} RESOURCE_LOCK sysrepo)
373
374 if (sysrepo_previous_fixture_name)
375 set_tests_properties(${test_name_init} PROPERTIES DEPENDS sysrepo:clean:${sysrepo_previous_fixture_name})
376 endif ()
377
378 set(sysrepo_previous_fixture_name ${name} PARENT_SCOPE)
379 endfunction()
380
Tomáš Pecka261c8862020-11-05 11:23:08 +0100381 velia_test(health_state-manager velia-health)
382 velia_test(health_input-semaphore velia-health DbusTesting)
383 velia_test(health_input-systemd velia-health DbusTesting)
384 velia_test(health_output-led velia-health)
Tomáš Pecka491f4f22020-11-05 15:44:00 +0100385
Tomáš Pecka991e4d52021-01-11 10:03:14 +0100386 velia_test(system_rauc velia-system DbusTesting)
Tomáš Peckacb7a5f82021-01-20 15:12:00 +0100387 set_tests_properties(
388 test-system_rauc
389 PROPERTIES RESOURCE_LOCK dbus-rauc
390 )
Tomáš Pecka991e4d52021-01-11 10:03:14 +0100391
Tomáš Pecka9b1c9672020-11-11 15:24:06 +0100392 velia_test(hardware_emmc velia-ietf-hardware FsTestUtils)
393 velia_test(hardware_hwmon velia-ietf-hardware FsTestUtils)
Tomáš Pecka83b62e12020-12-16 14:50:49 +0100394
Tomáš Pecka292bc9c2021-01-11 22:03:11 +0100395 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 +0100396 velia_test(sysrepo_system-ietfsystem velia-system DbusTesting)
Tomáš Pecka292bc9c2021-01-11 22:03:11 +0100397 set_tests_properties(
Tomáš Peckaf976c5b2021-01-23 21:19:52 +0100398 test-sysrepo_system-ietfsystem
Tomáš Pecka292bc9c2021-01-11 22:03:11 +0100399 PROPERTIES FIXTURES_REQUIRED sysrepo:env:sysrepo-ietf-system
400 RESOURCE_LOCK sysrepo
Tomáš Peckacb7a5f82021-01-20 15:12:00 +0100401)
402
403 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 +0100404 velia_test(sysrepo_system-firmware velia-system DbusTesting)
405 target_link_libraries(test-sysrepo_system-firmware SysrepoTesting)
Tomáš Peckacb7a5f82021-01-20 15:12:00 +0100406 set_tests_properties(
Tomáš Pecka594a6762021-01-29 11:06:08 +0100407 test-sysrepo_system-firmware
Tomáš Peckacb7a5f82021-01-20 15:12:00 +0100408 PROPERTIES FIXTURES_REQUIRED sysrepo:env:sysrepo-czechlight-system
409 RESOURCE_LOCK "sysrepo;dbus-rauc"
Tomáš Pecka292bc9c2021-01-11 22:03:11 +0100410 )
411
Václav Kubernátbabbab92021-01-27 09:25:05 +0100412 velia_test(sysrepo_authentication velia-system FsTestUtils)
413
414 set_tests_properties(
415 test-sysrepo_authentication
416 PROPERTIES FIXTURES_REQUIRED sysrepo:env:sysrepo-czechlight-system
417 RESOURCE_LOCK sysrepo
418 )
419
Tomáš Pecka5be83e42021-04-21 17:26:40 +0200420 velia_test(sysrepo_system-leds velia-system FsTestUtils)
Tomáš Peckaaf7b7042021-04-20 20:14:13 +0200421 set_tests_properties(
422 test-sysrepo_system-leds
423 PROPERTIES FIXTURES_REQUIRED sysrepo:env:sysrepo-czechlight-system
424 RESOURCE_LOCK sysrepo
425 )
426
Tomáš Pecka5c19e722021-02-15 20:41:29 +0100427 velia_test(sysrepo_system-network velia-system)
428 target_link_libraries(test-sysrepo_system-network FsTestUtils)
429 set_tests_properties(
430 test-sysrepo_system-network
431 PROPERTIES FIXTURES_REQUIRED sysrepo:env:sysrepo-czechlight-system
432 RESOURCE_LOCK sysrepo
433 )
434
Tomáš Peckaf10b9302021-02-23 19:02:02 +0100435 sysrepo_fixture_env(sysrepo-czechlight-network
436 YANG ${CMAKE_CURRENT_SOURCE_DIR}/yang/iana-if-type@2017-01-19.yang
437 YANG ${CMAKE_CURRENT_SOURCE_DIR}/yang/ietf-interfaces@2018-02-20.yang
438 YANG ${CMAKE_CURRENT_SOURCE_DIR}/yang/ietf-ip@2018-02-22.yang
Tomáš Pecka2a4ea7b2021-03-30 17:01:37 +0200439 YANG ${CMAKE_CURRENT_SOURCE_DIR}/yang/ietf-routing@2018-03-13.yang
440 YANG ${CMAKE_CURRENT_SOURCE_DIR}/yang/ietf-ipv4-unicast-routing@2018-03-13.yang
441 YANG ${CMAKE_CURRENT_SOURCE_DIR}/yang/ietf-ipv6-unicast-routing@2018-03-13.yang
Tomáš Peckaf10b9302021-02-23 19:02:02 +0100442 YANG ${CMAKE_CURRENT_SOURCE_DIR}/yang/czechlight-network@2021-02-22.yang)
Tomáš Pecka9fa5f6a2021-04-13 11:36:11 +0200443
Tomáš Peckaf10b9302021-02-23 19:02:02 +0100444 velia_test(sysrepo_system-ietfinterfaces velia-system)
445 set_tests_properties(
446 test-sysrepo_system-ietfinterfaces
Tomáš Pecka9fa5f6a2021-04-13 11:36:11 +0200447 PROPERTIES FIXTURES_REQUIRED "sysrepo:env:sysrepo-czechlight-network"
Tomáš Peckaf10b9302021-02-23 19:02:02 +0100448 RESOURCE_LOCK sysrepo
449 )
450
Tomáš Pecka9fa5f6a2021-04-13 11:36:11 +0200451 if(TEST_NETWORK_WITH_SUDO)
452 find_program(SUDO_EXECUTABLE sudo REQUIRED)
453 find_program(IPROUTE2_EXECUTABLE ip REQUIRED)
454 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/tests/test_vars.h.in ${CMAKE_CURRENT_BINARY_DIR}/test_vars.h @ONLY)
455
456 add_test(NAME network-czechlight0-prepare COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/tests/sysrepo_system-ietfinterfaces-sudo.sh ${SUDO_EXECUTABLE})
457 add_test(NAME network-czechlight0-cleanup COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/tests/sysrepo_system-ietfinterfaces-sudo.sh ${SUDO_EXECUTABLE})
458 set_tests_properties(network-czechlight0-prepare PROPERTIES FIXTURES_SETUP network-czechlight0)
459 set_tests_properties(network-czechlight0-cleanup PROPERTIES FIXTURES_CLEANUP network-czechlight0)
460
461 velia_test(sysrepo_system-ietfinterfaces-sudo velia-system)
462 set_tests_properties(
463 test-sysrepo_system-ietfinterfaces-sudo
464 PROPERTIES FIXTURES_REQUIRED "sysrepo:env:sysrepo-czechlight-network;network-czechlight0"
465 RESOURCE_LOCK sysrepo
466 )
467 endif()
468
Tomáš Pecka83b62e12020-12-16 14:50:49 +0100469 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 +0100470 velia_test(hardware_ietf-hardware velia-ietf-hardware velia-ietf-hardware-sysrepo FsTestUtils)
Tomáš Pecka98ad18d2020-11-13 15:39:55 +0100471 set_tests_properties(
472 test-hardware_ietf-hardware
Tomáš Pecka83b62e12020-12-16 14:50:49 +0100473 PROPERTIES FIXTURES_REQUIRED sysrepo:env:sysrepo-ietf-hardware
Tomáš Pecka55f64f82020-12-10 19:03:30 +0100474 RESOURCE_LOCK sysrepo
475 )
476
477 velia_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)
484 set_tests_properties(sysrepo_test_merge-start PROPERTIES FIXTURES_SETUP sysrepo:two-daemons RESOURCE_LOCK sysrepo)
485 set_tests_properties(sysrepo_test_merge-stop PROPERTIES FIXTURES_CLEANUP sysrepo:two-daemons RESOURCE_LOCK sysrepo)
Tomáš Pecka55f64f82020-12-10 19:03:30 +0100486
487 set_tests_properties(
488 test-sysrepo_two-daemons
489 PROPERTIES
490 FIXTURES_REQUIRED "sysrepo:two-daemons;sysrepo:env:sysrepo-ietf-hardware"
Tomáš Pecka98ad18d2020-11-13 15:39:55 +0100491 RESOURCE_LOCK sysrepo
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)
495 set_tests_properties(sysrepo:clean:sysrepo-ietf-hardware PROPERTIES DEPENDS sysrepo_test_merge-stop)
496
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
506 sysrepo_fixture_env(sysrepo-firewall
507 # 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
510 FEATURE eth
511 FEATURE match-on-eth
512 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
520 velia_test(sysrepo-firewall velia-firewall)
521 set_tests_properties(
522 test-sysrepo-firewall
523 PROPERTIES FIXTURES_REQUIRED sysrepo:env:sysrepo-firewall
524 RESOURCE_LOCK sysrepo
525 )
Tomáš Pecka261c8862020-11-05 11:23:08 +0100526endif()
Tomáš Peckac927d662020-07-13 11:16:16 +0200527
Tomáš Pecka5123e002020-06-05 15:29:21 +0200528if(WITH_DOCS)
529 set(doxyfile_in ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in)
530 set(doxyfile ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile)
531 configure_file(${doxyfile_in} ${doxyfile} @ONLY)
532 add_custom_target(doc
533 COMMAND ${DOXYGEN_EXECUTABLE} ${doxyfile}
534 WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
535 COMMENT "Generating API documentation with Doxygen"
536 VERBATIM
537 SOURCES ${doxyfile_in}
538 )
Tomáš Peckaa06d74d2020-06-14 18:18:13 +0200539endif()
Tomáš Pecka261c8862020-11-05 11:23:08 +0100540
Tomáš Pecka73a13cc2020-11-17 11:12:19 +0100541set(YANG_DIR ${CMAKE_INSTALL_PREFIX}/share/velia/yang)
542install(FILES ${YANG_SRCS} DESTINATION ${YANG_DIR})
Tomáš Peckaeb317722021-04-13 21:33:20 +0200543install(FILES ${CMAKE_SOURCE_DIR}/yang/ietf-ipv6-router-advertisements@2018-03-13.yang DESTINATION ${YANG_DIR})
Tomáš Peckacd19e622021-01-27 09:18:11 +0100544install(TARGETS veliad-health RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}/)
Tomáš Pecka625b7a12021-01-23 20:55:51 +0100545install(TARGETS veliad-system RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}/)
Tomáš Peckaaae9fe32021-01-25 19:57:22 +0100546install(TARGETS veliad-hardware RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}/)
Tomáš Peckafb14b182021-01-27 10:54:00 +0100547install(TARGETS veliad-firewall RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}/)