Skip to content

Commit

Permalink
Create a single CMake config package for all SPIRV-Cross targets
Browse files Browse the repository at this point in the history
  • Loading branch information
theblackunknown committed Jan 3, 2024
1 parent f349c91 commit 088f5f5
Showing 1 changed file with 34 additions and 2 deletions.
36 changes: 34 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ project(SPIRV-Cross LANGUAGES CXX C)
enable_testing()

include(GNUInstallDirs)
include(CMakePackageConfigHelpers)

option(SPIRV_CROSS_EXCEPTIONS_TO_ASSERTIONS "Instead of throwing exceptions assert" OFF)
option(SPIRV_CROSS_SHARED "Build the C API as a single shared library." OFF)
Expand Down Expand Up @@ -187,13 +188,12 @@ macro(spirv_cross_add_library name config_name library_type)

if (NOT SPIRV_CROSS_SKIP_INSTALL)
install(TARGETS ${name}
EXPORT ${config_name}Config
EXPORT SPIRV-CrossTargets
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/spirv_cross)
install(FILES ${hdrs} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/spirv_cross)
install(EXPORT ${config_name}Config DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${config_name}/cmake)
export(TARGETS ${name} FILE ${config_name}Config.cmake)
endif()
endmacro()
Expand Down Expand Up @@ -621,3 +621,35 @@ if (SPIRV_CROSS_CLI)
endif()
endif()
endif()

if (NOT SPIRV_CROSS_SKIP_INSTALL)
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/SPIRV-CrossConfig.cmake.in" [=[
@PACKAGE_INIT@
include("${CMAKE_CURRENT_LIST_DIR}/SPIRV-CrossTargets.cmake")
]=])

configure_package_config_file(
"${CMAKE_CURRENT_BINARY_DIR}/SPIRV-CrossConfig.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/SPIRV-CrossConfig.cmake"
INSTALL_DESTINATION ${CMAKE_INSTALL_DATADIR}/SPIRV-Cross
)

write_basic_package_version_file("${CMAKE_CURRENT_BINARY_DIR}/SPIRV-CrossConfigVersion.cmake"
VERSION ${SPIRV_CROSS_VERSION}
COMPATIBILITY SameMajorVersion
)

install(
EXPORT SPIRV-CrossTargets
NAMESPACE "SPIRV-Cross::"
DESTINATION "${CMAKE_INSTALL_DATADIR}/SPIRV-Cross"
)

install(
FILES
"${CMAKE_CURRENT_BINARY_DIR}/SPIRV-CrossConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/SPIRV-CrossConfigVersion.cmake"
DESTINATION
"${CMAKE_INSTALL_DATADIR}/SPIRV-Cross"
)
endif()

0 comments on commit 088f5f5

Please sign in to comment.