yum-mirror/slang

Making it easier to work with shaders

git clone https://git.yummers.dev/yum-mirror/slang

Sam EstepUpdate LLVM from 13.0.1 to 14.0.6 (#8031)4721b6ef2

master
5.2 KiB140 linesraw
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)
5    set(components ${ARGN})
6    llvm_map_components_to_libnames(llvm_libs
7        ${components}
8    )
9    add_library(${target_name} INTERFACE)
10    target_link_libraries(${target_name} INTERFACE ${llvm_libs})
11    target_include_directories(
12        ${target_name}
13        SYSTEM
14        INTERFACE ${LLVM_INCLUDE_DIRS}
15    )
16    target_compile_definitions(${target_name} INTERFACE ${LLVM_DEFINITIONS})
17    if(NOT LLVM_ENABLE_RTTI)
18        # Make sure that we don't disable rtti if this library wasn't compiled with
19        # support
20        add_supported_cxx_flags(${target_name} INTERFACE -fno-rtti /GR-)
21    endif()
22endfunction()
23
24# The same for clang
25function(clang_target_from_libs target_name)
26    set(clang_libs ${ARGN})
27    add_library(${target_name} INTERFACE)
28    target_link_libraries(${target_name} INTERFACE ${clang_libs})
29    target_include_directories(
30        ${target_name}
31        SYSTEM
32        INTERFACE ${CLANG_INCLUDE_DIRS}
33    )
34    target_compile_definitions(${target_name} INTERFACE ${CLANG_DEFINITIONS})
35    if(NOT LLVM_ENABLE_RTTI)
36        # Make sure that we don't disable rtti if this library wasn't compiled with
37        # support
38        add_supported_cxx_flags(${target_name} INTERFACE -fno-rtti /GR-)
39    endif()
40endfunction()
41
42function(fetch_or_build_slang_llvm)
43    if(SLANG_SLANG_LLVM_FLAVOR STREQUAL "FETCH_BINARY")
44        install_fetched_shared_library(
45            "slang-llvm"
46            "${SLANG_SLANG_LLVM_BINARY_URL}"
47        )
48    elseif(SLANG_SLANG_LLVM_FLAVOR STREQUAL "FETCH_BINARY_IF_POSSIBLE")
49        if(SLANG_SLANG_LLVM_BINARY_URL)
50            install_fetched_shared_library(
51                "slang-llvm"
52                "${SLANG_SLANG_LLVM_BINARY_URL}"
53                IGNORE_FAILURE
54            )
55            if(NOT TARGET slang-llvm)
56                message(
57                    WARNING
58                    "Unable to fetch slang-llvm prebuilt binary, configuring without LLVM support"
59                )
60            endif()
61        endif()
62    elseif(SLANG_SLANG_LLVM_FLAVOR STREQUAL "USE_SYSTEM_LLVM")
63        find_package(LLVM 14.0 REQUIRED CONFIG)
64        find_package(Clang REQUIRED CONFIG)
65
66        llvm_target_from_components(llvm-dep filecheck native orcjit)
67        clang_target_from_libs(
68            clang-dep
69            clangBasic
70            clangCodeGen
71            clangDriver
72            clangLex
73            clangFrontend
74            clangFrontendTool
75        )
76        slang_add_target(
77            source/slang-llvm
78            MODULE
79            LINK_WITH_PRIVATE core compiler-core llvm-dep clang-dep
80            # We include slang.h, but don't need to link with it
81            INCLUDE_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
85            INCLUDE_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
88            EXPORT_MACRO_PREFIX SLANG
89            INSTALL
90            INSTALL_COMPONENT slang-llvm
91            EXPORT_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.
95        set_target_properties(
96            slang-llvm
97            PROPERTIES CXX_VISIBILITY_PRESET hidden VISIBILITY_INLINES_HIDDEN ON
98        )
99        add_supported_cxx_linker_flags(
100            slang-llvm
101            PRIVATE
102            "-Wl,--exclude-libs,ALL"
103        )
104
105        # The LLVM headers need a warning disabling, which somehow slips through \external
106        if(MSVC)
107            target_compile_options(slang-llvm PRIVATE -wd4244)
108        endif()
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)
114    endif()
115
116    if(SLANG_ENABLE_PREBUILT_BINARIES)
117        if(CMAKE_SYSTEM_NAME MATCHES "Windows")
118            file(
119                GLOB prebuilt_binaries
120                "${slang_SOURCE_DIR}/external/slang-binaries/bin/windows-x64/*"
121            )
122            list(REMOVE_ITEM prebuilt_binaries ${prebuilt_d3d12_binaries})
123            add_custom_target(
124                copy-prebuilt-binaries
125                ALL
126                COMMAND
127                    ${CMAKE_COMMAND} -E make_directory
128                    ${CMAKE_BINARY_DIR}/$<CONFIG>/${runtime_subdir}
129                COMMAND
130                    ${CMAKE_COMMAND} -E copy_if_different ${prebuilt_binaries}
131                    ${CMAKE_BINARY_DIR}/$<CONFIG>/${runtime_subdir}
132                VERBATIM
133            )
134            set_target_properties(
135                copy-prebuilt-binaries
136                PROPERTIES FOLDER external
137            )
138        endif()
139    endif()
140endfunction()