File: HalideConfig.cmake

package info (click to toggle)
halide 21.0.0-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 55,752 kB
  • sloc: cpp: 289,334; ansic: 22,751; python: 7,486; makefile: 4,299; sh: 2,508; java: 1,549; javascript: 282; pascal: 207; xml: 127; asm: 9
file content (155 lines) | stat: -rw-r--r-- 4,849 bytes parent folder | download | duplicates (3)
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
cmake_minimum_required(VERSION 3.28)
@PACKAGE_INIT@

macro(Halide_fail message)
    set(${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE "${message}")
    set(${CMAKE_FIND_PACKAGE_NAME}_FOUND FALSE)
    return()
endmacro()

macro(Halide_find_component_dependency comp dep)
    set(Halide_quiet)
    if (${CMAKE_FIND_PACKAGE_NAME}_FIND_QUIETLY)
        set(Halide_quiet QUIET)
    endif ()

    find_package(${dep} ${ARGN} ${Halide_quiet})

    if (NOT ${dep}_FOUND AND ${CMAKE_FIND_PACKAGE_NAME}_FIND_REQUIRED_${comp})
        Halide_fail("${CMAKE_FIND_PACKAGE_NAME} could not be found because dependency ${dep} could not be found.")
    endif ()
endmacro()

set(Halide_known_components Halide Python PNG JPEG static shared)
set(Halide_components Halide PNG JPEG)

foreach (Halide_comp IN LISTS Halide_known_components)
    set(Halide_comp_${Halide_comp} NO)
endforeach ()

if (${CMAKE_FIND_PACKAGE_NAME}_FIND_COMPONENTS)
    set(Halide_components ${${CMAKE_FIND_PACKAGE_NAME}_FIND_COMPONENTS})
endif ()

# Parse components for static/shared preference.
foreach (Halide_comp IN LISTS Halide_components)
    if (Halide_comp IN_LIST Halide_known_components)
        set(Halide_comp_${Halide_comp} YES)
    else ()
        Halide_fail("Halide does not recognize component `${Halide_comp}`.")
    endif ()
endforeach ()

if (Halide_comp_static AND Halide_comp_shared)
    Halide_fail("Halide `static` and `shared` components are mutually exclusive.")
endif ()

# Inform downstreams of potential compatibility issues. For instance, exceptions
# and RTTI must both be enabled to build Python bindings and ASAN builds should
# not be mixed with non-ASAN builds.
set(WITH_AUTOSCHEDULERS "@WITH_AUTOSCHEDULERS@")
set(Halide_ENABLE_EXCEPTIONS "@Halide_ENABLE_EXCEPTIONS@")
set(Halide_ENABLE_RTTI "@Halide_ENABLE_RTTI@")
set(Halide_ASAN_ENABLED "@Halide_ASAN_ENABLED@")

##
## Find dependencies based on components
##

include(CMakeFindDependencyMacro)

find_dependency(
    HalideHelpers "@Halide_VERSION@" EXACT
    HINTS "@PACKAGE_Halide_INSTALL_HELPERSDIR@"
)

if (Halide_comp_PNG)
    Halide_find_component_dependency(PNG PNG)
endif ()

if (Halide_comp_JPEG)
    Halide_find_component_dependency(JPEG JPEG)
endif ()

##
## Select static or shared and load CMake scripts
##

set(Halide_static_targets "${CMAKE_CURRENT_LIST_DIR}/Halide-static-targets.cmake")
set(Halide_shared_targets "${CMAKE_CURRENT_LIST_DIR}/Halide-shared-targets.cmake")

set(Halide_static_deps "${CMAKE_CURRENT_LIST_DIR}/Halide-static-deps.cmake")
set(Halide_shared_deps "${CMAKE_CURRENT_LIST_DIR}/Halide-shared-deps.cmake")

macro(Halide_load_targets type)
    if (NOT EXISTS "${Halide_${type}_targets}")
        Halide_fail("Halide `${type}` libraries were requested but not found.")
    endif ()

    include("${Halide_${type}_targets}")
    include("${Halide_${type}_deps}" OPTIONAL)
endmacro()

if (Halide_comp_static)
    Halide_load_targets(static)
elseif (Halide_comp_shared)
    Halide_load_targets(shared)
elseif (DEFINED Halide_SHARED_LIBS AND Halide_SHARED_LIBS)
    Halide_load_targets(shared)
elseif (DEFINED Halide_SHARED_LIBS AND NOT Halide_SHARED_LIBS)
    Halide_load_targets(static)
elseif (BUILD_SHARED_LIBS OR NOT DEFINED BUILD_SHARED_LIBS)
    if (EXISTS "${Halide_shared_targets}")
        Halide_load_targets(shared)
    else ()
        Halide_load_targets(static)
    endif ()
else ()
    if (EXISTS "${Halide_static_targets}")
        Halide_load_targets(static)
    else ()
        Halide_load_targets(shared)
    endif ()
endif ()

## Load Python component
if (Halide_comp_Python OR "@WITH_PYTHON_BINDINGS@")
    Halide_find_component_dependency(
        Python Halide_Python
        HINTS "@PACKAGE_Halide_Python_INSTALL_CMAKEDIR@"
    )
endif ()

## Hide variables and helper macros that are not part of our API.

# Delete internal component tracking
foreach (comp IN LISTS Halide_known_components)
    unset(Halide_comp_${comp})
endforeach ()

unset(Halide_components)
unset(Halide_known_components)

# Delete paths to generated CMake files
unset(Halide_shared_deps)
unset(Halide_shared_targets)
unset(Halide_static_deps)
unset(Halide_static_targets)

# Delete internal macros -- CMake saves redefined macros and functions with a
# single underscore prefixed so, for example, Halide_fail is still available as
# _Halide_fail after one redefinition. Doing it twice overwrites both since the
# saving behavior doesn't continue past the first.
foreach (i RANGE 0 1)
    macro(Halide_fail)
        message(FATAL_ERROR "Cannot call internal API: Halide_fail")
    endmacro()

    macro(Halide_find_component_dependency)
        message(FATAL_ERROR "Cannot call internal API: Halide_find_component_dependency")
    endmacro()

    macro(Halide_load_targets)
        message(FATAL_ERROR "Cannot call internal API: Halide_load_targets")
    endmacro()
endforeach ()