Skip to content

Commit

Permalink
Add OpenColorIOConfig.cmake generation (AcademySoftwareFoundation#1397)
Browse files Browse the repository at this point in the history
* Initial OpenColorIO Config CMake implementation

Signed-off-by: Rémi Achard <remiachard@gmail.com>

* Remove macro, improve documentation

Signed-off-by: Rémi Achard <remiachard@gmail.com>

Co-authored-by: Patrick Hodoul <patrick.hodoul@autodesk.com>
Signed-off-by: Patrick Hodoul <Patrick.Hodoul@autodesk.com>
  • Loading branch information
remia and hodoulp committed Jun 28, 2021
1 parent 1eebf71 commit 80d2d4e
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 11 deletions.
39 changes: 39 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -265,3 +265,42 @@ 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
# Targets exported to ${PROJECT_NAME}_EXPORTED_TARGETS will be available for
# import using find_package(OpenColorIO).

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}"
)
21 changes: 17 additions & 4 deletions include/OpenColorIO/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

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

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

install(TARGETS OpenColorIOHeaders
EXPORT ${PROJECT_NAME}_EXPORTED_TARGETS
)
8 changes: 3 additions & 5 deletions src/OpenColorIO/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -279,6 +276,7 @@ if(MSVC AND BUILD_SHARED_LIBS)
endif()

install(TARGETS OpenColorIO
EXPORT ${PROJECT_NAME}_EXPORTED_TARGETS
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin
ARCHIVE DESTINATION lib
Expand Down
2 changes: 1 addition & 1 deletion src/bindings/python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,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()
Expand Down
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
Expand Up @@ -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
Expand Down

0 comments on commit 80d2d4e

Please sign in to comment.