| ... | @@ -8,27 +8,9 @@ | ... | @@ -8,27 +8,9 @@ |
| 8 | # LLVM_LIBDIRS | 8 | # LLVM_LIBDIRS |
| 9 | # LLVM_LINK_MODE | 9 | # LLVM_LINK_MODE |
| 10 | | 10 | |
| 11 | | 11 | function(check_llvm_config LLVM_CONFIG_EXE) |
| 12 | if(ZIG_USE_LLVM_CONFIG) | 12 | # Start with empty message for current llvm-config |
| 13 | set(LLVM_CONFIG_ERROR_MESSAGES "") | 13 | set(LLVM_CONFIG_ERROR_MESSAGES "" PARENT_SCOPE) |
| 14 | while(1) | | |
| 15 | unset(LLVM_CONFIG_EXE CACHE) | | |
| 16 | find_program(LLVM_CONFIG_EXE | | |
| 17 | NAMES llvm-config-15 llvm-config-15.0 llvm-config150 llvm-config15 llvm-config NAMES_PER_DIR | | |
| 18 | PATHS | | |
| 19 | "/mingw64/bin" | | |
| 20 | "/c/msys64/mingw64/bin" | | |
| 21 | "c:/msys64/mingw64/bin" | | |
| 22 | "C:/Libraries/llvm-15.0.0/bin") | | |
| 23 | | | |
| 24 | if ("${LLVM_CONFIG_EXE}" STREQUAL "LLVM_CONFIG_EXE-NOTFOUND") | | |
| 25 | if (NOT LLVM_CONFIG_ERROR_MESSAGES STREQUAL "") | | |
| 26 | list(JOIN LLVM_CONFIG_ERROR_MESSAGES "\n" LLVM_CONFIG_ERROR_MESSAGE) | | |
| 27 | message(FATAL_ERROR ${LLVM_CONFIG_ERROR_MESSAGE}) | | |
| 28 | else() | | |
| 29 | message(FATAL_ERROR "unable to find llvm-config") | | |
| 30 | endif() | | |
| 31 | endif() | | |
| 32 | | 14 | |
| 33 | # Check that this LLVM is the right version | 15 | # Check that this LLVM is the right version |
| 34 | execute_process( | 16 | execute_process( |
| ... | @@ -36,14 +18,10 @@ if(ZIG_USE_LLVM_CONFIG) | ... | @@ -36,14 +18,10 @@ if(ZIG_USE_LLVM_CONFIG) |
| 36 | OUTPUT_VARIABLE LLVM_CONFIG_VERSION | 18 | OUTPUT_VARIABLE LLVM_CONFIG_VERSION |
| 37 | OUTPUT_STRIP_TRAILING_WHITESPACE) | 19 | OUTPUT_STRIP_TRAILING_WHITESPACE) |
| 38 | | 20 | |
| 39 | get_filename_component(LLVM_CONFIG_DIR "${LLVM_CONFIG_EXE}" DIRECTORY) | 21 | if("${LLVM_CONFIG_VERSION}" VERSION_LESS 15 OR "${LLVM_CONFIG_VERSION}" VERSION_GREATER_EQUAL 16) |
| 40 | if("${LLVM_CONFIG_VERSION}" VERSION_LESS 15 OR "${LLVM_CONFIG_VERSION}" VERSION_EQUAL 16 OR "${LLVM_CONFIG_VERSION}" VERSION_GREATER 16) | 22 | # Save the error message for current llvm-config we find |
| 41 | # Save the error message, in case this is the last llvm-config we find | 23 | set(LLVM_CONFIG_ERROR_MESSAGES "Expected LLVM 15.x but found ${LLVM_CONFIG_VERSION}" PARENT_SCOPE) |
| 42 | list(APPEND LLVM_CONFIG_ERROR_MESSAGES "expected LLVM 15.x but found ${LLVM_CONFIG_VERSION} using ${LLVM_CONFIG_EXE}") | 24 | return() |
| 43 | | | |
| 44 | # Ignore this directory and try the search again | | |
| 45 | list(APPEND CMAKE_IGNORE_PATH "${LLVM_CONFIG_DIR}") | | |
| 46 | continue() | | |
| 47 | endif() | 25 | endif() |
| 48 | | 26 | |
| 49 | # Check that this LLVM supports linking as a shared/static library, if requested | 27 | # Check that this LLVM supports linking as a shared/static library, if requested |
| ... | @@ -60,17 +38,13 @@ if(ZIG_USE_LLVM_CONFIG) | ... | @@ -60,17 +38,13 @@ if(ZIG_USE_LLVM_CONFIG) |
| 60 | ERROR_VARIABLE LLVM_CONFIG_ERROR | 38 | ERROR_VARIABLE LLVM_CONFIG_ERROR |
| 61 | ERROR_STRIP_TRAILING_WHITESPACE) | 39 | ERROR_STRIP_TRAILING_WHITESPACE) |
| 62 | | 40 | |
| 63 | if (LLVM_CONFIG_ERROR) | 41 | if (LLVM_CONFIG_ERROR) |
| 64 | # Save the error message, in case this is the last llvm-config we find | | |
| 65 | if (ZIG_SHARED_LLVM) | 42 | if (ZIG_SHARED_LLVM) |
| 66 | list(APPEND LLVM_CONFIG_ERROR_MESSAGES "LLVM 15.x found at ${LLVM_CONFIG_EXE} does not support linking as a shared library") | 43 | set(LLVM_CONFIG_ERROR_MESSAGES "This LLVM does not support linking as a shared library" PARENT_SCOPE) |
| 67 | else() | 44 | else() |
| 68 | list(APPEND LLVM_CONFIG_ERROR_MESSAGES "LLVM 15.x found at ${LLVM_CONFIG_EXE} does not support linking as a static library") | 45 | set(LLVM_CONFIG_ERROR_MESSAGES "This LLVM does not support linking as a static library" PARENT_SCOPE) |
| 69 | endif() | 46 | endif() |
| 70 | | 47 | return() |
| 71 | # Ignore this directory and try the search again | | |
| 72 | list(APPEND CMAKE_IGNORE_PATH "${LLVM_CONFIG_DIR}") | | |
| 73 | continue() | | |
| 74 | endif() | 48 | endif() |
| 75 | endif() | 49 | endif() |
| 76 | | 50 | |
| ... | @@ -79,17 +53,15 @@ if(ZIG_USE_LLVM_CONFIG) | ... | @@ -79,17 +53,15 @@ if(ZIG_USE_LLVM_CONFIG) |
| 79 | OUTPUT_VARIABLE LLVM_TARGETS_BUILT_SPACES | 53 | OUTPUT_VARIABLE LLVM_TARGETS_BUILT_SPACES |
| 80 | OUTPUT_STRIP_TRAILING_WHITESPACE) | 54 | OUTPUT_STRIP_TRAILING_WHITESPACE) |
| 81 | string(REPLACE " " ";" LLVM_TARGETS_BUILT "${LLVM_TARGETS_BUILT_SPACES}") | 55 | string(REPLACE " " ";" LLVM_TARGETS_BUILT "${LLVM_TARGETS_BUILT_SPACES}") |
| 82 | function(NEED_TARGET TARGET_NAME) | 56 | |
| | 57 | macro(NEED_TARGET TARGET_NAME) |
| 83 | list (FIND LLVM_TARGETS_BUILT "${TARGET_NAME}" _index) | 58 | list (FIND LLVM_TARGETS_BUILT "${TARGET_NAME}" _index) |
| 84 | if (${_index} EQUAL -1) | 59 | if (${_index} EQUAL -1) |
| 85 | # Save the error message, in case this is the last llvm-config we find | 60 | set(LLVM_CONFIG_ERROR_MESSAGES "This LLVM is missing target ${TARGET_NAME}. Zig requires LLVM to be built with all default targets enabled." PARENT_SCOPE) |
| 86 | list(APPEND LLVM_CONFIG_ERROR_MESSAGES "LLVM (according to ${LLVM_CONFIG_EXE}) is missing target ${TARGET_NAME}. Zig requires LLVM to be built with all default targets enabled.") | 61 | return() |
| 87 | | | |
| 88 | # Ignore this directory and try the search again | | |
| 89 | list(APPEND CMAKE_IGNORE_PATH "${LLVM_CONFIG_DIR}") | | |
| 90 | continue() | | |
| 91 | endif() | 62 | endif() |
| 92 | endfunction(NEED_TARGET) | 63 | endmacro() |
| | 64 | |
| 93 | NEED_TARGET("AArch64") | 65 | NEED_TARGET("AArch64") |
| 94 | NEED_TARGET("AMDGPU") | 66 | NEED_TARGET("AMDGPU") |
| 95 | NEED_TARGET("ARM") | 67 | NEED_TARGET("ARM") |
| ... | @@ -108,9 +80,39 @@ if(ZIG_USE_LLVM_CONFIG) | ... | @@ -108,9 +80,39 @@ if(ZIG_USE_LLVM_CONFIG) |
| 108 | NEED_TARGET("WebAssembly") | 80 | NEED_TARGET("WebAssembly") |
| 109 | NEED_TARGET("X86") | 81 | NEED_TARGET("X86") |
| 110 | NEED_TARGET("XCore") | 82 | NEED_TARGET("XCore") |
| | 83 | endfunction() |
| | 84 | |
| | 85 | if(ZIG_USE_LLVM_CONFIG) |
| | 86 | while(1) |
| | 87 | unset(LLVM_CONFIG_EXE CACHE) |
| | 88 | find_program(LLVM_CONFIG_EXE |
| | 89 | NAMES llvm-config-15 llvm-config-15.0 llvm-config150 llvm-config15 llvm-config NAMES_PER_DIR |
| | 90 | PATHS |
| | 91 | "/mingw64/bin" |
| | 92 | "/c/msys64/mingw64/bin" |
| | 93 | "c:/msys64/mingw64/bin" |
| | 94 | "C:/Libraries/llvm-15.0.0/bin") |
| | 95 | |
| | 96 | if("${LLVM_CONFIG_EXE}" STREQUAL "LLVM_CONFIG_EXE-NOTFOUND") |
| | 97 | message(FATAL_ERROR "Suitable llvm-config is not found.") |
| | 98 | endif() |
| | 99 | |
| | 100 | message("Trying ${LLVM_CONFIG_EXE}...") |
| 111 | | 101 | |
| 112 | # Got it! | 102 | check_llvm_config(${LLVM_CONFIG_EXE}) |
| 113 | break() | 103 | if(LLVM_CONFIG_ERROR_MESSAGES STREQUAL "") |
| | 104 | message("This llvm-config is suitable for us, continuing...") |
| | 105 | break() |
| | 106 | else() |
| | 107 | |
| | 108 | message("This llvm-config is not suitable for us:") |
| | 109 | list(JOIN LLVM_CONFIG_ERROR_MESSAGES "\n" LLVM_CONFIG_ERROR_MESSAGE) |
| | 110 | message(${LLVM_CONFIG_ERROR_MESSAGE}) |
| | 111 | message("Trying another llvm-config...") |
| | 112 | |
| | 113 | get_filename_component(LLVM_CONFIG_DIR "${LLVM_CONFIG_EXE}" DIRECTORY) |
| | 114 | list(APPEND CMAKE_IGNORE_PATH "${LLVM_CONFIG_DIR}") |
| | 115 | endif() |
| 114 | endwhile() | 116 | endwhile() |
| 115 | | 117 | |
| 116 | if(ZIG_SHARED_LLVM OR ZIG_STATIC_LLVM) | 118 | if(ZIG_SHARED_LLVM OR ZIG_STATIC_LLVM) |