Skip to content

Commit 84b3c69

Browse files
committed
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.
1 parent 4331c89 commit 84b3c69

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

CMakeLists.txt

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,30 @@ endif()
132132
# Find Clang resource directory with Clang executable.
133133

134134
if(NOT CLANG_RESOURCE_DIR)
135-
find_program(CLANG_EXECUTABLE clang)
135+
find_program(CLANG_EXECUTABLE clang-${Clang_VERSION_MAJOR} NAMES clang)
136136
if(NOT CLANG_EXECUTABLE)
137137
message(FATAL_ERROR "clang executable not found.")
138138
endif()
139139

140+
execute_process(
141+
COMMAND ${CLANG_EXECUTABLE} -dumpversion
142+
RESULT_VARIABLE CLANG_DUMP_VERSION_RESULT
143+
OUTPUT_VARIABLE CLANG_DUMP_VERSION
144+
ERROR_VARIABLE CLANG_DUMP_VERSION_ERROR
145+
OUTPUT_STRIP_TRAILING_WHITESPACE
146+
)
147+
148+
if(CLANG_DUMP_VERSION_RESULT)
149+
message(FATAL_ERROR "Error retrieving Clang executable version. \
150+
Output:\n${CLANG_DUMP_VERSION_ERROR}")
151+
endif()
152+
153+
if (NOT ${CLANG_DUMP_VERSION} STREQUAL ${Clang_VERSION})
154+
message(FATAL_ERROR "Clang libraries and executable versions differs:\n\
155+
librairies have version ${Clang_VERSION} and executable has version \
156+
${CLANG_DUMP_VERSION}.")
157+
endif()
158+
140159
execute_process(
141160
COMMAND ${CLANG_EXECUTABLE} -print-resource-dir
142161
RESULT_VARIABLE CLANG_FIND_RESOURCE_DIR_RESULT
@@ -147,7 +166,7 @@ if(NOT CLANG_RESOURCE_DIR)
147166

148167
if(CLANG_FIND_RESOURCE_DIR_RESULT)
149168
message(FATAL_ERROR "Error retrieving Clang resource directory with Clang \
150-
executable. Output:\n ${CLANG_FIND_RESOURCE_DIR_ERROR}")
169+
executable. Output:\n${CLANG_FIND_RESOURCE_DIR_ERROR}")
151170
endif()
152171
endif()
153172

0 commit comments

Comments
 (0)