Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support compiling against imath #1829

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 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,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}")
107 changes: 107 additions & 0 deletions cmake/modules/FindImath.cmake
Original file line number Diff line number Diff line change
@@ -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()

8 changes: 7 additions & 1 deletion pxr/imaging/hioOpenVDB/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,20 @@ 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
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()

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
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
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()

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
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