yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
7a6a455f1
master
1# 2# Given a list of flags, add those which the C++ compiler supports to the target 3# 4include ( CheckCXXCompilerFlag ) 5function ( add_supported_cxx_flags target ) 6cmake_parse_arguments ( ARG "PRIVATE;PUBLIC;INTERFACE" "" "" ${ ARGN }) 7set ( flags ${ ARG_UNPARSED_ARGUMENTS }) 8if ( ARG_PRIVATE) 9set ( private PRIVATE ) 10endif () 11if ( ARG_PUBLIC) 12set ( public PUBLIC ) 13endif () 14if ( ARG_INTERFACE) 15set ( interface INTERFACE ) 16endif () 17 18foreach ( flag${ flags }) 19# remove the `no-` prefix from warnings because gcc doesn't treat it as an 20# error on its own 21string ( REGEX REPLACE "\\-Wno\\-(.+)" "-W\\1" flag_to_test " ${ flag } " ) 22string ( 23REGEX REPLACE 24"[^a-zA-Z0-9]+" 25"_" 26test_name 27"CXXFLAG_ ${ flag_to_test } " 28) 29check_cxx_compiler_flag ( " ${ flag_to_test } " ${ test_name }) 30if (${ test_name }) 31target_compile_options ( 32${ target } 33${ private } 34${ public } 35${ interface } 36${ flag } 37) 38endif () 39endforeach () 40endfunction () 41 42# 43# Given a list of linker flags, add those which the compiler supports to the 44# target 45# 46include ( CheckLinkerFlag ) 47function ( add_supported_cxx_linker_flags target ) 48cmake_parse_arguments ( ARG "PRIVATE;PUBLIC;INTERFACE;BEFORE" "" "" ${ ARGN }) 49set ( flags ${ ARG_UNPARSED_ARGUMENTS }) 50if ( ARG_BEFORE) 51set ( before BEFORE ) 52endif () 53if ( ARG_PRIVATE) 54set ( private PRIVATE ) 55endif () 56if ( ARG_PUBLIC) 57set ( public PUBLIC ) 58endif () 59if ( ARG_INTERFACE) 60set ( interface INTERFACE ) 61endif () 62 63foreach ( flag${ flags }) 64string ( 65REGEX REPLACE 66"[^a-zA-Z0-9]+" 67"_" 68test_name 69"CXXLINKFLAG_ ${ flag } " 70) 71check_linker_flag ( CXX " ${ flag } " ${ test_name }) 72if (${ test_name }) 73target_link_options ( 74${ target } 75${ before } 76${ private } 77${ public } 78${ interface } 79${ flag } 80) 81endif () 82endforeach () 83endfunction () 84 85# 86# Add our default compiler flags to a target 87# 88# Pass USE_EXTRA_WARNINGS to enable -WExtra or /W3 89# 90function ( set_default_compile_options target ) 91cmake_parse_arguments ( 92ARG 93"USE_EXTRA_WARNINGS;USE_FEWER_WARNINGS" 94"" 95"" 96${ ARGN } 97) 98 99set ( warning_flags ) 100if ( CMAKE_CXX_COMPILER_IDMATCHES "GNU|Clang" ) 101list ( 102APPEND 103warning_flags 104-Wall 105# Disabled warnings: 106-Wno-switch 107-Wno-parentheses 108-Wno-unused-local-typedefs 109-Wno-class-memaccess 110-Wno-assume 111-Wno-reorder 112-Wno-invalid-offsetof 113-Wno-newline-eof 114-Wno-return-std-move 115# Allowed warnings: 116# If a function returns an address/reference to a local, we want it to 117# produce an error, because it probably means something very bad. 118-Werror=return-local-addr 119# Allow unused variables with a pattern of `if (auto v = as<...>(...))`. 120# This pattern is very common in Slang code base. 121-Wno-error=unused-but-set-variable 122# Some warnings which are on by default in MSVC 123-Wnarrowing 124) 125if ( ARG_USE_EXTRA_WARNINGS) 126list ( APPEND warning_flags -Wextra ) 127endif () 128if ( ARG_USE_FEWER_WARNINGS) 129list ( 130APPEND 131warning_flags 132-Wno-class-memaccess 133-Wno-unused-variable 134-Wno-unused-parameter 135-Wno-sign-compare 136-Wno-unused-function 137-Wno-unused-value 138-Wno-unused-but-set-variable 139-Wno-implicit-fallthrough 140-Wno-missing-field-initializers 141-Wno-strict-aliasing 142-Wno-maybe-uninitialized 143) 144endif () 145elseif ( CMAKE_CXX_COMPILER_IDMATCHES "MSVC" ) 146list ( APPEND warning_flags ) 147if ( ARG_USE_EXTRA_WARNINGS) 148list ( APPEND warning_flags /W4 ) 149elseif ( ARG_USE_FEWER_WARNINGS) 150list ( APPEND warning_flags /W0 ) 151else () 152list ( APPEND warning_flags /W2 ) 153endif () 154endif () 155 156add_supported_cxx_flags ( $ { target } PRIVATE ${ warning_flags }) 157 158if ( NOT WIN32) 159# these options are for ELF specific and not for Windows 160add_supported_cxx_linker_flags ( 161${ target } 162PRIVATE 163# Don't assume that symbols will be resolved at runtime 164"-Wl,--no-undefined" 165# No reason not to do this? Useful when using split debug info 166"-Wl,--build-id" 167) 168endif () 169 170set_target_properties ( 171${ target } 172PROPERTIES # -fvisibility=hidden 173CXX_VISIBILITY_PRESET 174hidden 175C_VISIBILITY_PRESET 176hidden 177VISIBILITY_INLINES_HIDDEN 178ON 179# C++ standard 180CXX_STANDARD 18120 182# pic 183POSITION_INDEPENDENT_CODE 184ON 185) 186 187target_compile_definitions ( 188${ target } 189PRIVATE # Add _DEBUG depending on the build configuration 190$ < $ <CONFIG:Debug>:_DEBUG> 191# For including windows.h in a way that minimized namespace 192# pollution. Although we define these here, we still set them 193# manually in any header files which may be included by another 194# project 195WIN32_LEAN_AND_MEAN 196VC_EXTRALEAN 197NOMINMAX 198# Use multi-byte character set on Windows 199UNICODE 200_UNICODE 201) 202 203# 204# Settings dependent on config options 205# 206 207target_compile_definitions ( 208${ target } 209PRIVATE 210SLANG_ENABLE_DXIL_SUPPORT= $ <BOOL: ${ SLANG_ENABLE_DXIL } > 211$ < $ <BOOL: ${ SLANG_ENABLE_FULL_DEBUG_VALIDATION } >:SLANG_ENABLE_FULL_IR_VALIDATION> 212$ < $ <BOOL: ${ SLANG_ENABLE_IR_BREAK_ALLOC } >:SLANG_ENABLE_IR_BREAK_ALLOC> 213$ < $ <BOOL: ${ SLANG_ENABLE_DX_ON_VK } >:SLANG_CONFIG_DX_ON_VK> 214$ < $ <STREQUAL: ${ SLANG_LIB_TYPE } ,STATIC>:STB_IMAGE_STATIC> 215) 216 217if ( SLANG_ENABLE_ASAN) 218add_supported_cxx_flags ( 219${ target } 220PRIVATE 221/fsanitize=address 222-fsanitize=address 223) 224add_supported_cxx_linker_flags ( 225${ target } 226BEFORE 227PUBLIC 228/INCREMENTAL:NO 229-fsanitize=address 230) 231endif () 232endfunction ()