From 7843c96df87007561c107d11afa2fa74b46667fd Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Thu, 7 Feb 2019 12:18:01 -0500 Subject: [PATCH] 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 --- cmake/Findllvm.cmake | 40 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/cmake/Findllvm.cmake b/cmake/Findllvm.cmake index 70d50f9843..2f0afa09b7 100644 --- a/cmake/Findllvm.cmake +++ b/cmake/Findllvm.cmake @@ -15,14 +15,50 @@ find_program(LLVM_CONFIG_EXE "c:/msys64/mingw64/bin" "C:/Libraries/llvm-7.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(