diff --git a/share/cmake/modules/Findyaml-cpp.cmake b/share/cmake/modules/Findyaml-cpp.cmake index 55e25e2c84..5a850f9601 100644 --- a/share/cmake/modules/Findyaml-cpp.cmake +++ b/share/cmake/modules/Findyaml-cpp.cmake @@ -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 @@ -147,4 +152,17 @@ if(_yaml-cpp_TARGET_CREATE) ) mark_as_advanced(yaml-cpp_INCLUDE_DIR yaml-cpp_LIBRARY yaml-cpp_VERSION) -endif() \ No newline at end of file +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) diff --git a/share/cmake/modules/install/Installyaml-cpp.cmake b/share/cmake/modules/install/Installyaml-cpp.cmake index 2d9b14aafa..a117fdcff0 100644 --- a/share/cmake/modules/install/Installyaml-cpp.cmake +++ b/share/cmake/modules/install/Installyaml-cpp.cmake @@ -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) ### @@ -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) diff --git a/src/OpenColorIO/CMakeLists.txt b/src/OpenColorIO/CMakeLists.txt index 842202316c..d41fcc5d32 100755 --- a/src/OpenColorIO/CMakeLists.txt +++ b/src/OpenColorIO/CMakeLists.txt @@ -307,7 +307,7 @@ target_link_libraries(OpenColorIO "$" "$" "$" - yaml-cpp + ${YAML_CPP_LIBRARIES} MINIZIP::minizip-ng ) diff --git a/src/cmake/Config.cmake.in b/src/cmake/Config.cmake.in index a3b03cc83d..c122b013c7 100644 --- a/src/cmake/Config.cmake.in +++ b/src/cmake/Config.cmake.in @@ -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 - # /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 @@ -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() diff --git a/tests/cpu/CMakeLists.txt b/tests/cpu/CMakeLists.txt index 9b59b12383..91cbf5a994 100755 --- a/tests/cpu/CMakeLists.txt +++ b/tests/cpu/CMakeLists.txt @@ -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