From e27d004d84da1a6ae5214e416bf3a6f1e6552361 Mon Sep 17 00:00:00 2001 From: Dhruv Govil Date: Wed, 6 Apr 2022 15:55:40 -0700 Subject: [PATCH 1/3] Update USD CMake to work with imath 3 where possible, while falling back to the old behaviour when not --- cmake/modules/FindOpenEXR.cmake | 29 +++++++++++++++++++++++ pxr/imaging/hioOpenVDB/CMakeLists.txt | 8 ++++++- pxr/imaging/plugin/hioOiio/CMakeLists.txt | 12 ++++++++-- pxr/usd/plugin/usdAbc/CMakeLists.txt | 19 +++++++++++---- 4 files changed, 60 insertions(+), 8 deletions(-) diff --git a/cmake/modules/FindOpenEXR.cmake b/cmake/modules/FindOpenEXR.cmake index 639a01cf1f..2560331cd6 100644 --- a/cmake/modules/FindOpenEXR.cmake +++ b/cmake/modules/FindOpenEXR.cmake @@ -33,6 +33,18 @@ DOC "OpenEXR headers path" ) +find_path(IMATH_INCLUDE_DIR + Imath/half.h +HINTS + "${IMATH_LOCATION}" + "$ENV{IMATH_LOCATION}" + "${Imath_ROOT}" +PATH_SUFFIXES + include/ +DOC + "Imath headers path" +) + if(OPENEXR_INCLUDE_DIR) set(openexr_config_file "${OPENEXR_INCLUDE_DIR}/OpenEXR/OpenEXRConfig.h") if(EXISTS ${openexr_config_file}) @@ -86,9 +98,26 @@ foreach(OPENEXR_LIB endif() endforeach(OPENEXR_LIB) +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" +) +list(APPEND IMATH_LIBRARIES ${IMATH_LIBRARY}) + # So #include works list(APPEND OPENEXR_INCLUDE_DIRS ${OPENEXR_INCLUDE_DIR}) list(APPEND OPENEXR_INCLUDE_DIRS ${OPENEXR_INCLUDE_DIR}/OpenEXR) +list(APPEND IMATH_INCLUDE_DIRS ${IMATH_INCLUDE_DIR}) +list(APPEND IMATH_INCLUDE_DIRS ${IMATH_INCLUDE_DIR}/Imath) include(FindPackageHandleStandardArgs) find_package_handle_standard_args(OpenEXR diff --git a/pxr/imaging/hioOpenVDB/CMakeLists.txt b/pxr/imaging/hioOpenVDB/CMakeLists.txt index 2a2dfd5e72..6cb69f9c8f 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_LIBRARY) + 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..5b8a3a4e3a 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_LIBRARY) + set(__OIIO_IMATH_INCLUDE ${IMATH_INCLUDE_DIR}) + 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..2a41035ae7 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_LIBRARY) + 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 From 8431e4cd89ccde1a02813969d0cc0806db161e07 Mon Sep 17 00:00:00 2001 From: Dhruv Govil Date: Mon, 22 Aug 2022 17:05:46 -0700 Subject: [PATCH 2/3] Update to use separate FindImath.cmake file, and make names consistent casing --- cmake/defaults/Packages.cmake | 19 ++++++-- cmake/modules/FindImath.cmake | 56 +++++++++++++++++++++++ cmake/modules/FindOpenEXR.cmake | 29 ------------ pxr/imaging/hioOpenVDB/CMakeLists.txt | 4 +- pxr/imaging/plugin/hioOiio/CMakeLists.txt | 6 +-- pxr/usd/plugin/usdAbc/CMakeLists.txt | 6 +-- 6 files changed, 78 insertions(+), 42 deletions(-) create mode 100644 cmake/modules/FindImath.cmake 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..a7e2c07e5b --- /dev/null +++ b/cmake/modules/FindImath.cmake @@ -0,0 +1,56 @@ +# +# 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. +# + +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) + +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}) +endif() + diff --git a/cmake/modules/FindOpenEXR.cmake b/cmake/modules/FindOpenEXR.cmake index 2560331cd6..639a01cf1f 100644 --- a/cmake/modules/FindOpenEXR.cmake +++ b/cmake/modules/FindOpenEXR.cmake @@ -33,18 +33,6 @@ DOC "OpenEXR headers path" ) -find_path(IMATH_INCLUDE_DIR - Imath/half.h -HINTS - "${IMATH_LOCATION}" - "$ENV{IMATH_LOCATION}" - "${Imath_ROOT}" -PATH_SUFFIXES - include/ -DOC - "Imath headers path" -) - if(OPENEXR_INCLUDE_DIR) set(openexr_config_file "${OPENEXR_INCLUDE_DIR}/OpenEXR/OpenEXRConfig.h") if(EXISTS ${openexr_config_file}) @@ -98,26 +86,9 @@ foreach(OPENEXR_LIB endif() endforeach(OPENEXR_LIB) -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" -) -list(APPEND IMATH_LIBRARIES ${IMATH_LIBRARY}) - # So #include works list(APPEND OPENEXR_INCLUDE_DIRS ${OPENEXR_INCLUDE_DIR}) list(APPEND OPENEXR_INCLUDE_DIRS ${OPENEXR_INCLUDE_DIR}/OpenEXR) -list(APPEND IMATH_INCLUDE_DIRS ${IMATH_INCLUDE_DIR}) -list(APPEND IMATH_INCLUDE_DIRS ${IMATH_INCLUDE_DIR}/Imath) include(FindPackageHandleStandardArgs) find_package_handle_standard_args(OpenEXR diff --git a/pxr/imaging/hioOpenVDB/CMakeLists.txt b/pxr/imaging/hioOpenVDB/CMakeLists.txt index 6cb69f9c8f..fb9b47183a 100644 --- a/pxr/imaging/hioOpenVDB/CMakeLists.txt +++ b/pxr/imaging/hioOpenVDB/CMakeLists.txt @@ -13,8 +13,8 @@ if (WIN32) add_definitions(-D_USE_MATH_DEFINES) endif() -if (IMATH_LIBRARY) - LIST(APPEND __VDB_IMATH_LIBS ${IMATH_LIBRARY}) +if (Imath_FOUND) + LIST(APPEND __VDB_IMATH_LIBS ${Imath_LIBRARY}) else() LIST(APPEND __VDB_IMATH_LIBS ${OPENEXR_Half_LIBRARY}) endif() diff --git a/pxr/imaging/plugin/hioOiio/CMakeLists.txt b/pxr/imaging/plugin/hioOiio/CMakeLists.txt index 5b8a3a4e3a..5a2fca69d1 100644 --- a/pxr/imaging/plugin/hioOiio/CMakeLists.txt +++ b/pxr/imaging/plugin/hioOiio/CMakeLists.txt @@ -7,9 +7,9 @@ if (NOT ${PXR_BUILD_GPU_SUPPORT}) return() endif() -if (IMATH_LIBRARY) - set(__OIIO_IMATH_INCLUDE ${IMATH_INCLUDE_DIR}) - set(__OIIO_IMATH_LIBS ${IMATH_LIBRARIES}) +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}) diff --git a/pxr/usd/plugin/usdAbc/CMakeLists.txt b/pxr/usd/plugin/usdAbc/CMakeLists.txt index 2a41035ae7..fbdaa8f361 100644 --- a/pxr/usd/plugin/usdAbc/CMakeLists.txt +++ b/pxr/usd/plugin/usdAbc/CMakeLists.txt @@ -15,9 +15,9 @@ if (PXR_ENABLE_HDF5_SUPPORT) list(APPEND optionalIncludeDirs ${HDF5_INCLUDE_DIRS}) endif() -if (IMATH_LIBRARY) - set(__ALEMBIC_IMATH_INCLUDES ${IMATH_INCLUDE_DIRS}) - set(__ALEMBIC_IMATH_LIBS ${IMATH_LIBRARIES}) +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}) From 4b010de3b2684be1f188e37c6b7ba604ef62136e Mon Sep 17 00:00:00 2001 From: Dhruv Govil Date: Mon, 22 Aug 2022 17:53:39 -0700 Subject: [PATCH 3/3] Support looking for iMath debug files --- cmake/modules/FindImath.cmake | 83 ++++++++++++++++++++++++++++------- 1 file changed, 67 insertions(+), 16 deletions(-) diff --git a/cmake/modules/FindImath.cmake b/cmake/modules/FindImath.cmake index a7e2c07e5b..032370d9fa 100644 --- a/cmake/modules/FindImath.cmake +++ b/cmake/modules/FindImath.cmake @@ -22,6 +22,30 @@ # 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 @@ -36,21 +60,48 @@ find_path(Imath_INCLUDE_DIR list(APPEND Imath_INCLUDE_DIRS ${Imath_INCLUDE_DIR}) list(APPEND Imath_INCLUDE_DIRS ${Imath_INCLUDE_DIR}/Imath) -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}) +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()