yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
4721b6ef2
master
1# A convenience on top of the llvm package's cmake files, this creates a target 2# to pass to target_link_libraries which correctly pulls in the llvm include 3# dir and other compile dependencies 4function ( llvm_target_from_components target_name ) 5set ( components ${ ARGN }) 6llvm_map_components_to_libnames ( llvm_libs 7${ components } 8) 9add_library ( $ { target_name } INTERFACE ) 10target_link_libraries ( $ { target_name } INTERFACE ${ llvm_libs }) 11target_include_directories ( 12${ target_name } 13SYSTEM 14INTERFACE ${ LLVM_INCLUDE_DIRS } 15) 16target_compile_definitions ( $ { target_name } INTERFACE ${ LLVM_DEFINITIONS }) 17if ( NOT LLVM_ENABLE_RTTI) 18# Make sure that we don't disable rtti if this library wasn't compiled with 19# support 20add_supported_cxx_flags ( $ { target_name } INTERFACE -fno-rtti /GR- ) 21endif () 22endfunction () 23 24# The same for clang 25function ( clang_target_from_libs target_name ) 26set ( clang_libs ${ ARGN }) 27add_library ( $ { target_name } INTERFACE ) 28target_link_libraries ( $ { target_name } INTERFACE ${ clang_libs }) 29target_include_directories ( 30${ target_name } 31SYSTEM 32INTERFACE ${ CLANG_INCLUDE_DIRS } 33) 34target_compile_definitions ( $ { target_name } INTERFACE ${ CLANG_DEFINITIONS }) 35if ( NOT LLVM_ENABLE_RTTI) 36# Make sure that we don't disable rtti if this library wasn't compiled with 37# support 38add_supported_cxx_flags ( $ { target_name } INTERFACE -fno-rtti /GR- ) 39endif () 40endfunction () 41 42function ( fetch_or_build_slang_llvm ) 43if ( SLANG_SLANG_LLVM_FLAVORSTREQUAL "FETCH_BINARY" ) 44install_fetched_shared_library ( 45"slang-llvm" 46" ${ SLANG_SLANG_LLVM_BINARY_URL } " 47) 48elseif ( SLANG_SLANG_LLVM_FLAVORSTREQUAL "FETCH_BINARY_IF_POSSIBLE" ) 49if ( SLANG_SLANG_LLVM_BINARY_URL) 50install_fetched_shared_library ( 51"slang-llvm" 52" ${ SLANG_SLANG_LLVM_BINARY_URL } " 53IGNORE_FAILURE 54) 55if ( NOT TARGET slang-llvm) 56message ( 57WARNING 58"Unable to fetch slang-llvm prebuilt binary, configuring without LLVM support" 59) 60endif () 61endif () 62elseif ( SLANG_SLANG_LLVM_FLAVORSTREQUAL "USE_SYSTEM_LLVM" ) 63find_package ( LLVM 14.0 REQUIRED CONFIG ) 64find_package ( Clang REQUIRED CONFIG ) 65 66llvm_target_from_components ( llvm-dep filecheck native orcjit ) 67clang_target_from_libs ( 68clang-dep 69clangBasic 70clangCodeGen 71clangDriver 72clangLex 73clangFrontend 74clangFrontendTool 75) 76slang_add_target ( 77source/slang-llvm 78MODULE 79LINK_WITH_PRIVATE core compiler-core llvm-dep clang-dep 80# We include slang.h, but don't need to link with it 81INCLUDE_FROM_PRIVATE slang 82# We include tools/slang-test/filecheck.h, but don't need to link 83# with it and it might not be a target if SLANG_ENABLE_TESTS is 84# false, so just include the directory manually here 85INCLUDE_DIRECTORIES_PRIVATE ${ slang_SOURCE_DIR } /tools 86# This uses the SLANG_DLL_EXPORT macro from slang.h, so make sure to set 87# SLANG_DYNAMIC and SLANG_DYNAMIC_EXPORT 88EXPORT_MACRO_PREFIX SLANG 89INSTALL 90INSTALL_COMPONENT slang-llvm 91EXPORT_SET_NAME SlangTargets 92) 93# If we don't include this, then the symbols in the LLVM linked here may 94# conflict with those of other LLVMs linked at runtime, for instance in mesa. 95set_target_properties ( 96slang-llvm 97PROPERTIES CXX_VISIBILITY_PRESET hidden VISIBILITY_INLINES_HIDDEN ON 98) 99add_supported_cxx_linker_flags ( 100slang-llvm 101PRIVATE 102"-Wl,--exclude-libs,ALL" 103) 104 105# The LLVM headers need a warning disabling, which somehow slips through \external 106if ( MSVC) 107target_compile_options ( slang-llvm PRIVATE -wd4244 ) 108endif () 109 110# TODO: Put a check here that libslang-llvm.so doesn't have a 'NEEDED' 111# directive for libLLVM-14.so, it's almost certainly going to break at 112# runtime in surprising ways when linked alongside Mesa (or anything else 113# pulling in libLLVM.so) 114endif () 115 116if ( SLANG_ENABLE_PREBUILT_BINARIES) 117if ( CMAKE_SYSTEM_NAMEMATCHES "Windows" ) 118file ( 119GLOB prebuilt_binaries 120" ${ slang_SOURCE_DIR } /external/slang-binaries/bin/windows-x64/*" 121) 122list ( REMOVE_ITEM prebuilt_binaries ${ prebuilt_d3d12_binaries }) 123add_custom_target ( 124copy-prebuilt-binaries 125ALL 126COMMAND 127${ CMAKE_COMMAND } -E make_directory 128${ CMAKE_BINARY_DIR } / $ <CONFIG>/ ${ runtime_subdir } 129COMMAND 130${ CMAKE_COMMAND } -E copy_if_different ${ prebuilt_binaries } 131${ CMAKE_BINARY_DIR } / $ <CONFIG>/ ${ runtime_subdir } 132VERBATIM 133) 134set_target_properties ( 135copy-prebuilt-binaries 136PROPERTIES FOLDER external 137) 138endif () 139endif () 140endfunction ()