summaryrefslogtreecommitdiffstats
path: root/cmake/Glob.cmake
blob: 831a074961351075aa34691d3c5c5e079e08813c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#
# glob_append(MY_VAR my_glob) will append the results of file(GLOB
# CONFIGURE_DEPENDS my_glob) to MY_VAR
#
# Any number of globs may be specified
#
function(glob_append dest)
    file(GLOB files CONFIGURE_DEPENDS ${ARGN})
    list(APPEND ${dest} ${files})
    set(${dest} ${${dest}} PARENT_SCOPE)
endfunction()

#
# Perform a recursive glob, and exclude any files appropriately according to
# the host system and build options
#
function(slang_glob_sources var dir)
    set(patterns
        "*.cpp"
        "*.h"
        "*.natvis"
        "*.natstepfilter"
        "*.natjmc"
    )
    if (CMAKE_SYSTEM_NAME MATCHES "Darwin")
        list(APPEND patterns "*.mm")
    endif()        
    list(TRANSFORM patterns PREPEND "${dir}/")

    file(GLOB_RECURSE files CONFIGURE_DEPENDS ${patterns})

    if(NOT WIN32)
        list(FILTER files EXCLUDE REGEX "(^|/)windows/.*")
    endif()

    if(NOT UNIX)
        list(FILTER files EXCLUDE REGEX "(^|/)unix/.*")
    endif()

    if(NOT CMAKE_SYSTEM_NAME MATCHES "Windows" AND NOT SLANG_ENABLE_DX_ON_VK)
        list(FILTER files EXCLUDE REGEX "(^|/)d3d.*/.*")
    endif()

    if(NOT CMAKE_SYSTEM_NAME MATCHES "Windows|Linux|Darwin")
        list(FILTER files EXCLUDE REGEX "(^|/)vulkan/.*")
    endif()

    if(NOT CMAKE_SYSTEM_NAME MATCHES "Darwin")
        list(FILTER files EXCLUDE REGEX "(^|/)metal/.*")
    endif()

    if(NOT CMAKE_SYSTEM_NAME MATCHES "Windows")
        list(FILTER files EXCLUDE REGEX "(^|/)open-gl/.*")
    endif()

    list(APPEND ${var} ${files})
    set(${var} ${${var}} PARENT_SCOPE)
endfunction()