Skip to content

Commit

Permalink
Support compiling against imath
Browse files Browse the repository at this point in the history
   This change is a revised version of github PR: #1829

   - Use Imath's config package (https://github.com/AcademySoftwareFoundation/Imath/blob/main/docs/PortingGuide2-3.md#openexrimath-3x-only) instead of introducing a new FindImath.cmake,
     this allows for use of modern cmake design.
   - Attemps to find Imath and if not found, fallbacks to find OpenEXR.
   - Note on using Alembic plugin: Either OpenEXR or Imath is required depending on which library is used by the Alembic library specified in ALEMBIC_DIR.
   - Updates pxrConfig.cmake.in to set Imath_DIR accordingly to find the associated import targets which were used for this USD build.

   Fixes #1591

(Internal change: 2247708)
  • Loading branch information
tallytalwar authored and pixar-oss committed Sep 2, 2022
1 parent 0789ed3 commit 2818017
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 17 deletions.
12 changes: 8 additions & 4 deletions BUILDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
21 changes: 16 additions & 5 deletions cmake/defaults/Packages.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand All @@ -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}")
9 changes: 8 additions & 1 deletion pxr/imaging/hioOpenVDB/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,21 @@ 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
gf
hio
tf
usd
${OPENEXR_Half_LIBRARY}
${__VDB_IMATH_LIBS}
${OPENVDB_LIBRARY}

INCLUDE_DIRS
Expand Down
12 changes: 10 additions & 2 deletions pxr/imaging/plugin/hioOiio/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
12 changes: 12 additions & 0 deletions pxr/pxrConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -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 "")
Expand Down
19 changes: 14 additions & 5 deletions pxr/usd/plugin/usdAbc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 2818017

Please sign in to comment.