From 060a50a5f72a0ccdb754bf155aa2ed394a1bcda5 Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Thu, 7 Apr 2022 20:27:23 +0200 Subject: Cycles: refactor Hydra render delegate building * Leave code for building the render delegate against other applications and their USD libraries to the Cycles repository, since this is not a great fit. In the Blender repository, always use Blender's USD libraries now that they include Hydra support. * Hide non-USD symbols from the hdCycles shared library, to avoid library version conflicts. * Share Apple framework linking between the standalone app and plugin. * Add cycles_hydra module, to be shared between the standalone app and plugin. * Bring external libs code in sync with standalone repo, adding various missing libraries. * Move some cmake include directories to the top level cycles source folder because we need to control their global order, to ensure we link against the correct headers with mixed Blender libraries and external USD libraries. --- intern/cycles/hydra/CMakeLists.txt | 128 +++++++++++++++--------- intern/cycles/hydra/resources/apple_symbols.map | 1 + intern/cycles/hydra/resources/linux_symbols.map | 8 ++ 3 files changed, 91 insertions(+), 46 deletions(-) create mode 100644 intern/cycles/hydra/resources/apple_symbols.map create mode 100644 intern/cycles/hydra/resources/linux_symbols.map (limited to 'intern/cycles/hydra') diff --git a/intern/cycles/hydra/CMakeLists.txt b/intern/cycles/hydra/CMakeLists.txt index 7b7ea43cfe5..17a7f897ac6 100644 --- a/intern/cycles/hydra/CMakeLists.txt +++ b/intern/cycles/hydra/CMakeLists.txt @@ -81,18 +81,18 @@ endif() include_directories(${INC}) include_directories(SYSTEM ${INC_SYS}) -add_library(hdCyclesStatic STATIC +add_library(cycles_hydra STATIC ${SRC_HD_CYCLES} ${INC_HD_CYCLES} ) -target_compile_options(hdCyclesStatic +target_compile_options(cycles_hydra PRIVATE $<$:/wd4003 /wd4244 /wd4506> $<$:-Wno-float-conversion -Wno-double-promotion -Wno-deprecated> ) -target_compile_definitions(hdCyclesStatic +target_compile_definitions(cycles_hydra PRIVATE GLOG_NO_ABBREVIATED_SEVERITIES=1 OSL_DEBUG=$ @@ -100,57 +100,93 @@ target_compile_definitions(hdCyclesStatic $<$:NOMINMAX=1> ) -target_link_libraries(hdCyclesStatic +target_link_libraries(cycles_hydra PUBLIC - hd - hgi - hgiGL + ${USD_LIBRARIES} PRIVATE ${LIB} ) -set(HdCyclesPluginName hdCycles) -add_library(${HdCyclesPluginName} SHARED - plugin.h - plugin.cpp -) - -set_target_properties(${HdCyclesPluginName} - PROPERTIES PREFIX "" -) - -target_compile_definitions(${HdCyclesPluginName} - PRIVATE - MFB_PACKAGE_NAME=${HdCyclesPluginName} - MFB_ALT_PACKAGE_NAME=${HdCyclesPluginName} - GLOG_NO_ABBREVIATED_SEVERITIES=1 - OSL_DEBUG=$ - TBB_USE_DEBUG=$ - $<$:NOMINMAX=1> -) - -target_link_libraries(${HdCyclesPluginName} - hdCyclesStatic -) +if(WITH_CYCLES_HYDRA_RENDER_DELEGATE) + set(HdCyclesPluginName hdCycles) + add_library(${HdCyclesPluginName} SHARED + plugin.h + plugin.cpp + ) -if(WITH_CYCLES_BLENDER) - set(CYCLES_HYDRA_INSTALL_PATH "../") -else() - set(CYCLES_HYDRA_INSTALL_PATH ${CMAKE_INSTALL_PREFIX}) - # Put the root plugInfo.json one level up - delayed_install("${CMAKE_CURRENT_SOURCE_DIR}" "plugInfo.json" ${CMAKE_INSTALL_PREFIX}) -endif() + set_target_properties(${HdCyclesPluginName} + PROPERTIES PREFIX "" + ) -delayed_install("" $ ${CYCLES_HYDRA_INSTALL_PATH}) + target_compile_definitions(${HdCyclesPluginName} + PRIVATE + MFB_PACKAGE_NAME=${HdCyclesPluginName} + MFB_ALT_PACKAGE_NAME=${HdCyclesPluginName} + GLOG_NO_ABBREVIATED_SEVERITIES=1 + OSL_DEBUG=$ + TBB_USE_DEBUG=$ + $<$:NOMINMAX=1> + ) -set(PLUG_INFO_ROOT "..") + target_link_libraries(${HdCyclesPluginName} + cycles_hydra + ) -file(RELATIVE_PATH PLUG_INFO_LIBRARY_PATH "${CYCLES_HYDRA_INSTALL_PATH}/${HdCyclesPluginName}" "${CYCLES_HYDRA_INSTALL_PATH}/${HdCyclesPluginName}${CMAKE_SHARED_LIBRARY_SUFFIX}") -file(RELATIVE_PATH PLUG_INFO_RESOURCE_PATH "${CYCLES_HYDRA_INSTALL_PATH}/${HdCyclesPluginName}" "${CYCLES_INSTALL_PATH}") + if(APPLE) + set_property( + TARGET + ${HdCyclesPluginName} + APPEND_STRING PROPERTY LINK_FLAGS + " -Wl,-exported_symbols_list,'${CMAKE_CURRENT_SOURCE_DIR}/resources/apple_symbols.map'" + ) + elseif(UNIX) + set_property( + TARGET + ${HdCyclesPluginName} + APPEND_STRING PROPERTY LINK_FLAGS + " -Wl,--version-script='${CMAKE_CURRENT_SOURCE_DIR}/resources/linux_symbols.map'" + ) + endif() + + + if(WITH_CYCLES_BLENDER) + # Install inside add-on + set(CYCLES_HYDRA_INSTALL_PATH ${CYCLES_INSTALL_PATH}/hydra) + else() + # Install next to cycles executable + set(CYCLES_HYDRA_INSTALL_PATH ${CMAKE_INSTALL_PREFIX}/hydra) + endif() -configure_file(resources/plugInfo.json - ${CMAKE_CURRENT_BINARY_DIR}/resources/plugInfo.json - @ONLY -) + # Put the root plugInfo.json one level up + delayed_install("${CMAKE_CURRENT_SOURCE_DIR}" "plugInfo.json" ${CYCLES_HYDRA_INSTALL_PATH}) + delayed_install("" $ ${CYCLES_HYDRA_INSTALL_PATH}) + + set_target_properties(${HdCyclesPluginName} + PROPERTIES + RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) + + set(PLUG_INFO_ROOT "..") + + if(WITH_CYCLES_BLENDER) + # Full path not yet know at this point and RELATIVE_PATH requires + # absolute path as input. So just set manually. + set(PLUG_INFO_LIBRARY_PATH "../${HdCyclesPluginName}${CMAKE_SHARED_LIBRARY_SUFFIX}") + set(PLUG_INFO_RESOURCE_PATH "../..") + else() + file(RELATIVE_PATH + PLUG_INFO_LIBRARY_PATH + "${CYCLES_HYDRA_INSTALL_PATH}/${HdCyclesPluginName}" + "${CYCLES_HYDRA_INSTALL_PATH}/${HdCyclesPluginName}${CMAKE_SHARED_LIBRARY_SUFFIX}") + file(RELATIVE_PATH PLUG_INFO_RESOURCE_PATH + "${CYCLES_HYDRA_INSTALL_PATH}/${HdCyclesPluginName}" + "${CYCLES_INSTALL_PATH}") + endif() + + configure_file(resources/plugInfo.json + ${CMAKE_CURRENT_BINARY_DIR}/resources/plugInfo.json + @ONLY + ) -delayed_install("${CMAKE_CURRENT_BINARY_DIR}/resources" "plugInfo.json" "${CYCLES_HYDRA_INSTALL_PATH}/${HdCyclesPluginName}/resources") + delayed_install("${CMAKE_CURRENT_BINARY_DIR}/resources" "plugInfo.json" "${CYCLES_HYDRA_INSTALL_PATH}/${HdCyclesPluginName}/resources") +endif() diff --git a/intern/cycles/hydra/resources/apple_symbols.map b/intern/cycles/hydra/resources/apple_symbols.map new file mode 100644 index 00000000000..85be5ae55fe --- /dev/null +++ b/intern/cycles/hydra/resources/apple_symbols.map @@ -0,0 +1 @@ +*PXR* diff --git a/intern/cycles/hydra/resources/linux_symbols.map b/intern/cycles/hydra/resources/linux_symbols.map new file mode 100644 index 00000000000..397422c9854 --- /dev/null +++ b/intern/cycles/hydra/resources/linux_symbols.map @@ -0,0 +1,8 @@ +/* Hide everything except USD / Hydra symbols, to avoid conflicts with other + * application using different library versions. */ +{ +global: + PXR*; +local: + *; +}; -- cgit v1.2.3