authorgravatar for sin-ack@users.noreply.github.comsin-ack <sin-ack@users.noreply.github.com> 2022-07-30 10:57:44+00:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-07-31 12:56:00-07:00
logb35490c21732d74232680d2de2deb89f97356c0d
tree0fcf32b4a694d4514a5b29eb582ef0653ccf59d1
parentc0a1b4fa46dfd00d0cc4d1b6954bc07ae762e31e

cmake: Print all LLVM config errors instead of just the last one

If you have multiple llvm-config executables in your path, and all of them cause failures, then only the last failure will be printed. This can cause confusion when the multiple llvm-config executables are from different major LLVM versions, i.e. LLVM 13 and 14, which might mask an error that happened on the LLVM 14 llvm-config with an unrelated error. This commit makes it so that all errors are collected into a list and printed all at once; this way, you can see how each llvm-config executable failed to configure properly. Note that the failures still won't be printed if a successful configuration is found.

1 files changed, 7 insertions(+), 5 deletions(-)

cmake/Findllvm.cmake+7-5
......@@ -10,6 +10,7 @@
1010
1111
1212if(ZIG_USE_LLVM_CONFIG)
13 set(LLVM_CONFIG_ERROR_MESSAGES "")
1314 while(1)
1415 unset(LLVM_CONFIG_EXE CACHE)
1516 find_program(LLVM_CONFIG_EXE
......@@ -21,7 +22,8 @@ if(ZIG_USE_LLVM_CONFIG)
2122 "C:/Libraries/llvm-14.0.0/bin")
2223
2324 if ("${LLVM_CONFIG_EXE}" STREQUAL "LLVM_CONFIG_EXE-NOTFOUND")
24 if (DEFINED LLVM_CONFIG_ERROR_MESSAGE)
25 if (NOT LLVM_CONFIG_ERROR_MESSAGES STREQUAL "")
26 list(JOIN LLVM_CONFIG_ERROR_MESSAGES "\n" LLVM_CONFIG_ERROR_MESSAGE)
2527 message(FATAL_ERROR ${LLVM_CONFIG_ERROR_MESSAGE})
2628 else()
2729 message(FATAL_ERROR "unable to find llvm-config")
......@@ -37,7 +39,7 @@ if(ZIG_USE_LLVM_CONFIG)
3739 get_filename_component(LLVM_CONFIG_DIR "${LLVM_CONFIG_EXE}" DIRECTORY)
3840 if("${LLVM_CONFIG_VERSION}" VERSION_LESS 14 OR "${LLVM_CONFIG_VERSION}" VERSION_EQUAL 15 OR "${LLVM_CONFIG_VERSION}" VERSION_GREATER 15)
3941 # Save the error message, in case this is the last llvm-config we find
40 set(LLVM_CONFIG_ERROR_MESSAGE "expected LLVM 14.x but found ${LLVM_CONFIG_VERSION} using ${LLVM_CONFIG_EXE}")
42 list(APPEND LLVM_CONFIG_ERROR_MESSAGES "expected LLVM 14.x but found ${LLVM_CONFIG_VERSION} using ${LLVM_CONFIG_EXE}")
4143
4244 # Ignore this directory and try the search again
4345 list(APPEND CMAKE_IGNORE_PATH "${LLVM_CONFIG_DIR}")
......@@ -61,9 +63,9 @@ if(ZIG_USE_LLVM_CONFIG)
6163 if (LLVM_CONFIG_ERROR)
6264 # Save the error message, in case this is the last llvm-config we find
6365 if (ZIG_SHARED_LLVM)
64 set(LLVM_CONFIG_ERROR_MESSAGE "LLVM 14.x found at ${LLVM_CONFIG_EXE} does not support linking as a shared library")
66 list(APPEND LLVM_CONFIG_ERROR_MESSAGES "LLVM 14.x found at ${LLVM_CONFIG_EXE} does not support linking as a shared library")
6567 else()
66 set(LLVM_CONFIG_ERROR_MESSAGE "LLVM 14.x found at ${LLVM_CONFIG_EXE} does not support linking as a static library")
68 list(APPEND LLVM_CONFIG_ERROR_MESSAGES "LLVM 14.x found at ${LLVM_CONFIG_EXE} does not support linking as a static library")
6769 endif()
6870
6971 # Ignore this directory and try the search again
......@@ -81,7 +83,7 @@ if(ZIG_USE_LLVM_CONFIG)
8183 list (FIND LLVM_TARGETS_BUILT "${TARGET_NAME}" _index)
8284 if (${_index} EQUAL -1)
8385 # Save the error message, in case this is the last llvm-config we find
84 set(LLVM_CONFIG_ERROR_MESSAGE "LLVM (according to ${LLVM_CONFIG_EXE}) is missing target ${TARGET_NAME}. Zig requires LLVM to be built with all default targets enabled.")
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.")
8587
8688 # Ignore this directory and try the search again
8789 list(APPEND CMAKE_IGNORE_PATH "${LLVM_CONFIG_DIR}")