Skip to content

Commit 8585a24

Browse files
yutingyefacebook-github-bot
authored andcommitted
Fix #1561 properly (#1564)
Summary: #1561 reported build errors on windows in debug mode, but the fixes #1562 pulls in huge binaries to linux build and pulls in openfbx into Windows release build, increasing binary size of both linux and windows wheels. This diff scoped the fix to debug build only without affecting other build modes. Reviewed By: nickyhe-gemini Differential Revision: D110828952
1 parent ba450ee commit 8585a24

2 files changed

Lines changed: 48 additions & 24 deletions

File tree

CMakeLists.txt

Lines changed: 46 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,10 @@ find_package(Ceres CONFIG REQUIRED)
118118
find_package(CLI11 CONFIG REQUIRED)
119119
find_package(Dispenso CONFIG REQUIRED)
120120
find_package(drjit CONFIG REQUIRED)
121+
# DrJit's debug assertions emit jit_raise references when NDEBUG is unset. Keep
122+
# drjit-core out of release builds to avoid pulling large transitive libraries
123+
# into wheels.
124+
set(momentum_drjit_core_debug_link "$<$<CONFIG:Debug>:drjit-core>")
121125
find_package(Eigen3 CONFIG REQUIRED)
122126
if(DEFINED Eigen3_VERSION AND
123127
(Eigen3_VERSION VERSION_LESS 5.0.0 OR Eigen3_VERSION VERSION_GREATER_EQUAL 5.1.0))
@@ -129,31 +133,49 @@ find_package(fmt CONFIG REQUIRED)
129133
find_package(fx-gltf CONFIG REQUIRED)
130134
find_package(indicators 2.3 CONFIG REQUIRED)
131135
find_package(nlohmann_json CONFIG REQUIRED)
132-
if(MSVC)
136+
find_package(openfbx CONFIG REQUIRED)
137+
138+
set(momentum_needs_openfbx_debug_target OFF)
139+
if(MSVC AND (CMAKE_CONFIGURATION_TYPES OR CMAKE_BUILD_TYPE STREQUAL "Debug"))
140+
set(momentum_needs_openfbx_debug_target ON)
141+
endif()
142+
143+
set(momentum_openfbx_link_libraries OpenFBX)
144+
if(momentum_needs_openfbx_debug_target)
133145
include(FetchContent)
134-
# OpenFBX uses CMAKE_SOURCE_DIR when installing headers, which doesn't work in a tree build
135-
FetchContent_Populate(
136-
openfbx
146+
147+
# The conda-forge Windows package only provides a Release OpenFBX static
148+
# library. Use it for normal builds and wheels, but build OpenFBX from source
149+
# for MSVC Debug so its runtime library matches the rest of the Debug build.
150+
FetchContent_Declare(
151+
momentum_openfbx
137152
GIT_REPOSITORY https://github.com/nem0/OpenFBX.git
138153
GIT_TAG v0.9
154+
SOURCE_SUBDIR runtime
155+
)
156+
FetchContent_MakeAvailable(momentum_openfbx)
157+
158+
add_library(momentum_openfbx_debug STATIC EXCLUDE_FROM_ALL
159+
"${momentum_openfbx_SOURCE_DIR}/src/ofbx.cpp"
160+
)
161+
target_include_directories(momentum_openfbx_debug
162+
PUBLIC "${momentum_openfbx_SOURCE_DIR}/src"
163+
)
164+
target_link_libraries(momentum_openfbx_debug
165+
PRIVATE
166+
$<IF:$<TARGET_EXISTS:libdeflate::libdeflate_shared>,libdeflate::libdeflate_shared,libdeflate::libdeflate_static>
167+
)
168+
target_compile_definitions(momentum_openfbx_debug PRIVATE _LARGEFILE64_SOURCE)
169+
set_target_properties(momentum_openfbx_debug PROPERTIES
170+
OUTPUT_NAME OpenFBX
171+
POSITION_INDEPENDENT_CODE ON
172+
)
173+
174+
set(momentum_openfbx_link_libraries
175+
"$<BUILD_INTERFACE:$<$<CONFIG:Debug>:momentum_openfbx_debug>>"
176+
"$<BUILD_INTERFACE:$<$<NOT:$<CONFIG:Debug>>:OpenFBX>>"
177+
"$<INSTALL_INTERFACE:OpenFBX>"
139178
)
140-
file(READ "${openfbx_SOURCE_DIR}/CMakeLists.txt" contents)
141-
string(REPLACE
142-
"\${CMAKE_SOURCE_DIR}/src/ofbx.h"
143-
"\${CMAKE_CURRENT_SOURCE_DIR}/src/ofbx.h"
144-
contents
145-
"${contents}")
146-
file(WRITE "${openfbx_SOURCE_DIR}/CMakeLists.txt" "${contents}")
147-
add_subdirectory("${openfbx_SOURCE_DIR}" "${openfbx_BINARY_DIR}")
148-
# TODO: Replace the above with this below once the OpenFBX CMakeLists.txt has been updated
149-
# FetchContent_Declare(
150-
# openfbx
151-
# GIT_REPOSITORY https://github.com/nem0/OpenFBX.git
152-
# GIT_TAG v<version>
153-
# )
154-
# FetchContent_MakeAvailable(openfbx)
155-
else()
156-
find_package(openfbx CONFIG REQUIRED)
157179
endif()
158180
if(MOMENTUM_BUILD_IO_USD)
159181
find_package(pxr CONFIG REQUIRED HINTS ${CMAKE_INSTALL_PREFIX} ${CMAKE_INSTALL_PREFIX}/cmake)
@@ -271,7 +293,8 @@ mt_library(
271293
PUBLIC_LINK_LIBRARIES
272294
Eigen3::Eigen
273295
drjit
274-
drjit-core
296+
# DrJit's debug assertions emit jit_raise references when NDEBUG is unset.
297+
${momentum_drjit_core_debug_link}
275298
)
276299

277300
mt_library(
@@ -528,7 +551,7 @@ mt_library(
528551
io_common
529552
io_json_utils
530553
${io_fbx_private_link_libraries}
531-
OpenFBX
554+
${momentum_openfbx_link_libraries}
532555
)
533556

534557
if(MOMENTUM_ENABLE_FBX_SAVING)

axel/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ target_link_libraries(${target_name}
8888
Microsoft.GSL::GSL
8989
Dispenso::dispenso
9090
drjit
91-
drjit-core
91+
# DrJit's debug assertions emit jit_raise references when NDEBUG is unset.
92+
$<$<CONFIG:Debug>:drjit-core>
9293
nlohmann_json::nlohmann_json
9394
)
9495

0 commit comments

Comments
 (0)