-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
253 lines (204 loc) · 7.75 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
cmake_minimum_required(VERSION 3.20)
project(vide LANGUAGES CXX VERSION 2.3.1)
if (PROJECT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
set(VIDE_MASTER_PROJECT ON)
endif ()
include(ExternalProject)
include(cmake/wish_create.cmake)
include(cmake/wish_date.cmake)
include(cmake/wish_git.cmake)
include(cmake/wish_util.cmake)
include(cmake/wish_warning.cmake)
# https://github.com/USCiLab/cereal/commit/b2d68c522bdc3a3fd9ab65c26dbd0aedbc61e0e8
#option(SKIP_PORTABILITY_TEST "Skip portability (32 bit) tests" OFF)
#include(CheckCXXCompilerFlag)
#set(CMAKE_REQUIRED_FLAGS "-m32")
#check_cxx_compiler_flag("-m32" COMPILER_SUPPORT_M32)
#unset(CMAKE_REQUIRED_FLAGS)
#if (NOT COMPILER_SUPPORT_M32)
# set(SKIP_PORTABILITY_TEST ON CACHE BOOL "Skip portability (32 bit) tests" FORCE)
#endif ()
if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE RELEASE)
endif ()
set(CMAKE_CONFIGURATION_TYPES "DEBUG;RELEASE;DEV" CACHE STRING "" FORCE)
option(BUILD_DOC "Build documentation" ON)
option(BUILD_SANDBOX "Build sandbox examples" ON)
option(SKIP_PERFORMANCE_COMPARISON "Skip building performance sandbox comparison (requires boost)" OFF)
option(VIDE_INSTALL "Generate the install target" ${VIDE_MASTER_PROJECT})
option(FORCE_COLORED_OUTPUT "Always produce ANSI-colored output (GNU/Clang only)." FALSE)
option(JUST_INSTALL_VIDE "Don't do anything besides installing the library" OFF)
set(VIDE_THREAD_LIBS)
if (UNIX)
option(THREAD_SAFE "Use mutexes to ensure thread safety" OFF)
if (THREAD_SAFE)
message(STATUS "Use mutexes")
add_definitions(-DVIDE_THREAD_SAFE=1)
set(VIDE_THREAD_LIBS pthread)
endif ()
endif ()
if (${FORCE_COLORED_OUTPUT})
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
message(STATUS "Force colored output: GCC")
add_compile_options(-fdiagnostics-color=always)
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
message(STATUS "Force colored output: Clang")
add_compile_options(-fcolor-diagnostics)
endif ()
else ()
message(STATUS "Force colored output: False")
endif ()
#if(MSVC)
# add_compile_options(/bigobj /W3 /WX)
#else()
# add_compile_options(-Wall -Wextra -pedantic -Wshadow -Wold-style-cast)
#
## option(WITH_WERROR "Compile with '-Werror' C++ compiler flag" ON)
## if(WITH_WERROR)
## add_compile_options(-Werror)
## endif()
#
## option(CLANG_USE_LIBCPP "Use libc++ for clang compilation" OFF)
## if(APPLE OR CLANG_USE_LIBCPP)
## message(STATUS "Use libc++")
## add_compile_options(-stdlib=libc++)
## # TODO: use add_link_options(-stdlib=libc++ -lc++abi") bud this needs cmake 3.13! CK
## set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -stdlib=libc++ -lc++abi")
## endif()
#
## if(NOT DEFINED CMAKE_CXX_STANDARD OR CMAKE_CXX_STANDARD STREQUAL "98")
## set(CMAKE_CXX_STANDARD 11)
## endif()
#
## set(CMAKE_CXX_STANDARD_REQUIRED ON)
#
#endif()
# -------------------------------------------------------------------------------------------------
wish_warning(
MSVC /Wall
Clang -Weverything
Clang -Wmissing-override
Clang -Wconversion
GNU -Wall
# GNU -Warray-bounds
# GNU -Wcast-align=strict
# GNU -Wcast-qual
# GNU -Wconversion
# GNU -Wdelete-non-virtual-dtor
# GNU -Wdouble-promotion
# GNU -Wduplicated-branches
# GNU -Wduplicated-cond
GNU -Wextra
# GNU -Wlogical-op
# GNU -Wmultistatement-macros
# GNU -Wnon-virtual-dtor # Causes some false positives with efsw (suppressed)
# GNU -Wold-style-cast
GNU -Wpedantic
# GNU -Wrestrict
# GNU -Wshadow-compatible-local
# GNU -Wsuggest-override
# GNU -Wundef
# Warnings that I don't care about
Clang -Wno-comment
GNU -Wno-comment
# GNU -Wnull-dereference # Causes too many false positives as of GCC 11.2
)
# -------------------------------------------------------------------------------------------------
if (CMAKE_BUILD_TYPE STREQUAL "DEBUG")
#add_compile_options(-Og)
add_compile_options(-ggdb3)
# add_compile_options(-fno-omit-frame-pointer)
elseif (CMAKE_BUILD_TYPE STREQUAL "RELEASE")
add_compile_options(-O3)
# add_compile_options(-flto)
# SET(CMAKE_AR "gcc-ar")
# SET(CMAKE_NM "gcc-nm")
# SET(CMAKE_RANLIB "gcc-ranlib")
# add_definitions(-DNDEBUG)
wish_static_link_std()
add_compile_options(-static) # Normally wish_static_link_std() would take care of this, but vide is not really using wish
elseif (CMAKE_BUILD_TYPE STREQUAL "DEV")
add_compile_options(-O3)
# add_compile_options(-ftemplate-backtrace-limit=0)
else ()
message(WARNING "Failed to identify [${CMAKE_BUILD_TYPE}] as a build type")
endif ()
add_compile_options(-m64)
add_compile_options(-std=c++23)
# -------------------------------------------------------------------------------------------------
option(BUILD_DOC "Build documentation" ON)
option(BUILD_SANDBOX "Build sandbox examples" ON)
option(SKIP_PERFORMANCE_COMPARISON "Skip building performance sandbox comparison (requires boost)" OFF)
option(VIDE_INSTALL "Generate the install target" ${VIDE_MASTER_PROJECT})
option(VIDE_ALTERNATIVE_LINKER "Use an alternative linker. Leave empty for system default; alternatives are 'gold', 'lld', 'bfd', 'mold'" FALSE)
# -------------------------------------------------------------------------------------------------
function(vide_alternative_linker linker_name)
if (NOT linker_name)
return()
endif ()
find_program(linker_executable ld.${linker_name} ${linker_name})
if (linker_executable)
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" AND "${CMAKE_CXX_COMPILER_VERSION}" VERSION_LESS 12.0.0)
add_link_options("-ld-path=${linker_name}")
else ()
add_link_options("-fuse-ld=${linker_name}")
endif ()
message(STATUS "Vide: Alternative linker: ${linker_name}")
else ()
message(FATAL_ERROR "Vide: Could not enable alternative linker: ${linker_name} program was not found")
endif ()
endfunction()
vide_alternative_linker(${VIDE_ALTERNATIVE_LINKER})
# -------------------------------------------------------------------------------------------------
add_compile_options(-ftemplate-backtrace-limit=30)
add_library(vide INTERFACE)
add_library(vide::vide ALIAS vide)
target_include_directories(vide INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)
list(APPEND VIDE_THREAD_LIBS vide::vide)
target_compile_features(vide INTERFACE cxx_std_23)
if (VIDE_INSTALL)
include(CMakePackageConfigHelpers)
install(TARGETS vide EXPORT ${PROJECT_NAME}Targets)
install(DIRECTORY include/vide DESTINATION include)
set(configFile ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake)
set(versionFile ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake)
set(configInstallDestination lib/cmake/${PROJECT_NAME})
configure_package_config_file(
${CMAKE_CURRENT_SOURCE_DIR}/Config.cmake.in
${configFile}
INSTALL_DESTINATION ${configInstallDestination}
)
# https://github.com/USCiLab/cereal/commit/83b6fa06a043e1a9cc4361df79270253439b88ab
if (${CMAKE_VERSION} VERSION_GREATER 3.13)
write_basic_package_version_file("${versionFile}" COMPATIBILITY SameMajorVersion ARCH_INDEPENDENT)
else ()
write_basic_package_version_file("${versionFile}" COMPATIBILITY SameMajorVersion)
endif ()
install(FILES ${configFile} ${versionFile} DESTINATION ${configInstallDestination})
install(
EXPORT ${PROJECT_NAME}Targets
NAMESPACE "vide::"
DESTINATION ${configInstallDestination}
)
endif ()
if (JUST_INSTALL_VIDE)
return()
endif ()
#if(NOT SKIP_PERFORMANCE_COMPARISON)
# # Boost serialization for performance sandbox
# find_package(Boost REQUIRED COMPONENTS serialization)
#endif()
option(BUILD_TESTS "Build tests" ${VIDE_MASTER_PROJECT})
if (BUILD_TESTS)
enable_testing()
add_subdirectory(unittests)
endif ()
if (BUILD_SANDBOX)
add_subdirectory(sandbox)
endif ()
if (BUILD_DOC)
add_subdirectory(doc)
endif ()