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

CMake: Fixes for yaml-cpp and generated config #1823

Merged
Merged
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
20 changes: 19 additions & 1 deletion share/cmake/modules/Findyaml-cpp.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
# Global targets defined by this module:
# yaml-cpp
#
# For compatibility with the upstream CMake package, the following variables and targets are defined:
# yaml-cpp::yaml-cpp - Alias of the yaml-cpp target
# YAML_CPP_LIBRARIES - Libraries to link against yaml-cpp
# YAML_CPP_INCLUDE_DIR - Include directory
#
# Usually CMake will use the dynamic library rather than static, if both are present.
# In this case, you may set yaml-cpp_STATIC_LIBRARY to ON to request use of the static one.
# If only the static library is present (such as when OCIO builds the dependency), then the option
Expand Down Expand Up @@ -147,4 +152,17 @@ if(_yaml-cpp_TARGET_CREATE)
)

mark_as_advanced(yaml-cpp_INCLUDE_DIR yaml-cpp_LIBRARY yaml-cpp_VERSION)
endif()
endif()

###############################################################################
### Set variables for compatibility ###

if(TARGET yaml-cpp AND NOT TARGET yaml-cpp::yaml-cpp)
add_library(yaml-cpp::yaml-cpp ALIAS yaml-cpp)
endif()

if(yaml-cpp_INCLUDE_DIR)
set(YAML_CPP_INCLUDE_DIR "${yaml-cpp_INCLUDE_DIR}")
endif()

set(YAML_CPP_LIBRARIES yaml-cpp::yaml-cpp)
18 changes: 18 additions & 0 deletions share/cmake/modules/install/Installyaml-cpp.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
# Global targets defined by this module:
# yaml-cpp::yaml-cpp
#
# For compatibility with the upstream CMake package, the following variables and targets are defined:
# yaml-cpp::yaml-cpp - Alias of the yaml-cpp target
# YAML_CPP_LIBRARIES - Libraries to link against yaml-cpp
# YAML_CPP_INCLUDE_DIR - Include directory
#

###############################################################################
### Create target (if previous 'find_package' call hasn't) ###
Expand Down Expand Up @@ -151,3 +156,16 @@ if(_yaml-cpp_TARGET_CREATE)

mark_as_advanced(yaml-cpp_INCLUDE_DIR yaml-cpp_LIBRARY yaml-cpp_VERSION)
endif()

###############################################################################
### Set variables for compatibility ###

if(TARGET yaml-cpp AND NOT TARGET yaml-cpp::yaml-cpp)
add_library(yaml-cpp::yaml-cpp ALIAS yaml-cpp)
endif()

if(yaml-cpp_INCLUDE_DIR)
set(YAML_CPP_INCLUDE_DIR "${yaml-cpp_INCLUDE_DIR}")
endif()

set(YAML_CPP_LIBRARIES yaml-cpp::yaml-cpp)
2 changes: 1 addition & 1 deletion src/OpenColorIO/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ target_link_libraries(OpenColorIO
"$<BUILD_INTERFACE:utils::from_chars>"
"$<BUILD_INTERFACE:utils::strings>"
"$<BUILD_INTERFACE:xxHash>"
yaml-cpp
${YAML_CPP_LIBRARIES}
MINIZIP::minizip-ng
)

Expand Down
28 changes: 8 additions & 20 deletions src/cmake/Config.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -14,43 +14,31 @@ if (NOT @BUILD_SHARED_LIBS@) # NOT @BUILD_SHARED_LIBS@
set(CMAKE_FIND_APPBUNDLE LAST)
endif()

# Get the install directory.
set(_IMPORT_PREFIX "${CMAKE_CURRENT_LIST_DIR}")
# Get the install directory. Since the current file is under
# <install directory>/lib/cmake/OpenColorIO going back three directory.
foreach(i RANGE 1 3)
get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH)
if(_IMPORT_PREFIX STREQUAL "/")
set(_IMPORT_PREFIX "")
break()
endif()
endforeach()

# Append OCIO custom find module path.
list(APPEND CMAKE_MODULE_PATH "${_IMPORT_PREFIX}/share/OpenColorIO/cmake/modules")
list(APPEND CMAKE_MODULE_PATH "${_IMPORT_PREFIX}/share/OpenColorIO/cmake/macros")
list(APPEND CMAKE_MODULE_PATH "${PACKAGE_PREFIX_DIR}/share/OpenColorIO/cmake/modules")
list(APPEND CMAKE_MODULE_PATH "${PACKAGE_PREFIX_DIR}/share/OpenColorIO/cmake/macros")

########################
# Required dependencies
########################

if (NOT expat::expat)
if (NOT TARGET expat::expat)
find_dependency(expat @expat_VERSION@)
endif()

if (NOT Imath::Imath)
if (NOT TARGET Imath::Imath)
find_dependency(Imath @Imath_VERSION@)
endif()

if (NOT pystring::pystring)
if (NOT TARGET pystring::pystring)
find_dependency(pystring @pystring_VERSION@)
endif()

if (NOT yaml-cpp)
if (NOT TARGET yaml-cpp AND NOT TARGET yaml-cpp::yaml-cpp)
find_dependency(yaml-cpp @yaml-cpp_VERSION@)
endif()

if (NOT ZLIB::ZLIB)
if (NOT TARGET ZLIB::ZLIB)
# ZLIB_VERSION is available starting CMake 3.26+.
# ZLIB_VERSION_STRING is still available for backward compatibility.
# See https://cmake.org/cmake/help/git-stage/module/FindZLIB.html
Expand All @@ -62,7 +50,7 @@ if (NOT @BUILD_SHARED_LIBS@) # NOT @BUILD_SHARED_LIBS@
endif()
endif()

if (NOT MINIZIP::minizip-ng)
if (NOT TARGET MINIZIP::minizip-ng)
find_dependency(minizip-ng @minizip-ng_VERSION@)
endif()

Expand Down
2 changes: 1 addition & 1 deletion tests/cpu/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function(add_ocio_test NAME SOURCES PRIVATE_INCLUDES)
sampleicc::sampleicc
unittest_data
utils::strings
yaml-cpp
${YAML_CPP_LIBRARIES}
testutils
MINIZIP::minizip-ng
xxHash
Expand Down