Skip to content

Commit 8854e13

Browse files
FtZPetruskaremiadoug-walker
authored
CMake: Fixes for yaml-cpp and generated config (#1823)
* Use `TARGET` for the config if-statements. The check would always evaluate to true otherwise. Signed-off-by: Pierre Wendling <pierre.wendling.4@gmail.com> * Use PACKAGE_PREFIX_DIR from PACKAGE_INIT. This avoids guessing the path to the prefix. Signed-off-by: Pierre Wendling <pierre.wendling.4@gmail.com> * 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 <pierre.wendling.4@gmail.com> --------- Signed-off-by: Pierre Wendling <pierre.wendling.4@gmail.com> Co-authored-by: Rémi Achard <remiachard@gmail.com> Co-authored-by: Doug Walker <doug.walker@autodesk.com>
1 parent f9de269 commit 8854e13

5 files changed

Lines changed: 47 additions & 23 deletions

File tree

share/cmake/modules/Findyaml-cpp.cmake

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212
# Global targets defined by this module:
1313
# yaml-cpp
1414
#
15+
# For compatibility with the upstream CMake package, the following variables and targets are defined:
16+
# yaml-cpp::yaml-cpp - Alias of the yaml-cpp target
17+
# YAML_CPP_LIBRARIES - Libraries to link against yaml-cpp
18+
# YAML_CPP_INCLUDE_DIR - Include directory
19+
#
1520
# Usually CMake will use the dynamic library rather than static, if both are present.
1621
# In this case, you may set yaml-cpp_STATIC_LIBRARY to ON to request use of the static one.
1722
# 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)
147152
)
148153

149154
mark_as_advanced(yaml-cpp_INCLUDE_DIR yaml-cpp_LIBRARY yaml-cpp_VERSION)
150-
endif()
155+
endif()
156+
157+
###############################################################################
158+
### Set variables for compatibility ###
159+
160+
if(TARGET yaml-cpp AND NOT TARGET yaml-cpp::yaml-cpp)
161+
add_library(yaml-cpp::yaml-cpp ALIAS yaml-cpp)
162+
endif()
163+
164+
if(yaml-cpp_INCLUDE_DIR)
165+
set(YAML_CPP_INCLUDE_DIR "${yaml-cpp_INCLUDE_DIR}")
166+
endif()
167+
168+
set(YAML_CPP_LIBRARIES yaml-cpp::yaml-cpp)

share/cmake/modules/install/Installyaml-cpp.cmake

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212
# Global targets defined by this module:
1313
# yaml-cpp::yaml-cpp
1414
#
15+
# For compatibility with the upstream CMake package, the following variables and targets are defined:
16+
# yaml-cpp::yaml-cpp - Alias of the yaml-cpp target
17+
# YAML_CPP_LIBRARIES - Libraries to link against yaml-cpp
18+
# YAML_CPP_INCLUDE_DIR - Include directory
19+
#
1520

1621
###############################################################################
1722
### Create target (if previous 'find_package' call hasn't) ###
@@ -151,3 +156,16 @@ if(_yaml-cpp_TARGET_CREATE)
151156

152157
mark_as_advanced(yaml-cpp_INCLUDE_DIR yaml-cpp_LIBRARY yaml-cpp_VERSION)
153158
endif()
159+
160+
###############################################################################
161+
### Set variables for compatibility ###
162+
163+
if(TARGET yaml-cpp AND NOT TARGET yaml-cpp::yaml-cpp)
164+
add_library(yaml-cpp::yaml-cpp ALIAS yaml-cpp)
165+
endif()
166+
167+
if(yaml-cpp_INCLUDE_DIR)
168+
set(YAML_CPP_INCLUDE_DIR "${yaml-cpp_INCLUDE_DIR}")
169+
endif()
170+
171+
set(YAML_CPP_LIBRARIES yaml-cpp::yaml-cpp)

src/OpenColorIO/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ target_link_libraries(OpenColorIO
307307
"$<BUILD_INTERFACE:utils::from_chars>"
308308
"$<BUILD_INTERFACE:utils::strings>"
309309
"$<BUILD_INTERFACE:xxHash>"
310-
yaml-cpp
310+
${YAML_CPP_LIBRARIES}
311311
MINIZIP::minizip-ng
312312
)
313313

src/cmake/Config.cmake.in

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,43 +14,31 @@ if (NOT @BUILD_SHARED_LIBS@) # NOT @BUILD_SHARED_LIBS@
1414
set(CMAKE_FIND_APPBUNDLE LAST)
1515
endif()
1616

17-
# Get the install directory.
18-
set(_IMPORT_PREFIX "${CMAKE_CURRENT_LIST_DIR}")
19-
# Get the install directory. Since the current file is under
20-
# <install directory>/lib/cmake/OpenColorIO going back three directory.
21-
foreach(i RANGE 1 3)
22-
get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH)
23-
if(_IMPORT_PREFIX STREQUAL "/")
24-
set(_IMPORT_PREFIX "")
25-
break()
26-
endif()
27-
endforeach()
28-
2917
# Append OCIO custom find module path.
30-
list(APPEND CMAKE_MODULE_PATH "${_IMPORT_PREFIX}/share/OpenColorIO/cmake/modules")
31-
list(APPEND CMAKE_MODULE_PATH "${_IMPORT_PREFIX}/share/OpenColorIO/cmake/macros")
18+
list(APPEND CMAKE_MODULE_PATH "${PACKAGE_PREFIX_DIR}/share/OpenColorIO/cmake/modules")
19+
list(APPEND CMAKE_MODULE_PATH "${PACKAGE_PREFIX_DIR}/share/OpenColorIO/cmake/macros")
3220

3321
########################
3422
# Required dependencies
3523
########################
3624

37-
if (NOT expat::expat)
25+
if (NOT TARGET expat::expat)
3826
find_dependency(expat @expat_VERSION@)
3927
endif()
4028

41-
if (NOT Imath::Imath)
29+
if (NOT TARGET Imath::Imath)
4230
find_dependency(Imath @Imath_VERSION@)
4331
endif()
4432

45-
if (NOT pystring::pystring)
33+
if (NOT TARGET pystring::pystring)
4634
find_dependency(pystring @pystring_VERSION@)
4735
endif()
4836

49-
if (NOT yaml-cpp)
37+
if (NOT TARGET yaml-cpp AND NOT TARGET yaml-cpp::yaml-cpp)
5038
find_dependency(yaml-cpp @yaml-cpp_VERSION@)
5139
endif()
5240

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

65-
if (NOT MINIZIP::minizip-ng)
53+
if (NOT TARGET MINIZIP::minizip-ng)
6654
find_dependency(minizip-ng @minizip-ng_VERSION@)
6755
endif()
6856

tests/cpu/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ function(add_ocio_test NAME SOURCES PRIVATE_INCLUDES)
3535
sampleicc::sampleicc
3636
unittest_data
3737
utils::strings
38-
yaml-cpp
38+
${YAML_CPP_LIBRARIES}
3939
testutils
4040
MINIZIP::minizip-ng
4141
xxHash

0 commit comments

Comments
 (0)