diff options
| author | ov-l <186710607+ov-l@users.noreply.github.com> | 2024-12-03 18:50:11 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-12-03 17:50:11 +0000 |
| commit | 5d8cf475b352ab517c565ccee59461640da63a2a (patch) | |
| tree | 8e9a311cc712df112ffe290821751b0276e10f97 | |
| parent | 6c655ca927a440d1f03339295235fce2a764c26b (diff) | |
Add SlangConfig.cmake with slang build targets (#5674)
* Modify package config
* Apply formatting.
* Make sure build works for Emscripten
* Add documentation on install target.
---------
Co-authored-by: obhi-d <obi.de.online@gmail.com>
| -rw-r--r-- | CMakeLists.txt | 40 | ||||
| -rw-r--r-- | cmake/SlangConfig.cmake.in | 20 | ||||
| -rw-r--r-- | docs/building.md | 25 |
3 files changed, 85 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index dc281211e..5a53ba731 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -338,3 +338,43 @@ install(DIRECTORY "${slang_SOURCE_DIR}/docs/" DESTINATION share/doc/slang) install(DIRECTORY "${slang_SOURCE_DIR}/include" DESTINATION .) include(CPack) + +# Write basic package config version file using standard CMakePackageConfigHelpers utility +include(CMakePackageConfigHelpers) +write_basic_package_version_file( + "${PROJECT_NAME}ConfigVersion.cmake" + VERSION ${PROJECT_VERSION} + COMPATIBILITY SameMajorVersion +) + +# Write SlangConfig.cmake which should allow find_pacakage(SLANG) to work correctly +# SlangConfig.cmake will define slang::slang target that can be linked with using +# target_link_libraries. It will also define SLANG_EXECUTABLE export variable that +# should point to slangc if SLANG_ENABLE_SLANGC is ON. +configure_package_config_file( + "${PROJECT_SOURCE_DIR}/cmake/SlangConfig.cmake.in" + "${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" + INSTALL_DESTINATION cmake +) + +# Conditionally handle the case for Emscripten where slang does not create linkable +# targets. In this case do not export the targets. Otherwise, just export the +# slang target, as this is the library that is required to use the compiler. This possibly +# should later be expanded to include slang-rhi targets if some program intends to use them, +# but possibly wait for a future request before expanding this export set. +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 000000000..253958690 --- /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() + diff --git a/docs/building.md b/docs/building.md index 0f76bb780..ea40be212 100644 --- a/docs/building.md +++ b/docs/building.md @@ -110,6 +110,31 @@ cmake --build --preset emscripten --target slang-wasm > Note: If the last build step fails, try running the command that `emcmake` > outputs, directly. +## Installing + +Build targets may be installed using cmake: + +```bash +cmake --build . --target install +``` + +This should install `SlangConfig.cmake` that should allow `find_package` to work. +SlangConfig.cmake defines `SLANG_EXECUTABLE` variable that will point to `slangc` +executable and also define `slang::slang` target to be linked to. + +For now, `slang::slang` is the only exported target defined in the config which can +be linked to. + +Example usage + +```cmake +find_package(slang REQUIRED PATHS ${your_cmake_install_prefix_path} NO_DEFAULT_PATH) +# slang_FOUND should be automatically set +target_link_libraries(yourLib PUBLIC + slang::slang +) +``` + ## Testing ```bash |
