Skip to content

Commit a0f2149

Browse files
authored
Merge branch 'master' into conform-integer-literals
2 parents 9f3e0ef + 5d8cf47 commit a0f2149

File tree

3 files changed

+85
-0
lines changed

3 files changed

+85
-0
lines changed

CMakeLists.txt

+40
Original file line numberDiff line numberDiff line change
@@ -338,3 +338,43 @@ install(DIRECTORY "${slang_SOURCE_DIR}/docs/" DESTINATION share/doc/slang)
338338
install(DIRECTORY "${slang_SOURCE_DIR}/include" DESTINATION .)
339339

340340
include(CPack)
341+
342+
# Write basic package config version file using standard CMakePackageConfigHelpers utility
343+
include(CMakePackageConfigHelpers)
344+
write_basic_package_version_file(
345+
"${PROJECT_NAME}ConfigVersion.cmake"
346+
VERSION ${PROJECT_VERSION}
347+
COMPATIBILITY SameMajorVersion
348+
)
349+
350+
# Write SlangConfig.cmake which should allow find_pacakage(SLANG) to work correctly
351+
# SlangConfig.cmake will define slang::slang target that can be linked with using
352+
# target_link_libraries. It will also define SLANG_EXECUTABLE export variable that
353+
# should point to slangc if SLANG_ENABLE_SLANGC is ON.
354+
configure_package_config_file(
355+
"${PROJECT_SOURCE_DIR}/cmake/SlangConfig.cmake.in"
356+
"${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
357+
INSTALL_DESTINATION cmake
358+
)
359+
360+
# Conditionally handle the case for Emscripten where slang does not create linkable
361+
# targets. In this case do not export the targets. Otherwise, just export the
362+
# slang target, as this is the library that is required to use the compiler. This possibly
363+
# should later be expanded to include slang-rhi targets if some program intends to use them,
364+
# but possibly wait for a future request before expanding this export set.
365+
if(NOT CMAKE_SYSTEM_NAME STREQUAL "Emscripten")
366+
install(TARGETS slang EXPORT SlangExportTarget)
367+
install(
368+
EXPORT SlangExportTarget
369+
FILE ${PROJECT_NAME}Targets.cmake
370+
NAMESPACE ${PROJECT_NAME}::
371+
DESTINATION cmake
372+
)
373+
endif()
374+
375+
install(
376+
FILES
377+
"${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
378+
"${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
379+
DESTINATION cmake
380+
)

cmake/SlangConfig.cmake.in

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
2+
@PACKAGE_INIT@
3+
4+
if (NOT CMAKE_SYSTEM_NAME STREQUAL "Emscripten")
5+
include("${CMAKE_CURRENT_LIST_DIR}/slangTargets.cmake")
6+
check_required_components("slang")
7+
endif()
8+
9+
if(@SLANG_ENABLE_SLANGC@)
10+
11+
find_program(SLANGC_EXECUTABLE "slangc" HINTS ENV PATH "${PACKAGE_PREFIX_DIR}/bin")
12+
13+
if (NOT SLANGC_EXECUTABLE)
14+
message(STATUS "slangc executable not found; ensure it is available in your PATH.")
15+
endif()
16+
17+
set(SLANG_EXECUTABLE ${SLANGC_EXECUTABLE} CACHE STRING "Path to the slangc executable")
18+
19+
endif()
20+

docs/building.md

+25
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,31 @@ cmake --build --preset emscripten --target slang-wasm
110110
> Note: If the last build step fails, try running the command that `emcmake`
111111
> outputs, directly.
112112
113+
## Installing
114+
115+
Build targets may be installed using cmake:
116+
117+
```bash
118+
cmake --build . --target install
119+
```
120+
121+
This should install `SlangConfig.cmake` that should allow `find_package` to work.
122+
SlangConfig.cmake defines `SLANG_EXECUTABLE` variable that will point to `slangc`
123+
executable and also define `slang::slang` target to be linked to.
124+
125+
For now, `slang::slang` is the only exported target defined in the config which can
126+
be linked to.
127+
128+
Example usage
129+
130+
```cmake
131+
find_package(slang REQUIRED PATHS ${your_cmake_install_prefix_path} NO_DEFAULT_PATH)
132+
# slang_FOUND should be automatically set
133+
target_link_libraries(yourLib PUBLIC
134+
slang::slang
135+
)
136+
```
137+
113138
## Testing
114139

115140
```bash

0 commit comments

Comments
 (0)