-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
347 lines (315 loc) · 13.6 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
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
cmake_minimum_required(VERSION 3.13)
#########################
# Configuration Options #
#########################
project(posu LANGUAGES CXX VERSION 0.0.1)
option(POSU_ENABLE_WALL OFF)
option(POSU_ENABLE_WERROR OFF)
option(POSU_ENABLE_DETAILED_CONCEPTS_DIAGNOSTICS OFF)
option(POSU_ENABLE_TESTING OFF)
option(POSU_ENABLE_STATIC_STDLIB OFF)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
if(DEFINED POSU_STDLIB AND NOT POSU_STDLIB STREQUAL "default")
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=${POSU_STDLIB}")
else()
message(FATAL_ERROR "POSU_STDLIB must be \"default\" unless using Clang")
endif()
endif()
if(DEFINED POSU_STDLIB_PATH AND EXISTS ${POSU_STDLIB_PATH})
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -L ${POSU_STDLIB_PATH}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -rpath ${POSU_STDLIB_PATH}")
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wl,-rpath -Wl,${POSU_STDLIB_PATH}")
else()
message(SEND_ERROR "option : POSU_STDLIB_PATH")
message(SEND_ERROR "compiler: ${CMAKE_CXX_COMPILER_ID}")
message(FATAL_ERROR "setting the Standard Library link path on this compiler unsupported")
endif()
endif()
if(DEFINED POSU_STDLIB_INCLUDE AND EXISTS ${POSU_STDLIB_INCLUDE})
if(
CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR
CMAKE_CXX_COMPILER_ID STREQUAL "GNU"
)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -isystem ${POSU_STDLIB_INCLUDE}")
else()
message(SEND_ERROR "option : POSU_STDLIB_INCLUDE")
message(SEND_ERROR "compiler: ${CMAKE_CXX_COMPILER_ID}")
message(FATAL_ERROR "setting the Standard Library link path on this compiler unsupported")
endif()
endif()
if(POSU_ENABLE_STATIC_STDLIB)
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static")
else()
message(FATAL_ERROR "POSU_ENABLE_STATIC_STDLIB must be \"OFF\" unless using Clang")
endif()
endif()
# zip-range only standards-compliant with C++20 iterator rework
if(NOT DEFINED CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 20)
endif()
if(CMAKE_CXX_STANDARD LESS 20)
message(FATAL_ERROR "This library requires C++20")
endif()
# handle enable-all-warnings
if(POSU_ENABLE_WALL)
if(
CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR
CMAKE_CXX_COMPILER_ID STREQUAL "GNU"
)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra")
else()
message(SEND_ERROR "option : POSU_ENABLE_WALL")
message(SEND_ERROR "compiler: ${CMAKE_CXX_COMPILER_ID}")
message(FATAL_ERROR "enabling all warning on this compiler unsupported")
endif()
endif()
# handle treat-warnings-as-errors
if(POSU_ENABLE_WERROR)
if(
CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR
CMAKE_CXX_COMPILER_ID STREQUAL "GNU"
)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror")
else()
message(SEND_ERROR "option : POSU_ENABLE_WERROR")
message(SEND_ERROR "compiler: ${CMAKE_CXX_COMPILER_ID}")
message(FATAL_ERROR "warnings as errors on this compiler unsupported")
endif()
endif()
# handle detailed-concepts-diagnostics
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
if(POSU_ENABLE_DETAILED_CONCEPTS_DIAGNOSTICS)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fconcepts-diagnostics-depth=9")
endif()
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
if(POSU_ENABLE_DETAILED_CONCEPTS_DIAGNOSTICS)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ftemplate-backtrace-limit=0")
endif()
else()
if(POSU_ENABLE_DETAILED_CONCEPTS_DIAGNOSTICS)
message(SEND_ERROR "option : POSU_ENABLE_DETAILED_CONCEPTS_DIAGNOSTICS")
message(SEND_ERROR "compiler: ${CMAKE_CXX_COMPILER_ID}")
message(FATAL_ERROR "concepts diagnostics on this compiler unsupported")
endif()
endif()
#######################
# Gather Dependencies #
#######################
include(CTest)
find_program(POSU_CLANG_FORMAT clang-format)
find_program(POSU_CLANG_TIDY clang-tidy)
##################
# Gather Sources #
##################
set(
POSU_META_HPP_FILES
${CMAKE_CURRENT_LIST_DIR}/posu/meta/algorithm.hpp
${CMAKE_CURRENT_LIST_DIR}/posu/meta/list.hpp
${CMAKE_CURRENT_LIST_DIR}/posu/meta/ratio.hpp
)
set(
POSU_META_IPP_FILES
${CMAKE_CURRENT_LIST_DIR}/posu/meta/ipp/algorithm.ipp
${CMAKE_CURRENT_LIST_DIR}/posu/meta/ipp/list.ipp
${CMAKE_CURRENT_LIST_DIR}/posu/meta/ipp/ratio.ipp
)
set(
POSU_META_TEST_CPP_FILES
${CMAKE_CURRENT_LIST_DIR}/test/meta/test_list.cpp
${CMAKE_CURRENT_LIST_DIR}/test/meta/test_meta.cpp
${CMAKE_CURRENT_LIST_DIR}/test/meta/test_ratio.cpp
)
set(
POSU_UNITS_HPP_FILES
${CMAKE_CURRENT_LIST_DIR}/posu/units/base_unit.hpp
${CMAKE_CURRENT_LIST_DIR}/posu/units/derived_unit.hpp
${CMAKE_CURRENT_LIST_DIR}/posu/units/dimension.hpp
${CMAKE_CURRENT_LIST_DIR}/posu/units/kind.hpp
${CMAKE_CURRENT_LIST_DIR}/posu/units/unit_of_measure.hpp
${CMAKE_CURRENT_LIST_DIR}/posu/units/units.hpp
${CMAKE_CURRENT_LIST_DIR}/posu/units/system/acceleration.hpp
${CMAKE_CURRENT_LIST_DIR}/posu/units/system/amount_of_substance.hpp
${CMAKE_CURRENT_LIST_DIR}/posu/units/system/angle.hpp
${CMAKE_CURRENT_LIST_DIR}/posu/units/system/electric_charge.hpp
${CMAKE_CURRENT_LIST_DIR}/posu/units/system/electric_current.hpp
${CMAKE_CURRENT_LIST_DIR}/posu/units/system/energy.hpp
${CMAKE_CURRENT_LIST_DIR}/posu/units/system/force.hpp
${CMAKE_CURRENT_LIST_DIR}/posu/units/system/frequency.hpp
${CMAKE_CURRENT_LIST_DIR}/posu/units/system/length.hpp
${CMAKE_CURRENT_LIST_DIR}/posu/units/system/luminous_flux.hpp
${CMAKE_CURRENT_LIST_DIR}/posu/units/system/luminous_intensity.hpp
${CMAKE_CURRENT_LIST_DIR}/posu/units/system/mass.hpp
${CMAKE_CURRENT_LIST_DIR}/posu/units/system/power.hpp
${CMAKE_CURRENT_LIST_DIR}/posu/units/system/si.hpp
${CMAKE_CURRENT_LIST_DIR}/posu/units/system/solid_angle.hpp
${CMAKE_CURRENT_LIST_DIR}/posu/units/system/thermodynamic_temperature.hpp
${CMAKE_CURRENT_LIST_DIR}/posu/units/system/time.hpp
${CMAKE_CURRENT_LIST_DIR}/posu/units/system/velocity.hpp
${CMAKE_CURRENT_LIST_DIR}/posu/units/system/si/amount_of_substance.hpp
${CMAKE_CURRENT_LIST_DIR}/posu/units/system/si/angle.hpp
${CMAKE_CURRENT_LIST_DIR}/posu/units/system/si/defining_constants.hpp
${CMAKE_CURRENT_LIST_DIR}/posu/units/system/si/electric_charge.hpp
${CMAKE_CURRENT_LIST_DIR}/posu/units/system/si/electric_current.hpp
${CMAKE_CURRENT_LIST_DIR}/posu/units/system/si/energy.hpp
${CMAKE_CURRENT_LIST_DIR}/posu/units/system/si/force.hpp
${CMAKE_CURRENT_LIST_DIR}/posu/units/system/si/frequency.hpp
${CMAKE_CURRENT_LIST_DIR}/posu/units/system/si/length.hpp
${CMAKE_CURRENT_LIST_DIR}/posu/units/system/si/luminous_flux.hpp
${CMAKE_CURRENT_LIST_DIR}/posu/units/system/si/luminous_intensity.hpp
${CMAKE_CURRENT_LIST_DIR}/posu/units/system/si/mass.hpp
${CMAKE_CURRENT_LIST_DIR}/posu/units/system/si/power.hpp
${CMAKE_CURRENT_LIST_DIR}/posu/units/system/si/time.hpp
${CMAKE_CURRENT_LIST_DIR}/posu/units/system/si/solid_angle.hpp
${CMAKE_CURRENT_LIST_DIR}/posu/units/system/si/thermodynamic_temperature.hpp
)
set(
POSU_UNITS_IPP_FILES
${CMAKE_CURRENT_LIST_DIR}/posu/units/ipp/base_unit.ipp
${CMAKE_CURRENT_LIST_DIR}/posu/units/ipp/derived_unit.ipp
${CMAKE_CURRENT_LIST_DIR}/posu/units/system/si/ipp/amount_of_substance.ipp
${CMAKE_CURRENT_LIST_DIR}/posu/units/system/si/ipp/angle.ipp
${CMAKE_CURRENT_LIST_DIR}/posu/units/system/si/ipp/electric_charge.ipp
${CMAKE_CURRENT_LIST_DIR}/posu/units/system/si/ipp/electric_current.ipp
${CMAKE_CURRENT_LIST_DIR}/posu/units/system/si/ipp/energy.ipp
${CMAKE_CURRENT_LIST_DIR}/posu/units/system/si/ipp/force.ipp
${CMAKE_CURRENT_LIST_DIR}/posu/units/system/si/ipp/frequency.ipp
${CMAKE_CURRENT_LIST_DIR}/posu/units/system/si/ipp/length.ipp
${CMAKE_CURRENT_LIST_DIR}/posu/units/system/si/ipp/luminous_intensity.ipp
${CMAKE_CURRENT_LIST_DIR}/posu/units/system/si/ipp/luminous_flux.ipp
${CMAKE_CURRENT_LIST_DIR}/posu/units/system/si/ipp/mass.ipp
${CMAKE_CURRENT_LIST_DIR}/posu/units/system/si/ipp/power.ipp
${CMAKE_CURRENT_LIST_DIR}/posu/units/system/si/ipp/solid_angle.ipp
${CMAKE_CURRENT_LIST_DIR}/posu/units/system/si/ipp/speed.ipp
${CMAKE_CURRENT_LIST_DIR}/posu/units/system/si/ipp/thermodynamic_temperature.ipp
${CMAKE_CURRENT_LIST_DIR}/posu/units/system/si/ipp/time.ipp
)
set(
POSU_UNITS_TEST_CPP_FILES
${CMAKE_CURRENT_LIST_DIR}/test/units/test_base_unit.cpp
${CMAKE_CURRENT_LIST_DIR}/test/units/test_units.cpp
${CMAKE_CURRENT_LIST_DIR}/test/units/system/si/test_acceleration.cpp
${CMAKE_CURRENT_LIST_DIR}/test/units/system/si/test_amount_of_substance.cpp
${CMAKE_CURRENT_LIST_DIR}/test/units/system/si/test_angle.cpp
${CMAKE_CURRENT_LIST_DIR}/test/units/system/si/test_defining_constants.cpp
${CMAKE_CURRENT_LIST_DIR}/test/units/system/si/test_electric_charge.cpp
${CMAKE_CURRENT_LIST_DIR}/test/units/system/si/test_electric_current.cpp
${CMAKE_CURRENT_LIST_DIR}/test/units/system/si/test_energy.cpp
${CMAKE_CURRENT_LIST_DIR}/test/units/system/si/test_force.cpp
${CMAKE_CURRENT_LIST_DIR}/test/units/system/si/test_frequency.cpp
${CMAKE_CURRENT_LIST_DIR}/test/units/system/si/test_length.cpp
${CMAKE_CURRENT_LIST_DIR}/test/units/system/si/test_luminous_flux.cpp
${CMAKE_CURRENT_LIST_DIR}/test/units/system/si/test_luminous_intensity.cpp
${CMAKE_CURRENT_LIST_DIR}/test/units/system/si/test_mass.cpp
${CMAKE_CURRENT_LIST_DIR}/test/units/system/si/test_power.cpp
${CMAKE_CURRENT_LIST_DIR}/test/units/system/si/test_solid_angle.cpp
${CMAKE_CURRENT_LIST_DIR}/test/units/system/si/test_speed.cpp
${CMAKE_CURRENT_LIST_DIR}/test/units/system/si/test_thermodynamic_temperature.cpp
${CMAKE_CURRENT_LIST_DIR}/test/units/system/si/test_time.cpp
)
set(
POSU_HPP_FILES
${CMAKE_CURRENT_LIST_DIR}/posu/concepts.hpp
${CMAKE_CURRENT_LIST_DIR}/posu/ratio.hpp
${CMAKE_CURRENT_LIST_DIR}/posu/string_literal.hpp
${CMAKE_CURRENT_LIST_DIR}/posu/utility.hpp
${CMAKE_CURRENT_LIST_DIR}/posu/vmath.hpp
${CMAKE_CURRENT_LIST_DIR}/posu/zip_range.hpp
)
set(
POSU_IPP_FILES
${CMAKE_CURRENT_LIST_DIR}/posu/ipp/ratio.ipp
${CMAKE_CURRENT_LIST_DIR}/posu/ipp/utility.ipp
${CMAKE_CURRENT_LIST_DIR}/posu/ipp/vmath.ipp
${CMAKE_CURRENT_LIST_DIR}/posu/ipp/zip_range.ipp
)
set(
POSU_TEST_CPP_FILES
${CMAKE_CURRENT_LIST_DIR}/test/test_arith_tuple.cpp
${CMAKE_CURRENT_LIST_DIR}/test/test_concepts.cpp
${CMAKE_CURRENT_LIST_DIR}/test/test_posu.cpp
${CMAKE_CURRENT_LIST_DIR}/test/test_ratio.cpp
${CMAKE_CURRENT_LIST_DIR}/test/test_string_literal.cpp
${CMAKE_CURRENT_LIST_DIR}/test/test_zip_range.cpp
)
set(
POSU_ALL_HPP_FILES
${POSU_META_HPP_FILES}
${POSU_UNITS_HPP_FILES}
${POSU_HPP_FILES}
)
set(
POSU_ALL_IPP_FILES
${POSU_META_IPP_FILES}
${POSU_UNITS_IPP_FILES}
${POSU_IPP_FILES}
)
set(
POSU_ALL_CPP_FILES
${POSU_META_TEST_CPP_FILES}
${POSU_UNITS_TEST_CPP_FILES}
${POSU_TEST_CPP_FILES}
)
##################
# Declare Target #
##################
add_library(posu INTERFACE)
target_include_directories(posu INTERFACE ${CMAKE_CURRENT_LIST_DIR})
target_sources(posu INTERFACE ${POSU_HPP_FILES})
if(BUILD_TESTING AND POSU_ENABLE_TESTING)
find_package(Catch2 REQUIRED)
add_executable(test_posu ${POSU_TEST_CPP_FILES})
target_link_libraries(test_posu PRIVATE Catch2::Catch2)
target_link_libraries(test_posu PRIVATE posu)
add_test(NAME test_posu COMMAND test_posu)
add_executable(test_units ${POSU_UNITS_TEST_CPP_FILES})
target_link_libraries(test_units PRIVATE Catch2::Catch2)
target_link_libraries(test_units PRIVATE posu)
add_test(NAME test_units COMMAND test_units)
add_executable(test_meta ${POSU_META_TEST_CPP_FILES})
target_link_libraries(test_meta PRIVATE Catch2::Catch2)
target_link_libraries(test_meta PRIVATE posu)
add_test(NAME test_meta COMMAND test_meta)
endif()
################
# Clang-Format #
################
if(POSU_CLANG_FORMAT)
message(STATUS "generating target clang_format")
add_custom_target(
clang_format
COMMAND
${POSU_CLANG_FORMAT} -i
${POSU_ALL_HPP_FILES}
${POSU_ALL_IPP_FILES}
${POSU_ALL_CPP_FILES}
DEPENDS
${POSU_ALL_HPP_FILES}
${POSU_ALL_IPP_FILES}
${POSU_ALL_CPP_FILES}
)
else()
message(STATUS "clang-format not found")
endif()
##############
# Clang-Tidy #
##############
if(POSU_CLANG_TIDY)
message(STATUS "generating target clang_tidy")
add_custom_target(
clang_tidy
COMMAND
${POSU_CLANG_TIDY}
-p ${CMAKE_CURRENT_BINARY_DIR}
${POSU_ALL_CPP_FILES}
DEPENDS
${POSU_ALL_HPP_FILES}
${POSU_ALL_IPP_FILES}
${POSU_ALL_CPP_FILES}
)
else()
message(STATUS "clang-tidy not found")
endif()