Skip to content

Commit d52329b

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 7db0415 commit d52329b

File tree

1 file changed

+6
-22
lines changed

1 file changed

+6
-22
lines changed

core/clingutils/CMakeLists.txt

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -80,31 +80,15 @@ 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)
84-
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})
87-
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)
103-
endif()
83+
# If no explicit Clang prefix is set, assume it lives inside LLVM prefix.
84+
if(NOT DEFINED CLANG_INSTALL_PREFIX)
85+
set(CLANG_INSTALL_PREFIX ${LLVM_DIR})
10486
endif()
10587

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

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

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

0 commit comments

Comments
 (0)