blob: fbcbb1a0bcafbf02ffe84de8712e780c2dec867d [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
Tomáš Pecka74b885f2020-06-06 20:02:41 +020031find_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)
36
37pkg_check_modules(SYSTEMD REQUIRED IMPORTED_TARGET libsystemd)
Tomáš Pecka1f42cfe2020-10-21 18:38:27 +020038if(${SYSTEMD_VERSION} VERSION_EQUAL 245)
39 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.")
40endif()
Tomáš Pecka5123e002020-06-05 15:29:21 +020041
Tomáš Peckac927d662020-07-13 11:16:16 +020042include(GNUInstallDirs)
43
Tomáš Pecka261c8862020-11-05 11:23:08 +010044include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/)
45
Tomáš Pecka73a13cc2020-11-17 11:12:19 +010046set(YANG_SRCS
47 yang/iana-hardware@2018-03-13.yang
48 yang/ietf-hardware-state@2018-03-13.yang
49 yang/ietf-hardware@2018-03-13.yang
50 )
51
Tomáš Pecka5123e002020-06-05 15:29:21 +020052# Targets
Tomáš Pecka261c8862020-11-05 11:23:08 +010053# - utils
Tomáš Peckabd828862020-06-15 15:53:35 +020054add_library(velia-utils STATIC
Tomáš Peckaa193c032020-06-22 17:33:31 +020055 src/utils/exceptions.cpp
Tomáš Pecka261c8862020-11-05 11:23:08 +010056 src/utils/exceptions.h
Tomáš Pecka491f4f22020-11-05 15:44:00 +010057 src/utils/io.cpp
58 src/utils/io.h
Tomáš Peckaa4336812020-07-24 15:32:58 +020059 src/utils/journal.cpp
Tomáš Pecka261c8862020-11-05 11:23:08 +010060 src/utils/journal.h
61 src/utils/log.h
62 src/utils/log-fwd.h
Tomáš Pecka5123e002020-06-05 15:29:21 +020063 src/utils/log-init.cpp
Tomáš Pecka261c8862020-11-05 11:23:08 +010064 src/utils/log-init.h
Tomáš Pecka339bc672020-11-11 15:59:03 +010065 src/utils/time.cpp
66 src/utils/time.h
Tomáš Pecka5123e002020-06-05 15:29:21 +020067 )
Tomáš Pecka261c8862020-11-05 11:23:08 +010068target_link_libraries(velia-utils PUBLIC spdlog::spdlog PRIVATE PkgConfig::SYSTEMD)
Tomáš Peckaa4336812020-07-24 15:32:58 +020069
Tomáš Pecka261c8862020-11-05 11:23:08 +010070# - health
71add_library(velia-health STATIC
72 src/health/inputs/AbstractInput.cpp
73 src/health/inputs/DbusSemaphoreInput.cpp
74 src/health/inputs/DbusSystemdInput.cpp
75 src/health/manager/AbstractManager.cpp
76 src/health/manager/StateManager.cpp
77 src/health/outputs/LedSysfsDriver.cpp
78 src/health/outputs/callables.cpp
79 src/health/State.cpp
Tomáš Pecka74b885f2020-06-06 20:02:41 +020080 )
Tomáš Pecka261c8862020-11-05 11:23:08 +010081target_link_libraries(velia-health
82 PUBLIC
83 velia-utils
84 Boost::boost
85 SDBusCpp::sdbus-c++
86 ${STD_FILESYSTEM_LIBRARY}
87 )
Tomáš Pecka74b885f2020-06-06 20:02:41 +020088
Tomáš Peckabd828862020-06-15 15:53:35 +020089add_executable(veliad
Tomáš Pecka5123e002020-06-05 15:29:21 +020090 src/main.cpp
91 )
Tomáš Pecka261c8862020-11-05 11:23:08 +010092target_link_libraries(veliad
93 PUBLIC
94 velia-health
95 docopt
96 )
Tomáš Peckabd828862020-06-15 15:53:35 +020097add_dependencies(veliad target-VELIA_VERSION)
Tomáš Pecka261c8862020-11-05 11:23:08 +010098target_include_directories(veliad PUBLIC ${CMAKE_BINARY_DIR})
99
Tomáš Pecka491f4f22020-11-05 15:44:00 +0100100# - ietf-hardware
101add_library(velia-ietf-hardware STATIC
102 src/ietf-hardware/sysfs/EMMC.cpp
103 src/ietf-hardware/sysfs/EMMC.h
Tomáš Pecka9b1c9672020-11-11 15:24:06 +0100104 src/ietf-hardware/sysfs/HWMon.cpp
105 src/ietf-hardware/sysfs/HWMon.h
Tomáš Pecka339bc672020-11-11 15:59:03 +0100106 src/ietf-hardware/IETFHardware.cpp
107 src/ietf-hardware/IETFHardware.h
Tomáš Pecka491f4f22020-11-05 15:44:00 +0100108 )
109target_link_libraries(velia-ietf-hardware
110 PUBLIC
111 velia-utils
112 ${STD_FILESYSTEM_LIBRARY}
Tomáš Pecka9b1c9672020-11-11 15:24:06 +0100113 Boost::boost
Tomáš Pecka491f4f22020-11-05 15:44:00 +0100114 )
115target_include_directories(velia-ietf-hardware PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src/velia-hardware)
116
Tomáš Pecka5123e002020-06-05 15:29:21 +0200117
118# Testing
Tomáš Peckaa06d74d2020-06-14 18:18:13 +0200119include(CTest)
Tomáš Pecka5123e002020-06-05 15:29:21 +0200120if(BUILD_TESTING)
Tomáš Pecka5123e002020-06-05 15:29:21 +0200121 find_package(trompeloeil 33 REQUIRED)
122 find_package(doctest 2.3.1 REQUIRED)
123
Tomáš Peckaefd88432020-06-17 15:31:39 +0200124 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/tests/configure.cmake.h.in ${CMAKE_CURRENT_BINARY_DIR}/tests/configure.cmake.h)
125
Tomáš Pecka5123e002020-06-05 15:29:21 +0200126 add_library(DoctestIntegration STATIC
Tomáš Pecka261c8862020-11-05 11:23:08 +0100127 tests/doctest_integration.cpp
128 tests/trompeloeil_doctest.h
129 tests/wait-a-bit-longer.cpp
130 )
Tomáš Pecka5123e002020-06-05 15:29:21 +0200131 target_link_libraries(DoctestIntegration doctest::doctest trompeloeil spdlog::spdlog)
Tomáš Pecka261c8862020-11-05 11:23:08 +0100132 target_include_directories(DoctestIntegration PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/tests/)
Tomáš Pecka5123e002020-06-05 15:29:21 +0200133 target_compile_definitions(DoctestIntegration PUBLIC DOCTEST_CONFIG_SUPER_FAST_ASSERTS)
134
Tomáš Pecka0a2e8902020-06-09 21:11:20 +0200135 add_library(DbusTesting STATIC
136 tests/dbus-helpers/dbus_semaphore_server.cpp
Tomáš Pecka261c8862020-11-05 11:23:08 +0100137 tests/dbus-helpers/dbus_semaphore_server.h
Tomáš Peckaccd80c32020-06-22 14:44:32 +0200138 tests/dbus-helpers/dbus_systemd_server.cpp
Tomáš Pecka261c8862020-11-05 11:23:08 +0100139 tests/dbus-helpers/dbus_systemd_server.h
140 )
141 target_link_libraries(DbusTesting
142 PUBLIC
143 velia-utils
144 SDBusCpp::sdbus-c++
145 )
Tomáš Pecka0a2e8902020-06-09 21:11:20 +0200146
Tomáš Pecka9b1c9672020-11-11 15:24:06 +0100147 add_library(FsTestUtils STATIC
148 tests/fs-helpers/FileInjector.cpp
149 tests/fs-helpers/FileInjector.h
150 tests/fs-helpers/utils.cpp
151 tests/fs-helpers/utils.h
152 )
153 target_link_libraries(FsTestUtils
154 PUBLIC
155 ${STD_FILESYSTEM_LIBRARY}
156 )
157
Tomáš Pecka5123e002020-06-05 15:29:21 +0200158 function(velia_test name)
Tomáš Pecka261c8862020-11-05 11:23:08 +0100159 add_executable(test-${name} ${CMAKE_SOURCE_DIR}/tests/${name}.cpp)
160 target_link_libraries(test-${name} DoctestIntegration ${ARGN})
161 target_include_directories(test-${name}
162 PUBLIC
163 ${CMAKE_CURRENT_SOURCE_DIR}
164 PRIVATE
165 ${CMAKE_BINARY_DIR}
166 )
Tomáš Pecka5123e002020-06-05 15:29:21 +0200167
168 if(NOT CMAKE_CROSSCOMPILING)
Tomáš Pecka261c8862020-11-05 11:23:08 +0100169 add_test(test-${name} test-${name})
Tomáš Pecka5123e002020-06-05 15:29:21 +0200170 endif()
Tomáš Pecka5123e002020-06-05 15:29:21 +0200171 endfunction()
Tomáš Pecka5123e002020-06-05 15:29:21 +0200172
Tomáš Pecka261c8862020-11-05 11:23:08 +0100173 velia_test(health_state-manager velia-health)
174 velia_test(health_input-semaphore velia-health DbusTesting)
175 velia_test(health_input-systemd velia-health DbusTesting)
176 velia_test(health_output-led velia-health)
Tomáš Pecka491f4f22020-11-05 15:44:00 +0100177
Tomáš Pecka9b1c9672020-11-11 15:24:06 +0100178 velia_test(hardware_emmc velia-ietf-hardware FsTestUtils)
179 velia_test(hardware_hwmon velia-ietf-hardware FsTestUtils)
Tomáš Pecka339bc672020-11-11 15:59:03 +0100180 velia_test(hardware_ietf-hardware velia-ietf-hardware)
Tomáš Pecka73a13cc2020-11-17 11:12:19 +0100181
182 find_program(YANGLINT_PATH yanglint)
183 if (NOT YANGLINT_PATH)
184 message(FATAL_ERROR "Cannot find libyang's yanglint")
185 endif()
186 foreach(yang_file ${YANG_SRCS})
187 add_test(NAME yang-tree:${yang_file} COMMAND ${YANGLINT_PATH} -f tree ${CMAKE_CURRENT_SOURCE_DIR}/${yang_file})
188 endforeach()
Tomáš Pecka261c8862020-11-05 11:23:08 +0100189endif()
Tomáš Peckac927d662020-07-13 11:16:16 +0200190
Tomáš Pecka5123e002020-06-05 15:29:21 +0200191if(WITH_DOCS)
192 set(doxyfile_in ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in)
193 set(doxyfile ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile)
194 configure_file(${doxyfile_in} ${doxyfile} @ONLY)
195 add_custom_target(doc
196 COMMAND ${DOXYGEN_EXECUTABLE} ${doxyfile}
197 WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
198 COMMENT "Generating API documentation with Doxygen"
199 VERBATIM
200 SOURCES ${doxyfile_in}
201 )
Tomáš Peckaa06d74d2020-06-14 18:18:13 +0200202endif()
Tomáš Pecka261c8862020-11-05 11:23:08 +0100203
Tomáš Pecka73a13cc2020-11-17 11:12:19 +0100204set(YANG_DIR ${CMAKE_INSTALL_PREFIX}/share/velia/yang)
205install(FILES ${YANG_SRCS} DESTINATION ${YANG_DIR})
Tomáš Pecka261c8862020-11-05 11:23:08 +0100206install(TARGETS veliad RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}/)