Skip to content

Commit

Permalink
Update build to allow setting external paths
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jarcherNV committed Mar 6, 2025
1 parent 55dd2de commit b4bd772
Show file tree
Hide file tree
Showing 5 changed files with 129 additions and 13 deletions.
41 changes: 41 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,43 @@ option(
)
mark_as_advanced(SLANG_SPIRV_HEADERS_INCLUDE_DIR)

# Options for user defined paths for external modules.
advanced_option(
SLANG_OVERRIDE_LZ4_PATH
"Build using user defined path for LZ4"
OFF
)
advanced_option(
SLANG_OVERRIDE_MINIZ_PATH
"Build using user defined path for Miniz"
OFF
)
advanced_option(
SLANG_OVERRIDE_UNORDERED_DENSE_PATH
"Build using user defined path for unordered_dense"
OFF
)
advanced_option(
SLANG_OVERRIDE_VULKAN_HEADERS_PATH
"Build using user defined path for Vulkan headers"
OFF
)
advanced_option(
SLANG_OVERRIDE_SPIRV_HEADERS_PATH
"Build using user defined path for SPIR-V headers"
OFF
)
advanced_option(
SLANG_OVERRIDE_SPIRV_TOOLS_PATH
"Build using user defined path for SPIR-V tools"
OFF
)
advanced_option(
SLANG_OVERRIDE_GLSLANG_PATH
"Build using user defined path for glslang, this also requires "
OFF
)

if(${SLANG_USE_SYSTEM_LZ4})
add_compile_definitions(SLANG_USE_SYSTEM_LZ4_HEADER)
endif()
Expand All @@ -178,6 +215,10 @@ if(${SLANG_USE_SYSTEM_UNORDERED_DENSE})
add_compile_definitions(SLANG_USE_SYSTEM_UNORDERED_DENSE_HEADER)
endif()

if(SLANG_OVERRIDE_SPIRV_HEADERS_PATH)
add_compile_definitions(SLANG_USE_SYSTEM_SPIRV_HEADER)
endif()

