blob: e0b0108867861006c348b3f97805cb30a4d0997d [file] [log] [blame]
Tomáš Pecka9fa5f6a2021-04-13 11:36:11 +02001cmake_minimum_required(VERSION 3.19)
Tomáš Pecka698fabc2023-04-07 10:14:07 +02002project(velia LANGUAGES CXX)
Tomáš Pecka9fa5f6a2021-04-13 11:36:11 +02003cmake_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)
Jan Kundráte44fe292024-09-17 17:05:18 +020027prepare_git_version(VELIA_VERSION "1")
Tomáš Pecka5123e002020-06-05 15:29:21 +020028
29find_package(Doxygen)
30option(WITH_DOCS "Create and install internal documentation (needs Doxygen)" ${DOXYGEN_FOUND})
31
Tomáš Pecka72f540e2024-07-08 13:45:22 +020032find_package(date REQUIRED) # FIXME: Remove when we have STL with __cpp_lib_chrono >= 201907 (gcc 14)
Václav Kubernátde0e4e62021-02-08 17:46:14 +010033find_package(Boost 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)
Jan Kundrát242e6e12024-10-15 17:16:00 +020037find_package(fmt "9.0.0" REQUIRED)
Jan Kundrátfee3bea2022-02-15 20:36:08 +010038find_package(nlohmann_json REQUIRED)
Jan Kundrát9e8752a2023-02-02 20:55:39 +010039pkg_check_modules(DOCOPT REQUIRED IMPORTED_TARGET docopt)
Tomáš Peckaa4336812020-07-24 15:32:58 +020040
41pkg_check_modules(SYSTEMD REQUIRED IMPORTED_TARGET libsystemd)
Tomáš Pecka1f42cfe2020-10-21 18:38:27 +020042if(${SYSTEMD_VERSION} VERSION_EQUAL 245)
43 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.")
44endif()
Tomáš Pecka070f60d2021-10-13 21:48:14 +020045#TODO: Check patch 20333 active
Tomáš Pecka5123e002020-06-05 15:29:21 +020046
Jan Kundrát7935e812024-09-17 17:02:01 +020047pkg_check_modules(SYSREPO REQUIRED IMPORTED_TARGET sysrepo sysrepo-cpp>=3)
48pkg_check_modules(LIBYANG REQUIRED IMPORTED_TARGET libyang libyang-cpp>=3)
Tomáš Pecka2d578c82021-02-23 19:01:35 +010049pkg_check_modules(LIBNL REQUIRED IMPORTED_TARGET libnl-route-3.0)
Tomáš Pecka98ad18d2020-11-13 15:39:55 +010050
Tomáš Peckac927d662020-07-13 11:16:16 +020051include(GNUInstallDirs)
52
Tomáš Pecka261c8862020-11-05 11:23:08 +010053include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/)
54
Tomáš Pecka73a13cc2020-11-17 11:12:19 +010055set(YANG_SRCS
Jan Kundrát7a30cf42022-07-12 22:24:09 +020056 yang/czechlight-system@2022-07-08.yang
Tomáš Pecka73a13cc2020-11-17 11:12:19 +010057 yang/iana-hardware@2018-03-13.yang
Tomáš Pecka73a13cc2020-11-17 11:12:19 +010058 yang/ietf-hardware@2018-03-13.yang
Tomáš Peckaf98ce032021-01-14 13:35:00 +010059 yang/iana-crypt-hash@2014-08-06.yang
60 yang/ietf-inet-types@2013-07-15.yang
61 yang/ietf-netconf-acm@2018-02-14.yang
62 yang/ietf-system@2014-08-06.yang
63 yang/ietf-yang-types@2013-07-15.yang
Tomáš Pecka435ca2a2021-01-27 10:53:48 +010064 yang/ietf-ethertypes@2019-03-04.yang
65 yang/ietf-interfaces@2018-02-20.yang
66 yang/ietf-packet-fields@2019-03-04.yang
Václav Kubernát637fe802021-01-22 02:43:18 +010067 yang/ietf-access-control-list@2019-03-04.yang
Václav Kubernát457d1ad2021-01-22 02:43:18 +010068 yang/czechlight-firewall@2021-01-25.yang
Tomáš Peckadac27d42021-02-22 13:20:05 +010069 yang/czechlight-network@2021-02-22.yang
70 yang/iana-if-type@2017-01-19.yang
71 yang/ietf-ip@2018-02-22.yang
Tomáš Pecka2a4ea7b2021-03-30 17:01:37 +020072 yang/ietf-routing@2018-03-13.yang
73 yang/ietf-ipv4-unicast-routing@2018-03-13.yang
74 yang/ietf-ipv6-unicast-routing@2018-03-13.yang
Tomáš Pecka7acf3922021-08-10 11:16:57 +020075 yang/czechlight-lldp@2020-11-04.yang
76 yang/iana-afn-safi@2013-07-04.yang
Tomáš Pecka6a2334b2022-07-12 13:57:54 +020077 yang/ietf-alarms@2019-09-11.yang
78 yang/velia-alarms@2022-07-12.yang
Tomáš Pecka73a13cc2020-11-17 11:12:19 +010079 )
80
Jan Kundrát086de992024-08-31 08:49:55 +020081set(YANG_SUBMODULES
82 yang/ietf-ipv6-router-advertisements@2018-03-13.yang
83 )
84
Tomáš Pecka59a148f2023-01-16 19:14:15 +010085# temporary until our CI switches to fmt>=9
86add_compile_definitions(FMT_DEPRECATED_OSTREAM)
87
Tomáš Pecka5123e002020-06-05 15:29:21 +020088# Targets
Tomáš Pecka261c8862020-11-05 11:23:08 +010089# - utils
Tomáš Peckabd828862020-06-15 15:53:35 +020090add_library(velia-utils STATIC
Tomáš Peckaad3247f2023-05-11 15:56:26 +020091 src/utils/alarms.cpp
92 src/utils/alarms.h
Jan Kundrátb98b4f92024-10-17 17:39:24 +020093 src/utils/benchmark.cpp
94 src/utils/benchmark.h
Tomáš Peckaa193c032020-06-22 17:33:31 +020095 src/utils/exceptions.cpp
Tomáš Pecka261c8862020-11-05 11:23:08 +010096 src/utils/exceptions.h
Václav Kubernát6d9357e2021-01-28 15:38:24 +010097 src/utils/exec.cpp
98 src/utils/exec.h
Tomáš Pecka491f4f22020-11-05 15:44:00 +010099 src/utils/io.cpp
100 src/utils/io.h
Tomáš Peckaa4336812020-07-24 15:32:58 +0200101 src/utils/journal.cpp
Tomáš Pecka261c8862020-11-05 11:23:08 +0100102 src/utils/journal.h
Václav Kubernátcbdc98a2021-01-28 13:24:37 +0100103 src/utils/libyang.cpp
104 src/utils/libyang.h
Tomáš Pecka261c8862020-11-05 11:23:08 +0100105 src/utils/log.h
Václav Kubernát6018f082021-02-11 01:32:18 +0100106 src/utils/log.cpp
Tomáš Pecka261c8862020-11-05 11:23:08 +0100107 src/utils/log-fwd.h
Tomáš Pecka5123e002020-06-05 15:29:21 +0200108 src/utils/log-init.cpp
Tomáš Pecka261c8862020-11-05 11:23:08 +0100109 src/utils/log-init.h
Tomáš Peckaba2dc312021-01-23 22:29:11 +0100110 src/utils/sysrepo.cpp
111 src/utils/sysrepo.h
Tomáš Peckad0337072021-01-25 19:57:00 +0100112 src/utils/waitUntilSignalled.cpp
113 src/utils/waitUntilSignalled.h
Tomáš Pecka5123e002020-06-05 15:29:21 +0200114 )
Tomáš Pecka1eb1f352023-04-14 10:39:56 +0200115target_link_libraries(velia-utils PUBLIC spdlog::spdlog PRIVATE PkgConfig::SYSTEMD PkgConfig::LIBYANG PkgConfig::SYSREPO fmt::fmt PkgConfig::DOCOPT)
Tomáš Peckaa4336812020-07-24 15:32:58 +0200116
Tomáš Pecka261c8862020-11-05 11:23:08 +0100117# - health
118add_library(velia-health STATIC
Tomáš Peckae1f0abd2022-07-13 19:31:13 +0200119 src/health/outputs/AlarmsOutputs.cpp
120 src/health/outputs/AlarmsOutputs.h
Tomáš Pecka261c8862020-11-05 11:23:08 +0100121 src/health/outputs/LedSysfsDriver.cpp
122 src/health/outputs/callables.cpp
123 src/health/State.cpp
Tomáš Pecka1d2b95c2023-05-11 16:01:46 +0200124 src/health/SystemdUnits.cpp
125 src/health/SystemdUnits.h
Tomáš Pecka74b885f2020-06-06 20:02:41 +0200126 )
Tomáš Pecka261c8862020-11-05 11:23:08 +0100127target_link_libraries(velia-health
128 PUBLIC
129 velia-utils
130 Boost::boost
131 SDBusCpp::sdbus-c++
132 ${STD_FILESYSTEM_LIBRARY}
Tomáš Pecka6a2334b2022-07-12 13:57:54 +0200133 PRIVATE
134 PkgConfig::LIBYANG
Tomáš Pecka261c8862020-11-05 11:23:08 +0100135 )
Tomáš Pecka74b885f2020-06-06 20:02:41 +0200136
Tomáš Pecka491f4f22020-11-05 15:44:00 +0100137# - ietf-hardware
138add_library(velia-ietf-hardware STATIC
139 src/ietf-hardware/sysfs/EMMC.cpp
140 src/ietf-hardware/sysfs/EMMC.h
Tomáš Pecka9b1c9672020-11-11 15:24:06 +0100141 src/ietf-hardware/sysfs/HWMon.cpp
142 src/ietf-hardware/sysfs/HWMon.h
Tomáš Peckafd09bbf2024-10-15 13:50:37 +0200143 src/ietf-hardware/sysfs/IpmiFruEEPROM.cpp
144 src/ietf-hardware/sysfs/IpmiFruEEPROM.h
Tomáš Pecka339bc672020-11-11 15:59:03 +0100145 src/ietf-hardware/IETFHardware.cpp
146 src/ietf-hardware/IETFHardware.h
Tomáš Pecka45b67f92024-01-11 14:13:05 +0100147 src/ietf-hardware/FspYh.cpp
148 src/ietf-hardware/FspYh.h
Tomáš Pecka50584c52023-04-19 10:17:01 +0200149 src/ietf-hardware/thresholds.h
Tomáš Peckadad552b82023-05-04 20:18:18 +0200150 src/ietf-hardware/thresholds.cpp
Tomáš Pecka50584c52023-04-19 10:17:01 +0200151 src/ietf-hardware/thresholds_fwd.h
Tomáš Pecka491f4f22020-11-05 15:44:00 +0100152 )
153target_link_libraries(velia-ietf-hardware
154 PUBLIC
155 velia-utils
156 ${STD_FILESYSTEM_LIBRARY}
Tomáš Pecka9b1c9672020-11-11 15:24:06 +0100157 Boost::boost
Tomáš Pecka72f540e2024-07-08 13:45:22 +0200158 PRIVATE
159 PkgConfig::LIBYANG
160 date::date
Tomáš Pecka491f4f22020-11-05 15:44:00 +0100161 )
Tomáš Pecka491f4f22020-11-05 15:44:00 +0100162
Tomáš Pecka98ad18d2020-11-13 15:39:55 +0100163add_library(velia-ietf-hardware-sysrepo STATIC
Tomáš Pecka98ad18d2020-11-13 15:39:55 +0100164 src/ietf-hardware/sysrepo/Sysrepo.cpp
165 src/ietf-hardware/sysrepo/Sysrepo.h
166 )
167target_link_libraries(velia-ietf-hardware-sysrepo
168 PUBLIC
169 velia-utils
170 PkgConfig::SYSREPO
171 PkgConfig::LIBYANG
172 )
Tomáš Pecka5123e002020-06-05 15:29:21 +0200173
Václav Kubernát6d9357e2021-01-28 15:38:24 +0100174set(NOBODY_UID 65534 CACHE STRING "UID which refers to 'nobody'. Used for dropping root privileges.")
175set(NOBODY_GID 65534 CACHE STRING "GID which refers to 'nobody'. Used for dropping root privileges.")
176
Václav Kubernátde0e4e62021-02-08 17:46:14 +0100177if(NOT NFT_EXECUTABLE)
178 find_program(NFT_EXECUTABLE nft)
179endif()
Václav Kubernátbabbab92021-01-27 09:25:05 +0100180if(NOT SSH_KEYGEN_EXECUTABLE)
181 find_program(SSH_KEYGEN_EXECUTABLE ssh-keygen)
182endif()
183if(NOT CHPASSWD_EXECUTABLE)
184 find_program(CHPASSWD_EXECUTABLE chpasswd)
185endif()
Tomáš Pecka879a6032021-02-03 17:21:48 +0100186if(NOT SYSTEMCTL_EXECUTABLE)
187 find_program(SYSTEMCTL_EXECUTABLE systemctl)
188endif()
Tomáš Pecka5c19e722021-02-15 20:41:29 +0100189if(NOT NETWORKCTL_EXECUTABLE)
190 find_program(NETWORKCTL_EXECUTABLE networkctl)
191endif()
Václav Kubernát566c9402021-02-10 08:33:54 +0100192if(NOT HOSTNAMECTL_EXECUTABLE)
193 find_program(HOSTNAMECTL_EXECUTABLE hostnamectl)
194endif()
Václav Kubernátbabbab92021-01-27 09:25:05 +0100195
196set(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.")
197if(NOT VELIA_AUTHORIZED_KEYS_FORMAT)
198 message(FATAL_ERROR "VELIA_AUTHORIZED_KEYS_FORMAT not set.")
199endif()
200
201if(NOT VELIA_AUTHORIZED_KEYS_FORMAT MATCHES "{USER}" AND NOT VELIA_AUTHORIZED_KEYS_FORMAT MATCHES "{HOME}")
202 message(FATAL_ERROR "Wrong format string given for VELIA_AUTHORIZED_KEYS_FORMAT: at least one of {USER} or {HOME} expected.")
203endif()
204
205set(VELIA_REAL_ETC_PASSWD "/etc/passwd" CACHE STRING "Path to passwd file")
206if(NOT VELIA_REAL_ETC_PASSWD)
207 message(FATAL_ERROR "VELIA_REAL_ETC_PASSWD not set")
208endif()
209
210set(VELIA_REAL_ETC_SHADOW "/etc/shadow" CACHE STRING "Path to shadow file")
211if(NOT VELIA_REAL_ETC_SHADOW)
212 message(FATAL_ERROR "VELIA_REAL_ETC_SHADOW not set")
213endif()
214
215set(VELIA_BACKUP_ETC_SHADOW "/etc/shadow" CACHE STRING "Path to where /etc/shadow gets copied to upon each change")
216if(NOT VELIA_BACKUP_ETC_SHADOW)
217 message(FATAL_ERROR "VELIA_BACKUP_ETC_SHADOW not set")
218endif()
Václav Kubernátde0e4e62021-02-08 17:46:14 +0100219
Václav Kubernát566c9402021-02-10 08:33:54 +0100220set(VELIA_BACKUP_ETC_HOSTNAME "/etc/hostname" CACHE STRING "Path to hostname file")
221if(NOT VELIA_BACKUP_ETC_HOSTNAME )
222 message(FATAL_ERROR "VELIA_BACKUP_ETC_HOSTNAME not set")
223endif()
224
Václav Kubernát6d9357e2021-01-28 15:38:24 +0100225configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/system/system_vars.h.in ${CMAKE_CURRENT_BINARY_DIR}/system_vars.h @ONLY)
226include_directories(${CMAKE_CURRENT_BINARY_DIR})
227
Tomáš Pecka292bc9c2021-01-11 22:03:11 +0100228# - ietf-system
229add_library(velia-system STATIC
Tomáš Pecka991e4d52021-01-11 10:03:14 +0100230 src/system/RAUC.cpp
231 src/system/RAUC.h
Tomáš Pecka594a6762021-01-29 11:06:08 +0100232 src/system/Firmware.cpp
233 src/system/Firmware.h
Tomáš Peckaf976c5b2021-01-23 21:19:52 +0100234 src/system/IETFSystem.cpp
235 src/system/IETFSystem.h
Václav Kubernátbabbab92021-01-27 09:25:05 +0100236 src/system/Authentication.cpp
237 src/system/Authentication.h
Tomáš Pecka2d578c82021-02-23 19:01:35 +0100238 src/system/Rtnetlink.cpp
239 src/system/Rtnetlink.h
Tomáš Peckaf10b9302021-02-23 19:02:02 +0100240 src/system/IETFInterfaces.cpp
241 src/system/IETFInterfaces.h
Tomáš Pecka39bbb512021-05-23 22:07:22 +0200242 src/system/IETFInterfacesConfig.cpp
243 src/system/IETFInterfacesConfig.h
Tomáš Peckae566fd42024-01-02 17:00:10 +0100244 src/system/JournalUpload.cpp
245 src/system/JournalUpload.h
Tomáš Peckaaf7b7042021-04-20 20:14:13 +0200246 src/system/LED.cpp
247 src/system/LED.h
Tomáš Pecka7acf3922021-08-10 11:16:57 +0200248 src/system/LLDP.cpp
249 src/system/LLDP.h
250 src/system/LLDPCallback.cpp
251 src/system/LLDPCallback.h
Tomáš Pecka292bc9c2021-01-11 22:03:11 +0100252 )
253target_link_libraries(velia-system
254 PUBLIC
255 velia-utils
256 PkgConfig::SYSREPO
257 PkgConfig::LIBYANG
Tomáš Pecka2d578c82021-02-23 19:01:35 +0100258 PkgConfig::LIBNL
Václav Kubernát6dd52c82021-01-21 08:38:42 +0100259 SDBusCpp::sdbus-c++
Jan Kundrátfee3bea2022-02-15 20:36:08 +0100260 nlohmann_json::nlohmann_json
Tomáš Pecka72f540e2024-07-08 13:45:22 +0200261 PRIVATE
262 date::date-tz
Tomáš Pecka292bc9c2021-01-11 22:03:11 +0100263 )
264
Václav Kubernátd386aba2021-01-19 10:03:28 +0100265# - firewall
266add_library(velia-firewall STATIC
267 src/firewall/Firewall.cpp
268 )
269target_link_libraries(velia-firewall
270 PUBLIC
271 velia-utils
272 PkgConfig::SYSREPO
273 PRIVATE
274 PkgConfig::LIBYANG
275 )
276
277
Tomáš Pecka625b7a12021-01-23 20:55:51 +0100278# - daemons
Tomáš Peckacd19e622021-01-27 09:18:11 +0100279add_executable(veliad-health
280 src/main-health.cpp
Tomáš Pecka139e3612021-01-25 19:49:00 +0100281 src/health/Factory.cpp
282 src/health/Factory.h
283 )
Tomáš Peckacd19e622021-01-27 09:18:11 +0100284target_link_libraries(veliad-health
Tomáš Peckaaae9fe32021-01-25 19:57:22 +0100285 PUBLIC
Tomáš Peckad03044f2020-11-12 14:33:10 +0100286 velia-health
Jan Kundrát9e8752a2023-02-02 20:55:39 +0100287 PkgConfig::DOCOPT
Tomáš Peckaaae9fe32021-01-25 19:57:22 +0100288 )
Tomáš Peckacd19e622021-01-27 09:18:11 +0100289add_dependencies(veliad-health target-VELIA_VERSION)
290target_include_directories(veliad-health PUBLIC ${CMAKE_BINARY_DIR})
Tomáš Peckad03044f2020-11-12 14:33:10 +0100291
Tomáš Pecka625b7a12021-01-23 20:55:51 +0100292add_executable(veliad-system
293 src/main-system.cpp
294 )
295target_link_libraries(veliad-system
296 PUBLIC
297 velia-system
Jan Kundrát9e8752a2023-02-02 20:55:39 +0100298 PkgConfig::DOCOPT
Tomáš Pecka625b7a12021-01-23 20:55:51 +0100299 )
300add_dependencies(veliad-system target-VELIA_VERSION)
301target_include_directories(veliad-system PUBLIC ${CMAKE_BINARY_DIR})
302
Václav Kubernátd386aba2021-01-19 10:03:28 +0100303add_executable(veliad-firewall
304 src/main-firewall.cpp
305 )
306target_link_libraries(veliad-firewall
307 PUBLIC
308 velia-firewall
309 velia-utils
Jan Kundrát9e8752a2023-02-02 20:55:39 +0100310 PkgConfig::DOCOPT
Václav Kubernátd386aba2021-01-19 10:03:28 +0100311 )
312add_dependencies(veliad-firewall target-VELIA_VERSION)
313target_include_directories(veliad-firewall PUBLIC ${CMAKE_BINARY_DIR})
314
Tomáš Peckaaae9fe32021-01-25 19:57:22 +0100315add_executable(veliad-hardware
316 src/main-hardware.cpp
317 src/ietf-hardware/Factory.cpp
318 src/ietf-hardware/Factory.h
319 )
320target_link_libraries(veliad-hardware
321 PUBLIC
322 velia-ietf-hardware
323 velia-ietf-hardware-sysrepo
Jan Kundrát9e8752a2023-02-02 20:55:39 +0100324 PkgConfig::DOCOPT
Tomáš Peckaaae9fe32021-01-25 19:57:22 +0100325 )
326add_dependencies(veliad-hardware target-VELIA_VERSION)
327target_include_directories(veliad-hardware PUBLIC ${CMAKE_BINARY_DIR})
328
Tomáš Peckafd09bbf2024-10-15 13:50:37 +0200329add_executable(velia-ipmi-fru-eeprom
330 src/main-ipmi-fru-eeprom.cpp
331 )
332add_dependencies(velia-ipmi-fru-eeprom target-VELIA_VERSION)
333target_link_libraries(velia-ipmi-fru-eeprom
334 PUBLIC
335 velia-ietf-hardware
336 PkgConfig::DOCOPT
337 fmt::fmt
338 )
339add_dependencies(veliad-hardware target-VELIA_VERSION)
340target_include_directories(veliad-hardware PUBLIC ${CMAKE_BINARY_DIR})
341
Tomáš Pecka5123e002020-06-05 15:29:21 +0200342# Testing
Tomáš Peckaa06d74d2020-06-14 18:18:13 +0200343include(CTest)
Tomáš Pecka5123e002020-06-05 15:29:21 +0200344if(BUILD_TESTING)
Jan Kundrát613f07f2023-11-03 13:28:51 +0100345 find_package(trompeloeil 45 REQUIRED)
346 find_package(doctest 2.4.11 REQUIRED)
Jan Kundrátd012b322024-01-12 18:37:05 +0100347 include(cmake/SysrepoTest.cmake)
Tomáš Pecka5123e002020-06-05 15:29:21 +0200348
Tomáš Peckaefd88432020-06-17 15:31:39 +0200349 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/tests/configure.cmake.h.in ${CMAKE_CURRENT_BINARY_DIR}/tests/configure.cmake.h)
350
Tomáš Pecka5123e002020-06-05 15:29:21 +0200351 add_library(DoctestIntegration STATIC
Tomáš Pecka261c8862020-11-05 11:23:08 +0100352 tests/doctest_integration.cpp
353 tests/trompeloeil_doctest.h
354 tests/wait-a-bit-longer.cpp
355 )
Václav Kubernát7efd6d52021-11-09 01:31:11 +0100356 target_link_libraries(DoctestIntegration doctest::doctest spdlog::spdlog)
Tomáš Pecka261c8862020-11-05 11:23:08 +0100357 target_include_directories(DoctestIntegration PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/tests/)
Tomáš Pecka5123e002020-06-05 15:29:21 +0200358 target_compile_definitions(DoctestIntegration PUBLIC DOCTEST_CONFIG_SUPER_FAST_ASSERTS)
359
Tomáš Peckaa18702d2021-01-25 18:07:23 +0100360 add_library(SysrepoTesting STATIC
Tomáš Pecka0ed5f4f2023-05-17 12:20:23 +0200361 tests/mock/ietf_hardware.h
362 tests/mock/system.h
Tomáš Peckac164ca62024-01-24 13:38:03 +0100363 tests/sysrepo-helpers/common.cpp
364 tests/sysrepo-helpers/common.h
Tomáš Pecka7eb64592024-01-24 14:10:47 +0100365 tests/sysrepo-helpers/datastore.cpp
366 tests/sysrepo-helpers/datastore.h
Tomáš Pecka9f7b13e2024-01-24 13:47:04 +0100367 tests/sysrepo-helpers/notifications.cpp
368 tests/sysrepo-helpers/notifications.h
Tomáš Pecka6fcb7592024-01-24 14:42:14 +0100369 tests/sysrepo-helpers/rpc.cpp
370 tests/sysrepo-helpers/rpc.h
Tomáš Peckabaf289c2024-01-24 15:12:44 +0100371 tests/sysrepo-helpers/alarms.cpp
372 tests/sysrepo-helpers/alarms.h
Tomáš Peckaa18702d2021-01-25 18:07:23 +0100373 )
374 target_link_libraries(SysrepoTesting DoctestIntegration PkgConfig::SYSREPO)
375
Tomáš Pecka0a2e8902020-06-09 21:11:20 +0200376 add_library(DbusTesting STATIC
Tomáš Pecka991e4d52021-01-11 10:03:14 +0100377 tests/dbus-helpers/dbus_rauc_server.cpp
378 tests/dbus-helpers/dbus_rauc_server.h
Tomáš Pecka79344c82021-09-16 18:25:59 +0200379 tests/dbus-helpers/dbus_resolve1_server.cpp
380 tests/dbus-helpers/dbus_resolve1_server.h
Tomáš Pecka0a2e8902020-06-09 21:11:20 +0200381 tests/dbus-helpers/dbus_semaphore_server.cpp
Tomáš Pecka261c8862020-11-05 11:23:08 +0100382 tests/dbus-helpers/dbus_semaphore_server.h
Tomáš Peckaccd80c32020-06-22 14:44:32 +0200383 tests/dbus-helpers/dbus_systemd_server.cpp
Tomáš Pecka261c8862020-11-05 11:23:08 +0100384 tests/dbus-helpers/dbus_systemd_server.h
385 )
386 target_link_libraries(DbusTesting
387 PUBLIC
388 velia-utils
389 SDBusCpp::sdbus-c++
390 )
Tomáš Pecka0a2e8902020-06-09 21:11:20 +0200391
Tomáš Pecka9b1c9672020-11-11 15:24:06 +0100392 add_library(FsTestUtils STATIC
393 tests/fs-helpers/FileInjector.cpp
394 tests/fs-helpers/FileInjector.h
395 tests/fs-helpers/utils.cpp
396 tests/fs-helpers/utils.h
397 )
398 target_link_libraries(FsTestUtils
399 PUBLIC
400 ${STD_FILESYSTEM_LIBRARY}
401 )
402
Tomáš Pecka174cc842023-02-02 14:52:12 +0100403 find_program(IPROUTE2_EXECUTABLE ip REQUIRED)
Tomáš Pecka174cc842023-02-02 14:52:12 +0100404 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/tests/test_vars.h.in ${CMAKE_CURRENT_BINARY_DIR}/test_vars.h @ONLY)
Václav Kubernát5a745d22021-11-12 12:09:57 +0100405
Tomáš Pecka174cc842023-02-02 14:52:12 +0100406 function(velia_test)
Jan Kundrátd012b322024-01-12 18:37:05 +0100407 cmake_parse_arguments(TEST "" "NAME" "" ${ARGN})
408 sysrepo_test(NAME ${TEST_NAME} ${TEST_UNPARSED_ARGUMENTS})
Tomáš Peckac164ca62024-01-24 13:38:03 +0100409 target_link_libraries(test-${TEST_NAME} DoctestIntegration SysrepoTesting)
Tomáš Pecka98ad18d2020-11-13 15:39:55 +0100410 endfunction()
411
Tomáš Pecka0f85ab62023-02-02 14:53:14 +0100412 find_program(YANGLINT_PATH yanglint)
413 if (NOT YANGLINT_PATH)
414 message(FATAL_ERROR "Cannot find libyang's yanglint")
415 endif()
416 foreach(yang_file ${YANG_SRCS})
417 add_test(NAME yang-tree:${yang_file} COMMAND ${YANGLINT_PATH} -f tree ${CMAKE_CURRENT_SOURCE_DIR}/${yang_file})
418 endforeach()
419
Tomáš Pecka174cc842023-02-02 14:52:12 +0100420 velia_test(NAME system_rauc LIBRARIES velia-system DbusTesting RESOURCE_LOCK dbus-rauc)
421 velia_test(NAME system_lldp LIBRARIES velia-system DbusTesting)
Tomáš Pecka991e4d52021-01-11 10:03:14 +0100422
Tomáš Pecka50584c52023-04-19 10:17:01 +0200423 velia_test(NAME hardware_thresholds LIBRARIES velia-ietf-hardware)
Jan Kundrátc98da382024-10-08 16:47:04 +0200424 velia_test(NAME hardware_eeprom LIBRARIES velia-ietf-hardware)
Tomáš Pecka174cc842023-02-02 14:52:12 +0100425 velia_test(NAME hardware_emmc LIBRARIES velia-ietf-hardware FsTestUtils)
426 velia_test(NAME hardware_hwmon LIBRARIES velia-ietf-hardware FsTestUtils)
Tomáš Pecka45b67f92024-01-11 14:13:05 +0100427 velia_test(NAME hardware_fspyh LIBRARIES velia-ietf-hardware FsTestUtils)
Tomáš Pecka3f811962023-04-14 10:54:32 +0200428 velia_test(NAME hardware_ietf-hardware LIBRARIES velia-ietf-hardware)
Tomáš Pecka7acf3922021-08-10 11:16:57 +0200429
Jan Kundrátd012b322024-01-12 18:37:05 +0100430 set(fixture_sysrepo-czechlight-lldp --install ${CMAKE_CURRENT_SOURCE_DIR}/yang/czechlight-lldp@2020-11-04.yang)
Tomáš Pecka174cc842023-02-02 14:52:12 +0100431 velia_test(NAME sysrepo_system-lldp LIBRARIES velia-system DbusTesting FIXTURE fixture_sysrepo-czechlight-lldp)
Tomáš Pecka83b62e12020-12-16 14:50:49 +0100432
Jan Kundrátd012b322024-01-12 18:37:05 +0100433 set(fixture_sysrepo-ietf-system --install ${CMAKE_CURRENT_SOURCE_DIR}/yang/ietf-system@2014-08-06.yang)
Tomáš Pecka174cc842023-02-02 14:52:12 +0100434 velia_test(NAME sysrepo_system-ietfsystem LIBRARIES velia-system DbusTesting FIXTURE fixture_sysrepo-ietf-system)
Tomáš Peckacb7a5f82021-01-20 15:12:00 +0100435
Tomáš Pecka24b54832024-01-17 18:10:44 +0100436 set(fixture_sysrepo-czechlight-system --install ${CMAKE_CURRENT_SOURCE_DIR}/yang/czechlight-system@2022-07-08.yang --init-data ${CMAKE_CURRENT_SOURCE_DIR}/yang/czechlight-authentication.json)
Tomáš Peckac164ca62024-01-24 13:38:03 +0100437 velia_test(NAME sysrepo_system-firmware LIBRARIES velia-system DbusTesting FIXTURE fixture_sysrepo-czechlight-system RESOURCE_LOCK dbus-rauc)
Tomáš Pecka72f540e2024-07-08 13:45:22 +0200438 velia_test(NAME sysrepo_authentication LIBRARIES velia-system FsTestUtils date::date-tz FIXTURE fixture_sysrepo-czechlight-system)
Tomáš Pecka174cc842023-02-02 14:52:12 +0100439 velia_test(NAME sysrepo_system-leds LIBRARIES velia-system FsTestUtils FIXTURE fixture_sysrepo-czechlight-system)
Tomáš Peckae566fd42024-01-02 17:00:10 +0100440 velia_test(NAME sysrepo_system-journalupload LIBRARIES velia-system FIXTURE fixture_sysrepo-czechlight-system)
Tomáš Peckaaf7b7042021-04-20 20:14:13 +0200441
Václav Kubernát5a745d22021-11-12 12:09:57 +0100442 set(fixture_sysrepo-czechlight-network
Jan Kundrátd012b322024-01-12 18:37:05 +0100443 --install ${CMAKE_CURRENT_SOURCE_DIR}/yang/iana-if-type@2017-01-19.yang
444 --install ${CMAKE_CURRENT_SOURCE_DIR}/yang/ietf-interfaces@2018-02-20.yang
445 --install ${CMAKE_CURRENT_SOURCE_DIR}/yang/ietf-ip@2018-02-22.yang
446 --install ${CMAKE_CURRENT_SOURCE_DIR}/yang/ietf-routing@2018-03-13.yang
447 --install ${CMAKE_CURRENT_SOURCE_DIR}/yang/ietf-ipv4-unicast-routing@2018-03-13.yang
448 --install ${CMAKE_CURRENT_SOURCE_DIR}/yang/ietf-ipv6-unicast-routing@2018-03-13.yang
449 --install ${CMAKE_CURRENT_SOURCE_DIR}/yang/czechlight-network@2021-02-22.yang)
Jan Kundrátf1af3182023-02-08 21:55:15 +0100450 velia_test(NAME sysrepo_interfaces-systemd-networkd LIBRARIES velia-system FIXTURE fixture_sysrepo-czechlight-network)
Tomáš Peckaf10b9302021-02-23 19:02:02 +0100451
Tomáš Peckafd5ec7b2023-02-02 18:48:37 +0100452 find_program(UNSHARE_EXECUTABLE unshare REQUIRED)
Jan Kundrátcb93e662023-02-08 17:39:06 +0100453 find_program(MOUNT_EXECUTABLE mount REQUIRED)
Tomáš Peckafd5ec7b2023-02-02 18:48:37 +0100454 pkg_get_variable(SR_GROUP sysrepo SR_GROUP)
455 if (SR_GROUP)
456 set(UNSHARE_MAP_GROUP_ARG "--map-group=${SR_GROUP}")
457 else()
458 set(UNSHARE_MAP_GROUP_ARG "")
Tomáš Pecka9fa5f6a2021-04-13 11:36:11 +0200459 endif()
Jan Kundrátd16357d2023-02-08 21:57:57 +0100460 velia_test(NAME sysrepo_interfaces-libnl LIBRARIES velia-system FIXTURE fixture_sysrepo-czechlight-network
461 COMMAND ${UNSHARE_EXECUTABLE} --net --mount --map-root-user ${UNSHARE_MAP_GROUP_ARG} sh -c "set -ex $<SEMICOLON> ${MOUNT_EXECUTABLE} -t sysfs none /sys $<SEMICOLON> $<TARGET_FILE:test-sysrepo_interfaces-libnl>")
Tomáš Pecka55f64f82020-12-10 19:03:30 +0100462
Tomáš Pecka2117ce52023-05-12 11:28:34 +0200463 set(fixture_sysrepo-ietf-hardware
Jan Kundrátd012b322024-01-12 18:37:05 +0100464 --install ${CMAKE_CURRENT_SOURCE_DIR}/yang/iana-hardware@2018-03-13.yang
465 --install ${CMAKE_CURRENT_SOURCE_DIR}/yang/ietf-hardware@2018-03-13.yang
466 --enable-feature hardware-sensor
467 --enable-feature hardware-state
468 --install ${CMAKE_CURRENT_SOURCE_DIR}/yang/ietf-alarms@2019-09-11.yang
469 --enable-feature alarm-shelving
470 --enable-feature alarm-summary
471 --install ${CMAKE_CURRENT_SOURCE_DIR}/yang/velia-alarms@2022-07-12.yang
472 --install ${CMAKE_CURRENT_SOURCE_DIR}/tests/yang/sysrepo-ietf-alarms@2022-02-17.yang)
Tomáš Pecka3f811962023-04-14 10:54:32 +0200473 velia_test(NAME sysrepo_ietf-hardware LIBRARIES velia-ietf-hardware velia-ietf-hardware-sysrepo FsTestUtils FIXTURE fixture_sysrepo-ietf-hardware)
Tomáš Pecka174cc842023-02-02 14:52:12 +0100474
Tomáš Pecka83b62e12020-12-16 14:50:49 +0100475 # 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 +0100476 add_executable(test-sysrepo_test_merge-daemon ${CMAKE_SOURCE_DIR}/tests/sysrepo_two-daemons_daemon.cpp)
477 target_link_libraries(test-sysrepo_test_merge-daemon PkgConfig::SYSREPO PkgConfig::LIBYANG)
Tomáš Pecka174cc842023-02-02 14:52:12 +0100478 velia_test(NAME sysrepo_two-daemons LIBRARIES velia-ietf-hardware-sysrepo FIXTURE fixture_sysrepo-ietf-hardware)
Tomáš Pecka55f64f82020-12-10 19:03:30 +0100479
480 add_test(NAME sysrepo_test_merge-start COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/tests/sysrepo_two-daemons_control.sh start)
481 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 +0100482 set_tests_properties(sysrepo_test_merge-start PROPERTIES FIXTURES_SETUP sysrepo:two-daemons)
483 set_tests_properties(sysrepo_test_merge-stop PROPERTIES FIXTURES_CLEANUP sysrepo:two-daemons)
Jan Kundrátd012b322024-01-12 18:37:05 +0100484 get_property(TWO_DAEMONS_ENV TEST test-sysrepo_two-daemons PROPERTY ENVIRONMENT)
485 set_property(TEST sysrepo_test_merge-start sysrepo_test_merge-stop PROPERTY ENVIRONMENT ${TWO_DAEMONS_ENV})
Václav Kubernát5a745d22021-11-12 12:09:57 +0100486 set_property(TEST test-sysrepo_two-daemons APPEND PROPERTY FIXTURES_REQUIRED sysrepo:two-daemons)
487
Tomáš Pecka83b62e12020-12-16 14:50:49 +0100488 # ensure we run two-daemons merge test and ietf-hardware test sequentially and don't cleanup before everything ends
Tomáš Pecka3f811962023-04-14 10:54:32 +0200489 set_tests_properties(sysrepo_test_merge-start PROPERTIES DEPENDS test-sysrepo_ietf-hardware)
Václav Kubernát5a745d22021-11-12 12:09:57 +0100490 set_tests_properties(sysrepo:clean:sysrepo_two-daemons PROPERTIES DEPENDS sysrepo_test_merge-stop)
Tomáš Pecka83b62e12020-12-16 14:50:49 +0100491
Václav Kubernát5a745d22021-11-12 12:09:57 +0100492 set(fixture_sysrepo-firewall
Václav Kubernátd386aba2021-01-19 10:03:28 +0100493 # Installing czechlight-firewall automatically installs ietf-access-control-list as implemented (not just
494 # imported) but I still need to install it myself to enable the features.
Jan Kundrátd012b322024-01-12 18:37:05 +0100495 --install ${CMAKE_CURRENT_SOURCE_DIR}/yang/ietf-access-control-list@2019-03-04.yang
496 --enable-feature match-on-eth
497 --enable-feature eth
498 --enable-feature match-on-ipv4
499 --enable-feature ipv4
500 --enable-feature match-on-ipv6
501 --enable-feature ipv6
502 --enable-feature mixed-eth-ipv4-ipv6
503 --install ${CMAKE_CURRENT_SOURCE_DIR}/yang/czechlight-firewall@2021-01-25.yang
Václav Kubernátd386aba2021-01-19 10:03:28 +0100504 )
505
Tomáš Pecka174cc842023-02-02 14:52:12 +0100506 velia_test(NAME sysrepo-firewall LIBRARIES velia-firewall FIXTURE fixture_sysrepo-firewall)
Tomáš Pecka6a2334b2022-07-12 13:57:54 +0200507
508 set(fixture_sysrepo-alarms
Jan Kundrátd012b322024-01-12 18:37:05 +0100509 --install ${CMAKE_CURRENT_SOURCE_DIR}/yang/ietf-alarms@2019-09-11.yang
510 --enable-feature alarm-shelving
511 --enable-feature alarm-summary
512 --install ${CMAKE_CURRENT_SOURCE_DIR}/yang/velia-alarms@2022-07-12.yang
513 --install ${CMAKE_CURRENT_SOURCE_DIR}/tests/yang/sysrepo-ietf-alarms@2022-02-17.yang
Tomáš Pecka6a2334b2022-07-12 13:57:54 +0200514 )
Tomáš Pecka3906c892022-07-26 13:51:17 +0200515 velia_test(NAME health_systemd-units LIBRARIES velia-health DbusTesting FIXTURE fixture_sysrepo-alarms)
516 velia_test(NAME sysrepo_health-led-alarms LIBRARIES velia-health DbusTesting FIXTURE fixture_sysrepo-alarms)
Tomáš Peckabe797072022-07-15 20:45:52 +0200517
518 find_program(SYSREPO_IETF_ALARMSD_EXECUTABLE sysrepo-ietf-alarmsd)
519 if(SYSREPO_IETF_ALARMSD_EXECUTABLE)
520 velia_test(NAME sysrepo_ietf-alarms LIBRARIES velia-health DbusTesting FIXTURE fixture_sysrepo-alarms)
521
522 add_test(NAME sysrepo_ietf-alarms-start COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/tests/sysrepo_sysrepo-ietf-alarms_control.sh start ${SYSREPO_IETF_ALARMSD_EXECUTABLE} ${CMAKE_BINARY_DIR}/sysrepo-ietf-alarmsd.log)
523 add_test(NAME sysrepo_ietf-alarms-stop COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/tests/sysrepo_sysrepo-ietf-alarms_control.sh stop)
Jan Kundrátd012b322024-01-12 18:37:05 +0100524 get_property(IETF_ALARMS_ENV TEST test-sysrepo_ietf-alarms PROPERTY ENVIRONMENT)
525 set_property(TEST sysrepo_ietf-alarms-start sysrepo_ietf-alarms-stop PROPERTY ENVIRONMENT ${IETF_ALARMS_ENV})
Tomáš Peckabe797072022-07-15 20:45:52 +0200526 set_tests_properties(sysrepo_ietf-alarms-start PROPERTIES FIXTURES_SETUP sysrepo-ietf-alarmsd)
527 set_tests_properties(sysrepo_ietf-alarms-stop PROPERTIES FIXTURES_CLEANUP sysrepo-ietf-alarmsd)
528 set_property(TEST test-sysrepo_ietf-alarms APPEND PROPERTY FIXTURES_REQUIRED sysrepo-ietf-alarmsd)
529
530 set_tests_properties(sysrepo_ietf-alarms-start PROPERTIES DEPENDS sysrepo:prep:sysrepo_ietf-alarms)
531 set_tests_properties(sysrepo:clean:sysrepo_ietf-alarms PROPERTIES DEPENDS sysrepo_ietf-alarms-stop)
532 endif()
Tomáš Pecka261c8862020-11-05 11:23:08 +0100533endif()
Tomáš Peckac927d662020-07-13 11:16:16 +0200534
Tomáš Pecka5123e002020-06-05 15:29:21 +0200535if(WITH_DOCS)
536 set(doxyfile_in ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in)
537 set(doxyfile ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile)
538 configure_file(${doxyfile_in} ${doxyfile} @ONLY)
539 add_custom_target(doc
540 COMMAND ${DOXYGEN_EXECUTABLE} ${doxyfile}
541 WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
542 COMMENT "Generating API documentation with Doxygen"
543 VERBATIM
544 SOURCES ${doxyfile_in}
545 )
Tomáš Peckaa06d74d2020-06-14 18:18:13 +0200546endif()
Tomáš Pecka261c8862020-11-05 11:23:08 +0100547
Jan Kundrát9efb73c2024-08-31 08:52:19 +0200548set(YANG_DIR ${CMAKE_INSTALL_PREFIX}/share/yang/modules/velia)
Jan Kundrát086de992024-08-31 08:49:55 +0200549install(FILES ${YANG_SRCS} ${YANG_SUBMODULES} DESTINATION ${YANG_DIR})
Jan Kundrát9efb73c2024-08-31 08:52:19 +0200550set(YANG_DATA_DIR ${CMAKE_INSTALL_PREFIX}/share/yang/static-data/velia)
551install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/yang/czechlight-authentication.json DESTINATION ${YANG_DATA_DIR})
Jan Kundrátc8a08662024-10-16 17:34:23 +0200552install(TARGETS
553 veliad-health
554 veliad-system
555 veliad-hardware
556 veliad-firewall
557 velia-ipmi-fru-eeprom
558 RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR})
Tomáš Pecka848207c2024-09-24 15:22:41 +0200559
Jan Kundrát276f59b2024-10-16 17:35:18 +0200560set(JQ_SRCS)
561function(add_jq_utility NAME)
562 set(JQ_FILE ${CMAKE_CURRENT_SOURCE_DIR}/cli/${NAME}.jq)
563 set(JQ_WRAPPER ${CMAKE_CURRENT_SOURCE_DIR}/cli/${NAME}.in)
564 list(APPEND JQ_SRCS ${JQ_FILE} ${JQ_WRAPPER})
565 configure_file(${JQ_WRAPPER} ${CMAKE_CURRENT_BINARY_DIR}/${NAME} @ONLY)
566 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${NAME}
567 PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
568 DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR})
569 install(FILES ${JQ_FILE} DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBEXECDIR}/velia)
570endfunction()
571add_custom_target(jq_utils SOURCES ${JQ_SRCS})
572
Jan Kundrát6d341672024-10-17 01:30:35 +0200573find_program(JQ_EXECUTABLE jq)
574function(add_jq_test UTILITY_NAME TESTCASE_NAME)
575 set(test_name jq-${UTILITY_NAME}-${TESTCASE_NAME})
576 if(JQ_EXECUTABLE STREQUAL "JQ_EXECUTABLE-NOTFOUND")
577 message(WARNING "Cannot find the `jq` program, skipping test \"${test_name}\"")
578 return()
579 endif()
580 set(test_input_prefix ${CMAKE_CURRENT_SOURCE_DIR}/tests/jq/${UTILITY_NAME}/${TESTCASE_NAME})
581 if(EXISTS ${test_input_prefix}.config.json)
582 set(jq_extra_config "--argjson config \"$(< ${test_input_prefix}.config.json)\"")
583 else()
584 set(jq_extra_config "")
585 endif()
586 add_test(NAME ${test_name}
587 COMMAND sh -c
588 "${JQ_EXECUTABLE} -f ${CMAKE_CURRENT_SOURCE_DIR}/cli/${UTILITY_NAME}.jq ${jq_extra_config} \
589 < ${test_input_prefix}.json \
590 | diff -u ${test_input_prefix}.expected -")
591endfunction()
592
Jan Kundrát276f59b2024-10-16 17:35:18 +0200593add_jq_utility(velia-list-alarms)
Jan Kundrát6d341672024-10-17 01:30:35 +0200594add_jq_test(velia-list-alarms EDFA-LINE-SDN-ID210512)
595add_jq_test(velia-list-alarms active-since)
596add_jq_test(velia-list-alarms cleared-before)
Jan Kundráte2552412024-10-16 17:40:07 +0200597add_jq_utility(velia-list-hardware)
Jan Kundrát6d341672024-10-17 01:30:35 +0200598add_jq_test(velia-list-hardware EDFA-LINE-SDN-ID210512)