From 336dc08a20fc3a7d8d4eea02eaa5878bbf93a94f Mon Sep 17 00:00:00 2001 From: obhi-d Date: Sat, 30 Nov 2024 10:16:09 +0100 Subject: [PATCH] Add documentation on install target. --- CMakeLists.txt | 10 ++++++++++ docs/building.md | 25 +++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 047c874617..5a53ba731a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -339,6 +339,7 @@ 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" @@ -346,12 +347,21 @@ write_basic_package_version_file( 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( diff --git a/docs/building.md b/docs/building.md index 0f76bb780d..ea40be2122 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