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

Add OpenColorIOConfig.cmake generation #1397

Merged
Merged
Changes from 1 commit
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
Next Next commit
Initial OpenColorIO Config CMake implementation
Signed-off-by: Rémi Achard <remiachard@gmail.com>
  • Loading branch information
remia committed May 4, 2021

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit b173d4e0c6656026b9ad0c9dce769fc12ef65a68
45 changes: 45 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -239,6 +239,14 @@ endif()
include(FindExtPackages)


###############################################################################
# Target definition utilities
# This includes the install_targets macro, to make target available for
# import by external projects.

include(TargetUtils)


###############################################################################
# Progress to other sources

@@ -265,3 +273,40 @@ configure_file(${CMAKE_SOURCE_DIR}/share/ocio/${OCIO_SETUP_NAME}.in
${CMAKE_CURRENT_BINARY_DIR}/share/ocio/${OCIO_SETUP_NAME} @ONLY)

INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/share/ocio/${OCIO_SETUP_NAME} DESTINATION share/ocio/)


###############################################################################
# Generate OpenColorIO-config.cmake

include(CMakePackageConfigHelpers)

set(OCIO_TARGETS_EXPORT_NAME "${PROJECT_NAME}Targets.cmake")
set(OCIO_VERSION_CONFIG "${CMAKE_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake")
set(OCIO_PROJECT_CONFIG "${CMAKE_BINARY_DIR}/${PROJECT_NAME}Config.cmake")
set(OCIO_CONFIG_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}")

# Version fetched from the top level project()
write_basic_package_version_file(
${OCIO_VERSION_CONFIG}
# Version range supported only if generated by CMake 3.19.2 or newer.
COMPATIBILITY SameMajorVersion
)

configure_package_config_file(
${CMAKE_CURRENT_LIST_DIR}/src/cmake/Config.cmake.in ${OCIO_PROJECT_CONFIG}
INSTALL_DESTINATION ${OCIO_CONFIG_INSTALL_DIR}
NO_SET_AND_CHECK_MACRO
NO_CHECK_REQUIRED_COMPONENTS_MACRO
)

install(
EXPORT ${PROJECT_NAME}_EXPORTED_TARGETS
DESTINATION ${OCIO_CONFIG_INSTALL_DIR}
NAMESPACE ${PROJECT_NAME}::
FILE ${OCIO_TARGETS_EXPORT_NAME}
)

install(
FILES "${OCIO_PROJECT_CONFIG}" "${OCIO_VERSION_CONFIG}"
DESTINATION "${OCIO_CONFIG_INSTALL_DIR}"
)
19 changes: 15 additions & 4 deletions include/OpenColorIO/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -2,13 +2,22 @@
# Copyright Contributors to the OpenColorIO Project.

configure_file("OpenColorABI.h.in" "${CMAKE_CURRENT_BINARY_DIR}/OpenColorABI.h" @ONLY)
add_library(public_api INTERFACE)
add_library(OpenColorIOHeaders INTERFACE)

set_property(TARGET public_api
PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_CURRENT_SOURCE_DIR}/..;${CMAKE_CURRENT_SOURCE_DIR};${CMAKE_CURRENT_BINARY_DIR};${CMAKE_CURRENT_BINARY_DIR}/OpenColorIO
set(BUILD_INCLUDES
${CMAKE_CURRENT_SOURCE_DIR}/..
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_CURRENT_BINARY_DIR}/OpenColorIO
)

add_dependencies(public_api "${CMAKE_CURRENT_BINARY_DIR}/OpenColorABI.h")
target_include_directories(OpenColorIOHeaders
INTERFACE
"$<BUILD_INTERFACE:${BUILD_INCLUDES}>"
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>"
)

add_dependencies(OpenColorIOHeaders "${CMAKE_CURRENT_BINARY_DIR}/OpenColorABI.h")

# public interface

@@ -17,3 +26,5 @@ list(APPEND core_export_headers ${CMAKE_CURRENT_BINARY_DIR}/OpenColorABI.h)

install(FILES ${core_export_headers}
DESTINATION include/OpenColorIO)

install_targets(OpenColorIOHeaders)
22 changes: 22 additions & 0 deletions share/cmake/macros/TargetUtils.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# SPDX-License-Identifier: BSD-3-Clause
# Copyright Contributors to the OpenColorIO Project.
#
# Imported from the OpenImageIO project.
#

###########################################################################
# Macro to install targets to the appropriate locations. Use this instead
# of the install(TARGETS ...) signature. Note that it adds it to the
# export targets list for when we generate config files.
#
# Usage:
#
# install_targets (target1 [target2 ...])
#
macro (install_targets)
remia marked this conversation as resolved.
Show resolved Hide resolved
install (TARGETS ${ARGN}
EXPORT ${PROJECT_NAME}_EXPORTED_TARGETS
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" COMPONENT user
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" COMPONENT user
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" COMPONENT developer)
endmacro()
9 changes: 4 additions & 5 deletions src/OpenColorIO/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -182,9 +182,6 @@ if(NOT WIN32)
configure_file(res/OpenColorIO.pc.in ${CMAKE_CURRENT_BINARY_DIR}/OpenColorIO.pc @ONLY)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/OpenColorIO.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
endif()

# TODO: Install the OpenColorIO-config.cmake.

add_library(OpenColorIO ${SOURCES})

if(BUILD_SHARED_LIBS AND WIN32)
@@ -199,12 +196,12 @@ if(BUILD_SHARED_LIBS AND WIN32)
endif()

target_include_directories(OpenColorIO
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}
)

target_link_libraries(OpenColorIO
PUBLIC
public_api
OpenColorIOHeaders
PRIVATE
expat::expat
IlmBase::Half
@@ -283,3 +280,5 @@ install(TARGETS OpenColorIO
RUNTIME DESTINATION bin
ARCHIVE DESTINATION lib
)

install_targets(OpenColorIO)
2 changes: 1 addition & 1 deletion src/bindings/python/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -191,7 +191,7 @@ target_include_directories(PyOpenColorIO
# macOS, to prevent segfaults when potentially working with multiple Python
# installations. See note in:
# https://pybind11.readthedocs.io/en/stable/compiling.html#building-manually
set(PYOCIO_LINK_PUBLIC public_api)
set(PYOCIO_LINK_PUBLIC OpenColorIOHeaders)
if(WIN32)
list(INSERT PYOCIO_LINK_PUBLIC 0 ${Python_LIBRARIES})
endif()
5 changes: 5 additions & 0 deletions src/cmake/Config.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@PACKAGE_INIT@

include(CMakeFindDependencyMacro)

include(${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake)
2 changes: 1 addition & 1 deletion tests/cpu/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@ function(add_ocio_test NAME SOURCES PRIVATE_INCLUDES)
)
target_link_libraries(${TEST_BINARY}
PUBLIC
public_api
OpenColorIOHeaders
PRIVATE
expat::expat
IlmBase::Half