enum_option(
SLANG_LIB_TYPE
# Default
Expand Down
85 changes: 77 additions & 8 deletions external/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,31 @@ if(NOT SLANG_ENABLE_EXTERNAL_COMPILER_WARNINGS)
endif()
endif()

# Unordered dense
if(NOT ${SLANG_USE_SYSTEM_UNORDERED_DENSE})
add_subdirectory(unordered_dense EXCLUDE_FROM_ALL ${system})
if(NOT SLANG_OVERRIDE_UNORDERED_DENSE_PATH)
add_subdirectory(unordered_dense EXCLUDE_FROM_ALL ${system})
else()
add_subdirectory(
${SLANG_OVERRIDE_UNORDERED_DENSE_PATH}
unordered_dense
EXCLUDE_FROM_ALL
${system}
)
endif()
endif()

# Miniz
if(NOT ${SLANG_USE_SYSTEM_MINIZ})
add_subdirectory(miniz EXCLUDE_FROM_ALL ${system})
if(NOT SLANG_OVERRIDE_MINIZ_PATH)
add_subdirectory(miniz EXCLUDE_FROM_ALL ${system})
else()
add_subdirectory(
${SLANG_OVERRIDE_MINIZ_PATH}
miniz EXCLUDE_FROM_ALL
${system}
)
endif()
set_property(TARGET miniz PROPERTY POSITION_INDEPENDENT_CODE ON)
# Work around https://github.com/richgel999/miniz/pull/292
get_target_property(miniz_c_launcher miniz C_COMPILER_LAUNCHER)
Expand All @@ -46,7 +64,16 @@ endif()
# LZ4
if(NOT ${SLANG_USE_SYSTEM_LZ4})
set(LZ4_BUNDLED_MODE ON)
add_subdirectory(lz4/build/cmake EXCLUDE_FROM_ALL ${system})
if(NOT SLANG_OVERRIDE_LZ4_PATH)
add_subdirectory(lz4/build/cmake EXCLUDE_FROM_ALL ${system})
else()
add_subdirectory(
${SLANG_OVERRIDE_LZ4_PATH}/build/cmake
lz4/build/cmake
EXCLUDE_FROM_ALL
${system}
)
endif()
if(MSVC)
target_compile_options(
lz4_static
Expand All @@ -57,7 +84,16 @@ endif()

# Vulkan headers
if(NOT ${SLANG_USE_SYSTEM_VULKAN_HEADERS})
add_subdirectory(vulkan EXCLUDE_FROM_ALL ${system})
if(NOT SLANG_OVERRIDE_VULKAN_HEADERS_PATH)
add_subdirectory(vulkan EXCLUDE_FROM_ALL ${system})
else()
add_subdirectory(
${SLANG_OVERRIDE_VULKAN_HEADERS_PATH}
vulkan
EXCLUDE_FROM_ALL
${system}
)
endif()
endif()

# metal-cpp headers
Expand All @@ -69,22 +105,55 @@ target_include_directories(

# SPIRV-Headers
if(NOT ${SLANG_USE_SYSTEM_SPIRV_HEADERS})
add_subdirectory(spirv-headers EXCLUDE_FROM_ALL ${system})
if(NOT SLANG_OVERRIDE_SPIRV_HEADERS_PATH)
add_subdirectory(spirv-headers EXCLUDE_FROM_ALL ${system})
else()
add_subdirectory(
${SLANG_OVERRIDE_SPIRV_HEADERS_PATH}
spirv-headers
EXCLUDE_FROM_ALL
${system}
)
endif()
endif()

if(SLANG_ENABLE_SLANG_GLSLANG)
# SPIRV-Tools
set(SPIRV_TOOLS_BUILD_STATIC ON)
set(SPIRV_WERROR OFF)
set(SPIRV_HEADER_DIR "${CMAKE_CURRENT_LIST_DIR}/spirv-headers/")
# Headers
if(NOT SLANG_OVERRIDE_SPIRV_HEADERS_PATH)
set(SPIRV_HEADER_DIR "${CMAKE_CURRENT_LIST_DIR}/spirv-headers/")
else()
set(SPIRV_HEADER_DIR ${SLANG_OVERRIDE_SPIRV_HEADERS_PATH})
endif()
set(SPIRV_SKIP_TESTS ON)
add_subdirectory(spirv-tools EXCLUDE_FROM_ALL ${system})
# Tools
if(NOT SLANG_OVERRIDE_SPIRV_TOOLS_PATH)
add_subdirectory(spirv-tools EXCLUDE_FROM_ALL ${system})
else()
add_subdirectory(
${SLANG_OVERRIDE_SPIRV_TOOLS_PATH}
spirv-tools
EXCLUDE_FROM_ALL
${system}
)
endif()

# glslang
set(SKIP_GLSLANG_INSTALL ON)
set(ENABLE_OPT ON)
set(ENABLE_PCH OFF)
add_subdirectory(glslang EXCLUDE_FROM_ALL ${system})
if(NOT SLANG_OVERRIDE_GLSLANG_PATH)
add_subdirectory(glslang EXCLUDE_FROM_ALL ${system})
else()
add_subdirectory(
${SLANG_OVERRIDE_GLSLANG_PATH}
glslang
EXCLUDE_FROM_ALL
${system}
)
endif()
endif()

# imgui
Expand Down
2 changes: 1 addition & 1 deletion source/core/slang-dictionary.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#ifndef SLANG_CORE_DICTIONARY_H
#define SLANG_CORE_DICTIONARY_H

#include "../../external/unordered_dense/include/ankerl/unordered_dense.h"
#include "slang-common.h"
#include "slang-exception.h"
#include "slang-hash.h"
Expand All @@ -10,6 +9,7 @@
#include "slang-math.h"
#include "slang-uint-set.h"

#include <ankerl/unordered_dense.h>
#include <initializer_list>

namespace Slang
Expand Down
2 changes: 1 addition & 1 deletion source/core/slang-hash.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#ifndef SLANG_CORE_HASH_H
#define SLANG_CORE_HASH_H

#include "../../external/unordered_dense/include/ankerl/unordered_dense.h"
#include "slang-math.h"
#include "slang.h"

#include <ankerl/unordered_dense.h>
#include <cstring>
#include <type_traits>

Expand Down
12 changes: 9 additions & 3 deletions source/slang/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,15 @@ target_include_directories(
#

if(NOT SLANG_USE_SYSTEM_SPIRV_HEADERS)
set(SLANG_SPIRV_HEADERS_INCLUDE_DIR
"${slang_SOURCE_DIR}/external/spirv-headers/include"
)
if(NOT SLANG_OVERRIDE_SPIRV_HEADERS_PATH)
set(SLANG_SPIRV_HEADERS_INCLUDE_DIR
"${slang_SOURCE_DIR}/external/spirv-headers/include"
)
else()
set(SLANG_SPIRV_HEADERS_INCLUDE_DIR
"${SLANG_OVERRIDE_SPIRV_HEADERS_PATH}/include"
)
endif()
endif()

set(SLANG_LOOKUP_GENERATOR_INPUT_JSON
Expand Down

0 comments on commit b4bd772

Please sign in to comment.