Skip to content

Commit 02b0dc1

Browse files
committed
[CMake] Improve Clang directory deduction in core/clingutils
Assume that the Clang versions alsways matches the LLVM version to simplify the code, and also make it possible to find Clang installations separate from the LLVM directory by considering `CLANG_INSTALL_PREFIX`.
1 parent 3ef1193 commit 02b0dc1

File tree

1 file changed

+7
-19
lines changed

1 file changed

+7
-19
lines changed

core/clingutils/CMakeLists.txt

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -80,31 +80,19 @@ foreach(dict ${stldicts})
8080
target_include_directories(${dict}Dict PRIVATE ${CMAKE_SOURCE_DIR}/interpreter/cling/include/cling/cint)
8181
endforeach()
8282

83-
set(CLANG_RESOURCE_DIR_STEM)
8483
if (builtin_clang)
85-
set(CLANG_RESOURCE_DIR_STEM ${CMAKE_BINARY_DIR}/interpreter/llvm-project/llvm/${CMAKE_CFG_INTDIR}/lib/clang)
86-
set(CLANG_RESOURCE_DIR_VERSION ${LLVM_VERSION_MAJOR})
84+
set(CLANG_INSTALL_PREFIX ${CMAKE_BINARY_DIR}/interpreter/llvm-project/llvm/${CMAKE_CFG_INTDIR})
8785
else ()
88-
set(CLANG_RESOURCE_DIR_STEM ${LLVM_LIBRARY_DIR}/clang)
89-
# A user can define a clang version to use, otherwise find it (but will error if more than one version is present)
90-
if (NOT DEFINED CLANG_RESOURCE_DIR_VERSION)
91-
if (NOT EXISTS ${CLANG_RESOURCE_DIR_STEM})
92-
message(FATAL_ERROR "${CLANG_RESOURCE_DIR_STEM} does not exist. Please install clang.")
93-
endif()
94-
# There is no reasonable way to get the version of clang under which is its resource directory.
95-
# For example, lib/clang/5.0.0/include. Deduce it.
96-
file(GLOB CHILDREN RELATIVE ${CLANG_RESOURCE_DIR_STEM} ${CLANG_RESOURCE_DIR_STEM}/*)
97-
list(LENGTH CHILDREN CHILDREN_LENGTH)
98-
if (${CHILDREN_LENGTH} GREATER 1)
99-
message(FATAL_ERROR "Found more than one version of clang. CLANG_RESOURCE_DIR_VERSION contains: '${CHILDREN}'." )
100-
endif()
101-
102-
list(GET CHILDREN 0 CLANG_RESOURCE_DIR_VERSION)
86+
# If no explicit Clang prefix is set, assume it lives inside LLVM prefix.
87+
if(NOT DEFINED CLANG_INSTALL_PREFIX)
88+
set(CLANG_INSTALL_PREFIX ${LLVM_DIR})
10389
endif()
10490
endif()
10591

92+
# We only look for the Clang version that matches the LLVM version, because other setups are not supported.
93+
set(CLANG_RESOURCE_DIR_VERSION ${LLVM_VERSION_MAJOR})
10694

107-
set(CLANG_RESOURCE_DIR ${CLANG_RESOURCE_DIR_STEM}/${CLANG_RESOURCE_DIR_VERSION}/include)
95+
set(CLANG_RESOURCE_DIR ${CLANG_INSTALL_PREFIX}/lib/clang/${CLANG_RESOURCE_DIR_VERSION}/include)
10896

10997
#---Deal with clang resource here----------------------------------------------
11098
install(DIRECTORY ${CMAKE_BINARY_DIR}/etc/cling/lib/clang/${CLANG_RESOURCE_DIR_VERSION}/include/

0 commit comments

Comments
 (0)