1 option(LLVM_INCLUDE_SPIRV_TOOLS_TESTS "Include tests that use SPIRV-Tools" Off)
2 mark_as_advanced(LLVM_INCLUDE_SPIRV_TOOLS_TESTS)
4 if (NOT LLVM_INCLUDE_SPIRV_TOOLS_TESTS)
8 if (NOT "SPIRV" IN_LIST LLVM_TARGETS_TO_BUILD)
9 message(FATAL_ERROR "Building SPIRV-Tools tests is unsupported without the SPIR-V target")
12 # SPIRV_DIS and SPIRV_VAL variables can be used to provide paths to existing
13 # spirv-dis and spirv-val binaries, respectively. Otherwise, build them from
15 if (NOT SPIRV_DIS OR NOT SPIRV_VAL OR NOT SPIRV_AS)
16 include(ExternalProject)
18 set(BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/SPIRVTools-bin)
20 ExternalProject_Add(SPIRVTools
21 GIT_REPOSITORY https://github.com/KhronosGroup/SPIRV-Tools.git
23 BINARY_DIR ${BINARY_DIR}
24 BUILD_COMMAND ${CMAKE_COMMAND} --build ${BINARY_DIR} --target spirv-dis spirv-val spirv-as
25 BUILD_BYPRODUCTS ${BINARY_DIR}/tools/spirv-dis ${BINARY_DIR}/tools/spirv-val ${BINARY_DIR}/tools/spirv-as
26 DOWNLOAD_COMMAND git clone https://github.com/KhronosGroup/SPIRV-Tools.git SPIRVTools &&
28 ${Python3_EXECUTABLE} utils/git-sync-deps
29 UPDATE_COMMAND git pull origin main &&
30 ${Python3_EXECUTABLE} utils/git-sync-deps
31 # Don't auto-update on every build.
33 # Allow manual updating with an explicit SPIRVTools-update target.
35 # Install handled below.
41 set(LLVM_LINK_OR_COPY create_symlink)
43 set(LLVM_LINK_OR_COPY copy)
46 # Link the provided or just built spirv-dis and spirv-val binaries.
48 add_custom_target(spirv-dis
49 COMMAND ${CMAKE_COMMAND} -E ${LLVM_LINK_OR_COPY} "${SPIRV_DIS}" "${LLVM_RUNTIME_OUTPUT_INTDIR}/spirv-dis")
51 add_custom_target(spirv-dis
52 COMMAND ${CMAKE_COMMAND} -E ${LLVM_LINK_OR_COPY} "${BINARY_DIR}/tools/spirv-dis${CMAKE_EXECUTABLE_SUFFIX}" "${LLVM_RUNTIME_OUTPUT_INTDIR}/spirv-dis${CMAKE_EXECUTABLE_SUFFIX}"
58 add_custom_target(spirv-val
59 COMMAND ${CMAKE_COMMAND} -E ${LLVM_LINK_OR_COPY} "${SPIRV_VAL}" "${LLVM_RUNTIME_OUTPUT_INTDIR}/spirv-val")
61 add_custom_target(spirv-val
62 COMMAND ${CMAKE_COMMAND} -E ${LLVM_LINK_OR_COPY} "${BINARY_DIR}/tools/spirv-val${CMAKE_EXECUTABLE_SUFFIX}" "${LLVM_RUNTIME_OUTPUT_INTDIR}/spirv-val${CMAKE_EXECUTABLE_SUFFIX}"
68 add_custom_target(spirv-as
69 COMMAND ${CMAKE_COMMAND} -E ${LLVM_LINK_OR_COPY} "${SPIRV_VAL}" "${LLVM_RUNTIME_OUTPUT_INTDIR}/spirv-as")
71 add_custom_target(spirv-as
72 COMMAND ${CMAKE_COMMAND} -E ${LLVM_LINK_OR_COPY} "${BINARY_DIR}/tools/spirv-as${CMAKE_EXECUTABLE_SUFFIX}" "${LLVM_RUNTIME_OUTPUT_INTDIR}/spirv-as${CMAKE_EXECUTABLE_SUFFIX}"