blob: 70d45161204a1c6a1ee3fc74560ac94234ee7104 [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áš Pecka5123e002020-06-05 15:29:21 +020032find_package(spdlog REQUIRED)
Tomáš Pecka0a2e8902020-06-09 21:11:20 +020033find_package(sdbus-c++ REQUIRED)
Tomáš Pecka5123e002020-06-05 15:29:21 +020034
35include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/)
36
Tomáš Peckac927d662020-07-13 11:16:16 +020037include(GNUInstallDirs)
38
Tomáš Pecka5123e002020-06-05 15:29:21 +020039# Targets
Tomáš Peckabd828862020-06-15 15:53:35 +020040add_library(velia-utils STATIC
Tomáš Pecka5123e002020-06-05 15:29:21 +020041 src/utils/log-init.h
42 src/utils/log-init.cpp
43 )
Tomáš Peckabd828862020-06-15 15:53:35 +020044target_link_libraries(velia-utils PUBLIC spdlog::spdlog)
Tomáš Pecka5123e002020-06-05 15:29:21 +020045
Tomáš Pecka74b885f2020-06-06 20:02:41 +020046add_library(velia-state-manager STATIC
47 src/inputs/AbstractInput.cpp
Tomáš Pecka0a2e8902020-06-09 21:11:20 +020048 src/inputs/DbusSemaphoreInput.cpp
Tomáš Peckaccd80c32020-06-22 14:44:32 +020049 src/inputs/DbusSystemdInput.cpp
Tomáš Pecka74b885f2020-06-06 20:02:41 +020050 src/manager/AbstractManager.cpp
51 src/manager/StateManager.cpp
Tomáš Peckaefd88432020-06-17 15:31:39 +020052 src/outputs/LedSysfsDriver.cpp
Tomáš Peckaddf04a32020-06-17 15:32:01 +020053 src/outputs/callables.cpp
Tomáš Pecka74b885f2020-06-06 20:02:41 +020054 src/State.cpp
55 )
Tomáš Pecka5d4cf2a2020-07-13 13:19:41 +020056target_link_libraries(velia-state-manager PUBLIC velia-utils Boost::boost SDBusCpp::sdbus-c++ ${STD_FILESYSTEM_LIBRARY})
Tomáš Pecka74b885f2020-06-06 20:02:41 +020057
Tomáš Peckabd828862020-06-15 15:53:35 +020058add_executable(veliad
Tomáš Pecka5123e002020-06-05 15:29:21 +020059 src/main.cpp
60 )
61
Tomáš Peckabd828862020-06-15 15:53:35 +020062target_link_libraries(veliad PUBLIC velia-utils)
63add_dependencies(veliad target-VELIA_VERSION)
Tomáš Pecka5123e002020-06-05 15:29:21 +020064
65# Testing
Tomáš Peckaa06d74d2020-06-14 18:18:13 +020066include(CTest)
Tomáš Pecka5123e002020-06-05 15:29:21 +020067if(BUILD_TESTING)
Tomáš Pecka5123e002020-06-05 15:29:21 +020068 find_package(trompeloeil 33 REQUIRED)
69 find_package(doctest 2.3.1 REQUIRED)
70
Tomáš Peckaefd88432020-06-17 15:31:39 +020071 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/tests/configure.cmake.h.in ${CMAKE_CURRENT_BINARY_DIR}/tests/configure.cmake.h)
72
Tomáš Pecka5123e002020-06-05 15:29:21 +020073 add_library(DoctestIntegration STATIC
74 tests/doctest_integration.cpp
75 tests/trompeloeil_doctest.h
Tomáš Pecka0a2e8902020-06-09 21:11:20 +020076 tests/wait-a-bit-longer.cpp
Tomáš Pecka5123e002020-06-05 15:29:21 +020077 )
78 target_include_directories(DoctestIntegration PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/tests/ ${CMAKE_CURRENT_SOURCE_DIR}/src/)
79 target_link_libraries(DoctestIntegration doctest::doctest trompeloeil spdlog::spdlog)
80 target_compile_definitions(DoctestIntegration PUBLIC DOCTEST_CONFIG_SUPER_FAST_ASSERTS)
81
Tomáš Pecka0a2e8902020-06-09 21:11:20 +020082 add_library(DbusTesting STATIC
83 tests/dbus-helpers/dbus_semaphore_server.cpp
Tomáš Peckaccd80c32020-06-22 14:44:32 +020084 tests/dbus-helpers/dbus_systemd_server.cpp
Tomáš Pecka0a2e8902020-06-09 21:11:20 +020085 )
86 target_link_libraries(DbusTesting PUBLIC SDBusCpp::sdbus-c++)
87
Tomáš Pecka5123e002020-06-05 15:29:21 +020088 function(velia_test name)
89 add_executable(test_${name} tests/${name}.cpp)
90 target_link_libraries(test_${name} DoctestIntegration ${ARGN})
91 target_include_directories(test_${name} PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
92
93 if(NOT CMAKE_CROSSCOMPILING)
94 add_test(test_${name} test_${name})
95 endif()
96
97 endfunction()
Tomáš Pecka74b885f2020-06-06 20:02:41 +020098 velia_test(state-manager velia-state-manager)
Tomáš Pecka0a2e8902020-06-09 21:11:20 +020099 velia_test(input-semaphore velia-state-manager DbusTesting)
Tomáš Peckaccd80c32020-06-22 14:44:32 +0200100 velia_test(input-systemd velia-state-manager DbusTesting)
Tomáš Peckaefd88432020-06-17 15:31:39 +0200101 velia_test(output-led velia-state-manager)
Tomáš Pecka5123e002020-06-05 15:29:21 +0200102endif()
103
Tomáš Peckac927d662020-07-13 11:16:16 +0200104install(TARGETS
105 veliad
106 RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}/)
107
Tomáš Pecka5123e002020-06-05 15:29:21 +0200108if(WITH_DOCS)
109 set(doxyfile_in ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in)
110 set(doxyfile ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile)
111 configure_file(${doxyfile_in} ${doxyfile} @ONLY)
112 add_custom_target(doc
113 COMMAND ${DOXYGEN_EXECUTABLE} ${doxyfile}
114 WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
115 COMMENT "Generating API documentation with Doxygen"
116 VERBATIM
117 SOURCES ${doxyfile_in}
118 )
Tomáš Peckaa06d74d2020-06-14 18:18:13 +0200119endif()