forked from mendersoftware/mender
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cmake
184 lines (148 loc) · 5.56 KB
/
main.cmake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
# fail hard when some include doesn't 100% work
if (POLICY CMP0111)
cmake_policy(SET CMP0111 NEW)
endif (POLICY CMP0111)
# update timestamps of downloaded files after extraction instead of keeping the timestamps from the archive
if (POLICY CMP0135)
cmake_policy(SET CMP0135 NEW)
endif (POLICY CMP0135)
# The manual lists Debug, Release, RelWithDebInfo and MinSizeRel as standard build types. Let's set
# minimum size as the default, since network and I/O are likely to be bigger bottlenecks than CPU
# usage.
#
# Source:
# https://cmake.org/cmake/help/v3.27/manual/cmake-buildsystem.7.html#default-and-custom-configurations
if("${CMAKE_BUILD_TYPE}" STREQUAL "")
set(CMAKE_BUILD_TYPE "MinSizeRel")
endif()
include(cmake/asan.cmake)
include(cmake/threadsan.cmake)
# set(CMAKE_VERBOSE_MAKEFILE ON)
enable_testing()
option(COVERAGE "Turn coverage instrumentation on (Default: OFF)" OFF)
if($CACHE{COVERAGE})
set(CMAKE_CXX_FLAGS "--coverage $CACHE{CMAKE_CXX_FLAGS}")
endif()
set(GTEST_VERSION 1.12.1)
option(MENDER_DOWNLOAD_GTEST "Download google test if it is not found (Default: ON)" ON)
if (MENDER_DOWNLOAD_GTEST)
### BEGIN taken from https://google.github.io/googletest/quickstart-cmake.html
include(FetchContent)
FetchContent_Declare(
googletest
URL https://github.com/google/googletest/archive/refs/tags/release-${GTEST_VERSION}.zip
)
# For Windows: Prevent overriding the parent project's compiler/linker settings
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
### END
set(BUILD_GMOCK ON)
set(INSTALL_GTEST OFF)
FetchContent_MakeAvailable(googletest)
else()
find_package(GTest REQUIRED)
endif()
include(cmake/boost.cmake)
# TODO: proper platform detection
set(PLATFORM linux_x86)
set(MENDER_BUFSIZE 16384 CACHE STRING "Size of most internal block buffers. Can be reduced to conserve memory, but increases CPU usage.")
option(MENDER_LOG_BOOST "Use Boost as the underlying logging library provider (Default: ON)" ON)
option(MENDER_TAR_LIBARCHIVE "Use libarchive as the underlying tar library provider (Default: ON)" ON)
option(MENDER_SHA_OPENSSL "Use OpenSSL as the underlying shasum provider (Default: ON)" ON)
option(MENDER_CRYPTO_OPENSSL "Use OpenSSL as the underlying cryptography provider (Default: ON)" ON)
option(MENDER_ARTIFACT_GZIP_COMPRESSION "Enable GZIP compression support when downloading and extracting Artifacts (Default: ON)" ON)
option(MENDER_ARTIFACT_LZMA_COMPRESSION "Enable LZMA compression support when downloading and extracting Artifacts (Default: ON)" ON)
option(MENDER_ARTIFACT_ZSTD_COMPRESSION "Enable Zstd compression support when downloading and extracting Artifacts (Default: ON)" ON)
if (${PLATFORM} STREQUAL linux_x86)
set(MENDER_USE_NLOHMANN_JSON 1)
else()
set(MENDER_USE_NLOHMANN_JSON 0)
endif()
if (${PLATFORM} STREQUAL linux_x86)
set(MENDER_USE_TINY_PROC_LIB 1)
add_subdirectory(vendor/tiny-process-library)
else()
set(MENDER_USE_TINY_PROC_LIB 0)
endif()
if (${PLATFORM} STREQUAL linux_x86)
set(MENDER_USE_LMDB 1)
else()
set(MENDER_USE_LMDB 0)
endif()
if (${PLATFORM} STREQUAL linux_x86)
set(MENDER_USE_BOOST_ASIO 1)
set(MENDER_USE_ASIO_LIBDBUS 1)
else()
set(MENDER_USE_BOOST_ASIO 0)
set(MENDER_USE_ASIO_LIBDBUS 0)
endif()
add_subdirectory(vendor/expected)
include_directories(${CMAKE_SOURCE_DIR}/vendor/expected/include)
add_subdirectory(vendor/optional-lite)
include_directories(${CMAKE_SOURCE_DIR}/vendor/optional-lite/include)
if (${PLATFORM} STREQUAL linux_x86)
set(MENDER_USE_BOOST_BEAST 1)
else()
set(MENDER_USE_BOOST_BEAST 0)
endif()
include(cmake/build_mode.cmake)
if("${STD_FILESYSTEM_LIB_NAME}" STREQUAL "")
set(STD_FILESYSTEM_LIB_NAME stdc++fs)
endif()
if($CACHE{COVERAGE})
add_custom_target(coverage_enabled COMMAND true)
else()
add_custom_target(coverage_enabled
COMMAND echo 'Please run `cmake -D COVERAGE=ON .` first!'
COMMAND false
)
endif()
add_custom_target(coverage
DEPENDS coverage_enabled check
COMMAND ${CMAKE_COMMAND} --build . --target coverage_no_tests
)
# This doesn't build nor run the tests. Useful if you want to manually run just one test instead of
# all tests.
add_custom_target(coverage_no_tests
DEPENDS coverage_enabled
COMMAND lcov --capture --quiet --directory .
--output-file coverage.lcov
--exclude '/usr/*'
--exclude '*/googletest/*'
--exclude '*_test.*'
--exclude '*/googlemock/*'
--exclude '*/vendor/*'
)
# CMake is not clever enough to build the tests before running them so we use
# the 'check' target below that does both.
add_custom_target(check
COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure
DEPENDS tests
)
add_custom_target(tests
# This target itself does nothing, but all tests are added as dependencies for it.
COMMAND true
)
# CMake doesn't generate the 'uninstall' target.
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
IMMEDIATE @ONLY)
add_custom_target(uninstall
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake
)
add_custom_target(install-bin
DEPENDS install-mender-auth install-mender-update
)
add_custom_target(uninstall-bin
DEPENDS uninstall-mender-auth uninstall-mender-update
)
add_custom_target(install-dbus
DEPENDS install-dbus-interface-files install-dbus-policy-files
)
add_custom_target(uninstall-dbus
DEPENDS uninstall-dbus-interface-files uninstall-dbus-policy-files
)
include(GoogleTest)
set(MENDER_TEST_FLAGS EXTRA_ARGS --gtest_output=xml:${CMAKE_SOURCE_DIR}/reports/)
add_subdirectory(src)
message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")