yum-mirror/glslang
git clone https://git.yummers.dev/yum-mirror/glslang
31b9aacf
main
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) 149# error() and friends take "" as the format when there is no extra info. 150add_compile_options ( -Wno-format-zero-length) 151if ( NOT ENABLE_RTTI) 152add_compile_options ( -fno-rtti) 153endif () 154if ( NOT ENABLE_EXCEPTIONS) 155add_compile_options ( -fno-exceptions) 156endif () 157if ( NOT CMAKE_CXX_COMPILER_VERSIONVERSION_LESS "9.0.0" ) 158add_compile_options ( -Werror=deprecated-copy) 159endif () 160 161if ( NOT ( CMAKE_SYSTEM_NAMESTREQUAL "OpenBSD" )) 162if ( NOT APPLE) 163# Error if there's symbols that are not found at link time. 164add_link_options ( "-Wl,--no-undefined" ) 165endif () 166endif () 167elseif ( ${ CMAKE_CXX_COMPILER_ID } MATCHES "Clang" AND NOT MSVC) 168add_compile_options ( -Wall -Wuninitialized -Wunused -Wunused-local-typedefs -Wimplicit-fallthrough 169 -Wunused-parameter -Wunused-value -Wunused-variable) 170if ( NOT ENABLE_RTTI) 171add_compile_options ( -fno-rtti) 172endif () 173if ( NOT ENABLE_EXCEPTIONS) 174add_compile_options ( -fno-exceptions) 175endif () 176 177if ( NOT ( CMAKE_SYSTEM_NAMEMATCHES "OpenBSD|Emscripten" )) 178# Error if there's symbols that are not found at link time. Some linkers do not support this flag. 179if ( NOT APPLE) 180add_link_options ( "-Wl,--no-undefined" ) 181endif () 182endif () 183elseif ( MSVC) 184# A unary minus operator was applied to an unsigned type, resulting in an unsigned result. 185add_compile_options ( /w14146) 186# A negative integral constant converted to unsigned type, resulting in a possibly meaningless result. 187add_compile_options ( /w14308) 188# Use of an uninitialized local variable. 189add_compile_options ( /w14700) 190# Use of a potentially uninitialized local pointer variable. 191add_compile_options ( /w14703) 192if ( NOT ENABLE_RTTI) 193add_compile_options ( /GR-) # Disable RTTI 194endif () 195if ( ENABLE_EXCEPTIONS) 196add_compile_options ( /EHsc) # Enable Exceptions 197else () 198string ( REGEX REPLACE"/EHsc" "" CMAKE_CXX_FLAGS" ${ CMAKE_CXX_FLAGS } " ) # Try to remove default /EHsc cxx_flag 199add_compile_options ( /D_HAS_EXCEPTIONS=0) 200endif () 201endif () 202 203if ( PROJECT_IS_TOP_LEVEL) 204# enable parallel builds for msbuild 205list ( APPEND CMAKE_VS_GLOBALS UseMultiToolTask=true) 206list ( APPEND CMAKE_VS_GLOBALS EnforceProcessCountAcrossBuilds=true) 207endif () 208 209# NOTE we could potentially replace this logic with COMPILE_WARNING_AS_ERROR if cmake minimum is bumped to >= 3.24 210if ( BUILD_WERROR) 211if ( NOT MSVC) 212add_compile_options ( -Werror) 213else () 214add_compile_options ( /WX) 215endif () 216endif () 217 218if ( ENABLE_GLSLANG_JS) 219if ( MSVC) 220add_compile_options ( /Os /GR-) 221else () 222add_compile_options ( -Os -fno-rtti -fno-exceptions) 223if ( ${ CMAKE_CXX_COMPILER_ID } MATCHES "Clang" AND NOT MSVC) 224add_compile_options ( -Wno-unused-parameter) 225add_compile_options ( -Wno-unused-variable -Wno-unused-const-variable) 226endif () 227endif () 228endif () 229 230# Request C++17 231set ( CMAKE_CXX_STANDARD 17) 232set ( CMAKE_CXX_STANDARD_REQUIRED ON) 233set ( CMAKE_CXX_EXTENSIONS OFF) 234 235function ( glslang_set_link_args TARGET) 236# For MinGW compiles, statically link against the GCC and C++ runtimes. 237# This avoids the need to ship those runtimes as DLLs. 238# This is supported by GCC and Clang. 239if ( MINGW) 240target_link_options ( ${ TARGET } PRIVATE -static -static-libgcc -static-libstdc++) 241endif () 242endfunction () 243 244# Root directory for build-time generated include files 245set ( GLSLANG_GENERATED_INCLUDEDIR" ${ CMAKE_BINARY_DIR } /include" ) 246 247################################################################################ 248# Build version information generation 249################################################################################ 250include ( parse_version.cmake) 251set ( GLSLANG_CHANGES_FILE" ${ CMAKE_CURRENT_SOURCE_DIR } /CHANGES.md" ) 252set ( GLSLANG_BUILD_INFO_H_TMPL" ${ CMAKE_CURRENT_SOURCE_DIR } /build_info.h.tmpl" ) 253set ( GLSLANG_BUILD_INFO_H" ${ GLSLANG_GENERATED_INCLUDEDIR } /glslang/build_info.h" ) 254 255parse_version ( ${ GLSLANG_CHANGES_FILE } GLSLANG) 256 257function ( configurate_version ) 258set ( major${ GLSLANG_VERSION_MAJOR } ) 259set ( minor${ GLSLANG_VERSION_MINOR } ) 260set ( patch${ GLSLANG_VERSION_PATCH } ) 261set ( flavor${ GLSLANG_VERSION_FLAVOR } ) 262configure_file ( ${ GLSLANG_BUILD_INFO_H_TMPL } ${ GLSLANG_BUILD_INFO_H } @ONLY) 263endfunction () 264 265configurate_version () 266 267# glslang_add_build_info_dependency() adds the glslang-build-info dependency and 268# generated include directories to target. 269function ( glslang_add_build_info_dependency target) 270target_include_directories ( ${ target } PUBLIC$< BUILD_INTERFACE: ${ GLSLANG_GENERATED_INCLUDEDIR }> ) 271endfunction () 272 273# glslang_only_export_explicit_symbols() makes the symbol visibility hidden by 274# default for <target> when building shared libraries, and sets the 275# GLSLANG_IS_SHARED_LIBRARY define, and GLSLANG_EXPORTING to 1 when specifically 276# building <target>. 277function ( glslang_only_export_explicit_symbols target) 278if ( BUILD_SHARED_LIBS) 279target_compile_definitions ( ${ target } PUBLIC"GLSLANG_IS_SHARED_LIBRARY=1" ) 280set_target_properties ( ${ target } PROPERTIES CXX_VISIBILITY_PRESET hidden) 281set_target_properties ( ${ target } PROPERTIES C_VISIBILITY_PRESET hidden) 282if ( WIN32) 283target_compile_definitions ( ${ target } PRIVATE"GLSLANG_EXPORTING=1" ) 284endif () 285endif () 286endfunction () 287 288# glslang_pch() adds precompiled header rules to <target> for the pre-compiled 289# header file <pch>. As target_precompile_headers() was added in CMake 3.16, 290# this is a no-op if called on earlier versions of CMake. 291function ( glslang_pch target pch) 292if ( ENABLE_PCH) 293target_precompile_headers ( ${ target } PRIVATE${ pch } ) 294endif () 295endfunction () 296 297if ( BUILD_EXTERNALAND IS_DIRECTORY ${ CMAKE_CURRENT_SOURCE_DIR } /External) 298# We depend on these for later projects, so they should come first. 299add_subdirectory ( External) 300endif () 301 302option ( 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" ) 303if ( NOT TARGET SPIRV-Tools-opt) 304if ( ALLOW_EXTERNAL_SPIRV_TOOLS) 305# Look for external SPIR-V Tools build, if not building in-tree 306message ( STATUS"Trying to find local SPIR-V tools" ) 307find_package ( SPIRV-Tools-opt) 308if ( NOT TARGET SPIRV-Tools-opt) 309if ( ENABLE_OPT) 310message ( SEND_ERROR"ENABLE_OPT set but SPIR-V tools not found! Disabling SPIR-V optimization." ) 311endif () 312set ( ENABLE_OPT OFF) 313endif () 314else () 315if ( ENABLE_OPT) 316message ( SEND_ERROR"ENABLE_OPT set but SPIR-V tools not found. Please run update_glslang_sources.py, " 317"set the ALLOW_EXTERNAL_SPIRV_TOOLS option to use a local install of SPIRV-Tools, or set ENABLE_OPT=0." ) 318endif () 319endif () 320endif () 321 322if ( ENABLE_OPT) 323message ( STATUS"optimizer enabled" ) 324add_compile_definitions ( ENABLE_OPT=1) 325else () 326if ( ENABLE_HLSL) 327message ( STATUS"spirv-tools not linked - illegal SPIRV may be generated for HLSL" ) 328endif () 329add_compile_definitions ( ENABLE_OPT=0) 330endif () 331 332if ( ENABLE_SPIRV) 333add_subdirectory ( SPIRV) 334endif () 335add_subdirectory ( glslang) 336if ( ENABLE_GLSLANG_BINARIES) 337add_subdirectory ( StandAlone) 338endif () 339 340option ( ALLOW_EXTERNAL_GTEST"Allows to build against installed googletest. This is unsupported if the commit isn't the one in known_good.json" ) 341set ( GMOCK_TARGET gmock) 342if ( NOT TARGET ${ GMOCK_TARGET } ) 343if ( ALLOW_EXTERNAL_GTEST) 344message ( STATUS"Trying to find local googletest" ) 345find_package ( GTest) 346if ( TARGET GTest::gmock) 347set ( GMOCK_TARGET GTest::gmock) 348endif () 349endif () 350endif () 351 352if ( GLSLANG_TESTS) 353enable_testing () 354add_subdirectory ( gtests) 355 356# glslang-testsuite runs a bash script on Windows. 357# Make sure to use '-o igncr' flag to ignore carriage returns (\r). 358set ( IGNORE_CR_FLAG"" ) 359if ( WIN32) 360set ( IGNORE_CR_FLAG -o igncr) 361endif () 362 363if ( isMultiConfig) 364set ( RESULTS_PATH${ CMAKE_CURRENT_BINARY_DIR } /$< CONFIG> /localResults) 365set ( VALIDATOR_PATH${ CMAKE_CURRENT_BINARY_DIR } /StandAlone/$< CONFIG> /glslang) 366else () 367set ( RESULTS_PATH${ CMAKE_CURRENT_BINARY_DIR } /localResults) 368set ( VALIDATOR_PATH${ CMAKE_CURRENT_BINARY_DIR } /StandAlone/glslang) 369endif () 370 371# The TARGET_RUNTIME_DLL_DIRS feature requires CMake 3.27 or greater. 372if ( WIN32AND BUILD_SHARED_LIBSAND CMAKE_VERSIONVERSION_LESS "3.27" ) 373message ( WARNING"The Windows shared library test configuration requires CMake 3.27 or greater" ) 374else () 375if ( ENABLE_HLSL) 376set ( HLSL_ARG 1) 377else () 378set ( HLSL_ARG 0) 379endif () 380add_test ( NAME glslang-testsuite 381 COMMAND bash${ IGNORE_CR_FLAG } runtests${ RESULTS_PATH } ${ VALIDATOR_PATH } ${ HLSL_ARG } 382 WORKING_DIRECTORY${ CMAKE_CURRENT_SOURCE_DIR } /Test/) 383 384# Prepend paths to shared libraries. 385if ( BUILD_SHARED_LIBS) 386set_tests_properties ( glslang-testsuite PROPERTIES ENVIRONMENT_MODIFICATION"PATH=path_list_prepend: $< JOIN: $< TARGET_RUNTIME_DLL_DIRS: glslang-standalone> , \;> " ) 387endif () 388endif () 389endif () 390 391if ( GLSLANG_ENABLE_INSTALL) 392file ( WRITE" ${ CMAKE_CURRENT_BINARY_DIR } /glslang-config.cmake.in" [=[ 393@PACKAGE_INIT@ 394include(CMakeFindDependencyMacro) 395if(@ENABLE_OPT@) 396find_dependency(SPIRV-Tools-opt) 397endif() 398@INSTALL_CONFIG_UNIX@ 399include("@PACKAGE_PATH_EXPORT_TARGETS@") 400]=] ) 401 402set ( PATH_EXPORT_TARGETS" ${ CMAKE_INSTALL_LIBDIR } /cmake/ ${ PROJECT_NAME } /glslang-targets.cmake" ) 403if ( UNIXOR " ${ CMAKE_SYSTEM_NAME } " STREQUAL "Fuchsia" ) 404set ( INSTALL_CONFIG_UNIX[=[ 405set(THREADS_PREFER_PTHREAD_FLAG ON) 406find_dependency(Threads) 407]=] ) 408endif () 409configure_package_config_file ( 410" ${ CMAKE_CURRENT_BINARY_DIR } /glslang-config.cmake.in" 411" ${ CMAKE_CURRENT_BINARY_DIR } /glslang-config.cmake" 412 PATH_VARS 413 PATH_EXPORT_TARGETS 414 INSTALL_DESTINATION${ CMAKE_INSTALL_LIBDIR } /cmake/${ PROJECT_NAME } 415) 416 417write_basic_package_version_file ( " ${ CMAKE_CURRENT_BINARY_DIR } /glslang-config-version.cmake" 418 VERSION${ GLSLANG_VERSION } 419 COMPATIBILITY SameMajorVersion 420) 421 422install ( 423 EXPORT glslang-targets 424 NAMESPACE"glslang::" 425 DESTINATION" ${ CMAKE_INSTALL_LIBDIR } /cmake/ ${ PROJECT_NAME } " 426) 427 428install ( 429 FILES 430" ${ CMAKE_CURRENT_BINARY_DIR } /glslang-config.cmake" 431" ${ CMAKE_CURRENT_BINARY_DIR } /glslang-config-version.cmake" 432 DESTINATION 433" ${ CMAKE_INSTALL_LIBDIR } /cmake/ ${ PROJECT_NAME } " 434) 435endif ()