diff --git a/CMakeLists.txt b/CMakeLists.txt index dc281211e0..047c874617 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -338,3 +338,33 @@ install(DIRECTORY "${slang_SOURCE_DIR}/docs/" DESTINATION share/doc/slang) install(DIRECTORY "${slang_SOURCE_DIR}/include" DESTINATION .) include(CPack) + +include(CMakePackageConfigHelpers) +write_basic_package_version_file( + "${PROJECT_NAME}ConfigVersion.cmake" + VERSION ${PROJECT_VERSION} + COMPATIBILITY SameMajorVersion +) + +configure_package_config_file( + "${PROJECT_SOURCE_DIR}/cmake/SlangConfig.cmake.in" + "${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" + INSTALL_DESTINATION cmake +) + +if(NOT CMAKE_SYSTEM_NAME STREQUAL "Emscripten") + install(TARGETS slang EXPORT SlangExportTarget) + install( + EXPORT SlangExportTarget + FILE ${PROJECT_NAME}Targets.cmake + NAMESPACE ${PROJECT_NAME}:: + DESTINATION cmake + ) +endif() + +install( + FILES + "${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" + "${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake" + DESTINATION cmake +) diff --git a/cmake/SlangConfig.cmake.in b/cmake/SlangConfig.cmake.in new file mode 100644 index 0000000000..2539586902 --- /dev/null +++ b/cmake/SlangConfig.cmake.in @@ -0,0 +1,20 @@ + +@PACKAGE_INIT@ + +if (NOT CMAKE_SYSTEM_NAME STREQUAL "Emscripten") + include("${CMAKE_CURRENT_LIST_DIR}/slangTargets.cmake") + check_required_components("slang") +endif() + +if(@SLANG_ENABLE_SLANGC@) + + find_program(SLANGC_EXECUTABLE "slangc" HINTS ENV PATH "${PACKAGE_PREFIX_DIR}/bin") + + if (NOT SLANGC_EXECUTABLE) + message(STATUS "slangc executable not found; ensure it is available in your PATH.") + endif() + + set(SLANG_EXECUTABLE ${SLANGC_EXECUTABLE} CACHE STRING "Path to the slangc executable") + +endif() +