yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
d0641da8c
master
1# Don't let all these packages spam up with status messages, filter to only the 2# important stuff. 3# Don't change things however if the user has explicitly set 4# CMAKE_MESSAGE_LOG_LEVEL 5set ( set_cmake_log_level FALSE ) 6if ( NOT CMAKE_MESSAGE_LOG_LEVEL) 7set ( set_cmake_log_level TRUE ) 8set ( CMAKE_MESSAGE_LOG_LEVEL NOTICE ) 9endif () 10 11if (${ CMAKE_VERSION } VERSION_GREATER_EQUAL "3.25" ) 12set ( system SYSTEM ) 13else () 14message ( 15STATUS 16"CMake 3.25 is required to suppress warnings originating in headers in external/ but you are using ${ CMAKE_VERSION } , be prepared for some warnings" 17) 18set ( system ) 19endif () 20 21# Similarly, disable warnings for external projects 22if ( NOT SLANG_ENABLE_EXTERNAL_COMPILER_WARNINGS) 23if ( NOT MSVC) 24add_compile_options ( -w ) 25endif () 26endif () 27 28# Unordered dense 29if ( NOT ${ SLANG_USE_SYSTEM_UNORDERED_DENSE }) 30if ( NOT SLANG_OVERRIDE_UNORDERED_DENSE_PATH) 31add_subdirectory ( unordered_dense EXCLUDE_FROM_ALL ${ system }) 32else () 33add_subdirectory ( 34${ SLANG_OVERRIDE_UNORDERED_DENSE_PATH } /unordered_dense 35unordered_dense 36EXCLUDE_FROM_ALL 37${ system } 38) 39endif () 40endif () 41 42# Miniz 43if ( NOT ${ SLANG_USE_SYSTEM_MINIZ }) 44if ( NOT SLANG_OVERRIDE_MINIZ_PATH) 45add_subdirectory ( miniz EXCLUDE_FROM_ALL ${ system }) 46else () 47add_subdirectory ( 48${ SLANG_OVERRIDE_MINIZ_PATH } /miniz 49miniz 50EXCLUDE_FROM_ALL 51${ system } 52) 53endif () 54set_property ( TARGET miniz PROPERTY POSITION_INDEPENDENT_CODE ON ) 55# Work around https://github.com/richgel999/miniz/pull/292 56get_target_property ( miniz_c_launcher miniz C_COMPILER_LAUNCHER ) 57if ( MSVCAND miniz_c_launcherMATCHES "ccache" ) 58set_property ( TARGET miniz PROPERTY C_COMPILER_LAUNCHER ) 59set_property ( TARGET miniz PROPERTY MSVC_DEBUG_INFORMATION_FORMAT "" ) 60endif () 61endif () 62 63# LZ4 64if ( NOT ${ SLANG_USE_SYSTEM_LZ4 }) 65set ( LZ4_BUNDLED_MODE ON ) 66if ( NOT SLANG_OVERRIDE_LZ4_PATH) 67add_subdirectory ( lz4/build/cmake EXCLUDE_FROM_ALL ${ system }) 68else () 69add_subdirectory ( 70${ SLANG_OVERRIDE_LZ4_PATH } /lz4/build/cmake 71lz4/build/cmake 72EXCLUDE_FROM_ALL 73${ system } 74) 75endif () 76if ( MSVC) 77target_compile_options ( 78lz4_static 79PRIVATE /wd5045 /wd4820 /wd4711 /wd6385 /wd6262 80) 81endif () 82endif () 83 84# Vulkan headers 85if ( NOT TARGET Vulkan::Headers) 86if ( NOT ${ SLANG_USE_SYSTEM_VULKAN_HEADERS }) 87if ( NOT SLANG_OVERRIDE_VULKAN_HEADERS_PATH) 88add_subdirectory ( vulkan EXCLUDE_FROM_ALL ${ system }) 89else () 90add_subdirectory ( 91${ SLANG_OVERRIDE_VULKAN_HEADERS_PATH } /vulkan 92vulkan 93EXCLUDE_FROM_ALL 94${ system } 95) 96endif () 97endif () 98endif () 99 100# metal-cpp headers 101add_library ( metal-cpp INTERFACE ) 102target_include_directories ( 103metal-cpp 104INTERFACE " ${ CMAKE_CURRENT_LIST_DIR } /metal-cpp" 105) 106 107# SPIRV-Headers 108# Avoid using ${system} intentionally in `add_subdirectory`, because if we do, it will end up using 109# spirv.h installed in the system directory on MacOS. 110if ( NOT TARGET SPIRV-Headers) 111if ( SLANG_USE_SYSTEM_SPIRV_HEADERS) 112if ( SLANG_OVERRIDE_SPIRV_HEADERS_PATH) 113message ( 114WARNING 115"SLANG_OVERRIDE_SPIRV_HEADERS_PATH does nothing when SLANG_USE_SPIRV_HEADERS is set" 116) 117endif () 118elseif ( SLANG_OVERRIDE_SPIRV_HEADERS_PATH) 119add_subdirectory ( 120${ SLANG_OVERRIDE_SPIRV_HEADERS_PATH } /spirv-headers 121spirv-headers 122EXCLUDE_FROM_ALL 123) 124else () 125add_subdirectory ( spirv-headers EXCLUDE_FROM_ALL ) 126endif () 127endif () 128 129if ( SLANG_ENABLE_SLANG_GLSLANG) 130# When using spirv headers via find_package, SPIRV-Headers_SOURCE_DIR is not set 131# SPIRV-Tools requires that variable, as it uses it to detect if SPIRV-Headers is provided by the consumer. 132# Fake a source build by setting it here. Ideally SPIRV-Tools should not depend on _SOURCE_DIR 133if (${ SLANG_USE_SYSTEM_SPIRV_HEADERS }) 134get_target_property ( 135SPIRV-Headers_SOURCE_DIR 136SPIRV-Headers::SPIRV-Headers 137INTERFACE_INCLUDE_DIRECTORIES 138) 139cmake_path ( 140GET 141SPIRV-Headers_SOURCE_DIR 142PARENT_PATH SPIRV-Headers_SOURCE_DIR 143) 144endif () 145 146if ( NOT ${ SLANG_USE_SYSTEM_SPIRV_TOOLS }) 147# SPIRV-Tools 148set ( SPIRV_TOOLS_BUILD_STATIC ON ) 149set ( SPIRV_WERROR OFF ) 150set ( SPIRV_SKIP_TESTS ON ) 151 152# Enable mimalloc for SPIRV-Tools to improve compilation performance 153# Based on SPIRV-Tools PR #6267: https://github.com/KhronosGroup/SPIRV-Tools/pull/6267 154if ( SLANG_ENABLE_SPIRV_TOOLS_MIMALLOC) 155if ( NOT SLANG_OVERRIDE_MIMALLOC_PATH) 156# Place mimalloc in slang/external instead of spirv-tools/external for better organization 157set ( MIMALLOC_PATH " ${ CMAKE_CURRENT_SOURCE_DIR } /mimalloc" ) 158else () 159set ( MIMALLOC_PATH " ${ SLANG_OVERRIDE_MIMALLOC_PATH } /mimalloc" ) 160endif () 161 162# Download mimalloc if it's not available 163if ( NOT EXISTS " ${ MIMALLOC_PATH } /CMakeLists.txt" ) 164message ( 165STATUS 166"mimalloc not found at ${ MIMALLOC_PATH } - downloading..." 167) 168execute_process ( 169COMMAND 170${ GIT_EXECUTABLE } clone --depth 1 --branch v2.1.7 171https://github.com/microsoft/mimalloc.git 172" ${ MIMALLOC_PATH } " 173RESULT_VARIABLE git_result 174OUTPUT_QUIET 175ERROR_QUIET 176) 177if ( git_resultEQUAL 0 ) 178# Point SPIRV-Tools to our mimalloc location 179set ( mimalloc_SOURCE_DIR " ${ MIMALLOC_PATH } " ) 180set ( SPIRV_TOOLS_USE_MIMALLOC ON ) 181set ( SPIRV_TOOLS_USE_MIMALLOC_IN_STATIC_BUILD ON ) 182# set(MI_INSTALL_TOPLEVEL OFF) 183message ( 184STATUS 185"Successfully downloaded and enabled mimalloc for SPIRV-Tools at ${ MIMALLOC_PATH } " 186) 187else () 188message ( 189WARNING 190"Failed to download mimalloc. Building SPIRV-Tools without mimalloc support." 191) 192endif () 193endif () 194 195# Check if mimalloc is available now 196if ( EXISTS " ${ MIMALLOC_PATH } /CMakeLists.txt" ) 197# Point SPIRV-Tools to our mimalloc location 198set ( mimalloc_SOURCE_DIR " ${ MIMALLOC_PATH } " ) 199set ( SPIRV_TOOLS_USE_MIMALLOC ON ) 200# Also enable mimalloc in static builds for better performance 201set ( SPIRV_TOOLS_USE_MIMALLOC_IN_STATIC_BUILD ON ) 202# Disable mimalloc installation to avoid install target conflicts 203# set(MI_INSTALL_TOPLEVEL OFF) 204message ( 205STATUS 206"Enabling mimalloc for SPIRV-Tools (including static builds) from ${ MIMALLOC_PATH } " 207) 208endif () 209endif () 210 211# Tools 212if ( NOT SLANG_OVERRIDE_SPIRV_TOOLS_PATH) 213add_subdirectory ( spirv-tools EXCLUDE_FROM_ALL ) 214else () 215add_subdirectory ( 216${ SLANG_OVERRIDE_SPIRV_TOOLS_PATH } /spirv-tools 217spirv-tools 218EXCLUDE_FROM_ALL 219) 220endif () 221endif () 222 223if ( NOT ${ SLANG_USE_SYSTEM_GLSLANG }) 224# glslang 225set ( SKIP_GLSLANG_INSTALL ON ) 226set ( ENABLE_OPT ON ) 227set ( ENABLE_PCH OFF ) 228set ( ALLOW_EXTERNAL_SPIRV_TOOLS ${ SLANG_USE_SYSTEM_SPIRV_TOOLS }) 229if ( NOT SLANG_OVERRIDE_GLSLANG_PATH) 230add_subdirectory ( glslang EXCLUDE_FROM_ALL ${ system }) 231else () 232add_subdirectory ( 233${ SLANG_OVERRIDE_GLSLANG_PATH } /glslang 234glslang 235EXCLUDE_FROM_ALL 236${ system } 237) 238endif () 239endif () 240endif () 241 242# imgui 243add_library ( imgui INTERFACE ) 244if ( NOT SLANG_OVERRIDE_IMGUI_PATH) 245target_include_directories ( 246imgui 247${ system } 248INTERFACE " ${ CMAKE_CURRENT_LIST_DIR } /imgui" 249) 250else () 251target_include_directories ( 252imgui 253${ system } 254INTERFACE " ${ SLANG_OVERRIDE_IMGUI_PATH } /imgui" 255) 256endif () 257 258# stb 259add_library ( stb INTERFACE ) 260target_include_directories ( 261stb 262${ system } 263INTERFACE " ${ CMAKE_CURRENT_LIST_DIR } /stb" 264) 265 266# slang-rhi 267if ( SLANG_ENABLE_SLANG_RHI) 268set ( SLANG_RHI_BUILD_FROM_SLANG_REPO ON ) 269set ( SLANG_RHI_BUILD_TESTS ON ) 270set ( SLANG_RHI_BUILD_TESTS_WITH_GLFW OFF ) 271set ( SLANG_RHI_INSTALL OFF ) 272set ( SLANG_RHI_BINARY_DIR ${ CMAKE_BINARY_DIR } / $ <CONFIG>/bin ) 273set ( SLANG_RHI_FETCH_SLANG OFF ) 274set ( SLANG_RHI_SLANG_INCLUDE_DIR ${ slang_SOURCE_DIR } /include ) 275set ( SLANG_RHI_SLANG_BINARY_DIR ${ CMAKE_BINARY_DIR }) 276set ( SLANG_RHI_ENABLE_NVAPI ${ SLANG_ENABLE_NVAPI }) 277 278# CoopVec requires 1.717.0-preview, but we cannot use the version until slang-rhi 279# allow slang to override D3D12Version value 280#set(SLANG_RHI_AGILITY_SDK_VERSION D3D12_PREVIEW_SDK_VERSION) 281#set(SLANG_RHI_FETCH_AGILITY_SDK_VERSION 282# "1.717.0-preview" 283# CACHE STRING 284# "Agility SDK version to fetch" 285# FORCE 286#) 287 288if ( SLANG_ENABLE_DX_ON_VK) 289set ( SLANG_RHI_HAS_D3D12 ON ) 290endif () 291if ( CMAKE_SYSTEM_NAMESTREQUAL "Linux" ) 292set ( SLANG_RHI_ENABLE_WGPU OFF ) 293endif () 294if ( MINGW) 295set ( SLANG_RHI_ENABLE_D3D11 OFF ) 296set ( SLANG_RHI_ENABLE_D3D12 OFF ) 297endif () 298if ( NOT SLANG_OVERRIDE_SLANG_RHI_PATH) 299add_subdirectory ( slang-rhi ) 300else () 301add_subdirectory ( 302${ SLANG_OVERRIDE_SLANG_RHI_PATH } /slang-rhi 303slang-rhi 304EXCLUDE_FROM_ALL 305${ system } 306) 307endif () 308 309# Output slang-rhi-tests to the bin directory so we can run it easily. 310set_target_properties ( 311slang-rhi-tests 312PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${ CMAKE_BINARY_DIR } / $ <CONFIG>/bin 313) 314endif () 315 316# Tidy things up: 317 318# Restore log level if we set it 319if ( set_cmake_log_level) 320unset ( CMAKE_MESSAGE_LOG_LEVEL ) 321endif () 322 323# for this directory and all subdirectories, prepend 324# `external/` to the IDE FOLDER property to every target 325function ( make_external dir ) 326get_property ( external_targets DIRECTORY ${ dir } PROPERTY BUILDSYSTEM_TARGETS ) 327foreach ( external_target${ external_targets }) 328get_property ( folder TARGET ${ external_target } PROPERTY FOLDER ) 329set_property ( 330TARGET ${ external_target } 331PROPERTY FOLDER "external/ ${ folder } " 332) 333endforeach () 334 335get_property ( subdirs DIRECTORY ${ dir } PROPERTY SUBDIRECTORIES ) 336foreach ( subdir${ subdirs }) 337make_external ( $ { subdir }) 338endforeach () 339endfunction () 340make_external ( . )