@@ -42,6 +42,10 @@ set( LIBCLC_TARGETS_TO_BUILD "all"
42
42
43
43
option ( ENABLE_RUNTIME_SUBNORMAL "Enable runtime linking of subnormal support." OFF )
44
44
45
+ option (
46
+ LIBCLC_USE_SPIRV_BACKEND "Build SPIR-V targets with the SPIR-V backend." OFF
47
+ )
48
+
45
49
# Top level target used to build all Libclc libraries.
46
50
add_custom_target ( libclc ALL )
47
51
@@ -115,14 +119,17 @@ foreach( tool IN ITEMS clang opt llvm-as llvm-link )
115
119
endif ()
116
120
endforeach ()
117
121
118
- # llvm-spirv is an optional dependency, used to build spirv-* targets.
119
- # It may be provided in-tree or externally.
120
- if ( TARGET llvm-spirv )
121
- get_host_tool_path ( llvm-spirv LLVM_SPIRV llvm-spirv_exe llvm-spirv_target )
122
- else ()
123
- find_program ( LLVM_SPIRV llvm-spirv HINTS ${LLVM_TOOLS_BINARY_DIR} )
124
- set ( llvm-spirv_exe "${LLVM_SPIRV} " )
125
- set ( llvm-spirv_target )
122
+ if ( NOT LIBCLC_USE_SPIRV_BACKEND )
123
+ # llvm-spirv is an optional dependency, used to build spirv-* targets when
124
+ # the SPIR-V backend hasn't been requested. It may be provided in-tree or
125
+ # externally.
126
+ if ( TARGET llvm-spirv )
127
+ get_host_tool_path ( llvm-spirv LLVM_SPIRV llvm-spirv_exe llvm-spirv_target )
128
+ else ()
129
+ find_program ( LLVM_SPIRV llvm-spirv HINTS ${LLVM_TOOLS_BINARY_DIR} )
130
+ set ( llvm-spirv_exe "${LLVM_SPIRV} " )
131
+ set ( llvm-spirv_target )
132
+ endif ()
126
133
endif ()
127
134
128
135
# List of all targets. Note that some are added dynamically below.
@@ -138,22 +145,24 @@ set( LIBCLC_TARGETS_ALL
138
145
nvptx64--nvidiacl
139
146
)
140
147
141
- # mesa3d environment is only available since LLVM 4.0
148
+ # The mesa3d environment is only available since LLVM 4.0
142
149
if ( LLVM_PACKAGE_VERSION VERSION_GREATER_EQUAL 4.0.0 )
143
150
list ( APPEND LIBCLC_TARGETS_ALL amdgcn-mesa-mesa3d )
144
151
endif ()
145
152
146
- # spirv-mesa3d and spirv64-mesa3d targets can only be built with the (optional)
147
- # llvm-spirv external tool.
148
- if ( llvm-spirv_exe )
149
- list ( APPEND LIBCLC_TARGETS_ALL spirv-mesa3d- spirv64-mesa3d- )
153
+ # The spirv-mesa3d and spirv64-mesa3d targets are optional and can be built
154
+ # with either the LLVM SPIR-V backend or the external llvm-spirv tool.
155
+ if ( LIBCLC_USE_SPIRV_BACKEND OR llvm-spirv_exe )
156
+ list ( APPEND LIBCLC_TARGETS_ALL spirv-mesa3d- spirv64-mesa3d- )
150
157
endif ()
151
158
152
159
# Verify that the user hasn't requested mesa3d targets without an available
153
160
# llvm-spirv tool.
154
- if ( "spirv-mesa3d-" IN_LIST LIBCLC_TARGETS_TO_BUILD OR "spirv64-mesa3d-" IN_LIST LIBCLC_TARGETS_TO_BUILD )
155
- if ( NOT llvm-spirv_exe )
156
- message ( FATAL_ERROR "SPIR-V targets requested, but spirv-tools is not installed" )
161
+ if ( spirv-mesa3d- IN_LIST LIBCLC_TARGETS_TO_BUILD
162
+ OR spirv64-mesa3d- IN_LIST LIBCLC_TARGETS_TO_BUILD )
163
+ if ( NOT LIBCLC_USE_SPIRV_BACKEND AND NOT llvm-spirv_exe )
164
+ message ( FATAL_ERROR "SPIR-V targets requested, but spirv-tools is not "
165
+ "installed and the SPIR-V backend has not been requested." )
157
166
endif ()
158
167
endif ()
159
168
0 commit comments