-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
393 lines (315 loc) · 15.6 KB
/
Copy pathCMakeLists.txt
File metadata and controls
393 lines (315 loc) · 15.6 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
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
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
# Copyright 2025 Autodesk, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# 3.26 to match OpenUSD 25.05.
# 3.31 latest tested version.
cmake_minimum_required(VERSION 3.26...3.31)
# An option to enable tests.
option(ENABLE_TESTS "Enable tests" ON)
# An option to enable Vulkan.
option(HVT_ENABLE_VULKAN "Enable Vulkan" OFF)
# An option to enable benchmarks.
option(ENABLE_BENCHMARKS "Enable benchmarks" OFF)
# An option to tell vcpkg to only fetch release and not debug dependencies.
option(HVT_RELEASE_ONLY_VCPKG_DEPS "Use a release-optimized vcpkg base triplet" OFF)
# Add the path to the CMake helpers and import them.
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
# Try to import from the environment variable only if OPENUSD_INSTALL_PATH isn’t already set
if(NOT DEFINED OPENUSD_INSTALL_PATH AND DEFINED ENV{OPENUSD_INSTALL_PATH})
message(STATUS "Using OpenUSD install path from environment variable: $ENV{OPENUSD_INSTALL_PATH}")
set(OPENUSD_INSTALL_PATH "$ENV{OPENUSD_INSTALL_PATH}" CACHE PATH "Path to local USD install")
endif()
# Includes various helpers.
include(HvtHelpers)
# Setups and runs vcpkg.
include(VcpkgSetup)
# Detect whether this (HVT) is the top-level project.
# NOTE: We can't use PROJECT_IS_TOP_LEVEL here because the project is not yet defined.
string(COMPARE EQUAL "${CMAKE_CURRENT_SOURCE_DIR}" "${CMAKE_SOURCE_DIR}" _HVT_PROJECT_IS_TOP_LEVEL)
# Apple-specific configuration
if (_HVT_PROJECT_IS_TOP_LEVEL AND APPLE)
set_if_not_defined(CMAKE_OSX_DEPLOYMENT_TARGET "12.0" "Minimum OSX deployment version")
# Validate architecture (universal builds not supported due to libjpeg-turbo)
list(LENGTH CMAKE_OSX_ARCHITECTURES osx_arch_count)
if(osx_arch_count GREATER 1)
message(FATAL_ERROR "Universal builds are not supported because of libjpeg-turbo")
endif()
endif()
# Set the default build type.
set_if_not_defined(CMAKE_BUILD_TYPE "Release" "The build type")
# Enable only the typical build types.
set_if_not_defined(CMAKE_CONFIGURATION_TYPES "Debug;Release;MinSizeRel;RelWithDebInfo" "List of build types")
if (NOT "${CMAKE_BUILD_TYPE}" IN_LIST CMAKE_CONFIGURATION_TYPES)
message(FATAL_ERROR "CONFIG=${CMAKE_BUILD_TYPE} is unsupported. Supported values are: ${CMAKE_CONFIGURATION_TYPES}.")
endif()
# Declare the project.
project(HydraViewportToolbox
VERSION 0.26.05.0
DESCRIPTION "Utilities to support graphics viewports using OpenUSD Hydra"
LANGUAGES CXX
HOMEPAGE_URL https://github.com/Autodesk/hydra-viewport-toolbox
)
set(_VERSION "${HydraViewportToolbox_VERSION}")
if (NOT PROJECT_IS_TOP_LEVEL)
# Export version variable for parent scope (Components build system)
set(${PROJECT_NAME}_VERSION ${${PROJECT_NAME}_VERSION} PARENT_SCOPE)
endif()
# Declare C++17 support.
set(CMAKE_CXX_STANDARD 17)
# Disable fallback to other C++ version if standard is not supported.
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# Disable any compiler specific C++ extensions.
set(CMAKE_CXX_EXTENSIONS OFF)
# Required by Linux build.
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
# By default, set the output directory for all the sub-projects.
set_if_not_defined(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin" "Default output directory for binaries")
set_if_not_defined(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib" "Default output directory for libraries")
set_if_not_defined(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib" "Default output directory for archives")
# Set a default install prefix to avoid writing to system directories
# (e.g. /usr/local) when none is explicitly provided by the user.
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set(CMAKE_INSTALL_PREFIX "${PROJECT_BINARY_DIR}/install" CACHE PATH "Default install path" FORCE)
endif()
#---------------------------------------------------------------------------------------------------
# Enable code IDE to use folders, this will enable source_group(TREE,...)
if (PROJECT_IS_TOP_LEVEL)
# Enable code IDE to use folders, this will enable source_group(TREE,...)
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
# By default, generate all XCode schemes.
set(CMAKE_XCODE_GENERATE_SCHEME ON)
endif()
#---------------------------------------------------------------------------------------------------
# This section only adds cmake options.
include(CMakeDependentOption)
# An option to enable the use of precompiled headers.
# TODO: Implement precompiled headers.
option(ENABLE_PRECOMPILED_HEADERS "Enable precompiled headers" ON)
# Optional: Path to a local OpenUSD install (CMake config, not source tree).
# NOTE: This refers to an install of OpenUSD, not the source.
set(OPENUSD_INSTALL_PATH CACHE PATH "Path to a local OpenUSD install (optional)")
# Optional: Path to a local OpenUSD install for debug (CMake config, not source tree).
# NOTE: This refers to an install of OpenUSD, not the source.
set(OPENUSD_INSTALL_PATH_DEBUG CACHE PATH "Path to a local debug OpenUSD install (optional)")
# Enable the use of pending changes to OpenUSD from Autodesk.
# NOTE: These are not currently available publicly, but are expected to be available in a future
# version of OpenUSD.
option(ENABLE_ADSK_OPENUSD_PENDING "Enable the use of pending changes to OpenUSD from Autodesk" OFF)
# Enable/Disable warnings as errors.
option(ENABLE_WARNINGS_AS_ERRORS "Enable all the warnings as errors" ON)
# Use draw order.
cmake_dependent_option(ENABLE_DRAW_ORDER "Use draw order" ON ENABLE_ADSK_OPENUSD_PENDING OFF)
# By default, build as a dynamic library.
option(BUILD_SHARED_LIBS "Build dynamic libraries" ON)
#---------------------------------------------------------------------------------------------------
# This section lists all the third-party dependencies common to all sub-projects.
# Find OpenGL, which is mandatory for OpenUSD on Windows and macOS.
if (WIN32 OR (APPLE AND NOT IOS))
if(APPLE)
# It's possible to have X11 OpenGL installed on macOS,
# but USD requires Apple OpenGL. Basically the opposite of this:
# https://cmake.org/cmake/help/latest/module/FindOpenGL.html#macos-specific
set(previous_CMAKE_FIND_FRAMEWORK ${CMAKE_FIND_FRAMEWORK})
set(CMAKE_FIND_FRAMEWORK ONLY)
endif()
find_package(OpenGL REQUIRED)
if(APPLE)
set(CMAKE_FIND_FRAMEWORK ${previous_CMAKE_FIND_FRAMEWORK})
endif()
endif()
get_cmake_property(_MULTI_CONFIG GENERATOR_IS_MULTI_CONFIG)
# True if the build is done from a locally compiled OpenUSD
set(USE_LOCAL_USD OFF)
if(OPENUSD_INSTALL_PATH)
set(USE_LOCAL_USD ON)
endif()
if (OPENUSD_INSTALL_PATH AND EXISTS "${OPENUSD_INSTALL_PATH}")
set(pxr_DIR "${OPENUSD_INSTALL_PATH}")
if (_MULTI_CONFIG AND "Debug" IN_LIST CMAKE_CONFIGURATION_TYPES)
if (NOT OPENUSD_INSTALL_PATH_DEBUG OR NOT EXISTS "${OPENUSD_INSTALL_PATH_DEBUG}")
if(WIN32)
message(WARNING "The local OpenUSD debug install path is missing: on Windows, mixing debug and release will most likely result in a broken build! Defaulting to the release build.")
else()
message(STATUS "The local OpenUSD debug install path is missing: defaulting to the release one")
endif()
set(OPENUSD_INSTALL_PATH_DEBUG "${OPENUSD_INSTALL_PATH}")
endif()
endif()
else()
# Set the path to the vcpkg installed USD if not user provided USD.
if(_MULTI_CONFIG)
set(OPENUSD_INSTALL_PATH "${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}")
set(OPENUSD_INSTALL_PATH_DEBUG "${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/debug")
else()
if(CMAKE_BUILD_TYPE STREQUAL Debug)
set(OPENUSD_INSTALL_PATH "${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/debug")
else()
set(OPENUSD_INSTALL_PATH "${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}")
endif()
endif()
endif()
# Find OpenUSD if not already found.
if (NOT pxr_FOUND)
find_package(pxr CONFIG REQUIRED NO_CMAKE_FIND_ROOT_PATH)
endif()
#---------------------------------------------------------------------------------------------------
# Set the RPATH for Linux and macOS.
if (UNIX)
# Enable RPATH for build tree.
set(CMAKE_SKIP_BUILD_RPATH FALSE)
# Add the automatically determined parts of the RPATH
# which point to directories outside the build tree to the install RPATH.
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
# Don't use the install RPATH during build.
set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
# Set platform-specific install RPATH.
if (APPLE)
set(_RPATH "@loader_path;@loader_path/../lib")
else()
# Linux
set(_RPATH "$ORIGIN:$ORIGIN/../lib")
endif()
# Set the RPATH to be used when installing.
set(CMAKE_INSTALL_RPATH "${_RPATH}")
# On macOS, enable @rpath.
set(CMAKE_MACOSX_RPATH TRUE)
endif()
#---------------------------------------------------------------------------------------------------
# This section only adds settings applicable to all the projects.
# Set the HVT include (public API) and source (private API) directories, for use by sub-projects.
set(_HVT_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include")
set(_HVT_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/source")
if (ENABLE_ADSK_OPENUSD_PENDING)
# By default, set the symbol visibility to hidden (to avoid exporting private symbols by mistake).
# Note: Only supported by OpenUSD adsk/dev.
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
set(CMAKE_VISIBILITY_INLINES_HIDDEN ON)
endif()
# Allowing tbb to work in debug mode in different setups
add_compile_definitions(
$<$<CONFIG:Debug>:TBB_USE_DEBUG>
)
# Enable warnings and warnings as errors for all sub-projects.
if (MSVC)
# Displays level 1, level 2, and level 3 warnings, and all level 4 (informational) warnings.
add_compile_options(/W4)
# Disable specific warnings.
add_compile_options(/wd4251) # DLL interface warnings.
add_compile_options(/wd4275) # DLL interface warnings.
# Enable C++ exception handling (required for older MSVC versions < 19.44, harmless for newer versions).
add_compile_options(/EHsc)
if (ENABLE_WARNINGS_AS_ERRORS)
add_compile_options(/WX)
endif()
# Tell compiler to store the debugging information in a PDB for the OBJ file.
add_compile_options(/Zi)
# Tell linker to include symbol data.
if (BUILD_SHARED_LIBS)
add_link_options(/DEBUG:FULL /OPT:REF /OPT:ICF)
endif()
# The min() and max() macro definitions from windef.h (Windows) can conflict with std::min()
# and std::max(). For example, this happens when using OpenUSD with TBB instead of OneTBB. To
# prevent the conflict, we can specify the NOMINMAX symbol since we don't use the macros.
add_compile_definitions(NOMINMAX)
# Call function to check if Python debug libraries are available.
check_python_debug_libraries(_PYTHON_DEBUG_AVAILABLE)
if(_PYTHON_DEBUG_AVAILABLE)
# In debug builds, wrap_python.hpp will #undef _DEBUG when BOOST_DEBUG_PYTHON is not defined,
# and will then include pyconfig.h :
# https://github.com/PixarAnimationStudios/OpenUSD/blob/v25.08/pxr/external/boost/python/detail/wrap_python.hpp#L29-L52
# pyconfig.h will then autolink the Python lib; however, since _DEBUG was #undef'd, it will try to
# link against the release version of the Python lib, causing a linker error :
# https://github.com/python/cpython/blob/v3.11.4/PC/pyconfig.h#L269-L286
# The code below forces using Python debug libs, but should only be executed if Python debug libs
# were installed and are available.
add_compile_definitions(
$<$<CONFIG:Debug>:BOOST_DEBUG_PYTHON>
)
endif()
elseif(CMAKE_CXX_COMPILER_ID MATCHES "[C|c]lang" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU")
# By default, enables all warnings.
add_compile_options(-Wall -Wextra -Wpedantic)
if (ENABLE_WARNINGS_AS_ERRORS)
add_compile_options(-Werror)
# USD's pxr/base/tf/hashset.h uses the GNU STL extensions hashset,
# which generates a warning that is then reported as an error.
# Pending a change in USD, disable the warning here for now.
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU")
add_compile_options(-Wno-deprecated)
endif()
endif()
else()
message(FATAL_ERROR "Unsupported compiler: ${CMAKE_CXX_COMPILER_ID}.")
endif()
# TODO: Drop ENABLE_ADSK_OPENUSD_PENDING support i.e., only support origin/dev.
if (ENABLE_ADSK_OPENUSD_PENDING)
add_compile_definitions(ADSK_OPENUSD_PENDING)
endif()
# TODO: Drop DRAW_ORDER support
# Add a DRAW_ORDER definition if the draw order feature is enabled.
if (ENABLE_DRAW_ORDER)
add_compile_definitions(DRAW_ORDER)
endif()
# Add Vulkan dependencies.
if(HVT_ENABLE_VULKAN)
add_compile_definitions(ENABLE_VULKAN)
find_package(VulkanLoader CONFIG REQUIRED)
find_package(VulkanHeaders CONFIG REQUIRED)
# Add VMA include directory to fix vk_mem_alloc.h include issue.
find_package(VulkanMemoryAllocator CONFIG REQUIRED)
endif()
#---------------------------------------------------------------------------------------------------
add_subdirectory("source")
if (ENABLE_TESTS AND PROJECT_IS_TOP_LEVEL)
# Initialize CTest before adding test.
enable_testing()
add_subdirectory("test")
endif()
#---------------------------------------------------------------------------------------------------
message(STATUS "-------------------------------------------")
message(STATUS "Hydra Viewport Toolbox build configuration:")
message(STATUS " Platform : ${CMAKE_SYSTEM_NAME} [${CMAKE_SYSTEM}]")
if (APPLE)
execute_process(COMMAND sysctl -n machdep.cpu.brand_string OUTPUT_VARIABLE COMPUTED_ARCHITECTURE)
message(STATUS " Machine architecture : ${COMPUTED_ARCHITECTURE}")
endif()
message(STATUS " CMake : ${CMAKE_VERSION}")
message(STATUS " CMake generator : ${CMAKE_GENERATOR}")
message(STATUS " Compiler : ${CMAKE_CXX_COMPILER_ID}")
message(STATUS " Compiler version : ${CMAKE_CXX_COMPILER_VERSION}")
message(STATUS "")
if (APPLE)
message(STATUS " Build architecture : ${CMAKE_OSX_ARCHITECTURES}")
message(STATUS " Build deployment target : ${CMAKE_OSX_DEPLOYMENT_TARGET}")
endif()
if(_MULTI_CONFIG)
message(STATUS " Build types : ${CMAKE_CONFIGURATION_TYPES}")
else()
message(STATUS " Build type : ${CMAKE_BUILD_TYPE}")
endif()
message(STATUS " Warnings as errors : ${ENABLE_WARNINGS_AS_ERRORS}")
message(STATUS " Enable unit tests : ${ENABLE_TESTS}")
message(STATUS " Enable benchmarks : ${ENABLE_BENCHMARKS}")
message(STATUS "")
message(STATUS " OpenUSD build path : ${OPENUSD_INSTALL_PATH}")
if (_MULTI_CONFIG)
message(STATUS " OpenUSD build path (dbg) : ${OPENUSD_INSTALL_PATH_DEBUG}")
endif()
message(STATUS " OpenUSD version : ${pxr_VERSION}")
message(STATUS " Autodesk OpenUSD pending : ${ENABLE_ADSK_OPENUSD_PENDING}")
message(STATUS "")
message(STATUS " Vulkan : ${HVT_ENABLE_VULKAN}")
message(STATUS "")
message(STATUS "Features:")
message(STATUS " Draw order : ${ENABLE_DRAW_ORDER}")
message(STATUS "-------------------------------------------")