yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
d0641da8c
master
1cmake_minimum_required ( VERSION 3.22 ) 2 3# Our module dir, include that now so that we can get the version automatically 4# from git describe 5list ( APPEND CMAKE_MODULE_PATH " ${ CMAKE_CURRENT_LIST_DIR } /cmake" ) 6include ( GitVersion ) 7get_git_version ( 8SLANG_VERSION_NUMERIC 9SLANG_VERSION_FULL 10" ${ CMAKE_CURRENT_LIST_DIR } " 11) 12 13# 14# Our project 15# 16project ( slang VERSION " ${ SLANG_VERSION_NUMERIC } " LANGUAGES ) 17set ( PROJECT_VERSION " ${ SLANG_VERSION_FULL } " ) 18 19# 20# Global CMake options 21# 22if (${ CMAKE_VERSION } VERSION_GREATER_EQUAL "3.24" ) 23cmake_policy ( SET CMP0135 OLD ) 24endif () 25cmake_policy ( SET CMP0077 NEW ) 26set ( CMAKE_POLICY_DEFAULT_CMP0077 NEW ) 27if (${ CMAKE_VERSION } VERSION_GREATER_EQUAL "3.25" ) 28cmake_policy ( SET CMP0141 NEW ) 29endif () 30cmake_policy ( SET CMP0091 NEW ) 31 32# Don't use absolute paths to the build tree in RPATH, this makes the build 33# tree relocatable 34set ( CMAKE_BUILD_RPATH_USE_ORIGIN TRUE ) 35 36# Export the compile datebase as a json file, this can be used by VIM language server 37set ( CMAKE_EXPORT_COMPILE_COMMANDS ON ) 38 39# Enable placing targets into a hierarchy for IDE generators 40set_property ( GLOBAL PROPERTY USE_FOLDERS ON ) 41 42# 43# CMake-supplied modules and our utils 44# 45enable_language ( C CXX ) 46 47include ( FindPackageHandleStandardArgs ) 48include ( CMakeDependentOption ) 49include ( GNUInstallDirs ) 50 51include ( CCacheDebugInfoWorkaround ) 52include ( CompilerFlags ) 53include ( Glob ) 54include ( LLVM ) 55include ( SlangTarget ) 56include ( AutoOption ) 57include ( GitHubRelease ) 58include ( FetchedSharedLibrary ) 59 60# 61# Options 62# 63 64auto_option ( 65SLANG_ENABLE_CUDA 66CUDAToolkit 67"Enable CUDA tests using CUDA found in CUDA_PATH" 68) 69# Check if SLANG_ENABLE_OPTIX was explicitly set by user before auto_option 70set ( _SLANG_ENABLE_OPTIX_USER_SPECIFIED FALSE ) 71get_property ( 72_SLANG_ENABLE_OPTIX_CACHE_TYPE 73CACHE SLANG_ENABLE_OPTIX 74PROPERTY TYPE 75) 76if ( 77DEFINED SLANG_ENABLE_OPTIX 78AND NOT SLANG_ENABLE_OPTIXSTREQUAL "AUTO" 79AND _SLANG_ENABLE_OPTIX_CACHE_TYPESTREQUAL "BOOL" 80) 81set ( _SLANG_ENABLE_OPTIX_USER_SPECIFIED TRUE ) 82endif () 83 84auto_option ( 85SLANG_ENABLE_OPTIX 86OptiX 87"Enable OptiX build/tests, requires SLANG_ENABLE_CUDA" 88) 89auto_option ( 90SLANG_ENABLE_NVAPI 91NVAPI 92"Enable NVAPI usage (Only available for builds targeting Windows)" 93) 94if ( CMAKE_SYSTEM_NAMEMATCHES "Linux" ) 95auto_option ( 96SLANG_ENABLE_XLIB 97X11 98"Build gfx and platform with Xlib to support windowed apps on Linux" 99) 100else () 101set ( SLANG_ENABLE_XLIB OFF ) 102endif () 103auto_option ( 104SLANG_ENABLE_AFTERMATH 105Aftermath 106"Enable Aftermath in GFX, and add aftermath crash example to project" 107) 108advanced_option ( 109SLANG_ENABLE_DX_ON_VK 110"Use dxvk and vkd3d-proton for DirectX support" 111OFF 112) 113advanced_option ( SLANG_ENABLE_SLANG_RHI "Use slang-rhi as dependency" ON ) 114 115option ( 116SLANG_EMBED_CORE_MODULE_SOURCE 117"Embed core module source in the binary" 118ON 119) 120option ( 121SLANG_EMBED_CORE_MODULE 122"Build slang with an embedded version of the core module" 123ON 124) 125 126option ( SLANG_ENABLE_DXIL "Enable generating DXIL with DXC" ON ) 127 128option ( SLANG_ENABLE_FULL_IR_VALIDATION "Enable full IR validation (SLOW!)" ) 129option ( SLANG_ENABLE_IR_BREAK_ALLOC "Enable _debugUID on IR allocation" ) 130option ( SLANG_ENABLE_ASAN "Enable ASAN (address sanitizer)" ) 131 132option ( SLANG_ENABLE_PREBUILT_BINARIES "Enable using prebuilt binaries" ON ) 133option ( SLANG_ENABLE_GFX "Enable gfx targets" ON ) 134option ( SLANG_ENABLE_SLANGD "Enable language server target" ON ) 135option ( SLANG_ENABLE_SLANGC "Enable standalone compiler target" ON ) 136option ( SLANG_ENABLE_SLANGI "Enable Slang interpreter target" ON ) 137option ( SLANG_ENABLE_SLANGRT "Enable runtime target" ON ) 138option ( 139SLANG_ENABLE_SLANG_GLSLANG 140"Enable glslang dependency and slang-glslang wrapper target" 141ON 142) 143option ( 144SLANG_ENABLE_TESTS 145"Enable test targets, some tests may require SLANG_ENABLE_SLANG_RHI, SLANG_ENABLE_SLANGD or SLANG_ENABLE_SLANGRT" 146ON 147) 148option ( 149SLANG_ENABLE_EXAMPLES 150"Enable example targets, requires SLANG_ENABLE_SLANG_RHI" 151ON 152) 153option ( SLANG_ENABLE_REPLAYER "Enable slang-replay tool" ON ) 154 155option ( 156SLANG_GITHUB_TOKEN 157"Use a given token value for accessing Github REST API" 158"" 159) 160 161advanced_option ( SLANG_USE_SYSTEM_MINIZ "Build using system Miniz library" OFF ) 162advanced_option ( SLANG_USE_SYSTEM_LZ4 "Build using system LZ4 library" OFF ) 163advanced_option ( 164SLANG_USE_SYSTEM_VULKAN_HEADERS 165"Build using system Vulkan headers" 166OFF 167) 168advanced_option ( 169SLANG_USE_SYSTEM_SPIRV_HEADERS 170"Build using system SPIR-V headers" 171OFF 172) 173advanced_option ( 174SLANG_USE_SYSTEM_UNORDERED_DENSE 175"Build using system unordered dense" 176OFF 177) 178advanced_option ( 179SLANG_USE_SYSTEM_SPIRV_TOOLS 180"Build using system SPIR-V tools library" 181OFF 182) 183advanced_option ( 184SLANG_USE_SYSTEM_GLSLANG 185"Build using system glslang library" 186OFF 187) 188if ( WIN32) 189set ( SLANG_ENABLE_SPIRV_TOOLS_MIMALLOC_DEFAULT ON ) 190else () 191set ( SLANG_ENABLE_SPIRV_TOOLS_MIMALLOC_DEFAULT OFF ) 192endif () 193 194advanced_option ( 195SLANG_ENABLE_SPIRV_TOOLS_MIMALLOC 196"Enable mimalloc for SPIRV-Tools to improve compilation performance" 197${ SLANG_ENABLE_SPIRV_TOOLS_MIMALLOC_DEFAULT } 198) 199 200option ( 201SLANG_SPIRV_HEADERS_INCLUDE_DIR 202"Provide a specific path for the SPIR-V headers and grammar files" 203) 204mark_as_advanced ( SLANG_SPIRV_HEADERS_INCLUDE_DIR ) 205 206# Options for user defined paths for external modules. 207# 208# Note that these paths point to a directory containing an subdirectory of the 209# dependency name, rather than to the dependency directory itself, for example 210# SLANG_OVERRIDE_LZ4_PATH points to a directory containing a directory called 211# `lz4` containing the lz4 source. 212# 213advanced_option ( 214SLANG_OVERRIDE_LZ4_PATH 215"Build using user defined path for LZ4" 216OFF 217) 218advanced_option ( 219SLANG_OVERRIDE_MINIZ_PATH 220"Build using user defined path for Miniz" 221OFF 222) 223advanced_option ( 224SLANG_OVERRIDE_UNORDERED_DENSE_PATH 225"Build using user defined path for unordered_dense" 226OFF 227) 228advanced_option ( 229SLANG_OVERRIDE_VULKAN_HEADERS_PATH 230"Build using user defined path for Vulkan headers" 231OFF 232) 233advanced_option ( 234SLANG_OVERRIDE_SPIRV_HEADERS_PATH 235"Build using user defined path for SPIR-V headers" 236OFF 237) 238advanced_option ( 239SLANG_OVERRIDE_SPIRV_TOOLS_PATH 240"Build using user defined path for SPIR-V tools" 241OFF 242) 243advanced_option ( 244SLANG_OVERRIDE_GLSLANG_PATH 245"Build using user defined path for glslang" 246OFF 247) 248advanced_option ( 249SLANG_OVERRIDE_GLM_PATH 250"Build using user defined path for glm" 251OFF 252) 253advanced_option ( 254SLANG_OVERRIDE_IMGUI_PATH 255"Build using user defined path for imgui" 256OFF 257) 258advanced_option ( 259SLANG_OVERRIDE_SLANG_RHI_PATH 260"Build using user defined path for slang-rhi" 261OFF 262) 263advanced_option ( 264SLANG_OVERRIDE_TINYOBJLOADER_PATH 265"Build using user defined path for tinyobjloader" 266OFF 267) 268advanced_option ( 269SLANG_OVERRIDE_LUA_PATH 270"Build using user defined path for lua" 271OFF 272) 273advanced_option ( 274SLANG_OVERRIDE_MIMALLOC_PATH 275"Build using user defined path for mimalloc" 276OFF 277) 278 279advanced_option ( 280SLANG_EXCLUDE_DAWN 281"Optionally exclude webgpu_dawn from the build" 282OFF 283) 284 285advanced_option ( 286SLANG_EXCLUDE_TINT 287"Optionally exclude slang-tint from the build" 288OFF 289) 290 291enum_option ( 292SLANG_LIB_TYPE 293# Default 294SHARED 295"How to build the slang lib:" 296# Options 297SHARED 298"Build slang as a shared library (default)" 299STATIC 300"Build slang as a static library" 301) 302 303option ( 304SLANG_ENABLE_RELEASE_DEBUG_INFO 305"Generate debug info for Release builds" 306ON 307) 308 309option ( SLANG_ENABLE_RELEASE_LTO "Enable LTO for Release builds" OFF ) 310 311option ( 312SLANG_ENABLE_SPLIT_DEBUG_INFO 313"Generate split debug info for debug builds" 314ON 315) 316 317set ( SLANG_GENERATORS_PATH 318"" 319CACHE PATH 320"An optional path to the outputs of the all-generators target compiled for the build platform, used when cross-compiling" 321) 322 323enum_option ( 324SLANG_SLANG_LLVM_FLAVOR 325# Default 326FETCH_BINARY_IF_POSSIBLE 327"How to get or build slang-llvm:" 328# Options 329FETCH_BINARY 330"Use a binary distribution of the slang-llvm library instead of building or using LLVM" 331FETCH_BINARY_IF_POSSIBLE 332"Like FETCH_BINARY, except falls back to DISABLE if a prebuilt slang-llvm can't be downloaded" 333USE_SYSTEM_LLVM 334"Build slang-llvm using system-provided LLVM and Clang binaries" 335DISABLE 336"Do not build llvm or fetch slang-llvm" 337) 338 339if ( SLANG_SLANG_LLVM_FLAVORMATCHES FETCH_BINARY) 340# If the user didn't specify a URL, find the best one now 341if ( NOT SLANG_SLANG_LLVM_BINARY_URL) 342get_best_slang_binary_release_url ( " ${ SLANG_GITHUB_TOKEN } " url ) 343if ( NOT DEFINED url) 344if ( SLANG_SLANG_LLVM_FLAVORSTREQUAL FETCH_BINARY_IF_POSSIBLE) 345message ( 346WARNING 347"Unable to find a prebuilt binary for slang-llvm, Slang will be built without LLVM support. Please consider setting SLANG_SLANG_LLVM_BINARY_URL manually" 348) 349else () 350message ( 351FATAL_ERROR 352"Unable to find binary release for slang-llvm, please set a different SLANG_SLANG_LLVM_FLAVOR or set SLANG_SLANG_LLVM_BINARY_URL manually" 353) 354endif () 355endif () 356endif () 357set ( SLANG_SLANG_LLVM_BINARY_URL 358${ url } 359CACHE STRING 360"URL specifying the location of the slang-llvm prebuilt library" 361) 362endif () 363 364if ( NOT SLANG_EXCLUDE_DAWN) 365set ( webgpu_dawn_release_tag "webgpu_dawn-0" ) 366if ( 367 CMAKE_SYSTEM_NAMEMATCHES "Windows" 368AND CMAKE_SYSTEM_PROCESSORMATCHES "x86_64|amd64|AMD64" 369) 370set ( SLANG_WEBGPU_DAWN_BINARY_URL 371"https://github.com/shader-slang/dawn/releases/download/ ${ webgpu_dawn_release_tag } /webgpu_dawn-windows-x64.zip" 372) 373endif () 374endif () 375 376if ( NOT SLANG_EXCLUDE_TINT) 377set ( slang_tint_release_tag "slang-tint-0" ) 378if ( 379 CMAKE_SYSTEM_NAMEMATCHES "Windows" 380AND CMAKE_SYSTEM_PROCESSORMATCHES "x86_64|amd64|AMD64" 381) 382set ( SLANG_SLANG_TINT_BINARY_URL 383"https://github.com/shader-slang/dawn/releases/download/ ${ slang_tint_release_tag } /slang-tint-windows-x64.zip" 384) 385endif () 386endif () 387 388# 389# Option validation 390# 391 392if ( NOT SLANG_EMBED_CORE_MODULEAND NOT SLANG_EMBED_CORE_MODULE_SOURCE) 393message ( 394SEND_ERROR 395"One of SLANG_EMBED_CORE_MODULE and SLANG_EMBED_CORE_MODULE_SOURCE must be enabled" 396) 397endif () 398 399if ( SLANG_ENABLE_OPTIXAND NOT SLANG_ENABLE_CUDA) 400if ( _SLANG_ENABLE_OPTIX_USER_SPECIFIED) 401message ( 402SEND_ERROR 403"SLANG_ENABLE_OPTIX is not supported without SLANG_ENABLE_CUDA" 404) 405else () 406message ( 407STATUS 408"OptiX is not supported without CUDA. Automatically disabling SLANG_ENABLE_OPTIX." 409) 410set ( SLANG_ENABLE_OPTIX OFF ) 411endif () 412endif () 413 414if ( SLANG_ENABLE_NVAPIAND NOT CMAKE_SYSTEM_NAMEMATCHES "Windows" ) 415message ( SEND_ERROR "SLANG_ENABLE_NVAPI is only supported on Windows" ) 416endif () 417 418if ( SLANG_ENABLE_TESTSAND NOT SLANG_ENABLE_SLANG_RHI) 419message ( SEND_ERROR "SLANG_ENABLE_TESTS requires SLANG_ENABLE_SLANG_RHI" ) 420endif () 421 422# 423# Dependencies, most of these are however handled inside the "auto_option" 424# calls above 425# 426 427find_package ( Threads REQUIRED ) 428 429if (${ SLANG_USE_SYSTEM_UNORDERED_DENSE }) 430find_package ( unordered_dense CONFIG QUIET ) 431endif () 432 433if ( SLANG_USE_SYSTEM_SPIRV_HEADERS) 434find_package ( SPIRV-Headers REQUIRED ) 435endif () 436 437if (${ SLANG_USE_SYSTEM_MINIZ }) 438find_package ( miniz REQUIRED ) 439add_library ( miniz ALIAS miniz::miniz ) 440endif () 441 442if (${ SLANG_USE_SYSTEM_LZ4 }) 443find_package ( lz4 REQUIRED ) 444add_library ( lz4_static ALIAS LZ4::lz4 ) 445endif () 446 447if (${ SLANG_USE_SYSTEM_VULKAN_HEADERS }) 448find_package ( VulkanHeaders REQUIRED ) 449endif () 450 451if (${ SLANG_USE_SYSTEM_SPIRV_TOOLS }) 452find_package ( SPIRV-Tools REQUIRED ) 453endif () 454 455if (${ SLANG_USE_SYSTEM_GLSLANG }) 456find_package ( glslang REQUIRED ) 457add_library ( glslang ALIAS glslang::glslang ) 458endif () 459 460add_subdirectory ( external ) 461 462# webgpu_dawn is only available as a fetched shared library, since Dawn's nested source 463# trees are too large and onerous for us to depend on. 464# We ignore the failure to fetch the library, since it's not required for the build to succeed. 465if ( SLANG_WEBGPU_DAWN_BINARY_URL) 466copy_fetched_shared_library ( 467"webgpu_dawn" 468" ${ SLANG_WEBGPU_DAWN_BINARY_URL } " 469IGNORE_FAILURE 470SLANG_GITHUB_TOKEN ${ SLANG_GITHUB_TOKEN } 471) 472endif () 473 474# slang-tint is only available as a fetched shared library, since it's hosted in the Dawn 475# repository, and Dawn's nested source trees are too large and onerous for us to depend 476# on. 477# We ignore the failure to fetch the library, since it's not required for the build to succeed. 478if ( SLANG_SLANG_TINT_BINARY_URL) 479copy_fetched_shared_library ( 480"slang-tint" 481" ${ SLANG_SLANG_TINT_BINARY_URL } " 482IGNORE_FAILURE 483SLANG_GITHUB_TOKEN ${ SLANG_GITHUB_TOKEN } 484) 485endif () 486 487fetch_or_build_slang_llvm () 488 489# 490# Our targets 491# 492 493add_subdirectory ( source/core ) 494add_subdirectory ( source/slang-rt ) 495add_subdirectory ( source/compiler-core ) 496add_subdirectory ( source/slang-wasm ) 497add_subdirectory ( source/slang-glslang ) 498add_subdirectory ( tools ) 499add_subdirectory ( prelude ) 500add_subdirectory ( source/slang-core-module ) 501add_subdirectory ( source/slang-glsl-module ) 502add_subdirectory ( source/slang ) 503add_subdirectory ( source/slangc ) 504add_subdirectory ( examples ) 505 506# 507# Packaging 508# 509set ( CPACK_ARCHIVE_COMPONENT_INSTALL ON ) 510set ( CPACK_COMPONENTS_ALL_IN_ONE_PACKAGE ON ) 511set ( CPACK_STRIP_FILES FALSE ) 512install ( 513FILES " ${ slang_SOURCE_DIR } /README.md" " ${ slang_SOURCE_DIR } /LICENSE" 514DESTINATION . 515COMPONENT metadata 516EXCLUDE_FROM_ALL 517) 518install ( 519DIRECTORY " ${ slang_SOURCE_DIR } /docs/" 520DESTINATION share/doc/slang 521PATTERN ".*" EXCLUDE 522) 523install ( 524DIRECTORY " ${ slang_SOURCE_DIR } /include" 525DESTINATION . 526PATTERN ".*" EXCLUDE 527) 528include ( CPack ) 529 530# Write basic package config version file using standard CMakePackageConfigHelpers utility 531include ( CMakePackageConfigHelpers ) 532write_basic_package_version_file ( 533" ${ PROJECT_NAME } ConfigVersion.cmake" 534VERSION ${ PROJECT_VERSION } 535COMPATIBILITY SameMajorVersion 536) 537 538# Write SlangConfig.cmake which should allow find_package(SLANG) to work correctly 539# SlangConfig.cmake will define slang::slang target that can be linked with using 540# target_link_libraries. It will also define SLANG_EXECUTABLE export variable that 541# should point to slangc if SLANG_ENABLE_SLANGC is ON. 542if ( WIN32) 543set ( SLANG_CMAKE_CONFIG_DIR cmake ) 544else () 545set ( SLANG_CMAKE_CONFIG_DIR ${ CMAKE_INSTALL_LIBDIR } /cmake/ ${ PROJECT_NAME }) 546endif () 547configure_package_config_file ( 548" ${ PROJECT_SOURCE_DIR } /cmake/SlangConfig.cmake.in" 549" ${ PROJECT_BINARY_DIR } / ${ PROJECT_NAME } Config.cmake" 550INSTALL_DESTINATION ${ SLANG_CMAKE_CONFIG_DIR } 551) 552 553# Conditionally handle the case for Emscripten where slang does not create 554# linkable targets. In this case do not export the targets. Otherwise, just 555# export the slang targets. 556if ( NOT CMAKE_SYSTEM_NAMESTREQUAL "Emscripten" ) 557if ( NOT ${ SLANG_LIB_TYPE } STREQUAL "STATIC" ) 558install ( 559EXPORT SlangTargets 560FILE ${ PROJECT_NAME } Targets.cmake 561NAMESPACE ${ PROJECT_NAME } :: 562DESTINATION ${ SLANG_CMAKE_CONFIG_DIR } 563) 564endif () 565endif () 566 567install ( 568FILES 569" ${ PROJECT_BINARY_DIR } / ${ PROJECT_NAME } Config.cmake" 570" ${ PROJECT_BINARY_DIR } / ${ PROJECT_NAME } ConfigVersion.cmake" 571DESTINATION ${ SLANG_CMAKE_CONFIG_DIR } 572)