-
Notifications
You must be signed in to change notification settings - Fork 9
/
CMakeLists.txt
308 lines (258 loc) · 11.1 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
# Copyright (c) 2015-2020 DNEG
#
# All rights reserved. This software is distributed under the
# Mozilla Public License 2.0 ( http://www.mozilla.org/MPL/2.0/ )
#
# Redistributions of source code must retain the above copyright
# and license notice and the following restrictions and disclaimer.
#
# * Neither the name of DNEG nor the names
# of its contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# IN NO EVENT SHALL THE COPYRIGHT HOLDERS' AND CONTRIBUTORS' AGGREGATE
# LIABILITY FOR ALL CLAIMS REGARDLESS OF THEIR BASIS EXCEED US$250.00.
#
#[=======================================================================[
CMake Configuration for OpenVDB AX
#]=======================================================================]
cmake_minimum_required(VERSION 3.12)
project(OpenVDBAX LANGUAGES CXX)
include(CMakeDependentOption)
include(GNUInstallDirs)
option(OPENVDB_BUILD_AX "Build the OpenVDB AX library" ON)
option(OPENVDB_BUILD_AX_BINARIES "Build the OpenVDB AX command line binary" ON)
option(OPENVDB_BUILD_AX_PYTHON_MODULE "Build the OpenVDB AX Python module" OFF)
option(OPENVDB_BUILD_AX_HOUDINI_PLUGIN "Build the OpenVDB AX Houdini plugin" OFF)
option(OPENVDB_BUILD_AX_UNITTESTS "Build the OpenVDB AX unit tests" OFF)
option(OPENVDB_BUILD_AX_DOCS "Build the OpenVDB AX documentation" OFF)
option(USE_CCACHE "Build using Ccache if found on the path" ON)
option(USE_HOUDINI "Build the library against a Houdini installation." OFF)
option(DISABLE_CMAKE_SEARCH_PATHS [=[
Disable CMakes default system search paths when locating dependencies. When enabled, CMake will fall back to
its default system search routine if it cannot find a dependency with the provided settings. When disabled, only
paths provided through the Xxx_ROOT, supported XXX_INCLUDEDIR/XXX_LIBRARYDIR variables or the SYSTEM_LIBRARY_PATHS
list will be searched.]=] OFF)
set(_OPENVDB_SIMD_OPTIONS None SSE42 AVX)
if(NOT OPENVDB_SIMD)
set(OPENVDB_SIMD None CACHE STRING
"Choose whether to enable SIMD compiler flags or not, options are: None SSE42 AVX.
Although not required, it is strongly recommended to enable SIMD. AVX implies SSE42.
None is the default." FORCE
)
elseif(NOT ${OPENVDB_SIMD} IN_LIST _OPENVDB_SIMD_OPTIONS)
message(WARNING "Unrecognized or unsupported value for OPENVDB_SIMD, "
"using None instead.")
set(OPENVDB_SIMD None CACHE STRING FORCE)
endif()
###### Deprecated options
if(DEFINED USE_SYSTEM_LIBRARY_PATHS)
message(DEPRECATION "The USE_SYSTEM_LIBRARY_PATHS option is deprecated and will be removed. "
"Use DISABLE_CMAKE_SEARCH_PATHS.")
if(USE_SYSTEM_LIBRARY_PATHS)
set(DISABLE_CMAKE_SEARCH_PATHS OFF)
else()
set(DISABLE_CMAKE_SEARCH_PATHS ON)
endif()
endif()
##### Dependent options
cmake_dependent_option(OPENVDB_BUILD_AX_GRAMMAR "Rebuild the OpenVDB AX grammar. CMake 3.4 with flex and bison."
ON "OPENVDB_BUILD_AX" OFF)
#########################################################################
# General CMake and CXX settings
if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 14 CACHE STRING
"The C++ standard whose features are requested to build this target." FORCE)
elseif(CMAKE_CXX_STANDARD LESS 14)
message(FATAL_ERROR "Provided C++ Standard is less than the supported minimum."
"Required is at least \"14\" (found ${CMAKE_CXX_STANDARD})")
endif()
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_DISABLE_SOURCE_CHANGES ON)
set(CMAKE_DISABLE_IN_SOURCE_BUILD ON)
if(OPENVDB_ENABLE_RPATH)
# Configure rpath for installation base on the following:
# https://gitlab.kitware.com/cmake/community/wikis/doc/cmake/RPATH-handling
set(CMAKE_SKIP_BUILD_RPATH FALSE)
set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
endif()
# For CMake's find Threads module which brings in pthread - This flag
# forces the compiler -pthread flag vs -lpthread
set(THREADS_PREFER_PTHREAD_FLAG TRUE)
enable_testing()
# Add our cmake modules and the VDB backports in case we're building against
# VDB pre 6.1.0
list(APPEND CMAKE_MODULE_PATH
"${CMAKE_CURRENT_LIST_DIR}/cmake;${CMAKE_CURRENT_LIST_DIR}/cmake/backports")
if(OPENVDB_BUILD_AX_HOUDINI_PLUGIN)
set(USE_HOUDINI ON)
endif()
# Can't include OpenVDBHoudiniSetup twice and finding openvdb_houdini
# will cause it to be called, so only include here if not building the
# openvdb_houdini lib
if(USE_HOUDINI AND NOT OPENVDB_BUILD_AX_HOUDINI_PLUGIN)
include(OpenVDBHoudiniSetup)
endif()
#########################################################################
# Add the doxygen command if required - do this here so we guarantee not
# to error on unrelated build issues
if(OPENVDB_BUILD_AX_DOCS)
add_subdirectory(openvdb_ax/doc)
endif()
#########################################################################
# ccache setup
if(USE_CCACHE)
find_program(CCACHE_PATH ccache)
if(CCACHE_PATH)
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache)
set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache)
message(STATUS "Using ccache: ${CCACHE_PATH}")
endif()
endif()
# Build type configuration - default to Release if none is set
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release CACHE STRING
"Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel." FORCE
)
endif()
message(STATUS "CMake Build Type: ${CMAKE_BUILD_TYPE}")
#########################################################################
# Compiler configuration. Add definitions for a number of compiler warnings
# for sub projects and verify version requirements
set(HAS_AVAILABLE_WARNINGS FALSE)
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
if(OPENVDB_CXX_STRICT)
message(STATUS "Configuring Clang CXX warnings")
set(HAS_AVAILABLE_WARNINGS TRUE)
add_compile_options(
-Werror
-Wall
-Wextra
-Wconversion
-Wno-sign-conversion
)
endif()
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
if(OPENVDB_CXX_STRICT)
message(STATUS "Configuring GCC CXX warnings")
set(HAS_AVAILABLE_WARNINGS TRUE)
add_compile_options(
-Werror
-Wall
-Wextra
-pedantic
-Wcast-align
-Wcast-qual
-Wconversion
-Wdisabled-optimization
-Woverloaded-virtual
)
endif()
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
# Increase the number of sections that an object file can contain
add_compile_options(/bigobj)
# Math constants are not included in <cmath> unless _USE_MATH_DEFINES is
# defined on MSVC
# https://msdn.microsoft.com/en-us/library/4hwaceh6.aspx
add_definitions(-D_USE_MATH_DEFINES)
# Disable the non-portable Windows definitions of min() and max() macros
add_definitions(-DNOMINMAX)
# Excludes APIs such as Cryptography, DDE, RPC, Shell, and Windows Sockets
add_definitions(-DWIN32_LEAN_AND_MEAN)
# Disable non-secure CRT library function warnings
# https://docs.microsoft.com/en-us/cpp/error-messages/compiler-warnings/
# compiler-warning-level-3-c4996?view=vs-2019#unsafe-crt-library-functions
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
# Disable POSIX function name warnings
# https://docs.microsoft.com/en-us/cpp/error-messages/compiler-warnings/
# compiler-warning-level-3-c4996?view=vs-2019#posix-function-names
add_definitions(-D_CRT_NONSTDC_NO_WARNINGS)
if(NOT OPENVDB_CXX_STRICT)
message(STATUS "Suppressing some noisy MSVC CXX warnings, "
"set OPENVDB_CXX_STRICT=ON to re-enable them.")
# Conversion from int64_t to long
add_compile_options(/wd4244)
# It's not possible to use STL types in DLL interfaces in a portable and
# reliable way so disable this warning
add_compile_options(/wd4251)
# Conversion from size_t to uLong
add_compile_options(/wd4267)
# Non dll-interface class used as base for dll-interface class
add_compile_options(/wd4275)
# Truncation from 'int' to 'bool'
add_compile_options(/wd4305)
endif()
endif()
if(OPENVDB_CXX_STRICT AND NOT HAS_AVAILABLE_WARNINGS)
message(WARNING "No available CXX warnings for compiler ${CMAKE_CXX_COMPILER_ID}")
endif()
unset(HAS_AVAILABLE_WARNINGS)
# Configure SIMD. AVX implies SSE 4.2.
if(OPENVDB_SIMD STREQUAL "AVX")
add_compile_options(-mavx -msse4.2)
add_definitions(-DOPENVDB_USE_AVX)
add_definitions(-DOPENVDB_USE_SSE42)
elseif(OPENVDB_SIMD STREQUAL "SSE42")
add_compile_options(-msse4.2)
add_definitions(-DOPENVDB_USE_SSE42)
endif()
##########################################################################
set(REQUIRED_OPENVDB_COMPONENTS openvdb)
if (OPENVDB_BUILD_AX_HOUDINI_PLUGIN)
list(APPEND REQUIRED_OPENVDB_COMPONENTS openvdb_houdini)
endif()
if (OPENVDB_BUILD_AX_PYTHON_MODULE)
list(APPEND REQUIRED_OPENVDB_COMPONENTS pyopenvdb)
endif()
if (NOT OPENVDB_BUILD_AX)
list(APPEND REQUIRED_OPENVDB_COMPONENTS openvdb_ax)
endif()
find_package(OpenVDB REQUIRED COMPONENTS ${REQUIRED_OPENVDB_COMPONENTS})
##########################################################################
# Detect matrix grid support from the core library, if available
execute_process(COMMAND ${CMAKE_COMMAND} -E echo_append "-- Detecting support for OpenVDB Matrix Grids...")
if(NOT DEFINED OPENVDB_HAS_MATRIX_SUPPORT)
# Try and build a file which instantiates a mat3f grid
set(MAT_GRID_CODE_TEST "#include <openvdb/openvdb.h>
using T = openvdb::BoolGrid::ValueConverter<openvdb::math::Mat3<float>>::Type\;
int main() { T grid\; return 0\; }")
set(MAT_GRID_TEST ${CMAKE_CURRENT_BINARY_DIR}/tmp.cc)
file(WRITE ${MAT_GRID_TEST} ${MAT_GRID_CODE_TEST})
try_compile(OPENVDB_HAS_MATRIX_SUPPORT ${CMAKE_CURRENT_BINARY_DIR} ${MAT_GRID_TEST}
CMAKE_FLAGS "-DINCLUDE_DIRECTORIES=${OpenVDB_INCLUDE_DIRS};${IlmBase_INCLUDE_DIRS};${Tbb_INCLUDE_DIRS}"
LINK_LIBRARIES ${OpenVDB_openvdb_LIBRARY} ${IlmBase_LIBRARIES} ${Tbb_LIBRARIES}
COMPILE_DEFINITIONS ${OpenVDB_DEFINITIONS}
CXX_STANDARD 14
CXX_STANDARD_REQUIRED ON
CXX_EXTENSIONS OFF)
endif()
execute_process(COMMAND ${CMAKE_COMMAND} -E echo " ${OPENVDB_HAS_MATRIX_SUPPORT}")
#########################################################################
if(OPENVDB_BUILD_AX)
add_subdirectory(openvdb_ax)
endif()
if(OPENVDB_BUILD_AX_BINARIES)
add_subdirectory(openvdb_ax/cmd)
endif()
if(OPENVDB_BUILD_AX_UNITTESTS)
add_subdirectory(openvdb_ax/test)
endif()
if(OPENVDB_BUILD_AX_PYTHON_MODULE)
add_subdirectory(openvdb_ax/python)
endif()
if(OPENVDB_BUILD_AX_HOUDINI_PLUGIN)
add_subdirectory(openvdb_ax_houdini)
endif()