Skip to content

Commit b50d311

Browse files
cmake: option to build a static library version of slang (shader-slang#3578)
* cmake: slang lib type setting * cmake: change name for slang lib type setting --------- Co-authored-by: Yong He <yonghe@outlook.com>
1 parent c639cac commit b50d311

File tree

4 files changed

+21
-1
lines changed

4 files changed

+21
-1
lines changed

CMakeLists.txt

+12
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,18 @@ option(SLANG_ENABLE_SLANG_GLSLANG "Enable glslang dependency and slang-glslang w
9595
option(SLANG_ENABLE_TESTS "Enable test targets, requires SLANG_ENABLE_GFX, SLANG_ENABLE_SLANGD and SLANG_ENABLE_SLANGRT" ON)
9696
option(SLANG_ENABLE_EXAMPLES "Enable example targets, requires SLANG_ENABLE_GFX" ON)
9797

98+
enum_option(
99+
SLANG_LIB_TYPE
100+
# Default
101+
SHARED
102+
"How to build the slang lib:"
103+
# Options
104+
SHARED
105+
"Build slang as a shared library (default)"
106+
STATIC
107+
"Build slang as a static library"
108+
)
109+
98110
set(SLANG_GENERATORS_PATH
99111
""
100112
CACHE PATH

cmake/SlangTarget.cmake

+7
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,13 @@ function(slang_add_target dir type)
241241
PUBLIC "${ARG_EXPORT_MACRO_PREFIX}_DYNAMIC"
242242
PRIVATE "${ARG_EXPORT_MACRO_PREFIX}_DYNAMIC_EXPORT"
243243
)
244+
elseif(
245+
target_type STREQUAL STATIC_LIBRARY
246+
)
247+
target_compile_definitions(
248+
${target}
249+
PUBLIC "${ARG_EXPORT_MACRO_PREFIX}_STATIC"
250+
)
244251
endif()
245252
endif()
246253

docs/building.md

+1
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ See the [documentation on testing](../tools/slang-test/README.md) for more infor
260260
| `SLANG_ENABLE_SLANG_GLSLANG` | `TRUE` | Enable glslang dependency and slang-glslang wrapper target |
261261
| `SLANG_ENABLE_TESTS` | `TRUE` | Enable test targets, requires SLANG_ENABLE_GFX, SLANG_ENABLE_SLANGD and SLANG_ENABLE_SLANGRT |
262262
| `SLANG_ENABLE_EXAMPLES` | `TRUE` | Enable example targets, requires SLANG_ENABLE_GFX |
263+
| `SLANG_LIB_TYPE` | `SHARED` | How to build the slang library |
263264
| `SLANG_SLANG_LLVM_FLAVOR` | `FETCH_BINARY` | How to set up llvm support |
264265
| `SLANG_SLANG_LLVM_BINARY_URL` | System dependent | URL specifying the location of the slang-llvm prebuilt library |
265266
| `SLANG_GENERATORS_PATH` | `` | Path to an installed `all-generators` target for cross compilation |

source/slang/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ target_include_directories(
243243
#
244244
slang_add_target(
245245
.
246-
SHARED
246+
${SLANG_LIB_TYPE}
247247
LINK_WITH_PRIVATE
248248
core
249249
compiler-core

0 commit comments

Comments
 (0)