Commit f8ba50f5ed

Andrew Kelley <andrew@ziglang.org>
2019-02-07 18:18:01
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 a94304d
Changed files (1)
cmake/Findllvm.cmake
@@ -15,15 +15,51 @@ find_program(LLVM_CONFIG_EXE
         "c:/msys64/mingw64/bin"
         "C:/Libraries/llvm-8.0.0/bin")
 
+if ("${LLVM_CONFIG_EXE}" STREQUAL "LLVM_CONFIG_EXE-NOTFOUND")
+  message(FATAL_ERROR "unable to find llvm-config")
+endif()
+
 execute_process(
 	COMMAND ${LLVM_CONFIG_EXE} --version
 	OUTPUT_VARIABLE LLVM_CONFIG_VERSION
 	OUTPUT_STRIP_TRAILING_WHITESPACE)
 
-if(LLVM_CONFIG_VERSION VERSION_LESS 7)
-  message(FATAL_ERROR "expected LLVM version >=7 but found ${LLVM_CONFIG_VERSION}")
+if("${LLVM_CONFIG_VERSION}" VERSION_LESS 7)
+  message(FATAL_ERROR "expected LLVM 7.x but found ${LLVM_CONFIG_VERSION}")
+endif()
+if("${LLVM_CONFIG_VERSION}" VERSION_EQUAL 8)
+  message(FATAL_ERROR "expected LLVM 7.x but found ${LLVM_CONFIG_VERSION}")
+endif()
+if("${LLVM_CONFIG_VERSION}" VERSION_GREATER 8)
+  message(FATAL_ERROR "expected LLVM 7.x but found ${LLVM_CONFIG_VERSION}")
 endif()
 
+execute_process(
+	COMMAND ${LLVM_CONFIG_EXE} --targets-built
+    OUTPUT_VARIABLE LLVM_TARGETS_BUILT_SPACES
+	OUTPUT_STRIP_TRAILING_WHITESPACE)
+string(REPLACE " " ";" LLVM_TARGETS_BUILT "${LLVM_TARGETS_BUILT_SPACES}")
+function(NEED_TARGET TARGET_NAME)
+    list (FIND LLVM_TARGETS_BUILT "${TARGET_NAME}" _index)
+    if (${_index} EQUAL -1)
+        message(FATAL_ERROR "LLVM is missing target ${TARGET_NAME}. Zig requires LLVM to be built with all default targets enabled.")
+    endif()
+endfunction(NEED_TARGET)
+NEED_TARGET("AArch64")
+NEED_TARGET("AMDGPU")
+NEED_TARGET("ARM")
+NEED_TARGET("BPF")
+NEED_TARGET("Hexagon")
+NEED_TARGET("Lanai")
+NEED_TARGET("Mips")
+NEED_TARGET("MSP430")
+NEED_TARGET("NVPTX")
+NEED_TARGET("PowerPC")
+NEED_TARGET("Sparc")
+NEED_TARGET("SystemZ")
+NEED_TARGET("X86")
+NEED_TARGET("XCore")
+
 if(NOT(CMAKE_BUILD_TYPE STREQUAL "Debug") OR ZIG_STATIC)
   execute_process(
       COMMAND ${LLVM_CONFIG_EXE} --libfiles --link-static