@@ -42,6 +42,10 @@ set( LIBCLC_TARGETS_TO_BUILD "all"
4242
4343option ( ENABLE_RUNTIME_SUBNORMAL "Enable runtime linking of subnormal support." OFF )
4444
45+ option (
46+ LIBCLC_USE_SPIRV_BACKEND "Build SPIR-V targets with the SPIR-V backend." OFF
47+ )
48+
4549# Top level target used to build all Libclc libraries.
4650add_custom_target ( libclc ALL )
4751
@@ -115,14 +119,17 @@ foreach( tool IN ITEMS clang opt llvm-as llvm-link )
115119 endif ()
116120endforeach ()
117121
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 ()
126133endif ()
127134
128135# List of all targets. Note that some are added dynamically below.
@@ -138,22 +145,24 @@ set( LIBCLC_TARGETS_ALL
138145 nvptx64--nvidiacl
139146)
140147
141- # mesa3d environment is only available since LLVM 4.0
148+ # The mesa3d environment is only available since LLVM 4.0
142149if ( LLVM_PACKAGE_VERSION VERSION_GREATER_EQUAL 4.0.0 )
143150 list ( APPEND LIBCLC_TARGETS_ALL amdgcn-mesa-mesa3d )
144151endif ()
145152
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- )
150157endif ()
151158
152159# Verify that the user hasn't requested mesa3d targets without an available
153160# 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." )
157166 endif ()
158167endif ()
159168
0 commit comments