diff --git a/BUILDING.md b/BUILDING.md index efa0a182fd..9ac8e5a4f2 100644 --- a/BUILDING.md +++ b/BUILDING.md @@ -247,10 +247,14 @@ by specifying the cmake flag ```PXR_BUILD_ALEMBIC_PLUGIN=TRUE``` when invoking c The additional dependencies that must be supplied when invoking cmake are: -| Dependency Name | Description | -| ------------------ |-------------------------------------------------- | -| ALEMBIC_DIR | The location of [Alembic](https://https://github.com/alembic/alembic) | -| OPENEXR_LOCATION | The location of [OpenEXR](http://www.openexr.com) | +| Dependency Name | Description | +| ----------------------------------|-------------------------------------------------- | +| ALEMBIC_DIR | The location of [Alembic](https://https://github.com/alembic/alembic) | +| OPENEXR_LOCATION | The location of [OpenEXR](http://www.openexr.com) | +| Imath_DIR (If not using OpenEXR) | Path to the CMake package config of a Imath SDK install. (With OpenEXR 3+, Imath can be used explicitly instead of OpenEXR.)| + +Either OpenEXR or Imath is required depending on which library is used by the +Alembic library specified in ALEMBIC_DIR. See [3rd Party Library and Application Versions](VERSIONS.md) for version information. diff --git a/cmake/defaults/Packages.cmake b/cmake/defaults/Packages.cmake index abeccb76a8..41df13bca4 100644 --- a/cmake/defaults/Packages.cmake +++ b/cmake/defaults/Packages.cmake @@ -187,7 +187,7 @@ endif() if (PXR_BUILD_IMAGING) # --OpenImageIO if (PXR_BUILD_OPENIMAGEIO_PLUGIN) - find_package(OpenEXR REQUIRED) + set(REQUIRES_Imath TRUE) find_package(OpenImageIO REQUIRED) add_definitions(-DPXR_OIIO_PLUGIN_ENABLED) if (OIIO_idiff_BINARY) @@ -215,7 +215,7 @@ if (PXR_BUILD_IMAGING) if (PXR_ENABLE_VULKAN_SUPPORT) if (EXISTS $ENV{VULKAN_SDK}) # Prioritize the VULKAN_SDK includes and packages before any system - # installed headers. This is to prevent linking against older SDKs + # installed headers. This is to prevent linking against older SDKs # that may be installed by the OS. # XXX This is fixed in cmake 3.18+ include_directories(BEFORE SYSTEM $ENV{VULKAN_SDK} $ENV{VULKAN_SDK}/include $ENV{VULKAN_SDK}/lib) @@ -256,7 +256,7 @@ if (PXR_BUILD_IMAGING) endif() # --OpenVDB if (PXR_ENABLE_OPENVDB_SUPPORT) - find_package(OpenEXR REQUIRED) + set(REQUIRES_Imath TRUE) find_package(OpenVDB REQUIRED) add_definitions(-DPXR_OPENVDB_SUPPORT_ENABLED) endif() @@ -285,7 +285,7 @@ endif() if (PXR_BUILD_ALEMBIC_PLUGIN) find_package(Alembic REQUIRED) - find_package(OpenEXR REQUIRED) + set(REQUIRES_Imath TRUE) if (PXR_ENABLE_HDF5_SUPPORT) find_package(HDF5 REQUIRED COMPONENTS @@ -306,10 +306,21 @@ endif() if(PXR_ENABLE_OSL_SUPPORT) find_package(OSL REQUIRED) - find_package(OpenEXR REQUIRED) + set(REQUIRES_Imath TRUE) add_definitions(-DPXR_OSL_SUPPORT_ENABLED) endif() # ---------------------------------------------- +# Try and find Imath or fallback to OpenEXR +# Use ImathConfig.cmake, +# Refer: https://github.com/AcademySoftwareFoundation/Imath/blob/main/docs/PortingGuide2-3.md#openexrimath-3x-only +if(REQUIRES_Imath) + find_package(Imath CONFIG) + if (NOT Imath_FOUND) + MESSAGE(STATUS "Imath not found. Looking for OpenEXR instead.") + find_package(OpenEXR REQUIRED) + endif() +endif() + set(BUILD_SHARED_LIBS "${build_shared_libs}") diff --git a/pxr/imaging/hioOpenVDB/CMakeLists.txt b/pxr/imaging/hioOpenVDB/CMakeLists.txt index 2a2dfd5e72..e32762cea0 100644 --- a/pxr/imaging/hioOpenVDB/CMakeLists.txt +++ b/pxr/imaging/hioOpenVDB/CMakeLists.txt @@ -13,6 +13,13 @@ if (WIN32) add_definitions(-D_USE_MATH_DEFINES) endif() +# Use the import targets set by Imath's package config +if (Imath_FOUND) + LIST(APPEND __VDB_IMATH_LIBS "Imath::Imath") +else() + LIST(APPEND __VDB_IMATH_LIBS ${OPENEXR_Half_LIBRARY}) +endif() + pxr_library(hioOpenVDB LIBRARIES ar @@ -20,7 +27,7 @@ pxr_library(hioOpenVDB hio tf usd - ${OPENEXR_Half_LIBRARY} + ${__VDB_IMATH_LIBS} ${OPENVDB_LIBRARY} INCLUDE_DIRS diff --git a/pxr/imaging/plugin/hioOiio/CMakeLists.txt b/pxr/imaging/plugin/hioOiio/CMakeLists.txt index f7491e2e6e..0a055b711d 100644 --- a/pxr/imaging/plugin/hioOiio/CMakeLists.txt +++ b/pxr/imaging/plugin/hioOiio/CMakeLists.txt @@ -7,6 +7,14 @@ if (NOT ${PXR_BUILD_GPU_SUPPORT}) return() endif() +# Use the import targets set by Imath's package config +if (Imath_FOUND) + set(__OIIO_IMATH_LIBS "Imath::Imath") +else() + set(__OIIO_IMATH_INCLUDE ${OPENEXR_INCLUDE_DIRS}) + set(__OIIO_IMATH_LIBS ${OPENEXR_LIBRARIES}) +endif() + pxr_plugin(hioOiio LIBRARIES ar @@ -15,11 +23,11 @@ pxr_plugin(hioOiio hio tf ${OIIO_LIBRARIES} - ${OPENEXR_LIBRARIES} + ${__OIIO_IMATH_LIBS} INCLUDE_DIRS ${OIIO_INCLUDE_DIRS} - ${OPENEXR_INCLUDE_DIRS} + ${__OIIO_IMATH_INCLUDE} CPPFILES oiioImage.cpp diff --git a/pxr/pxrConfig.cmake.in b/pxr/pxrConfig.cmake.in index df8d3c56d8..86772f0a2b 100644 --- a/pxr/pxrConfig.cmake.in +++ b/pxr/pxrConfig.cmake.in @@ -27,6 +27,18 @@ if(@PXR_ENABLE_MATERIALX_SUPPORT@) find_package(MaterialX REQUIRED) endif() +# Similar to MaterialX above, we are using Imath's cmake package config, so set +# the Imath_DIR accordingly to find the associated import targets which were +# used for this USD build. +# Note that we only need to do this, when it is determined by Imath is being +# used instead of OpenExr (refer Packages.cmake) +if(@REQUIRES_Imath@) + if (NOT DEFINED Imath_DIR) + set(Imath_DIR "@Imath_DIR@") + endif() + find_package(Imath REQUIRED) +endif() + include("${PXR_CMAKE_DIR}/cmake/pxrTargets.cmake") set(libs "@PXR_ALL_LIBS@") set(PXR_LIBRARIES "") diff --git a/pxr/usd/plugin/usdAbc/CMakeLists.txt b/pxr/usd/plugin/usdAbc/CMakeLists.txt index 22c3e4a912..0d8e8bf1af 100644 --- a/pxr/usd/plugin/usdAbc/CMakeLists.txt +++ b/pxr/usd/plugin/usdAbc/CMakeLists.txt @@ -15,6 +15,18 @@ if (PXR_ENABLE_HDF5_SUPPORT) list(APPEND optionalIncludeDirs ${HDF5_INCLUDE_DIRS}) endif() +# Use the import targets set by Imath's package config +if (Imath_FOUND) + set(__ALEMBIC_IMATH_LIBS "Imath::Imath") +else() + set(__ALEMBIC_IMATH_INCLUDES ${OPENEXR_INCLUDE_DIRS}) + LIST(APPEND __ALEMBIC_IMATH_LIBS ${OPENEXR_Half_LIBRARY}) + LIST(APPEND __ALEMBIC_IMATH_LIBS ${OPENEXR_Imath_LIBRARY}) + LIST(APPEND __ALEMBIC_IMATH_LIBS ${OPENEXR_Iex_LIBRARY}) + LIST(APPEND __ALEMBIC_IMATH_LIBS ${OPENEXR_IexMath_LIBRARY}) +endif() + + pxr_plugin(usdAbc LIBRARIES tf @@ -23,15 +35,12 @@ pxr_plugin(usdAbc usd usdGeom ${ALEMBIC_LIBRARIES} - ${OPENEXR_Half_LIBRARY} - ${OPENEXR_Imath_LIBRARY} - ${OPENEXR_Iex_LIBRARY} - ${OPENEXR_IexMath_LIBRARY} + ${__ALEMBIC_IMATH_LIBS} ${optionalLibs} INCLUDE_DIRS ${ALEMBIC_INCLUDE_DIR} - ${OPENEXR_INCLUDE_DIRS} + ${__ALEMBIC_IMATH_INCLUDES} ${optionalIncludeDirs} PRIVATE_CLASSES