Skip to content

Instantly share code, notes, and snippets.

@remia
Created October 29, 2023 12:12
Show Gist options
  • Save remia/667de7a84aad7f81f39cebc46d69974a to your computer and use it in GitHub Desktop.
Save remia/667de7a84aad7f81f39cebc46d69974a to your computer and use it in GitHub Desktop.
OCIO yaml-cpp target handling
From 2eaaf6a8e8c715706c51391276c04f966cb9f737 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?R=C3=A9mi=20Achard?= <remiachard@gmail.com>
Date: Sun, 29 Oct 2023 12:08:02 +0000
Subject: [PATCH 1/1] Handle yaml-cpp target name update
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: Rémi Achard <remiachard@gmail.com>
---
share/cmake/modules/Findyaml-cpp.cmake | 27 +++++++++----------
.../modules/install/Installyaml-cpp.cmake | 19 +++++--------
src/OpenColorIO/CMakeLists.txt | 2 +-
tests/cpu/CMakeLists.txt | 2 +-
4 files changed, 21 insertions(+), 29 deletions(-)
diff --git a/share/cmake/modules/Findyaml-cpp.cmake b/share/cmake/modules/Findyaml-cpp.cmake
index 5a850f96..3f35e74a 100644
--- a/share/cmake/modules/Findyaml-cpp.cmake
+++ b/share/cmake/modules/Findyaml-cpp.cmake
@@ -10,7 +10,7 @@
# yaml-cpp_VERSION - Library's version
#
# Global targets defined by this module:
-# yaml-cpp
+# 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
@@ -50,7 +50,13 @@ if(NOT OCIO_INSTALL_EXT_PACKAGES STREQUAL ALL)
endif()
if(yaml-cpp_FOUND)
- get_target_property(yaml-cpp_LIBRARY yaml-cpp LOCATION)
+ # yaml-cpp < 0.8 creates a yaml-cpp target
+ if(TARGET yaml-cpp)
+ message(STATUS "yaml-cpp ${yaml-cpp_VERSION} detected, aliasing targets.")
+ add_library(yaml-cpp::yaml-cpp ALIAS yaml-cpp)
+ endif()
+
+ get_target_property(yaml-cpp_LIBRARY yaml-cpp::yaml-cpp LOCATION)
else()
# As yaml-cpp-config.cmake search fails, search an installed library
@@ -137,8 +143,8 @@ endif()
###############################################################################
### Create target
-if(yaml-cpp_FOUND AND NOT TARGET yaml-cpp)
- add_library(yaml-cpp UNKNOWN IMPORTED GLOBAL)
+if(yaml-cpp_FOUND AND NOT TARGET yaml-cpp::yaml-cpp)
+ add_library(yaml-cpp::yaml-cpp UNKNOWN IMPORTED GLOBAL)
set(_yaml-cpp_TARGET_CREATE TRUE)
endif()
@@ -146,7 +152,7 @@ endif()
### Configure target ###
if(_yaml-cpp_TARGET_CREATE)
- set_target_properties(yaml-cpp PROPERTIES
+ set_target_properties(yaml-cpp::yaml-cpp PROPERTIES
IMPORTED_LOCATION ${yaml-cpp_LIBRARY}
INTERFACE_INCLUDE_DIRECTORIES ${yaml-cpp_INCLUDE_DIR}
)
@@ -157,12 +163,5 @@ 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)
+get_target_property(YAML_CPP_INCLUDE_DIR yaml-cpp::yaml-cpp INCLUDE_DIRECTORIES)
+get_target_property(YAML_CPP_LIBRARIES yaml-cpp::yaml-cpp LOCATION)
diff --git a/share/cmake/modules/install/Installyaml-cpp.cmake b/share/cmake/modules/install/Installyaml-cpp.cmake
index a117fdcf..8528d43f 100644
--- a/share/cmake/modules/install/Installyaml-cpp.cmake
+++ b/share/cmake/modules/install/Installyaml-cpp.cmake
@@ -21,8 +21,8 @@
###############################################################################
### Create target (if previous 'find_package' call hasn't) ###
-if(NOT TARGET yaml-cpp)
- add_library(yaml-cpp UNKNOWN IMPORTED GLOBAL)
+if(NOT TARGET yaml-cpp::yaml-cpp)
+ add_library(yaml-cpp::yaml-cpp UNKNOWN IMPORTED GLOBAL)
set(_yaml-cpp_TARGET_CREATE TRUE)
endif()
@@ -138,7 +138,7 @@ if(NOT yaml-cpp_FOUND AND OCIO_INSTALL_EXT_PACKAGES AND NOT OCIO_INSTALL_EXT_PAC
--parallel
)
- add_dependencies(yaml-cpp yaml-cpp_install)
+ add_dependencies(yaml-cpp::yaml-cpp yaml-cpp_install)
if(OCIO_VERBOSE)
message(STATUS "Installing yaml-cpp: ${yaml-cpp_LIBRARY} (version \"${yaml-cpp_VERSION}\")")
endif()
@@ -149,7 +149,7 @@ endif()
### Configure target ###
if(_yaml-cpp_TARGET_CREATE)
- set_target_properties(yaml-cpp PROPERTIES
+ set_target_properties(yaml-cpp::yaml-cpp PROPERTIES
IMPORTED_LOCATION ${yaml-cpp_LIBRARY}
INTERFACE_INCLUDE_DIRECTORIES ${yaml-cpp_INCLUDE_DIR}
)
@@ -160,12 +160,5 @@ 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)
+get_target_property(YAML_CPP_INCLUDE_DIR yaml-cpp::yaml-cpp INCLUDE_DIRECTORIES)
+get_target_property(YAML_CPP_LIBRARIES yaml-cpp::yaml-cpp LOCATION)
diff --git a/src/OpenColorIO/CMakeLists.txt b/src/OpenColorIO/CMakeLists.txt
index 7ff40bfd..77a92005 100755
--- a/src/OpenColorIO/CMakeLists.txt
+++ b/src/OpenColorIO/CMakeLists.txt
@@ -309,7 +309,7 @@ target_link_libraries(OpenColorIO
"$<BUILD_INTERFACE:utils::from_chars>"
"$<BUILD_INTERFACE:utils::strings>"
"$<BUILD_INTERFACE:xxHash>"
- ${YAML_CPP_LIBRARIES}
+ yaml-cpp::yaml-cpp
MINIZIP::minizip-ng
)
diff --git a/tests/cpu/CMakeLists.txt b/tests/cpu/CMakeLists.txt
index 896bb3f9..ba1498f4 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_LIBRARIES}
+ yaml-cpp::yaml-cpp
testutils
MINIZIP::minizip-ng
xxHash
--
2.42.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment