blob: 9267f23900bf6f3b6294ac3bca207f5333c0fedc [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áš Pecka5123e002020-06-05 15:29:21 +020038
Tomáš Peckaa193c032020-06-22 17:33:31 +020039include_directories(${CMAKE_CURRENT_BINARY_DIR})
Tomáš Pecka5123e002020-06-05 15:29:21 +020040include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/)
41
Tomáš Peckac927d662020-07-13 11:16:16 +020042include(GNUInstallDirs)
43
Tomáš Pecka5123e002020-06-05 15:29:21 +020044# Targets
Tomáš Peckabd828862020-06-15 15:53:35 +020045add_library(velia-utils STATIC
Tomáš Peckaa193c032020-06-22 17:33:31 +020046 src/utils/exceptions.cpp
Tomáš Peckaa4336812020-07-24 15:32:58 +020047 src/utils/journal.cpp
Tomáš Pecka5123e002020-06-05 15:29:21 +020048 src/utils/log-init.h
49 src/utils/log-init.cpp
50 )
Tomáš Peckabd828862020-06-15 15:53:35 +020051target_link_libraries(velia-utils PUBLIC spdlog::spdlog)
Tomáš Peckaa4336812020-07-24 15:32:58 +020052target_link_libraries(velia-utils PRIVATE PkgConfig::SYSTEMD)
53
Tomáš Pecka5123e002020-06-05 15:29:21 +020054
Tomáš Pecka74b885f2020-06-06 20:02:41 +020055add_library(velia-state-manager STATIC
56 src/inputs/AbstractInput.cpp
Tomáš Pecka0a2e8902020-06-09 21:11:20 +020057 src/inputs/DbusSemaphoreInput.cpp
Tomáš Peckaccd80c32020-06-22 14:44:32 +020058 src/inputs/DbusSystemdInput.cpp
Tomáš Pecka74b885f2020-06-06 20:02:41 +020059 src/manager/AbstractManager.cpp
60 src/manager/StateManager.cpp
Tomáš Peckaefd88432020-06-17 15:31:39 +020061 src/outputs/LedSysfsDriver.cpp
Tomáš Peckaddf04a32020-06-17 15:32:01 +020062 src/outputs/callables.cpp
Tomáš Pecka74b885f2020-06-06 20:02:41 +020063 src/State.cpp
64 )
Tomáš Pecka5d4cf2a2020-07-13 13:19:41 +020065target_link_libraries(velia-state-manager PUBLIC velia-utils Boost::boost SDBusCpp::sdbus-c++ ${STD_FILESYSTEM_LIBRARY})
Tomáš Pecka74b885f2020-06-06 20:02:41 +020066
Tomáš Peckabd828862020-06-15 15:53:35 +020067add_executable(veliad
Tomáš Pecka5123e002020-06-05 15:29:21 +020068 src/main.cpp
69 )
70
Tomáš Peckaa193c032020-06-22 17:33:31 +020071target_link_libraries(veliad PUBLIC velia-utils velia-state-manager docopt)
Tomáš Peckabd828862020-06-15 15:53:35 +020072add_dependencies(veliad target-VELIA_VERSION)
Tomáš Pecka5123e002020-06-05 15:29:21 +020073
74# Testing
Tomáš Peckaa06d74d2020-06-14 18:18:13 +020075include(CTest)
Tomáš Pecka5123e002020-06-05 15:29:21 +020076if(BUILD_TESTING)
Tomáš Pecka5123e002020-06-05 15:29:21 +020077 find_package(trompeloeil 33 REQUIRED)
78 find_package(doctest 2.3.1 REQUIRED)
79
Tomáš Peckaefd88432020-06-17 15:31:39 +020080 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/tests/configure.cmake.h.in ${CMAKE_CURRENT_BINARY_DIR}/tests/configure.cmake.h)
81
Tomáš Pecka5123e002020-06-05 15:29:21 +020082 add_library(DoctestIntegration STATIC
83 tests/doctest_integration.cpp
84 tests/trompeloeil_doctest.h
Tomáš Pecka0a2e8902020-06-09 21:11:20 +020085 tests/wait-a-bit-longer.cpp
Tomáš Pecka5123e002020-06-05 15:29:21 +020086 )
87 target_include_directories(DoctestIntegration PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/tests/ ${CMAKE_CURRENT_SOURCE_DIR}/src/)
88 target_link_libraries(DoctestIntegration doctest::doctest trompeloeil spdlog::spdlog)
89 target_compile_definitions(DoctestIntegration PUBLIC DOCTEST_CONFIG_SUPER_FAST_ASSERTS)
90
Tomáš Pecka0a2e8902020-06-09 21:11:20 +020091 add_library(DbusTesting STATIC
92 tests/dbus-helpers/dbus_semaphore_server.cpp
Tomáš Peckaccd80c32020-06-22 14:44:32 +020093 tests/dbus-helpers/dbus_systemd_server.cpp
Tomáš Pecka0a2e8902020-06-09 21:11:20 +020094 )
95 target_link_libraries(DbusTesting PUBLIC SDBusCpp::sdbus-c++)
96
Tomáš Pecka5123e002020-06-05 15:29:21 +020097 function(velia_test name)
98 add_executable(test_${name} tests/${name}.cpp)
99 target_link_libraries(test_${name} DoctestIntegration ${ARGN})
100 target_include_directories(test_${name} PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
101
102 if(NOT CMAKE_CROSSCOMPILING)
103 add_test(test_${name} test_${name})
104 endif()
105
106 endfunction()
Tomáš Pecka74b885f2020-06-06 20:02:41 +0200107 velia_test(state-manager velia-state-manager)
Tomáš Pecka0a2e8902020-06-09 21:11:20 +0200108 velia_test(input-semaphore velia-state-manager DbusTesting)
Tomáš Peckaccd80c32020-06-22 14:44:32 +0200109 velia_test(input-systemd velia-state-manager DbusTesting)
Tomáš Peckaefd88432020-06-17 15:31:39 +0200110 velia_test(output-led velia-state-manager)
Tomáš Pecka5123e002020-06-05 15:29:21 +0200111endif()
112
Tomáš Peckac927d662020-07-13 11:16:16 +0200113install(TARGETS
114 veliad
115 RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}/)
116
Tomáš Pecka5123e002020-06-05 15:29:21 +0200117if(WITH_DOCS)
118 set(doxyfile_in ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in)
119 set(doxyfile ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile)
120 configure_file(${doxyfile_in} ${doxyfile} @ONLY)
121 add_custom_target(doc
122 COMMAND ${DOXYGEN_EXECUTABLE} ${doxyfile}
123 WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
124 COMMENT "Generating API documentation with Doxygen"
125 VERBATIM
126 SOURCES ${doxyfile_in}
127 )
Tomáš Peckaa06d74d2020-06-14 18:18:13 +0200128endif()