-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathCMakeLists.txt
279 lines (242 loc) · 9.21 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
cmake_minimum_required(VERSION 3.11.0)
execute_process(
COMMAND git describe --tags
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
OUTPUT_VARIABLE GIT_VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE
)
string(REGEX MATCH "v?([0-9.]+)-?.*" _dummy "${GIT_VERSION}")
set(GIT_VERSION "${CMAKE_MATCH_1}")
message(STATUS "Building version ${GIT_VERSION}")
project(hdf_plugins
VERSION ${GIT_VERSION}
LANGUAGES CXX C
)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(CMAKE_CXX_STANDARD 17)
include(ExternalProject)
include(GenerateExportHeader)
# If we're including hdf_plugins as a subdir then we might not be able
# to override BUILD_TESTING from CTest's default ON value.
if (NOT DEFINED BUILD_TESTING OR BUILD_TESTING)
include(CTest)
endif()
if (NOT CMAKE_CONFIGURATION_TYPES AND NOT CMAKE_BUILD_TYPE)
message(STATUS "No CMAKE_BUILD_TYPE set - defaulting to Debug")
# Default to Debug build
get_property(_bt_docstring
CACHE CMAKE_BUILD_TYPE
PROPERTY HELPSTRING)
set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "${_bt_docstring}" FORCE)
endif()
set(HDF_PLUGIN_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})
if (NOT DEFINED VBZ_BUILD_ARCHIVE)
option(VBZ_BUILD_ARCHIVE "Build vbz release as an single archive" OFF)
endif()
if (NOT DEFINED ENABLE_PYTHON)
option(ENABLE_PYTHON "Build python wheel" ON)
endif()
if (NOT DEFINED ENABLE_PACKAGING)
option(ENABLE_PACKAGING "Enable packaging support" ON)
endif()
if (NOT DEFINED ENABLE_PERF_TESTING)
option(ENABLE_PERF_TESTING "Enable performance tests" ON)
endif()
if (NOT DEFINED ENABLE_CONAN)
option(ENABLE_CONAN "Enable conan for dependency installation" ON)
endif()
if (NOT DEFINED STANDARD_LIB_INSTALL)
set(STD_LIB_INSTALL_DEFAULT OFF)
if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_CURRENT_DIR)
set(STD_LIB_INSTALL_DEFAULT ON)
endif()
option(STANDARD_LIB_INSTALL
"Install library to standard lib / bin paths"
${STD_LIB_INSTALL_DEFAULT}
)
endif()
if (NOT VBZ_BUILD_ARCHIVE)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
endif()
option(BUILD_SHARED_LIBS "Build shared library for VBZ plugin" ON)
if (ENABLE_CONAN)
#
# Dependencies: Conan
#
if (CONAN_EXPORTED)
# we're being run by conan
include("${CMAKE_BINARY_DIR}/conanbuildinfo.cmake")
else()
include(conan)
set(_requirements
"zstd/1.4.8@")
set(_generators
cmake_find_package
json)
set(_imports
"bin, *.dll -> ../bin"
"lib, *.dylib* -> ../bin")
set(_extra_args)
if (ENABLE_PERF_TESTING)
list(APPEND _requirements
"benchmark/1.5.6@"
)
endif()
if (CMAKE_BUILD_TYPE)
set(_build_type_DEBUG Debug)
set(_build_type_RELEASE Release)
set(_build_type_RELWITHDEBINFO Release)
set(_build_type_MINSIZEREL Release)
string(TOUPPER "${CMAKE_BUILD_TYPE}" _build_type)
if(DEFINED _build_type_${_build_type})
list(APPEND _extra_args BUILD_TYPE "${_build_type_${_build_type}}")
endif()
endif()
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
list(APPEND CONAN_EXTRA_SETTINGS "compiler.cppstd=${CMAKE_CXX_STANDARD}")
endif()
if (CONAN_EXTRA_SETTINGS)
list(APPEND _extra_args
SETTINGS
${CONAN_EXTRA_SETTINGS}
BUILD missing
)
endif()
conan_cmake_run(
GENERATORS ${_generators}
REQUIRES ${_requirements}
IMPORTS ${_imports}
UPDATE
${_extra_args})
endif()
conan_check_compiler()
conan_define_targets()
conan_set_find_paths()
endif()
if (ENABLE_PACKAGING)
include(packaging/hdf_plugin_packaging.cmake)
endif()
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/third_party")
if (NOT APPLE)
list(PREPEND CMAKE_MODULE_PATH ${CMAKE_BINARY_DIR})
list(PREPEND CMAKE_PREFIX_PATH ${CMAKE_BINARY_DIR})
endif()
find_package(HDF5 1.8.16)
find_package(Sanitizers)
# We need CONFIG on macOS to avoid linking to brew. This also changes
# the name of the target.
if (APPLE)
find_package(zstd 1.3.1 REQUIRED CONFIG)
set(zstd_target zstd::libzstd_static)
set(ZSTD_LIBRARY $<TARGET_FILE:zstd::libzstd_static>)
else()
find_package(zstd 1.3.1 REQUIRED)
set(zstd_target zstd::zstd)
endif()
get_filename_component(STREAMVBYTE_SOURCE_DIR
third_party/streamvbyte
ABSOLUTE
)
set(STREAMVBYTE_INSTALL_DIR "${CMAKE_BINARY_DIR}/streamvbyte_lib/")
set(STREAMVBYTE_PREFIX ${CMAKE_BINARY_DIR}/streamvbyte)
set(STREAMVBYTE_STATIC_LIB_NAME ${CMAKE_STATIC_LIBRARY_PREFIX}streamvbyte${CMAKE_STATIC_LIBRARY_SUFFIX})
set(STREAMVBYTE_STATIC_LIB_SUBDIR ".")
get_property(is_multi_config GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
if (is_multi_config)
set(STREAMVBYTE_STATIC_LIB_SUBDIR "$<CONFIG>")
endif()
ExternalProject_Add(
streamvbyte
SOURCE_DIR ${STREAMVBYTE_SOURCE_DIR}
UPDATE_DISCONNECTED TRUE
PREFIX ${STREAMVBYTE_PREFIX}
CMAKE_ARGS
-D CMAKE_INSTALL_PREFIX=${STREAMVBYTE_INSTALL_DIR}
-D CMAKE_OSX_DEPLOYMENT_TARGET=${CMAKE_OSX_DEPLOYMENT_TARGET}
-D CMAKE_OSX_ARCHITECTURES=${CMAKE_OSX_ARCHITECTURES}
-D STREAMVBYTE_SANITIZE=${SANITIZE_ADDRESS}
-D STREAMVBYTE_SANITIZE_UNDEFINED=${SANITIZE_UNDEFINED}
# We need to tell CMake about libraries we will link to, otherwise some generators (eg: Ninja)
# complain about how knowing how to build libstreamvbyte_static.a, for example.
# Ideally, we'd set a hypothetical INSTALL_BYPRODUCTS, and link to the installed file, but that
# doesn't seem to be an option.
BUILD_BYPRODUCTS "<BINARY_DIR>/${STREAMVBYTE_STATIC_LIB_SUBDIR}/${STREAMVBYTE_STATIC_LIB_NAME}"
)
ExternalProject_Get_Property(streamvbyte BINARY_DIR)
set(STREAMVBYTE_STATIC_LIB "${BINARY_DIR}/${STREAMVBYTE_STATIC_LIB_SUBDIR}/${STREAMVBYTE_STATIC_LIB_NAME}")
########################################################################
#
# Warnings
#
########################################################################
if (MSVC)
add_compile_options(
# Level 3 warnings, as errors
/W3 /WX
##
## Disable warnings:
##
# C4251: A base class or structure must be declared with the __declspec(dllexport) keyword
# for a function in a derived class to be exported.
#
# Happens when using STL types as members of a class tagged with WHATEVER_EXPORT. Since we
# don't care about our DLLs maintaining compatibility with other versions of the CRT
# (Microsoft's C Runtime Library), this is just noise.
/wd4251
# C4275: An exported class was derived from a class that was not exported.
#
# Very similar to C4251, but for inheritance rather than members. Again, just noise for us.
/wd4275
# C4373: '%$S': virtual function overrides '%$pS', previous versions of the compiler did not
# override when parameters only differed by const/volatile qualifiers
#
# The current behaviour (virtuals are overridden when their arguments differ only in
# constness) is what you'd expect - the warning only exists because VS 2008 and earlier had
# *different* behaviour. Since we never used VS 2008, this warning isn't useful to us.
/wd4373
##
## Enable additional warnings:
##
# C5038: data member 'member1' will be initialized after data member 'member2'
#
# Enable warning about incorrect order of initialisation in classes.
# Matches clang warnings which are enabled on the build server.
/w35038
)
if (CMAKE_CXX_COMPILER_ID MATCHES "IntelLLVM") # Intel oneAPI
add_compile_options(
-Wno-unused-command-line-argument # errors on -Qstd=c++11 as this isn't an option for MSVC
)
endif()
set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS
# MSVC's standard library warns about a lot of "insecure" code by default (eg: unchecked
# iterators). However, the recommended replacements are not cross-platform, so aren't really
# an option for us.
_SCL_SECURE_NO_WARNINGS
)
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
add_compile_options(
# "All" warnings as errors
-Wall -Wextra -Werror
# Unused parameters are too common (and unimportant) to warn about
-Wno-unused-parameter
# Missing field init warning is too general to be useful in C++ code
-Wno-missing-field-initializers
# boost::optional triggers this on release builds
-Wno-maybe-uninitialized
)
elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang") # AppleClang and Clang
add_compile_options(
# "All" warnings as errors
-Wall -Werror
)
endif()
include(SigningUtils)
if (ENABLE_PYTHON)
add_subdirectory(python)
endif()
add_subdirectory(vbz)
add_subdirectory(vbz_plugin)