yum-mirror/glslang
git clone https://git.yummers.dev/yum-mirror/glslang
5ccb6159
vulkan-sdk-1.4.357.0
1# Copyright (C) 2020-2025 The Khronos Group Inc. 2# 3# All rights reserved. 4# 5# Redistribution and use in source and binary forms, with or without 6# modification, are permitted provided that the following conditions 7# are met: 8# 9# Redistributions of source code must retain the above copyright 10# notice, this list of conditions and the following disclaimer. 11# 12# Redistributions in binary form must reproduce the above 13# copyright notice, this list of conditions and the following 14# disclaimer in the documentation and/or other materials provided 15# with the distribution. 16# 17# Neither the name of The Khronos Group Inc. nor the names of its 18# contributors may be used to endorse or promote products derived 19# from this software without specific prior written permission. 20# 21# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 24# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 25# COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 26# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 27# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 28# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 29# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 31# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32# POSSIBILITY OF SUCH DAMAGE. 33cmake_minimum_required ( VERSION 3.22.1) 34project ( glslang) 35 36set ( GLSLANG_TESTS_DEFAULT ON) # Can be turned off, below, based on environment. 37set ( GLSLANG_ENABLE_INSTALL_DEFAULT ON) # Can be turned off, below, based on environment. 38 39set_property ( GLOBAL PROPERTY USE_FOLDERS ON) # Can be removed when min is 3.26 see policy CMP0143. 40 41# Adhere to GNU filesystem layout conventions 42include ( GNUInstallDirs) 43include ( CMakePackageConfigHelpers) 44 45# Needed for cmake_dependent_option macro 46include ( CMakeDependentOption) 47 48option ( BUILD_EXTERNAL"Build external dependencies in /External" ON) 49option ( BUILD_WERROR"Enable warnings as errors (default is OFF)" OFF) 50 51set ( LIB_TYPE STATIC) 52 53if ( BUILD_SHARED_LIBS) 54set ( LIB_TYPE SHARED) 55endif () 56 57get_cmake_property ( isMultiConfig"GENERATOR_IS_MULTI_CONFIG" ) 58if ( NOT isMultiConfigAND NOT CMAKE_BUILD_TYPE) 59# This logic inside SPIRV-Tools, which can upset build target dependencies 60# if changed after targets are already defined. To prevent these issues, 61# ensure CMAKE_BUILD_TYPE is assigned early and at the glslang root scope. 62message ( STATUS"No build type selected, default to Debug" ) 63set ( CMAKE_BUILD_TYPE"Debug" ) 64endif () 65 66# Currently iOS and Android are very similar. 67# They both have their own packaging (APP/APK). 68# Which makes regular executables/testing problematic. 69# 70# Currently the only deliverables for these platforms are 71# libraries (either STATIC or SHARED). 72# 73# Furthermore testing is equally problematic. 74if ( IOSOR ANDROID) 75set ( ENABLE_GLSLANG_BINARIES OFF) 76set ( GLSLANG_TESTS_DEFAULT OFF) 77endif () 78 79# Simplify the default case of including this project. 80# Otherwise add_subdirectory users have a harder time consuming the library. 81# Since glslang will pollute the installation and add undesirable testing. 82if ( NOT PROJECT_IS_TOP_LEVEL) 83set ( GLSLANG_TESTS_DEFAULT OFF) 84set ( GLSLANG_ENABLE_INSTALL_DEFAULT OFF) 85endif () 86 87# Control whether Glslang self-tests are built and tested. 88# Always expose this as an option, so the defaults can be overridden. 89option ( GLSLANG_TESTS"Enable glslang testing" ${ GLSLANG_TESTS_DEFAULT } ) 90 91# Control whether to install Glslang. 92# Always expose this as an option, so the defaults can be overridden. 93option ( GLSLANG_ENABLE_INSTALL"Enable glslang installation" ${ GLSLANG_ENABLE_INSTALL_DEFAULT } ) 94 95option ( ENABLE_SPIRV"Enables SPIRV output support" ON) 96 97option ( ENABLE_GLSLANG_BINARIES"Builds glslang" ON) 98 99option ( ENABLE_GLSLANG_JS"If using Emscripten, build glslang.js. Otherwise, builds a sample executable for binary-size testing." ) 100cmake_dependent_option ( ENABLE_EMSCRIPTEN_SINGLE_FILE 101"If using Emscripten, enables SINGLE_FILE build" 102 OFF"ENABLE_GLSLANG_JS AND EMSCRIPTEN" 103 OFF) 104cmake_dependent_option ( ENABLE_EMSCRIPTEN_ENVIRONMENT_NODE 105"If using Emscripten, builds to run on Node instead of Web" 106 OFF"ENABLE_GLSLANG_JS AND EMSCRIPTEN" 107 OFF) 108 109option ( ENABLE_HLSL"Enables HLSL input support" ON) 110if ( ENABLE_HLSL) 111message ( DEPRECATION 112"ENABLE_HLSL is deprecated. The HLSL front-end will be removed in " 113"a future major release of glslang. " 114"See https://github.com/KhronosGroup/glslang/issues/4210 for details." ) 115endif () 116option ( ENABLE_RTTI"Enables RTTI" ) 117option ( ENABLE_EXCEPTIONS"Enables Exceptions" ) 118cmake_dependent_option ( ENABLE_OPT"Enables spirv-opt capability if present" ON"ENABLE_SPIRV" OFF) 119 120if ( MINGWOR ( APPLEAND ${ CMAKE_CXX_COMPILER_ID } MATCHES "GNU" )) 121# Workaround for CMake behavior on Mac OS with gcc, cmake generates -Xarch_* arguments 122# which gcc rejects 123set ( ENABLE_PCH OFF) 124message ( NOTICE"Disabling PCH" ) 125endif () 126 127option ( ENABLE_PCH"Enables Precompiled header" ON) 128 129if ( ENABLE_SPIRV) 130add_compile_definitions ( ENABLE_SPIRV) 131endif () 132 133if ( ENABLE_HLSL) 134add_compile_definitions ( ENABLE_HLSL) 135endif () 136 137if ( WIN32) 138set ( CMAKE_DEBUG_POSTFIX"d" ) 139add_compile_definitions ( GLSLANG_OSINCLUDE_WIN32) 140elseif ( UNIXOR ANDROID) 141add_compile_definitions ( GLSLANG_OSINCLUDE_UNIX) 142else () 143message ( "unknown platform" ) 144endif () 145 146if ( ${ CMAKE_CXX_COMPILER_ID } MATCHES "GNU" ) 147add_compile_options ( -Wall -Wmaybe-uninitialized -Wuninitialized -Wunused -Wunused-local-typedefs -Wimplicit-fallthrough 148 -Wunused-parameter -Wunused-value -Wunused-variable -Wunused-but-set-parameter -Wunused-but-set-variable) 149if ( NOT ENABLE_RTTI) 150add_compile_options ( -fno-rtti) 151endif () 152if ( NOT ENABLE_EXCEPTIONS) 153add_compile_options ( -fno-exceptions) 154endif () 155if ( NOT CMAKE_CXX_COMPILER_VERSIONVERSION_LESS "9.0.0" ) 156add_compile_options ( -Werror=deprecated-copy) 157endif () 158 159if ( NOT ( CMAKE_SYSTEM_NAMESTREQUAL "OpenBSD" )) 160if ( NOT APPLE) 161# Error if there's symbols that are not found at link time. 162add_link_options ( "-Wl,--no-undefined" ) 163endif () 164endif () 165elseif ( ${ CMAKE_CXX_COMPILER_ID } MATCHES "Clang" AND NOT MSVC) 166add_compile_options ( -Wall -Wuninitialized -Wunused -Wunused-local-typedefs -Wimplicit-fallthrough 167 -Wunused-parameter -Wunused-value -Wunused-variable) 168if ( NOT ENABLE_RTTI) 169add_compile_options ( -fno-rtti) 170endif () 171if ( NOT ENABLE_EXCEPTIONS) 172add_compile_options ( -fno-exceptions) 173endif () 174 175if ( NOT ( CMAKE_SYSTEM_NAMEMATCHES "OpenBSD|Emscripten" )) 176# Error if there's symbols that are not found at link time. Some linkers do not support this flag. 177if ( NOT APPLE) 178add_link_options ( "-Wl,--no-undefined" ) 179endif () 180endif () 181elseif ( MSVC) 182# A unary minus operator was applied to an unsigned type, resulting in an unsigned result. 183add_compile_options ( /w14146) 184# A negative integral constant converted to unsigned type, resulting in a possibly meaningless result. 185add_compile_options ( /w14308) 186# Use of an uninitialized local variable. 187add_compile_options ( /w14700) 188# Use of a potentially uninitialized local pointer variable. 189add_compile_options ( /w14703) 190if ( NOT ENABLE_RTTI) 191add_compile_options ( /GR-) # Disable RTTI 192endif () 193if ( ENABLE_EXCEPTIONS) 194add_compile_options ( /EHsc) # Enable Exceptions 195else () 196string ( REGEX REPLACE"/EHsc" "" CMAKE_CXX_FLAGS" ${ CMAKE_CXX_FLAGS } " ) # Try to remove default /EHsc cxx_flag 197add_compile_options ( /D_HAS_EXCEPTIONS=0) 198endif () 199endif () 200 201if ( PROJECT_IS_TOP_LEVEL) 202# enable parallel builds for msbuild 203list ( APPEND CMAKE_VS_GLOBALS UseMultiToolTask=true) 204list ( APPEND CMAKE_VS_GLOBALS EnforceProcessCountAcrossBuilds=true) 205endif () 206 207# NOTE we could potentially replace this logic with COMPILE_WARNING_AS_ERROR if cmake minimum is bumped to >= 3.24 208if ( BUILD_WERROR) 209if ( NOT MSVC) 210add_compile_options ( -Werror) 211else () 212add_compile_options ( /WX) 213endif () 214endif () 215 216if ( ENABLE_GLSLANG_JS) 217if ( MSVC) 218add_compile_options ( /Os /GR-) 219else () 220add_compile_options ( -Os -fno-rtti -fno-exceptions) 221if ( ${ CMAKE_CXX_COMPILER_ID } MATCHES "Clang" AND NOT MSVC) 222add_compile_options ( -Wno-unused-parameter) 223add_compile_options ( -Wno-unused-variable -Wno-unused-const-variable) 224endif () 225endif () 226endif () 227 228# Request C++17 229set ( CMAKE_CXX_STANDARD 17) 230set ( CMAKE_CXX_STANDARD_REQUIRED ON) 231set ( CMAKE_CXX_EXTENSIONS OFF) 232 233function ( glslang_set_link_args TARGET) 234# For MinGW compiles, statically link against the GCC and C++ runtimes. 235# This avoids the need to ship those runtimes as DLLs. 236# This is supported by GCC and Clang. 237if ( MINGW) 238target_link_options ( ${ TARGET } PRIVATE -static -static-libgcc -static-libstdc++) 239endif () 240endfunction () 241 242# Root directory for build-time generated include files 243set ( GLSLANG_GENERATED_INCLUDEDIR" ${ CMAKE_BINARY_DIR } /include" ) 244 245################################################################################ 246# Build version information generation 247################################################################################ 248include ( parse_version.cmake) 249set ( GLSLANG_CHANGES_FILE" ${ CMAKE_CURRENT_SOURCE_DIR } /CHANGES.md" ) 250set ( GLSLANG_BUILD_INFO_H_TMPL" ${ CMAKE_CURRENT_SOURCE_DIR } /build_info.h.tmpl" ) 251set ( GLSLANG_BUILD_INFO_H" ${ GLSLANG_GENERATED_INCLUDEDIR } /glslang/build_info.h" ) 252 253parse_version ( ${ GLSLANG_CHANGES_FILE } GLSLANG) 254 255function ( configurate_version ) 256set ( major${ GLSLANG_VERSION_MAJOR } ) 257set ( minor${ GLSLANG_VERSION_MINOR } ) 258set ( patch${ GLSLANG_VERSION_PATCH } ) 259set ( flavor${ GLSLANG_VERSION_FLAVOR } ) 260configure_file ( ${ GLSLANG_BUILD_INFO_H_TMPL } ${ GLSLANG_BUILD_INFO_H } @ONLY) 261endfunction () 262 263configurate_version () 264 265# glslang_add_build_info_dependency() adds the glslang-build-info dependency and 266# generated include directories to target. 267function ( glslang_add_build_info_dependency target) 268target_include_directories ( ${ target } PUBLIC$< BUILD_INTERFACE: ${ GLSLANG_GENERATED_INCLUDEDIR }> ) 269endfunction () 270 271# glslang_only_export_explicit_symbols() makes the symbol visibility hidden by 272# default for <target> when building shared libraries, and sets the 273# GLSLANG_IS_SHARED_LIBRARY define, and GLSLANG_EXPORTING to 1 when specifically 274# building <target>. 275function ( glslang_only_export_explicit_symbols target) 276if ( BUILD_SHARED_LIBS) 277target_compile_definitions ( ${ target } PUBLIC"GLSLANG_IS_SHARED_LIBRARY=1" ) 278set_target_properties ( ${ target } PROPERTIES CXX_VISIBILITY_PRESET hidden) 279set_target_properties ( ${ target } PROPERTIES C_VISIBILITY_PRESET hidden) 280if ( WIN32) 281target_compile_definitions ( ${ target } PRIVATE"GLSLANG_EXPORTING=1" ) 282endif () 283endif () 284endfunction () 285 286# glslang_pch() adds precompiled header rules to <target> for the pre-compiled 287# header file <pch>. As target_precompile_headers() was added in CMake 3.16, 288# this is a no-op if called on earlier versions of CMake. 289function ( glslang_pch target pch) 290if ( ENABLE_PCH) 291target_precompile_headers ( ${ target } PRIVATE${ pch } ) 292endif () 293endfunction () 294 295if ( BUILD_EXTERNALAND IS_DIRECTORY ${ CMAKE_CURRENT_SOURCE_DIR } /External) 296# We depend on these for later projects, so they should come first. 297add_subdirectory ( External) 298endif () 299 300option ( ALLOW_EXTERNAL_SPIRV_TOOLS"Allows to build against installed SPIRV-Tools-opt. This is unsupported if the commit isn't the one in known_good.json" ) 301if ( NOT TARGET SPIRV-Tools-opt) 302if ( ALLOW_EXTERNAL_SPIRV_TOOLS) 303# Look for external SPIR-V Tools build, if not building in-tree 304message ( STATUS"Trying to find local SPIR-V tools" ) 305find_package ( SPIRV-Tools-opt) 306if ( NOT TARGET SPIRV-Tools-opt) 307if ( ENABLE_OPT) 308message ( SEND_ERROR"ENABLE_OPT set but SPIR-V tools not found! Disabling SPIR-V optimization." ) 309endif () 310set ( ENABLE_OPT OFF) 311endif () 312else () 313if ( ENABLE_OPT) 314message ( SEND_ERROR"ENABLE_OPT set but SPIR-V tools not found. Please run update_glslang_sources.py, " 315"set the ALLOW_EXTERNAL_SPIRV_TOOLS option to use a local install of SPIRV-Tools, or set ENABLE_OPT=0." ) 316endif () 317endif () 318endif () 319 320if ( ENABLE_OPT) 321message ( STATUS"optimizer enabled" ) 322add_compile_definitions ( ENABLE_OPT=1) 323else () 324if ( ENABLE_HLSL) 325message ( STATUS"spirv-tools not linked - illegal SPIRV may be generated for HLSL" ) 326endif () 327add_compile_definitions ( ENABLE_OPT=0) 328endif () 329 330if ( ENABLE_SPIRV) 331add_subdirectory ( SPIRV) 332endif () 333add_subdirectory ( glslang) 334if ( ENABLE_GLSLANG_BINARIES) 335add_subdirectory ( StandAlone) 336endif () 337 338option ( ALLOW_EXTERNAL_GTEST"Allows to build against installed googletest. This is unsupported if the commit isn't the one in known_good.json" ) 339set ( GMOCK_TARGET gmock) 340if ( NOT TARGET ${ GMOCK_TARGET } ) 341if ( ALLOW_EXTERNAL_GTEST) 342message ( STATUS"Trying to find local googletest" ) 343find_package ( GTest) 344if ( TARGET GTest::gmock) 345set ( GMOCK_TARGET GTest::gmock) 346endif () 347endif () 348endif () 349 350if ( GLSLANG_TESTS) 351enable_testing () 352add_subdirectory ( gtests) 353 354# glslang-testsuite runs a bash script on Windows. 355# Make sure to use '-o igncr' flag to ignore carriage returns (\r). 356set ( IGNORE_CR_FLAG"" ) 357if ( WIN32) 358set ( IGNORE_CR_FLAG -o igncr) 359endif () 360 361if ( isMultiConfig) 362set ( RESULTS_PATH${ CMAKE_CURRENT_BINARY_DIR } /$< CONFIG> /localResults) 363set ( VALIDATOR_PATH${ CMAKE_CURRENT_BINARY_DIR } /StandAlone/$< CONFIG> /glslang) 364else () 365set ( RESULTS_PATH${ CMAKE_CURRENT_BINARY_DIR } /localResults) 366set ( VALIDATOR_PATH${ CMAKE_CURRENT_BINARY_DIR } /StandAlone/glslang) 367endif () 368 369# The TARGET_RUNTIME_DLL_DIRS feature requires CMake 3.27 or greater. 370if ( WIN32AND BUILD_SHARED_LIBSAND CMAKE_VERSIONVERSION_LESS "3.27" ) 371message ( WARNING"The Windows shared library test configuration requires CMake 3.27 or greater" ) 372else () 373if ( ENABLE_HLSL) 374set ( HLSL_ARG 1) 375else () 376set ( HLSL_ARG 0) 377endif () 378add_test ( NAME glslang-testsuite 379 COMMAND bash${ IGNORE_CR_FLAG } runtests${ RESULTS_PATH } ${ VALIDATOR_PATH } ${ HLSL_ARG } 380 WORKING_DIRECTORY${ CMAKE_CURRENT_SOURCE_DIR } /Test/) 381 382# Prepend paths to shared libraries. 383if ( BUILD_SHARED_LIBS) 384set_tests_properties ( glslang-testsuite PROPERTIES ENVIRONMENT_MODIFICATION"PATH=path_list_prepend: $< JOIN: $< TARGET_RUNTIME_DLL_DIRS: glslang-standalone> , \;> " ) 385endif () 386endif () 387endif () 388 389if ( GLSLANG_ENABLE_INSTALL) 390file ( WRITE" ${ CMAKE_CURRENT_BINARY_DIR } /glslang-config.cmake.in" [=[ 391@PACKAGE_INIT@ 392include(CMakeFindDependencyMacro) 393if(@ENABLE_OPT@) 394find_dependency(SPIRV-Tools-opt) 395endif() 396@INSTALL_CONFIG_UNIX@ 397include("@PACKAGE_PATH_EXPORT_TARGETS@") 398]=] ) 399 400set ( PATH_EXPORT_TARGETS" ${ CMAKE_INSTALL_LIBDIR } /cmake/ ${ PROJECT_NAME } /glslang-targets.cmake" ) 401if ( UNIXOR " ${ CMAKE_SYSTEM_NAME } " STREQUAL "Fuchsia" ) 402set ( INSTALL_CONFIG_UNIX[=[ 403set(THREADS_PREFER_PTHREAD_FLAG ON) 404find_dependency(Threads) 405]=] ) 406endif () 407configure_package_config_file ( 408" ${ CMAKE_CURRENT_BINARY_DIR } /glslang-config.cmake.in" 409" ${ CMAKE_CURRENT_BINARY_DIR } /glslang-config.cmake" 410 PATH_VARS 411 PATH_EXPORT_TARGETS 412 INSTALL_DESTINATION${ CMAKE_INSTALL_LIBDIR } /cmake/${ PROJECT_NAME } 413) 414 415write_basic_package_version_file ( " ${ CMAKE_CURRENT_BINARY_DIR } /glslang-config-version.cmake" 416 VERSION${ GLSLANG_VERSION } 417 COMPATIBILITY SameMajorVersion 418) 419 420install ( 421 EXPORT glslang-targets 422 NAMESPACE"glslang::" 423 DESTINATION" ${ CMAKE_INSTALL_LIBDIR } /cmake/ ${ PROJECT_NAME } " 424) 425 426install ( 427 FILES 428" ${ CMAKE_CURRENT_BINARY_DIR } /glslang-config.cmake" 429" ${ CMAKE_CURRENT_BINARY_DIR } /glslang-config-version.cmake" 430 DESTINATION 431" ${ CMAKE_INSTALL_LIBDIR } /cmake/ ${ PROJECT_NAME } " 432) 433endif ()