From 84b3c69ff5208a6c5d1d1ed1a66271d154d5a8d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20H=C3=A9rilier?= Date: Fri, 29 Nov 2024 08:32:15 +0100 Subject: [PATCH] cmake: Make sure to get the resource directory from the right clang compiler The resource directory was always retrieved from the system's default clang compiler instead of the targeted one. --- CMakeLists.txt | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index af9bcc1a..a36228fe 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -132,11 +132,30 @@ endif() # Find Clang resource directory with Clang executable. if(NOT CLANG_RESOURCE_DIR) - find_program(CLANG_EXECUTABLE clang) + find_program(CLANG_EXECUTABLE clang-${Clang_VERSION_MAJOR} NAMES clang) if(NOT CLANG_EXECUTABLE) message(FATAL_ERROR "clang executable not found.") endif() + execute_process( + COMMAND ${CLANG_EXECUTABLE} -dumpversion + RESULT_VARIABLE CLANG_DUMP_VERSION_RESULT + OUTPUT_VARIABLE CLANG_DUMP_VERSION + ERROR_VARIABLE CLANG_DUMP_VERSION_ERROR + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + + if(CLANG_DUMP_VERSION_RESULT) + message(FATAL_ERROR "Error retrieving Clang executable version. \ +Output:\n${CLANG_DUMP_VERSION_ERROR}") + endif() + + if (NOT ${CLANG_DUMP_VERSION} STREQUAL ${Clang_VERSION}) + message(FATAL_ERROR "Clang libraries and executable versions differs:\n\ +librairies have version ${Clang_VERSION} and executable has version \ +${CLANG_DUMP_VERSION}.") + endif() + execute_process( COMMAND ${CLANG_EXECUTABLE} -print-resource-dir RESULT_VARIABLE CLANG_FIND_RESOURCE_DIR_RESULT @@ -147,7 +166,7 @@ if(NOT CLANG_RESOURCE_DIR) if(CLANG_FIND_RESOURCE_DIR_RESULT) message(FATAL_ERROR "Error retrieving Clang resource directory with Clang \ - executable. Output:\n ${CLANG_FIND_RESOURCE_DIR_ERROR}") + executable. Output:\n${CLANG_FIND_RESOURCE_DIR_ERROR}") endif() endif()