diff --git a/cmake/defaults/Packages.cmake b/cmake/defaults/Packages.cmake index abeccb76a8..1991ccd983 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,19 @@ 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 +if(REQUIRES_Imath) + find_package(Imath) + 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/cmake/modules/FindImath.cmake b/cmake/modules/FindImath.cmake new file mode 100644 index 0000000000..032370d9fa --- /dev/null +++ b/cmake/modules/FindImath.cmake @@ -0,0 +1,107 @@ +# +# Copyright 2022 Apple +# +# Licensed under the Apache License, Version 2.0 (the "Apache License") +# with the following modification; you may not use this file except in +# compliance with the Apache License and the following modification to it: +# Section 6. Trademarks. is deleted and replaced with: +# +# 6. Trademarks. This License does not grant permission to use the trade +# names, trademarks, service marks, or product names of the Licensor +# and its affiliates, except as required to comply with Section 4(c) of +# the License and to reproduce the content of the NOTICE file. +# +# You may obtain a copy of the Apache License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the Apache License with the above modification is +# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the Apache License for the specific +# language governing permissions and limitations under the Apache License. +# + + +# FindImath +# ------- +# +# Find Imath include directories and libraries. +# +# Input Variables: +# +# * Imath_ROOT : The Root location of the built Imath project, where we should look for the headers and dylibs +# * Imath_USE_DEBUG_BUILD : Use the Debug libraries instead of the release library +# +# Output Variables: +# * FOUND_Imath : Set if the project is found +# * Imath_LIBRARY | Imath_LIBRARIES : The (list of) Imath libraries +# * Imath_INCLUDE_DIR | Imath_INCLUDE_DIRS : The location(s) that include the Imath headers + +if(NOT DEFINED Imath_USE_DEBUG_BUILD) + if(CMAKE_BUILD_TYPE MATCHES "(Debug|DEBUG|debug|RelWithDebInfo|RELWITHDEBINFO|relwithdebinfo)") + set(Imath_USE_DEBUG_BUILD TRUE) + else() + set(Imath_USE_DEBUG_BUILD FALSE) + endif() +endif() + +find_path(Imath_INCLUDE_DIR + Imath/half.h + HINTS + "${Imath_LOCATION}" + "$ENV{IMATH_LOCATION}" + "${Imath_ROOT}" + PATH_SUFFIXES + include/ + DOC + "Imath headers path" + ) +list(APPEND Imath_INCLUDE_DIRS ${Imath_INCLUDE_DIR}) +list(APPEND Imath_INCLUDE_DIRS ${Imath_INCLUDE_DIR}/Imath) + +if(Imath_USE_DEBUG_BUILD) + find_library(Imath_LIBRARY + NAMES + Imath-${Imath_MAJOR_VERSION}_${Imath_MINOR_VERSION}_d + Imath_d + HINTS + "${Imath_LOCATION}" + "$ENV{Imath_LOCATION}" + "${Imath_ROOT}" + PATH_SUFFIXES + lib/ + DOC + "Imath library path" + ) + if(Imath_LIBRARY) + SET(Imath_FOUND TRUE) + list(APPEND Imath_LIBRARIES ${Imath_LIBRARY}) + else() + SET(Imath_FOUND FALSE) + MESSAGE(WARNING "Could not find Debug Imath library") + endif() +endif() + +if (NOT Imath_FOUND) + find_library(Imath_LIBRARY + NAMES + Imath-${Imath_MAJOR_VERSION}_${Imath_MINOR_VERSION} + Imath + HINTS + "${Imath_LOCATION}" + "$ENV{Imath_LOCATION}" + "${Imath_ROOT}" + PATH_SUFFIXES + lib/ + DOC + "Imath library path" + ) + if(Imath_LIBRARY) + SET(Imath_FOUND TRUE) + list(APPEND Imath_LIBRARIES ${Imath_LIBRARY}) + else() + SET(Imath_FOUND FALSE) + endif() +endif() + diff --git a/pxr/imaging/hioOpenVDB/CMakeLists.txt b/pxr/imaging/hioOpenVDB/CMakeLists.txt index 2a2dfd5e72..fb9b47183a 100644 --- a/pxr/imaging/hioOpenVDB/CMakeLists.txt +++ b/pxr/imaging/hioOpenVDB/CMakeLists.txt @@ -13,6 +13,12 @@ if (WIN32) add_definitions(-D_USE_MATH_DEFINES) endif() +if (Imath_FOUND) + LIST(APPEND __VDB_IMATH_LIBS ${Imath_LIBRARY}) +else() + LIST(APPEND __VDB_IMATH_LIBS ${OPENEXR_Half_LIBRARY}) +endif() + pxr_library(hioOpenVDB LIBRARIES ar @@ -20,7 +26,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..5a2fca69d1 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() +if (Imath_FOUND) + set(__OIIO_IMATH_INCLUDE ${Imath_INCLUDE_DIRS}) + set(__OIIO_IMATH_LIBS ${Imath_LIBRARIES}) +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/usd/plugin/usdAbc/CMakeLists.txt b/pxr/usd/plugin/usdAbc/CMakeLists.txt index fb169cf2e8..fbdaa8f361 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() +if (Imath_FOUND) + set(__ALEMBIC_IMATH_INCLUDES ${Imath_INCLUDE_DIRS}) + set(__ALEMBIC_IMATH_LIBS ${Imath_LIBRARIES}) +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