-
Notifications
You must be signed in to change notification settings - Fork 765
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
264 lines (231 loc) · 11.1 KB
/
Copy pathCMakeLists.txt
File metadata and controls
264 lines (231 loc) · 11.1 KB
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
# Copyright Contributors to the OpenVDB Project
# SPDX-License-Identifier: Apache-2.0
cmake_minimum_required(VERSION 3.24)
# CMP0091 allows for MSVC ABI targetting via CMAKE_MSVC_RUNTIME_LIBRARY
# from CMake 3.15 and above. Must come before project().
if(POLICY CMP0091)
cmake_policy(SET CMP0091 NEW)
endif()
if(POLICY CMP0074)
cmake_policy(SET CMP0074 NEW)
endif()
#project(vdb_tool LANGUAGES CXX)
#set(CMAKE_CXX_STANDARD 14)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release" CACHE STRING
"Choose the type of build, supported options are: Debug Release."
FORCE)
endif()
list(APPEND CMAKE_MODULE_PATH ${OPENVDB_CMAKE_PATH})
# Pseudo library to manage dependencies
add_library(vdb_tool_common INTERFACE)
# Optional components
option(OPENVDB_BUILD_VDB_TOOL_UNITTESTS "Build unit tests" OFF)
option(OPENVDB_TOOL_USE_NANO "Compile with NanoVDB support" OFF)
option(OPENVDB_TOOL_NANO_USE_ZIP "Compile NanoVDB with zip compression support. Requires OPENVDB_TOOL_USE_NANO=ON to have effect" ON)
option(OPENVDB_TOOL_NANO_USE_BLOSC "Compile NanoVDB with Blosc compression support. Requires OPENVDB_TOOL_USE_NANO=ON to have effect" ON)
option(OPENVDB_TOOL_USE_PNG "Compile with PNG support" OFF)
option(OPENVDB_TOOL_USE_EXR "Compile with EXR support" OFF)
option(OPENVDB_TOOL_USE_JPG "Compile with JPG support" OFF)
option(OPENVDB_TOOL_USE_MPEG "Compile with MPEG support" OFF)
option(OPENVDB_TOOL_USE_PDAL "Compile with extended points support" OFF)
option(OPENVDB_TOOL_USE_ABC "Compile with Alembic support" OFF)
option(OPENVDB_TOOL_USE_USD "Compile with OpenUSD geometry read support" OFF)
option(OPENVDB_TOOL_USE_GLTF "Compile with glTF (.gltf / .glb) read support via tinygltf" OFF)
option(OPENVDB_TOOL_USE_AX "Compile with the OpenVDB AX expression action (-ax). Requires the openvdb_ax library and LLVM" OFF)
option(OPENVDB_TOOL_USE_ALL "Compile with all optional components" OFF)
if(OPENVDB_TOOL_USE_ALL)
set(OPENVDB_TOOL_USE_NANO ON)
set(OPENVDB_TOOL_USE_PNG ON)
set(OPENVDB_TOOL_USE_EXR ON)
set(OPENVDB_TOOL_USE_JPG ON)
set(OPENVDB_TOOL_USE_MPEG ON)
set(OPENVDB_TOOL_USE_ABC ON)
set(OPENVDB_TOOL_USE_PDAL ON)
set(OPENVDB_TOOL_USE_USD ON)
set(OPENVDB_TOOL_USE_GLTF ON)
set(OPENVDB_TOOL_USE_AX ON)
endif()
if(OPENVDB_TOOL_USE_NANO)
target_compile_definitions(vdb_tool_common INTERFACE "VDB_TOOL_USE_NANO")
if(OPENVDB_TOOL_NANO_USE_ZIP)
target_compile_definitions(vdb_tool_common INTERFACE "NANOVDB_USE_ZIP")
find_package(ZLIB ${MINIMUM_ZLIB_VERSION} REQUIRED)
target_link_libraries(vdb_tool_common INTERFACE ZLIB::ZLIB)
endif()
if(OPENVDB_TOOL_NANO_USE_BLOSC)
target_compile_definitions(vdb_tool_common INTERFACE "NANOVDB_USE_BLOSC")
find_package(Blosc ${MINIMUM_BLOSC_VERSION} REQUIRED)
target_link_libraries(vdb_tool_common INTERFACE blosc)
endif()
#target_include_directories(vdb_tool_common INTERFACE ${PROJECT_SOURCE_DIR}/../nanovdb/)
if(NOT OPENVDB_BUILD_NANOVDB)
find_package(OpenVDB COMPONENTS nanovdb)
if(NOT OpenVDB_nanovdb_FOUND OR NOT OpenVDB_FOUND)
message(FATAL_ERROR
" Couldn't find NanoVDB\n"
" Either set OPENVDB_CMAKE_PATH to <OpenVDB install path>/lib/cmake/OpenVDB"
" or please pass -DUSE_NANOVDB=ON as a cmake argument.")
endif()
set(NANOVDB_LIB OpenVDB::nanovdb)
target_include_directories(vdb_tool_common INTERFACE ${OPENVDB_nanovdb_INCLUDE_DIR})
else()
set(NANOVDB_LIB nanovdb)
endif()
target_link_libraries(vdb_tool_common INTERFACE ${NANOVDB_LIB})
endif()
if(OPENVDB_TOOL_USE_PNG)
target_compile_definitions(vdb_tool_common INTERFACE "VDB_TOOL_USE_PNG")
if(WIN32)
find_package(libpng CONFIG REQUIRED)
else()
find_package(PNG REQUIRED)
endif()
target_link_libraries(vdb_tool_common INTERFACE png)
endif()
if(OPENVDB_TOOL_USE_PDAL)
target_compile_definitions(vdb_tool_common INTERFACE "VDB_TOOL_USE_PDAL")
if(WIN32)
find_package(libdpal CONFIG REQUIRED)
else()
find_package(PDAL REQUIRED)
endif()
message(STATUS "PDAL: ${PDAL_LIBRARIES} ${PDAL_INCLUDE_DIRS}")
target_link_libraries(vdb_tool_common INTERFACE ${PDAL_LIBRARIES})
target_include_directories(vdb_tool_common INTERFACE ${PDAL_INCLUDE_DIRS})
endif()
if(OPENVDB_TOOL_USE_JPG)
target_compile_definitions(vdb_tool_common INTERFACE "VDB_TOOL_USE_JPG")
find_package(JPEG REQUIRED)
target_link_libraries(vdb_tool_common INTERFACE ${JPEG_LIBRARIES})
target_include_directories(vdb_tool_common INTERFACE ${JPEG_INCLUDE_DIR})
endif()
if(OPENVDB_TOOL_USE_MPEG)
target_compile_definitions(vdb_tool_common INTERFACE "VDB_TOOL_USE_MPEG")
find_program(FFMPEG_PATH NAMES ffmpeg REQUIRED)
target_compile_definitions(vdb_tool_common INTERFACE "VDB_TOOL_FFMPEG_PATH=\"${FFMPEG_PATH}\"")
endif()
if(OPENVDB_TOOL_USE_EXR)
target_compile_definitions(vdb_tool_common INTERFACE "VDB_TOOL_USE_EXR")
find_package(OpenEXR ${MINIMUM_OPENEXR_VERSION} REQUIRED)
find_package(Imath ${MINIMUM_IMATH_VERSION} CONFIG REQUIRED)
if(TARGET OpenEXR::OpenEXR)
target_link_libraries(vdb_tool_common INTERFACE OpenEXR::OpenEXR Imath::Imath)
else()
target_link_libraries(vdb_tool_common INTERFACE OpenEXR::IlmImf Imath::Imath)
endif()
endif()
if(OPENVDB_TOOL_USE_ABC)
target_compile_definitions(vdb_tool_common INTERFACE "VDB_TOOL_USE_ABC")
find_package(Alembic CONFIG REQUIRED)
target_link_libraries(vdb_tool_common INTERFACE Alembic::Alembic)
endif()
if(OPENVDB_TOOL_USE_USD)
target_compile_definitions(vdb_tool_common INTERFACE "VDB_TOOL_USE_USD")
# OpenUSD exports its CMake config under the "pxr" package name.
find_package(pxr CONFIG REQUIRED)
# Minimum set of OpenUSD libraries needed to traverse a stage and pull
# UsdGeomMesh data; pxr will transitively pull the rest.
target_link_libraries(vdb_tool_common INTERFACE usd usdGeom sdf gf vt tf)
endif()
if(OPENVDB_TOOL_USE_GLTF)
# tinygltf is a single-header BSD-3 reader for .gltf / .glb. Fetched at
# configure time so no system install is required. Used in header-only
# mode via TINYGLTF_HEADER_ONLY (set in Geometry.h), so every TU including
# the header gets inline definitions — no separate impl source file needed.
target_compile_definitions(vdb_tool_common INTERFACE "VDB_TOOL_USE_GLTF")
include(FetchContent)
FetchContent_Declare(tinygltf
GIT_REPOSITORY https://github.com/syoyo/tinygltf.git
GIT_TAG v2.9.5
GIT_SHALLOW TRUE
)
# tinygltf's CMakeLists builds examples by default — disable.
set(TINYGLTF_BUILD_LOADER_EXAMPLE OFF CACHE BOOL "" FORCE)
set(TINYGLTF_BUILD_GL_EXAMPLES OFF CACHE BOOL "" FORCE)
set(TINYGLTF_BUILD_VALIDATOR_EXAMPLE OFF CACHE BOOL "" FORCE)
set(TINYGLTF_BUILD_BUILDER_EXAMPLE OFF CACHE BOOL "" FORCE)
set(TINYGLTF_HEADER_ONLY ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(tinygltf)
target_include_directories(vdb_tool_common INTERFACE ${tinygltf_SOURCE_DIR})
endif()
if(OPENVDB_TOOL_USE_AX)
target_compile_definitions(vdb_tool_common INTERFACE "VDB_TOOL_USE_AX")
# Resolve the AX library the same way the vdb_ax CLI does: use the in-tree
# target when AX is built alongside (OPENVDB_BUILD_AX), otherwise the
# installed OpenVDB::openvdb_ax component (which transitively pulls LLVM).
if(OPENVDB_BUILD_AX)
set(OPENVDBAX_LIB openvdb_ax)
else()
find_package(OpenVDB REQUIRED COMPONENTS openvdb_ax)
set(OPENVDBAX_LIB OpenVDB::openvdb_ax)
endif()
target_link_libraries(vdb_tool_common INTERFACE ${OPENVDBAX_LIB})
endif()
if(WIN32 AND (OPENVDB_TOOL_USE_ALL OR (OPENVDB_TOOL_USE_ABC AND OPENVDB_TOOL_USE_EXR)))
message(WARNING
" The OpenEXR and Alembic VCPKG packages are using conflicting Imath versions.\n"
" Disable one, if you encounter unresolved external symbols")
endif()
# Compiler flags
# GCC flags
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
target_compile_options(vdb_tool_common INTERFACE -Wno-invalid-offsetof -pthread -lpthread)
target_compile_options(vdb_tool_common INTERFACE "$<$<CONFIG:DEBUG>:-O1>")
endif()
# MSVC flags
# Increase the number of sections that an object file can contain
target_compile_options(vdb_tool_common INTERFACE "$<$<COMPILE_LANG_AND_ID:CXX,MSVC>:/bigobj>")
# Excludes APIs such as Cryptography, DDE, RPC, Shell, and Windows Sockets
target_compile_definitions(vdb_tool_common INTERFACE "$<$<CXX_COMPILER_ID:MSVC>:WIN32_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
target_compile_definitions(vdb_tool_common INTERFACE "$<$<CXX_COMPILER_ID:MSVC>:_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
target_compile_definitions(vdb_tool_common INTERFACE "$<$<CXX_COMPILER_ID:MSVC>:_CRT_NONSTDC_NO_WARNINGS>")
if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
target_compile_options(vdb_tool_common INTERFACE "$<$<CONFIG:RELEASE>:/Oi>")
message(STATUS "Suppressing some noisy MSVC CXX warnings.")
endif()
# Conversion from int64_t to long
target_compile_options(vdb_tool_common INTERFACE "$<$<COMPILE_LANG_AND_ID:CXX,MSVC>:/wd4244>")
# It's not possible to use STL types in DLL interfaces in a portable and
# reliable way so disable this warning
target_compile_options(vdb_tool_common INTERFACE "$<$<COMPILE_LANG_AND_ID:CXX,MSVC>:/wd4251>")
# Conversion from size_t to uLong
target_compile_options(vdb_tool_common INTERFACE "$<$<COMPILE_LANG_AND_ID:CXX,MSVC>:/wd4267>")
# Non dll-interface class used as base for dll-interface class
#target_compile_options(vdb_tool_common INTERFACE "$<$<COMPILE_LANG_AND_ID:CXX,MSVC>:/wd4275>")
# Truncation from 'int' to 'bool'
#target_compile_options(vdb_tool_common INTERFACE "$<$<COMPILE_LANG_AND_ID:CXX,MSVC>:/wd4305>")
if(OPENVDB_BUILD_CORE)
target_link_libraries(vdb_tool_common INTERFACE ${OPENVDB_BINARIES_DEPENDENT_LIBS})
else()
find_package(OpenVDB)
if(NOT OpenVDB_FOUND)
message(FATAL_ERROR
" Couldn't find OpenVDB\n"
" Set OPENVDB_CMAKE_PATH to <OpenVDB install path>/lib/cmake/OpenVDB")
endif()
target_link_libraries(vdb_tool_common INTERFACE TBB::tbb OpenVDB::openvdb)
endif()
target_include_directories(vdb_tool_common INTERFACE "${Boost_INCLUDE_DIRS}" "${OpenVDB_INCLUDE_DIRS}" "include")
# vdb_tool
add_executable(vdb_tool src/main.cpp)
target_include_directories(vdb_tool PRIVATE vdb_tool_common)
target_link_libraries(vdb_tool PRIVATE vdb_tool_common)
install(TARGETS vdb_tool RUNTIME DESTINATION ${OPENVDB_INSTALL_BINDIR})
# unit test
if(OPENVDB_BUILD_VDB_TOOL_UNITTESTS)
find_package(GTest ${MINIMUM_GOOGLETEST_VERSION} CONFIG REQUIRED)
add_executable(vdb_tool_test src/unittest.cpp)
target_include_directories(vdb_tool_test PRIVATE vdb_tool_common)
# The test provides its own main() and uses only gtest (no gmock), so link just
# GTest::gtest. Listing gmock / *_main as well pulls gtest/gmock onto the link
# line multiple times, which the macOS linker flags as "ignoring duplicate libraries".
target_link_libraries(vdb_tool_test PRIVATE vdb_tool_common GTest::gtest)
add_test(vdb_tool_unit_test vdb_tool_test)
endif()