Skip to content

Commit 6179736

Browse files
hahnjodpiparo
authored andcommitted
Revert "[CMake] Improve Clang directory deduction in core/clingutils"
This reverts commit 02b0dc1. It was partially incorrect and should not use LLVM_DIR, which is only a hint specified by the user. Doing such build system changes just before branching is dangerous because there isn't enough time to properly test all possible configurations.
1 parent ff4f255 commit 6179736

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

core/clingutils/CMakeLists.txt

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,19 +80,31 @@ 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)
8384
if (builtin_clang)
84-
set(CLANG_INSTALL_PREFIX ${CMAKE_BINARY_DIR}/interpreter/llvm-project/llvm/${CMAKE_CFG_INTDIR})
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})
8587
else ()
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})
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)
89103
endif()
90104
endif()
91105

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})
94106

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

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

0 commit comments

Comments
 (0)