forked from boost-ext/ut
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
261 lines (221 loc) · 8.3 KB
/
CMakeLists.txt
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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
#
# This file is part of the µOS++ distribution.
# (https://github.com/micro-os-plus)
# Copyright (c) 2022 Liviu Ionescu
#
# Permission to use, copy, modify, and/or distribute this software
# for any purpose is hereby granted, under the terms of the MIT license.
#
# If a copy of the license was not distributed with this file, it can
# be obtained from https://opensource.org/licenses/MIT/.
#
# -----------------------------------------------------------------------------
# This file is intended to be consumed by applications with:
#
# `add_subdirectory("xpacks/xpack-3rd-party-boost-ut")`
#
# The result is an interface library that can be added to the linker with:
#
# `target_link_libraries(your-target PUBLIC xpack-3rd-party::boost-ut)`
# -----------------------------------------------------------------------------
## Preamble ##
# https://cmake.org/cmake/help/v3.20/
cmake_minimum_required(VERSION 3.20)
project(xpack-3rd-party-boost-ut
DESCRIPTION "Boost C++20 μ(micro)/Unit Testing Framework"
)
if(COMMAND xpack_get_package_name_and_version)
xpack_get_package_name_and_version("${CMAKE_CURRENT_SOURCE_DIR}/package.json")
message(VERBOSE "Processing xPack ${PACKAGE_JSON_NAME}@${PACKAGE_JSON_VERSION}...")
endif()
# -----------------------------------------------------------------------------
## The project library definitions ##
add_library(xpack-3rd-party-boost-ut-interface INTERFACE EXCLUDE_FROM_ALL)
# -----------------------------------------------------------------------------
# Target settings.
target_include_directories(xpack-3rd-party-boost-ut-interface INTERFACE
"include"
)
target_sources(xpack-3rd-party-boost-ut-interface INTERFACE
# None.
)
target_compile_definitions(xpack-3rd-party-boost-ut-interface INTERFACE
# None.
)
target_compile_options(xpack-3rd-party-boost-ut-interface INTERFACE
-Wno-padded
-Wno-aggregate-return
$<$<C_COMPILER_ID:Clang,AppleClang>:-Wno-c++98-c++11-c++14-c++17-compat-pedantic>
$<$<C_COMPILER_ID:Clang,AppleClang>:-Wno-c++98-c++11-compat>
$<$<C_COMPILER_ID:Clang,AppleClang>:-Wno-c++98-compat>
$<$<C_COMPILER_ID:Clang,AppleClang>:-Wno-c++98-compat-pedantic>
$<$<C_COMPILER_ID:Clang,AppleClang>:-Wno-c99-extensions>
$<$<C_COMPILER_ID:Clang,AppleClang>:-Wno-pedantic>
$<$<C_COMPILER_ID:Clang,AppleClang>:-Wno-exit-time-destructors>
$<$<C_COMPILER_ID:Clang,AppleClang>:-Wno-ctad-maybe-unsupported>
$<$<C_COMPILER_ID:Clang,AppleClang>:-Wno-global-constructors>
$<$<C_COMPILER_ID:Clang,AppleClang>:-Wno-extra-semi-stmt>
)
target_link_libraries(xpack-3rd-party-boost-ut-interface INTERFACE
# None.
)
if (COMMAND xpack_display_target_lists)
xpack_display_target_lists(xpack-3rd-party-boost-ut-interface)
endif()
# -----------------------------------------------------------------------------
# Aliases.
# https://cmake.org/cmake/help/v3.20/command/add_library.html#alias-libraries
add_library(xpack-3rd-party::boost-ut ALIAS xpack-3rd-party-boost-ut-interface)
message(VERBOSE "> xpack-3rd-party::boost-ut -> xpack-3rd-party-boost-ut-interface")
# -----------------------------------------------------------------------------
if(false)
#
# Copyright (c) 2019-2020 Kris Jusiak (kris at jusiak dot net)
#
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#
cmake_minimum_required(VERSION 3.12...3.20)
project(
ut
VERSION 1.1.8
LANGUAGES CXX
)
set(MASTER_PROJECT OFF)
if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
set(MASTER_PROJECT ON)
endif()
if(NOT DEFINED CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD
20
CACHE STRING "Default value for CXX_STANDARD property of targets."
)
option(CMAKE_CXX_STANDARD_REQUIRED "Default value for CXX_STANDARD_REQUIRED property of targets." YES)
option(CMAKE_CXX_EXTENSIONS "Default value for CXX_EXTENSIONS property of targets." NO)
endif()
option(BOOST_UT_ENABLE_MEMCHECK "Run the unit tests and examples under valgrind if it is found" OFF)
option(BOOST_UT_ENABLE_COVERAGE "Run coverage" OFF)
option(BOOST_UT_ENABLE_SANITIZERS "Run static analysis" OFF)
option(BOOST_UT_BUILD_BENCHMARKS "Build the benchmarks" ${MASTER_PROJECT})
option(BOOST_UT_BUILD_EXAMPLES "Build the examples" ${MASTER_PROJECT})
option(BOOST_UT_BUILD_TESTS "Build the tests" ${MASTER_PROJECT})
option(BOOST_UT_DISABLE_MODULE "Disable ut module" OFF)
# ---- Add dependencies via CPM ----
# see https://github.com/cpm-cmake/CPM.cmake for more info
if(CMAKE_VERSION VERSION_LESS 3.20.0)
# see https://github.com/TheLartians/PackageProject.cmake/pull/19
include(cmake/PackageProject.cmake)
else()
include(cmake/CPM.cmake)
# PackageProject.cmake will be used to make our target installable
CPMAddPackage(
NAME PackageProject.cmake
GITHUB_REPOSITORY TheLartians/PackageProject.cmake
VERSION 1.6.0
)
endif()
add_library(ut INTERFACE)
set(INCLUDE_INSTALL_DIR include/${PROJECT_NAME}-${PROJECT_VERSION}/include)
# XXX variant: set(INCLUDE_INSTALL_DIR include)
target_include_directories(ut INTERFACE $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include> $<INSTALL_INTERFACE:${INCLUDE_INSTALL_DIR}>)
if(APPLE)
target_compile_features(ut INTERFACE cxx_std_20)
else()
target_compile_features(ut INTERFACE cxx_std_17)
endif()
if("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
if(WIN32) # clang-cl
# FIXME: we should not export this pedantic options! CK
target_compile_options(
ut
INTERFACE -Wall
-Wextra
# FIXME -Werror
-Wno-c++98-c++11-c++14-c++17-compat-pedantic
-Wno-c++98-c++11-compat
-Wno-c++98-compat
-Wno-c++98-compat-pedantic
-Wno-c99-extensions
-Wno-pedantic
)
else()
add_compile_options(-Wall -Wextra -Wpedantic -Werror)
endif()
elseif("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU")
# FIXME: we should not export this pedantic options! CK
target_compile_options(
ut
INTERFACE -Wall
-Wextra
# TODO: why not simpply -Wpedantic
-Werror
-Wcast-align
#-Wcast-align=strict
-Wcast-qual
-Wdouble-promotion
-Wduplicated-branches
-Wduplicated-cond
-Wlogical-op
-Wmissing-declarations
-Wmissing-include-dirs
-Wnull-dereference
-Wold-style-cast
-Wpointer-arith
-Wredundant-decls
-Wsign-conversion
-Wswitch-enum
-Wtrampolines
-Wunused-but-set-variable
-Wunused-result
-Wuseless-cast
-Wzero-as-null-pointer-constant
# FIXME
-Wno-undef
-Wno-missing-declarations
-Wno-sign-conversion
-Wno-float-equal
)
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
add_compile_options(/W4 /WX)
endif()
add_custom_target(style)
add_custom_command(
TARGET style COMMAND find ${CMAKE_CURRENT_LIST_DIR}/benchmark ${CMAKE_CURRENT_LIST_DIR}/example ${CMAKE_CURRENT_LIST_DIR}/include
${CMAKE_CURRENT_LIST_DIR}/test -iname "*.hpp" -or -iname "*.cpp" | xargs clang-format -i
)
if(BOOST_UT_ENABLE_COVERAGE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -O0")
endif()
if(BOOST_UT_ENABLE_SANITIZERS)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0 -g -fno-omit-frame-pointer -fsanitize=address -fsanitize=leak -fsanitize=undefined")
endif()
if(BOOST_UT_DISABLE_MODULE)
target_compile_definitions(ut INTERFACE BOOST_UT_DISABLE_MODULE)
endif()
# Create target Boost::ut and install target
packageProject(
NAME ${PROJECT_NAME}
VERSION ${PROJECT_VERSION}
NAMESPACE Boost
BINARY_DIR ${PROJECT_BINARY_DIR}
INCLUDE_DIR ${PROJECT_SOURCE_DIR}/include
INCLUDE_DESTINATION ${INCLUDE_INSTALL_DIR}
# XXX variant: DISABLE_VERSION_SUFFIX YES
# Optional VERSION_HEADER ${VERSION_HEADER_LOCATION}
COMPATIBILITY SameMajorVersion
# Note: only if needed i.e. DEPENDENCIES "fmt 7.1.3; span"
)
# Note: now we can use the target Boost::ut
include(cmake/AddCustomCommandOrTest.cmake)
if(BOOST_UT_BUILD_BENCHMARKS)
add_subdirectory(benchmark)
endif()
if(BOOST_UT_BUILD_EXAMPLES)
add_subdirectory(example)
endif()
if(BOOST_UT_BUILD_TESTS)
enable_testing()
add_subdirectory(test)
endif()
endif() # false