From b4bd772882bcdd5879e4f99334182d5ed49212ae Mon Sep 17 00:00:00 2001 From: Jesse Archer Date: Wed, 5 Mar 2025 12:17:27 -0800 Subject: [PATCH 1/2] 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. --- CMakeLists.txt | 41 ++++++++++++++++ external/CMakeLists.txt | 85 ++++++++++++++++++++++++++++++---- source/core/slang-dictionary.h | 2 +- source/core/slang-hash.h | 2 +- source/slang/CMakeLists.txt | 12 +++-- 5 files changed, 129 insertions(+), 13 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 48d263d143..a74047e0fd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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() @@ -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 diff --git a/external/CMakeLists.txt b/external/CMakeLists.txt index f23027f684..b79d8ce752 100644 --- a/external/CMakeLists.txt +++ b/external/CMakeLists.txt @@ -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) @@ -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 @@ -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 @@ -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 diff --git a/source/core/slang-dictionary.h b/source/core/slang-dictionary.h index 79f6dee30f..639978a088 100644 --- a/source/core/slang-dictionary.h +++ b/source/core/slang-dictionary.h @@ -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" @@ -10,6 +9,7 @@ #include "slang-math.h" #include "slang-uint-set.h" +#include #include namespace Slang diff --git a/source/core/slang-hash.h b/source/core/slang-hash.h index ebe3d19733..eee58878b6 100644 --- a/source/core/slang-hash.h +++ b/source/core/slang-hash.h @@ -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 #include #include diff --git a/source/slang/CMakeLists.txt b/source/slang/CMakeLists.txt index b9e78407b5..9c51ed767e 100644 --- a/source/slang/CMakeLists.txt +++ b/source/slang/CMakeLists.txt @@ -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 From 69f1a0942ab5419a6fa18ae1dbf9d2716e4ec9b3 Mon Sep 17 00:00:00 2001 From: slangbot <186143334+slangbot@users.noreply.github.com> Date: Thu, 6 Mar 2025 22:07:01 +0000 Subject: [PATCH 2/2] format code --- external/CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/external/CMakeLists.txt b/external/CMakeLists.txt index b79d8ce752..a590fe538d 100644 --- a/external/CMakeLists.txt +++ b/external/CMakeLists.txt @@ -48,7 +48,8 @@ if(NOT ${SLANG_USE_SYSTEM_MINIZ}) else() add_subdirectory( ${SLANG_OVERRIDE_MINIZ_PATH} - miniz EXCLUDE_FROM_ALL + miniz + EXCLUDE_FROM_ALL ${system} ) endif()