Skip to content

Commit 9d7d943

Browse files
authored
Update build to allow setting external paths (#6528)
* Update build to allow setting external paths Update the build to allow setting user-specific paths for the external modules. This allows building Slang without also fetching the external modules, assuming they are already present elsewhere locally.
1 parent 2aaa910 commit 9d7d943

File tree

5 files changed

+130
-13
lines changed

5 files changed

+130
-13
lines changed

CMakeLists.txt

+41
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,43 @@ option(
166166
)
167167
mark_as_advanced(SLANG_SPIRV_HEADERS_INCLUDE_DIR)
168168

169+
# Options for user defined paths for external modules.
170+
advanced_option(
171+
SLANG_OVERRIDE_LZ4_PATH
172+
"Build using user defined path for LZ4"
173+
OFF
174+
)
175+
advanced_option(
176+
SLANG_OVERRIDE_MINIZ_PATH
177+
"Build using user defined path for Miniz"
178+
OFF
179+
)
180+
advanced_option(
181+
SLANG_OVERRIDE_UNORDERED_DENSE_PATH
182+
"Build using user defined path for unordered_dense"
183+
OFF
184+
)
185+
advanced_option(
186+
SLANG_OVERRIDE_VULKAN_HEADERS_PATH
187+
"Build using user defined path for Vulkan headers"
188+
OFF
189+
)
190+
advanced_option(
191+
SLANG_OVERRIDE_SPIRV_HEADERS_PATH
192+
"Build using user defined path for SPIR-V headers"
193+
OFF
194+
)
195+
advanced_option(
196+
SLANG_OVERRIDE_SPIRV_TOOLS_PATH
197+
"Build using user defined path for SPIR-V tools"
198+
OFF
199+
)
200+
advanced_option(
201+
SLANG_OVERRIDE_GLSLANG_PATH
202+
"Build using user defined path for glslang, this also requires "
203+
OFF
204+
)
205+
169206
if(${SLANG_USE_SYSTEM_LZ4})
170207
add_compile_definitions(SLANG_USE_SYSTEM_LZ4_HEADER)
171208
endif()
@@ -178,6 +215,10 @@ if(${SLANG_USE_SYSTEM_UNORDERED_DENSE})
178215
add_compile_definitions(SLANG_USE_SYSTEM_UNORDERED_DENSE_HEADER)
179216
endif()
180217

218+
if(SLANG_OVERRIDE_SPIRV_HEADERS_PATH)
219+
add_compile_definitions(SLANG_USE_SYSTEM_SPIRV_HEADER)
220+
endif()
221+
181222
enum_option(
182223
SLANG_LIB_TYPE
183224
# Default

external/CMakeLists.txt

+78-8
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,32 @@ if(NOT SLANG_ENABLE_EXTERNAL_COMPILER_WARNINGS)
2727
endif()
2828
endif()
2929

30+
# Unordered dense
3031
if(NOT ${SLANG_USE_SYSTEM_UNORDERED_DENSE})
31-
add_subdirectory(unordered_dense EXCLUDE_FROM_ALL ${system})
32+
if(NOT SLANG_OVERRIDE_UNORDERED_DENSE_PATH)
33+
add_subdirectory(unordered_dense EXCLUDE_FROM_ALL ${system})
34+
else()
35+
add_subdirectory(
36+
${SLANG_OVERRIDE_UNORDERED_DENSE_PATH}
37+
unordered_dense
38+
EXCLUDE_FROM_ALL
39+
${system}
40+
)
41+
endif()
3242
endif()
3343

3444
# Miniz
3545
if(NOT ${SLANG_USE_SYSTEM_MINIZ})
36-
add_subdirectory(miniz EXCLUDE_FROM_ALL ${system})
46+
if(NOT SLANG_OVERRIDE_MINIZ_PATH)
47+
add_subdirectory(miniz EXCLUDE_FROM_ALL ${system})
48+
else()
49+
add_subdirectory(
50+
${SLANG_OVERRIDE_MINIZ_PATH}
51+
miniz
52+
EXCLUDE_FROM_ALL
53+
${system}
54+
)
55+
endif()
3756
set_property(TARGET miniz PROPERTY POSITION_INDEPENDENT_CODE ON)
3857
# Work around https://github.com/richgel999/miniz/pull/292
3958
get_target_property(miniz_c_launcher miniz C_COMPILER_LAUNCHER)
@@ -46,7 +65,16 @@ endif()
4665
# LZ4
4766
if(NOT ${SLANG_USE_SYSTEM_LZ4})
4867
set(LZ4_BUNDLED_MODE ON)
49-
add_subdirectory(lz4/build/cmake EXCLUDE_FROM_ALL ${system})
68+
if(NOT SLANG_OVERRIDE_LZ4_PATH)
69+
add_subdirectory(lz4/build/cmake EXCLUDE_FROM_ALL ${system})
70+
else()
71+
add_subdirectory(
72+
${SLANG_OVERRIDE_LZ4_PATH}/build/cmake
73+
lz4/build/cmake
74+
EXCLUDE_FROM_ALL
75+
${system}
76+
)
77+
endif()
5078
if(MSVC)
5179
target_compile_options(
5280
lz4_static
@@ -57,7 +85,16 @@ endif()
5785

5886
# Vulkan headers
5987
if(NOT ${SLANG_USE_SYSTEM_VULKAN_HEADERS})
60-
add_subdirectory(vulkan EXCLUDE_FROM_ALL ${system})
88+
if(NOT SLANG_OVERRIDE_VULKAN_HEADERS_PATH)
89+
add_subdirectory(vulkan EXCLUDE_FROM_ALL ${system})
90+
else()
91+
add_subdirectory(
92+
${SLANG_OVERRIDE_VULKAN_HEADERS_PATH}
93+
vulkan
94+
EXCLUDE_FROM_ALL
95+
${system}
96+
)
97+
endif()
6198
endif()
6299

63100
# metal-cpp headers
@@ -69,22 +106,55 @@ target_include_directories(
69106

70107
# SPIRV-Headers
71108
if(NOT ${SLANG_USE_SYSTEM_SPIRV_HEADERS})
72-
add_subdirectory(spirv-headers EXCLUDE_FROM_ALL ${system})
109+
if(NOT SLANG_OVERRIDE_SPIRV_HEADERS_PATH)
110+
add_subdirectory(spirv-headers EXCLUDE_FROM_ALL ${system})
111+
else()
112+
add_subdirectory(
113+
${SLANG_OVERRIDE_SPIRV_HEADERS_PATH}
114+
spirv-headers
115+
EXCLUDE_FROM_ALL
116+
${system}
117+
)
118+
endif()
73119
endif()
74120

75121
if(SLANG_ENABLE_SLANG_GLSLANG)
76122
# SPIRV-Tools
77123
set(SPIRV_TOOLS_BUILD_STATIC ON)
78124
set(SPIRV_WERROR OFF)
79-
set(SPIRV_HEADER_DIR "${CMAKE_CURRENT_LIST_DIR}/spirv-headers/")
125+
# Headers
126+
if(NOT SLANG_OVERRIDE_SPIRV_HEADERS_PATH)
127+
set(SPIRV_HEADER_DIR "${CMAKE_CURRENT_LIST_DIR}/spirv-headers/")
128+
else()
129+
set(SPIRV_HEADER_DIR ${SLANG_OVERRIDE_SPIRV_HEADERS_PATH})
130+
endif()
80131
set(SPIRV_SKIP_TESTS ON)
81-
add_subdirectory(spirv-tools EXCLUDE_FROM_ALL ${system})
132+
# Tools
133+
if(NOT SLANG_OVERRIDE_SPIRV_TOOLS_PATH)
134+
add_subdirectory(spirv-tools EXCLUDE_FROM_ALL ${system})
135+
else()
136+
add_subdirectory(
137+
${SLANG_OVERRIDE_SPIRV_TOOLS_PATH}
138+
spirv-tools
139+
EXCLUDE_FROM_ALL
140+
${system}
141+
)
142+
endif()
82143

83144
# glslang
84145
set(SKIP_GLSLANG_INSTALL ON)
85146
set(ENABLE_OPT ON)
86147
set(ENABLE_PCH OFF)
87-
add_subdirectory(glslang EXCLUDE_FROM_ALL ${system})
148+
if(NOT SLANG_OVERRIDE_GLSLANG_PATH)
149+
add_subdirectory(glslang EXCLUDE_FROM_ALL ${system})
150+
else()
151+
add_subdirectory(
152+
${SLANG_OVERRIDE_GLSLANG_PATH}
153+
glslang
154+
EXCLUDE_FROM_ALL
155+
${system}
156+
)
157+
endif()
88158
endif()
89159

90160
# imgui

source/core/slang-dictionary.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#ifndef SLANG_CORE_DICTIONARY_H
22
#define SLANG_CORE_DICTIONARY_H
33

4-
#include "../../external/unordered_dense/include/ankerl/unordered_dense.h"
54
#include "slang-common.h"
65
#include "slang-exception.h"
76
#include "slang-hash.h"
@@ -10,6 +9,7 @@
109
#include "slang-math.h"
1110
#include "slang-uint-set.h"
1211

12+
#include <ankerl/unordered_dense.h>
1313
#include <initializer_list>
1414

1515
namespace Slang

source/core/slang-hash.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#ifndef SLANG_CORE_HASH_H
22
#define SLANG_CORE_HASH_H
33

4-
#include "../../external/unordered_dense/include/ankerl/unordered_dense.h"
54
#include "slang-math.h"
65
#include "slang.h"
76

7+
#include <ankerl/unordered_dense.h>
88
#include <cstring>
99
#include <type_traits>
1010

source/slang/CMakeLists.txt

+9-3
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,15 @@ target_include_directories(
110110
#
111111

112112
if(NOT SLANG_USE_SYSTEM_SPIRV_HEADERS)
113-
set(SLANG_SPIRV_HEADERS_INCLUDE_DIR
114-
"${slang_SOURCE_DIR}/external/spirv-headers/include"
115-
)
113+
if(NOT SLANG_OVERRIDE_SPIRV_HEADERS_PATH)
114+
set(SLANG_SPIRV_HEADERS_INCLUDE_DIR
115+
"${slang_SOURCE_DIR}/external/spirv-headers/include"
116+
)
117+
else()
118+
set(SLANG_SPIRV_HEADERS_INCLUDE_DIR
119+
"${SLANG_OVERRIDE_SPIRV_HEADERS_PATH}/include"
120+
)
121+
endif()
116122
endif()
117123

118124
set(SLANG_LOOKUP_GENERATOR_INPUT_JSON

0 commit comments

Comments
 (0)