Skip to content

Commit 7843c96

Browse files
committed
build: make sure LLVM is exactly correct
* check the version to be the correct major version * ensure that it has all the default targets enabled
1 parent 2b2bf53 commit 7843c96

File tree

1 file changed

+38
-2
lines changed

1 file changed

+38
-2
lines changed

cmake/Findllvm.cmake

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,51 @@ find_program(LLVM_CONFIG_EXE
1515
"c:/msys64/mingw64/bin"
1616
"C:/Libraries/llvm-7.0.0/bin")
1717

18+
if ("${LLVM_CONFIG_EXE}" STREQUAL "LLVM_CONFIG_EXE-NOTFOUND")
19+
message(FATAL_ERROR "unable to find llvm-config")
20+
endif()
21+
1822
execute_process(
1923
COMMAND ${LLVM_CONFIG_EXE} --version
2024
OUTPUT_VARIABLE LLVM_CONFIG_VERSION
2125
OUTPUT_STRIP_TRAILING_WHITESPACE)
2226

23-
if(LLVM_CONFIG_VERSION VERSION_LESS 7)
24-
message(FATAL_ERROR "expected LLVM version >=7 but found ${LLVM_CONFIG_VERSION}")
27+
if("${LLVM_CONFIG_VERSION}" VERSION_LESS 7)
28+
message(FATAL_ERROR "expected LLVM 7.x but found ${LLVM_CONFIG_VERSION}")
29+
endif()
30+
if("${LLVM_CONFIG_VERSION}" VERSION_EQUAL 8)
31+
message(FATAL_ERROR "expected LLVM 7.x but found ${LLVM_CONFIG_VERSION}")
32+
endif()
33+
if("${LLVM_CONFIG_VERSION}" VERSION_GREATER 8)
34+
message(FATAL_ERROR "expected LLVM 7.x but found ${LLVM_CONFIG_VERSION}")
2535
endif()
2636

37+
execute_process(
38+
COMMAND ${LLVM_CONFIG_EXE} --targets-built
39+
OUTPUT_VARIABLE LLVM_TARGETS_BUILT_SPACES
40+
OUTPUT_STRIP_TRAILING_WHITESPACE)
41+
string(REPLACE " " ";" LLVM_TARGETS_BUILT "${LLVM_TARGETS_BUILT_SPACES}")
42+
function(NEED_TARGET TARGET_NAME)
43+
list (FIND LLVM_TARGETS_BUILT "${TARGET_NAME}" _index)
44+
if (${_index} EQUAL -1)
45+
message(FATAL_ERROR "LLVM is missing target ${TARGET_NAME}. Zig requires LLVM to be built with all default targets enabled.")
46+
endif()
47+
endfunction(NEED_TARGET)
48+
NEED_TARGET("AArch64")
49+
NEED_TARGET("AMDGPU")
50+
NEED_TARGET("ARM")
51+
NEED_TARGET("BPF")
52+
NEED_TARGET("Hexagon")
53+
NEED_TARGET("Lanai")
54+
NEED_TARGET("Mips")
55+
NEED_TARGET("MSP430")
56+
NEED_TARGET("NVPTX")
57+
NEED_TARGET("PowerPC")
58+
NEED_TARGET("Sparc")
59+
NEED_TARGET("SystemZ")
60+
NEED_TARGET("X86")
61+
NEED_TARGET("XCore")
62+
2763
if(NOT(CMAKE_BUILD_TYPE STREQUAL "Debug") OR ZIG_STATIC)
2864
execute_process(
2965
COMMAND ${LLVM_CONFIG_EXE} --libfiles --link-static

0 commit comments

Comments
 (0)