From d5229399c01d957cc08e41e0e8e6832ff369349b Mon Sep 17 00:00:00 2001 From: Pierre Wendling Date: Thu, 17 Aug 2023 14:56:00 -0400 Subject: [PATCH 1/3] Use `TARGET` for the config if-statements. The check would always evaluate to true otherwise. Signed-off-by: Pierre Wendling --- src/cmake/Config.cmake.in | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/cmake/Config.cmake.in b/src/cmake/Config.cmake.in index a3b03cc83d..2b30a2ef83 100644 --- a/src/cmake/Config.cmake.in +++ b/src/cmake/Config.cmake.in @@ -34,23 +34,23 @@ if (NOT @BUILD_SHARED_LIBS@) # NOT @BUILD_SHARED_LIBS@ # 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) 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 +62,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() From 63731613dbe0988b24f25979f65f75a7fbd103b0 Mon Sep 17 00:00:00 2001 From: Pierre Wendling Date: Thu, 17 Aug 2023 15:00:54 -0400 Subject: [PATCH 2/3] Use PACKAGE_PREFIX_DIR from PACKAGE_INIT. This avoids guessing the path to the prefix. Signed-off-by: Pierre Wendling --- src/cmake/Config.cmake.in | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/src/cmake/Config.cmake.in b/src/cmake/Config.cmake.in index 2b30a2ef83..211b693328 100644 --- a/src/cmake/Config.cmake.in +++ b/src/cmake/Config.cmake.in @@ -14,21 +14,9 @@ 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 From fc6b4ab141dfcbd74f1d72a8d1cd8f82e4a1415a Mon Sep 17 00:00:00 2001 From: Pierre Wendling Date: Thu, 17 Aug 2023 15:06:22 -0400 Subject: [PATCH 3/3] Add compatibility with yaml-cpp 0.8.0 target. The target was renamed to `yaml-cpp::yaml-cpp`, which breaks when using the upstream CMake package over the Find module. Signed-off-by: Pierre Wendling --- share/cmake/modules/Findyaml-cpp.cmake | 20 ++++++++++++++++++- .../modules/install/Installyaml-cpp.cmake | 18 +++++++++++++++++ src/OpenColorIO/CMakeLists.txt | 2 +- src/cmake/Config.cmake.in | 2 +- tests/cpu/CMakeLists.txt | 2 +- 5 files changed, 40 insertions(+), 4 deletions(-) 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 08252e860b..605324cea6 100755 --- a/src/OpenColorIO/CMakeLists.txt +++ b/src/OpenColorIO/CMakeLists.txt @@ -289,7 +289,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 211b693328..c122b013c7 100644 --- a/src/cmake/Config.cmake.in +++ b/src/cmake/Config.cmake.in @@ -34,7 +34,7 @@ if (NOT @BUILD_SHARED_LIBS@) # NOT @BUILD_SHARED_LIBS@ find_dependency(pystring @pystring_VERSION@) endif() - if (NOT TARGET yaml-cpp) + if (NOT TARGET yaml-cpp AND NOT TARGET yaml-cpp::yaml-cpp) find_dependency(yaml-cpp @yaml-cpp_VERSION@) endif() diff --git a/tests/cpu/CMakeLists.txt b/tests/cpu/CMakeLists.txt index 170d0974b6..8f68fb0f0d 100755 --- a/tests/cpu/CMakeLists.txt +++ b/tests/cpu/CMakeLists.txt @@ -20,7 +20,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