From bf2f2237ece4d316ad9a60fd33208b01fea80052 Mon Sep 17 00:00:00 2001 From: Jonas Hahnfeld Date: Thu, 2 Jan 2025 11:47:54 +0100 Subject: [PATCH 1/5] [cling] Prevent builtin_llvm with builtin_clang=OFF --- interpreter/CMakeLists.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/interpreter/CMakeLists.txt b/interpreter/CMakeLists.txt index 72c437090e8ce..8a110c5cae75d 100644 --- a/interpreter/CMakeLists.txt +++ b/interpreter/CMakeLists.txt @@ -2,6 +2,10 @@ set(CMAKE_MODULE_PATH "") #--- Check if we need to build llvm and clang ------------------------------------------------------ +if (builtin_llvm AND NOT builtin_clang) + message(FATAL_ERROR "Cannot enable builtin LLVM, but provide external Clang") +endif() + if (NOT builtin_clang) message(WARNING "Due to ROOT-specific patches you need a special version of clang. You cannot use vanilla clang.") endif() From 163f4a78e07a57560ea1c7ae352ba3de23f4ed05 Mon Sep 17 00:00:00 2001 From: Jonas Hahnfeld Date: Thu, 2 Jan 2025 12:01:33 +0100 Subject: [PATCH 2/5] [interpreter/cling] Consistently set and use CLANG_CONFIG_CMAKE_DIR For standard CMake, Clang_DIR should include the lib/cmake/clang subdirectory suffix. This currently works only because Clad defines HINTS itself. --- interpreter/CMakeLists.txt | 6 +++--- interpreter/cling/CMakeLists.txt | 2 +- interpreter/cling/cmake/modules/CMakeLists.txt | 2 +- interpreter/cling/tools/plugins/clad/CMakeLists.txt | 6 +----- 4 files changed, 6 insertions(+), 10 deletions(-) diff --git a/interpreter/CMakeLists.txt b/interpreter/CMakeLists.txt index 8a110c5cae75d..a49f88a4fc97c 100644 --- a/interpreter/CMakeLists.txt +++ b/interpreter/CMakeLists.txt @@ -450,18 +450,18 @@ endif(builtin_llvm) if (builtin_clang) if (builtin_llvm) - # For builtin LLVM this is set in interpreter/llvm-project/llvm/CMakeLists.txt set(Clang_DIR "${LLVM_BINARY_DIR}/tools/clang/") else() set(Clang_DIR "${CMAKE_BINARY_DIR}/interpreter/llvm-project/clang/") - set(Clang_Config_ExtraPathHints "${Clang_DIR}cmake/modules/CMakeFiles") endif() set(CLANG_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/interpreter/llvm-project/clang/include ${Clang_DIR}/include CACHE STRING "Clang include directories.") + # FIXME: This is due to a downstream patch! + set(CLANG_CONFIG_CMAKE_DIR "${Clang_DIR}/lib/cmake/clang/") else() - set(Clang_DIR "${LLVM_BINARY_DIR}/lib/cmake/clang/") + set(CLANG_CONFIG_CMAKE_DIR "${LLVM_BINARY_DIR}/lib/cmake/clang/") endif() # Reset the compiler flags after compiling LLVM and Clang diff --git a/interpreter/cling/CMakeLists.txt b/interpreter/cling/CMakeLists.txt index 710de930b4ac4..16adffabec047 100644 --- a/interpreter/cling/CMakeLists.txt +++ b/interpreter/cling/CMakeLists.txt @@ -23,7 +23,7 @@ if( CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR ) find_package(Clang REQUIRED CONFIG) message(STATUS "Found supported version: Clang ${CLANG_PACKAGE_VERSION}") - message(STATUS "Using ClangConfig.cmake in: ${Clang_DIR}") + message(STATUS "Using ClangConfig.cmake in: ${CLANG_CONFIG_CMAKE_DIR}") find_program(LLVM_TABLEGEN_EXE "llvm-tblgen" ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH) diff --git a/interpreter/cling/cmake/modules/CMakeLists.txt b/interpreter/cling/cmake/modules/CMakeLists.txt index e28220db6a06b..bf03e79ac2b8f 100644 --- a/interpreter/cling/cmake/modules/CMakeLists.txt +++ b/interpreter/cling/cmake/modules/CMakeLists.txt @@ -13,7 +13,7 @@ export(TARGETS ${CLING_EXPORTS} FILE ${cling_cmake_builddir}/ClingTargets.cmake) # Generate ClingConfig.cmake for the build tree. set(CLING_CONFIG_CMAKE_DIR "${cling_cmake_builddir}") -set(CLING_CONFIG_CLANG_CMAKE_DIR "${clang_cmake_builddir}") +set(CLING_CONFIG_CLANG_CMAKE_DIR "${CLANG_CONFIG_CMAKE_DIR}") set(CLING_CONFIG_EXPORTS_FILE "${cling_cmake_builddir}/ClingTargets.cmake") set(CLING_CONFIG_INCLUDE_DIRS "${CLING_SOURCE_DIR}/include" diff --git a/interpreter/cling/tools/plugins/clad/CMakeLists.txt b/interpreter/cling/tools/plugins/clad/CMakeLists.txt index 3c70d00a10f3b..16db4d4bd38b6 100644 --- a/interpreter/cling/tools/plugins/clad/CMakeLists.txt +++ b/interpreter/cling/tools/plugins/clad/CMakeLists.txt @@ -46,10 +46,6 @@ if (CMAKE_CXX_STANDARD) list(APPEND _clad_extra_cmake_args -DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD}) endif(CMAKE_CXX_STANDARD) -if (Clang_DIR) - list(APPEND _clad_extra_cmake_args -DClang_DIR=${Clang_DIR} -DClang_CONFIG_EXTRA_PATH_HINTS=${Clang_Config_ExtraPathHints}) -endif(Clang_DIR) - if (LLVM_FORCE_USE_OLD_TOOLCHAIN) list(APPEND _clad_extra_cmake_args -DLLVM_FORCE_USE_OLD_TOOLCHAIN=${LLVM_FORCE_USE_OLD_TOOLCHAIN}) endif(LLVM_FORCE_USE_OLD_TOOLCHAIN) @@ -94,7 +90,7 @@ ExternalProject_Add( -DCMAKE_CXX_FLAGS=${CLAD_CXX_FLAGS} -DCMAKE_INSTALL_PREFIX=${clad_install_dir}/plugins -DLLVM_DIR=${LLVM_BINARY_DIR} - -DCLANG_INCLUDE_DIRS=${CLANG_INCLUDE_DIRS} + -DClang_DIR=${CLANG_CONFIG_CMAKE_DIR} ${_clad_extra_cmake_args} # FIXME # Building with 1 core is a temporary workaround for #16654 and has to be From f49a44aec3bab15c3fb88af7bbe8eaaa043f7b48 Mon Sep 17 00:00:00 2001 From: Jonas Hahnfeld Date: Thu, 2 Jan 2025 12:06:12 +0100 Subject: [PATCH 3/5] [interpreter] Rename variable as CLANG_BINARY_DIR This is the name used in the Clang build system. --- interpreter/CMakeLists.txt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/interpreter/CMakeLists.txt b/interpreter/CMakeLists.txt index a49f88a4fc97c..f936ce1699c6a 100644 --- a/interpreter/CMakeLists.txt +++ b/interpreter/CMakeLists.txt @@ -450,16 +450,16 @@ endif(builtin_llvm) if (builtin_clang) if (builtin_llvm) - set(Clang_DIR "${LLVM_BINARY_DIR}/tools/clang/") + set(CLANG_BINARY_DIR "${LLVM_BINARY_DIR}/tools/clang/") else() - set(Clang_DIR "${CMAKE_BINARY_DIR}/interpreter/llvm-project/clang/") + set(CLANG_BINARY_DIR "${CMAKE_BINARY_DIR}/interpreter/llvm-project/clang/") endif() set(CLANG_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/interpreter/llvm-project/clang/include - ${Clang_DIR}/include + ${CLANG_BINARY_DIR}/include CACHE STRING "Clang include directories.") # FIXME: This is due to a downstream patch! - set(CLANG_CONFIG_CMAKE_DIR "${Clang_DIR}/lib/cmake/clang/") + set(CLANG_CONFIG_CMAKE_DIR "${CLANG_BINARY_DIR}/lib/cmake/clang/") else() set(CLANG_CONFIG_CMAKE_DIR "${LLVM_BINARY_DIR}/lib/cmake/clang/") endif() From 9bb7be203c41dc61971a2cd457f8e00faa0f2e82 Mon Sep 17 00:00:00 2001 From: Jonas Hahnfeld Date: Thu, 2 Jan 2025 12:08:53 +0100 Subject: [PATCH 4/5] [cling] Use CMAKE_CURRENT_{SOURCE,BINARY}_DIR This is clearer and should also help in case ROOT is built as a subdirectory itself. --- interpreter/CMakeLists.txt | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/interpreter/CMakeLists.txt b/interpreter/CMakeLists.txt index f936ce1699c6a..1a1b802c74a48 100644 --- a/interpreter/CMakeLists.txt +++ b/interpreter/CMakeLists.txt @@ -56,7 +56,7 @@ set(LLVM_FORCE_USE_OLD_TOOLCHAIN ON CACHE BOOL "") set(CMAKE_DISABLE_FIND_PACKAGE_CUDA ON) # will be set again in case NOT builtin_llvm -set(LLVM_DIR "${CMAKE_BINARY_DIR}/interpreter/llvm-project/llvm") +set(LLVM_DIR "${CMAKE_CURRENT_BINARY_DIR}/llvm-project/llvm") if (clad) set(CLING_BUILD_PLUGINS ON) endif() @@ -227,8 +227,8 @@ if(builtin_llvm) add_subdirectory(llvm-project/llvm EXCLUDE_FROM_ALL) endif() - set(LLVM_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/interpreter/llvm-project/llvm/include - ${CMAKE_BINARY_DIR}/interpreter/llvm-project/llvm/include + set(LLVM_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/llvm-project/llvm/include + ${CMAKE_CURRENT_BINARY_DIR}/llvm-project/llvm/include CACHE STRING "LLVM include directories." ) list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/llvm-project/llvm/cmake/modules") @@ -452,10 +452,10 @@ if (builtin_clang) if (builtin_llvm) set(CLANG_BINARY_DIR "${LLVM_BINARY_DIR}/tools/clang/") else() - set(CLANG_BINARY_DIR "${CMAKE_BINARY_DIR}/interpreter/llvm-project/clang/") + set(CLANG_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/llvm-project/clang/") endif() set(CLANG_INCLUDE_DIRS - ${CMAKE_SOURCE_DIR}/interpreter/llvm-project/clang/include + ${CMAKE_CURRENT_SOURCE_DIR}/llvm-project/clang/include ${CLANG_BINARY_DIR}/include CACHE STRING "Clang include directories.") # FIXME: This is due to a downstream patch! @@ -509,7 +509,7 @@ if (builtin_cling) add_subdirectory(cling EXCLUDE_FROM_ALL) add_dependencies(CLING ${CLING_LIBRARIES}) - set(CLING_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/interpreter/cling/include CACHE STRING "") + set(CLING_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/cling/include CACHE STRING "") From a8431551dacc50e78dd57cde89a2200b73b8f91e Mon Sep 17 00:00:00 2001 From: Jonas Hahnfeld Date: Thu, 2 Jan 2025 12:15:30 +0100 Subject: [PATCH 5/5] [interpreter] Revert patch to move ClangConfig.cmake Commit 8a45c096f1 already modified the setup of ClingConfig.cmake, this reverts the second part of commit 2b283ccf3a and removes one downstream patch from our Clang sources. TODO: This needs a new tag and update interpreter/llvm-project.tag! --- interpreter/CMakeLists.txt | 3 +-- interpreter/llvm-project/clang/cmake/modules/CMakeLists.txt | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/interpreter/CMakeLists.txt b/interpreter/CMakeLists.txt index 1a1b802c74a48..d239b13ae5bf3 100644 --- a/interpreter/CMakeLists.txt +++ b/interpreter/CMakeLists.txt @@ -458,8 +458,7 @@ if (builtin_clang) ${CMAKE_CURRENT_SOURCE_DIR}/llvm-project/clang/include ${CLANG_BINARY_DIR}/include CACHE STRING "Clang include directories.") - # FIXME: This is due to a downstream patch! - set(CLANG_CONFIG_CMAKE_DIR "${CLANG_BINARY_DIR}/lib/cmake/clang/") + set(CLANG_CONFIG_CMAKE_DIR "${CMAKE_BINARY_DIR}/lib/cmake/clang/") else() set(CLANG_CONFIG_CMAKE_DIR "${LLVM_BINARY_DIR}/lib/cmake/clang/") endif() diff --git a/interpreter/llvm-project/clang/cmake/modules/CMakeLists.txt b/interpreter/llvm-project/clang/cmake/modules/CMakeLists.txt index 9a3ffb0ee624a..d2d68121371bf 100644 --- a/interpreter/llvm-project/clang/cmake/modules/CMakeLists.txt +++ b/interpreter/llvm-project/clang/cmake/modules/CMakeLists.txt @@ -9,7 +9,7 @@ include(FindPrefixFromConfig) set(CLANG_INSTALL_PACKAGE_DIR "${CMAKE_INSTALL_PACKAGEDIR}/clang" CACHE STRING "Path for CMake subdirectory for Clang (defaults to '${CMAKE_INSTALL_PACKAGEDIR}/clang')") # CMAKE_INSTALL_PACKAGEDIR might be absolute, so don't reuse below. -set(clang_cmake_builddir "${CLANG_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX}/cmake/clang") +set(clang_cmake_builddir "${CMAKE_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX}/cmake/clang") # Keep this in sync with llvm/cmake/CMakeLists.txt! set(LLVM_INSTALL_PACKAGE_DIR "${CMAKE_INSTALL_PACKAGEDIR}/llvm" CACHE STRING