-
Notifications
You must be signed in to change notification settings - Fork 158
/
CMakeLists.txt
376 lines (306 loc) · 12.7 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
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
cmake_minimum_required(VERSION 3.9)
# Enable MACOSX_RPATH by default
cmake_policy(SET CMP0042 NEW)
# Fail immediately if not using an out-of-source build
if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_CURRENT_BINARY_DIR)
message(FATAL_ERROR
"In-source builds are not supported. Please create a build directory "
"separate from the source directory")
endif()
#------------------------------------------------------------------------------#
# Parse version number from zfp.h
#------------------------------------------------------------------------------#
file(READ ${CMAKE_CURRENT_SOURCE_DIR}/include/zfp/version.h _zfp_h_contents)
string(REGEX REPLACE ".*#define[ \t]+ZFP_VERSION_MAJOR[ \t]+([0-9]+).*"
"\\1" ZFP_VERSION_MAJOR ${_zfp_h_contents})
string(REGEX REPLACE ".*#define[ \t]+ZFP_VERSION_MINOR[ \t]+([0-9]+).*"
"\\1" ZFP_VERSION_MINOR ${_zfp_h_contents})
string(REGEX REPLACE ".*#define[ \t]+ZFP_VERSION_PATCH[ \t]+([0-9]+).*"
"\\1" ZFP_VERSION_PATCH ${_zfp_h_contents})
string(REGEX REPLACE ".*#define[ \t]+ZFP_VERSION_TWEAK[ \t]+([0-9]+).*"
"\\1" ZFP_VERSION_TWEAK ${_zfp_h_contents})
if(${ZFP_VERSION_TWEAK} EQUAL 0)
set(ZFP_VERSION
"${ZFP_VERSION_MAJOR}.${ZFP_VERSION_MINOR}.${ZFP_VERSION_PATCH}")
else()
set(ZFP_VERSION
"${ZFP_VERSION_MAJOR}.${ZFP_VERSION_MINOR}.${ZFP_VERSION_PATCH}.${ZFP_VERSION_TWEAK}")
endif()
project(ZFP VERSION ${ZFP_VERSION})
#------------------------------------------------------------------------------#
# Some boilerplate to setup nice output directories
#------------------------------------------------------------------------------#
include(GNUInstallDirs)
set(CMAKE_INSTALL_CMAKEDIR ${CMAKE_INSTALL_LIBDIR}/cmake/zfp
CACHE STRING "Installation CMake subdirectory")
list(INSERT CMAKE_MODULE_PATH 0 "${ZFP_SOURCE_DIR}/cmake")
if(NOT CMAKE_RUNTIME_OUTPUT_DIRECTORY)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${ZFP_BINARY_DIR}/${CMAKE_INSTALL_BINDIR})
endif()
if(NOT CMAKE_LIBRARY_OUTPUT_DIRECTORY)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${ZFP_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR})
endif()
if(NOT CMAKE_ARCHIVE_OUTPUT_DIRECTORY)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${ZFP_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR})
endif()
# Setup RPath
set(CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_FULL_LIBDIR})
#------------------------------------------------------------------------------#
# Top level options
#------------------------------------------------------------------------------#
# Windows (Visual Studio) specific options
if(MSVC)
# Use this to get a usable export library when building a DLL on Windows
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
# Silence extraneous Visual Studio specific warnings
add_definitions(-D_CRT_SECURE_NO_WARNINGS -D_SCL_SECURE_NO_WARNINGS)
add_compile_options(/wd4146)
add_compile_options(/wd4305)
endif()
# Suggest C99
if(NOT CMAKE_C_STANDARD)
set(CMAKE_C_STANDARD 99)
endif()
if(MSVC OR MINGW)
set(CMAKE_C_STANDARD 90)
endif()
message(STATUS "Compiling with C standard: ${CMAKE_C_STANDARD}")
# Suggest C++98
if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 98)
endif()
message(STATUS "Compiling with C++ standard: ${CMAKE_CXX_STANDARD}")
include(CMakeDependentOption)
# Typically you'd always be able to enable shared libraries but default
# configurations with the Cray toolchain will explicitly disable shared lib
# support and only allow static libs. Making this a cmake_dependent_option
# will ensure that shared library support will be disabled if the system does
# not support it.
# Setup shared library / -fPIC stuff
get_property(SHARED_LIBS_SUPPORTED GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS)
cmake_dependent_option(BUILD_SHARED_LIBS
"Whether or not to build shared libraries" ON
"SHARED_LIBS_SUPPORTED" OFF)
# PIC is always on for shared libs. This allows it to be selectable for
# static libs.
if(DEFINED ZFP_ENABLE_PIC)
set(ZFP_ENABLE_PIC_DEFAULT ${ZFP_ENABLE_PIC})
elseif(DEFINED CMAKE_POSITION_INDEPENDENT_CODE)
set(ZFP_ENABLE_PIC_DEFAULT ${CMAKE_POSITION_INDEPENDENT_CODE})
else()
set(ZFP_ENABLE_PIC_DEFAULT ${SHARED_LIBS_SUPPORTED})
endif()
cmake_dependent_option(ZFP_ENABLE_PIC
"Build with Position Independent Code" ${ZFP_ENABLE_PIC_DEFAULT}
"SHARED_LIBS_SUPPORTED" OFF)
set(CMAKE_POSITION_INDEPENDENT_CODE ${ZFP_ENABLE_PIC})
# Compile-time options.
set(ZFP_BIT_STREAM_WORD_SIZE 64 CACHE STRING
"Use smaller bit stream word type for finer rate granularity")
set_property(CACHE ZFP_BIT_STREAM_WORD_SIZE PROPERTY STRINGS "8;16;32;64")
if(CMAKE_C_COMPILER_ID MATCHES "PGI|NVHPC")
# Use default alignment to address PGI compiler bug.
set(ZFP_CACHE_LINE_SIZE 0 CACHE STRING "Cache line alignment in bytes")
mark_as_advanced(ZFP_CACHE_LINE_SIZE)
endif()
set(PPM_CHROMA 2 CACHE STRING "Chroma block dimensionality for ppm example")
set_property(CACHE PPM_CHROMA PROPERTY STRINGS "1;2")
set(ZFP_ROUNDING_MODE ZFP_ROUND_NEVER CACHE STRING
"Rounding mode for reducing bias")
set_property(CACHE ZFP_ROUNDING_MODE PROPERTY STRINGS "ZFP_ROUND_NEVER;ZFP_ROUND_FIRST;ZFP_ROUND_LAST")
option(ZFP_WITH_DAZ "Treat subnormals as zero to avoid overflow" OFF)
option(ZFP_WITH_CUDA "Enable CUDA parallel compression" OFF)
option(ZFP_WITH_BIT_STREAM_STRIDED "Enable strided access for progressive zfp streams" OFF)
mark_as_advanced(ZFP_WITH_BIT_STREAM_STRIDED)
option(ZFP_WITH_TIGHT_ERROR "Reduce slack in absolute errors" OFF)
option(ZFP_WITH_ALIGNED_ALLOC "Enable aligned memory allocation" OFF)
mark_as_advanced(ZFP_WITH_ALIGNED_ALLOC)
option(ZFP_WITH_CACHE_TWOWAY "Use two-way skew-associative cache" OFF)
mark_as_advanced(ZFP_WITH_CACHE_TWOWAY)
option(ZFP_WITH_CACHE_FAST_HASH
"Use a faster but more collision prone hash function" OFF)
mark_as_advanced(ZFP_WITH_CACHE_FAST_HASH)
option(ZFP_WITH_CACHE_PROFILE "Count cache misses" OFF)
mark_as_advanced(ZFP_WITH_CACHE_PROFILE)
# Handle compile-time macros
if((DEFINED ZFP_INT64) AND (DEFINED ZFP_INT64_SUFFIX))
list(APPEND zfp_public_defs ZFP_INT64=${ZFP_INT64})
list(APPEND zfp_public_defs ZFP_INT64_SUFFIX=${ZFP_INT64_SUFFIX})
endif()
if((DEFINED ZFP_UINT64) AND (DEFINED ZFP_UINT64_SUFFIX))
list(APPEND zfp_public_defs ZFP_UINT64=${ZFP_UINT64})
list(APPEND zfp_public_defs ZFP_UINT64_SUFFIX=${ZFP_UINT64_SUFFIX})
endif()
# This odd cmake pattern here lets the OpenMP feature be either auto-detected,
# explicitly enabled, or explicitly disabled, instead of just on or off.
if(DEFINED ZFP_WITH_OPENMP)
option(ZFP_WITH_OPENMP "Enable OpenMP parallel compression"
${ZFP_WITH_OPENMP})
if(ZFP_WITH_OPENMP)
if(BUILD_EXAMPLES)
find_package(OpenMP COMPONENTS C CXX REQUIRED)
else()
find_package(OpenMP COMPONENTS C REQUIRED)
endif()
endif()
else()
if(BUILD_EXAMPLES)
find_package(OpenMP COMPONENTS C CXX)
else()
find_package(OpenMP COMPONENTS C)
endif()
option(ZFP_WITH_OPENMP "Enable OpenMP parallel compression" ${OPENMP_FOUND})
endif()
# Suppress CMake warning about unused variable in this file
set(TOUCH_UNUSED_VARIABLE ${ZFP_OMP_TESTS_ONLY})
# Some compilers don't use explicit libraries on the link line for OpenMP but
# instead need to treat the OpenMP C flags as both compile and link flags
# i.e. -fopenmp for compiling and -lgomp for linking, use -fomp for both
# compiling and linking
if(ZFP_WITH_OPENMP AND NOT OpenMP_C_LIBRARIES)
set(OpenMP_C_LIBRARIES ${OpenMP_C_FLAGS})
endif()
if(ZFP_WITH_CUDA)
# use CUDA_BIN_DIR hint
set(ENV{CUDA_BIN_PATH} ${CUDA_BIN_DIR})
find_package(CUDA)
if(NOT CUDA_FOUND)
message(FATAL_ERROR "ZFP_WITH_CUDA is enabled, but a CUDA installation was not found.")
endif()
if(${CUDA_VERSION_MAJOR} LESS 7)
message(FATAL_ERROR "zfp requires at least CUDA 7.0.")
endif()
endif()
if(NOT (ZFP_BIT_STREAM_WORD_SIZE EQUAL 64))
list(APPEND zfp_private_defs BIT_STREAM_WORD_TYPE=uint${ZFP_BIT_STREAM_WORD_SIZE})
endif()
if(DEFINED ZFP_CACHE_LINE_SIZE)
# Add to zfp_public_defs since many tests currently include files from src.
# list(APPEND zfp_public_defs ZFP_CACHE_LINE_SIZE=${ZFP_CACHE_LINE_SIZE})
list(APPEND zfp_private_defs ZFP_CACHE_LINE_SIZE=${ZFP_CACHE_LINE_SIZE})
endif()
if(ZFP_WITH_BIT_STREAM_STRIDED)
list(APPEND zfp_public_defs BIT_STREAM_STRIDED)
endif()
if(NOT (ZFP_ROUNDING_MODE EQUAL ZFP_ROUND_NEVER))
list(APPEND zfp_private_defs ZFP_ROUNDING_MODE=${ZFP_ROUNDING_MODE})
endif()
if(ZFP_WITH_TIGHT_ERROR)
if((ZFP_ROUNDING_MODE EQUAL 0) OR (ZFP_ROUNDING_MODE STREQUAL ZFP_ROUND_NEVER))
message(FATAL_ERROR "ZFP_WITH_TIGHT_ERROR requires ZFP_ROUND_FIRST or ZFP_ROUND_LAST rounding mode")
endif()
list(APPEND zfp_private_defs ZFP_WITH_TIGHT_ERROR)
endif()
if(ZFP_WITH_DAZ)
list(APPEND zfp_private_defs ZFP_WITH_DAZ)
endif()
if(ZFP_WITH_ALIGNED_ALLOC)
list(APPEND zfp_compressed_array_defs ZFP_WITH_ALIGNED_ALLOC)
endif()
if(ZFP_WITH_CACHE_TWOWAY)
list(APPEND zfp_compressed_array_defs ZFP_WITH_CACHE_TWOWAY)
endif()
if(ZFP_WITH_CACHE_FAST_HASH)
list(APPEND zfp_compressed_array_defs ZFP_WITH_CACHE_FAST_HASH)
endif()
if(ZFP_WITH_CACHE_PROFILE)
list(APPEND zfp_compressed_array_defs ZFP_WITH_CACHE_PROFILE)
endif()
list(APPEND ppm_private_defs PPM_CHROMA=${PPM_CHROMA})
# Link libm only if necessary
include(CheckCSourceCompiles)
check_c_source_compiles("#include<math.h>\nint main(int n,char*v[]){return sqrt(n);}" HAVE_MATH)
if(NOT HAVE_MATH)
set(CMAKE_REQUIRED_LIBRARIES m)
check_c_source_compiles("#include<math.h>\nint main(int n,char*v[]){return sqrt(n);}" HAVE_LIBM_MATH)
unset(CMAKE_REQUIRED_LIBRARIES)
if(NOT HAVE_LIBM_MATH)
message(FATAL_ERROR "Unable to use C math library functions (with or without -lm)")
endif()
endif()
#------------------------------------------------------------------------------#
# Add source code
#------------------------------------------------------------------------------#
include(CTest)
if(BUILD_TESTING OR BUILD_TESTING_FULL)
enable_testing()
endif()
set(ZFP_LIBRARY_PREFIX "" CACHE STRING
"Prefix to prepend to the output library name")
mark_as_advanced(ZFP_LIBRARY_PREFIX)
add_subdirectory(src)
option(BUILD_ALL "Build all subdirectories" OFF)
if(BUILD_ALL)
set(BUILD_CFP ON CACHE BOOL "Build CFP arrays library" FORCE)
set(BUILD_ZFORP ON CACHE BOOL "Build Fortran library" FORCE)
set(BUILD_ZFPY ON CACHE BOOL "Build python bindings for zfp" FORCE)
set(BUILD_UTILITIES ON CACHE BOOL "Build command line utilities for zfp" FORCE)
set(BUILD_EXAMPLES ON CACHE BOOL "Build Examples" FORCE)
endif()
option(BUILD_CFP "Build CFP arrays library" OFF)
if(BUILD_CFP)
add_subdirectory(cfp)
endif()
option(BUILD_ZFORP "Build Fortran library" OFF)
if(BUILD_ZFORP)
add_subdirectory(fortran)
endif()
option(BUILD_ZFPY "Build python bindings for zfp" OFF)
if(BUILD_ZFPY)
add_subdirectory(python)
endif()
option(BUILD_UTILITIES "Build command line utilities for zfp" ON)
if(BUILD_UTILITIES)
add_subdirectory(utils)
endif()
option(BUILD_EXAMPLES "Build Examples" OFF)
if(BUILD_EXAMPLES)
add_subdirectory(examples)
endif()
if(BUILD_TESTING OR BUILD_TESTING_FULL)
# Disable gtest install to prevent clobbering existing installations
option(INSTALL_GMOCK "Install Googlemock" OFF)
option(INSTALL_GTEST "Install Googletest" OFF)
add_subdirectory(tests)
endif()
#------------------------------------------------------------------------------#
# Header install
#------------------------------------------------------------------------------#
if(BUILD_CFP)
install(DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
else()
install(DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
PATTERN "cfp" EXCLUDE)
endif()
#------------------------------------------------------------------------------#
# Build type: one of None, Debug, Release, RelWithDebInfo, MinSizeRel
#------------------------------------------------------------------------------#
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY VALUE Release)
endif()
#------------------------------------------------------------------------------#
# Packaging
#------------------------------------------------------------------------------#
# Add all targets to the build-tree export set
export(TARGETS zfp NAMESPACE zfp::
FILE "${PROJECT_BINARY_DIR}/zfp-targets.cmake")
if(BUILD_CFP)
export(TARGETS cfp NAMESPACE zfp::
APPEND FILE "${PROJECT_BINARY_DIR}/zfp-targets.cmake")
endif()
configure_file(zfp-config.cmake.in
"${PROJECT_BINARY_DIR}/zfp-config.cmake" @ONLY)
configure_file(zfp-config-version.cmake.in
"${PROJECT_BINARY_DIR}/zfp-config-version.cmake" @ONLY)
# Install the zfp-config.cmake and zfp-config-version.cmake
install(FILES
"${PROJECT_BINARY_DIR}/zfp-config.cmake"
"${PROJECT_BINARY_DIR}/zfp-config-version.cmake"
DESTINATION "${CMAKE_INSTALL_CMAKEDIR}")
# Install the export set for use with the install-tree
install(EXPORT zfp-targets NAMESPACE zfp::
DESTINATION "${CMAKE_INSTALL_CMAKEDIR}")
if(BUILD_CFP)
install(EXPORT cfp-targets NAMESPACE zfp::
DESTINATION "${CMAKE_INSTALL_CMAKEDIR}")
endif()