Skip to content

Conversation

@guitargeek
Copy link
Contributor

@guitargeek guitargeek commented Apr 22, 2025

If Clang was installed standalone (in particular, not in the LLVM tree),
use the CLANG_INSTALL_PREFIX variable to indicate where it is.

Actually, we can always use CLANG_INSTALL_PREFIX. It's defined by
ClangConfig.cmake. We should also need to take into account
LLVM_LIBDIR_SUFFIX.

Follows up on:

@hahnjo
Copy link
Member

hahnjo commented Apr 22, 2025

I disagree with merging any build system related work at this point.

@guitargeek
Copy link
Contributor Author

Sure, this can also be done after the branching of 6.36!

@github-actions
Copy link

github-actions bot commented Apr 22, 2025

Test Results

    18 files      18 suites   3d 17h 17m 17s ⏱️
 2 731 tests  2 731 ✅ 0 💤 0 ❌
47 771 runs  47 771 ✅ 0 💤 0 ❌

Results for commit fbec790.

♻️ This comment has been updated with latest results.

@ferdymercury ferdymercury added this to the 6.38.00 milestone Apr 22, 2025
@guitargeek
Copy link
Contributor Author

@hahnjo, what do you think about this for master?

@guitargeek guitargeek changed the title [CMake] Support standalone builds of Clang [CMake] Get Clang directory from CLANG_INSTALL_PREFIX Apr 30, 2025
Copy link
Member

@hahnjo hahnjo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm wait, CLANG_INSTALL_PREFIX is not set for me with builtin_clang=OFF... Could be that we have to forward it

Copy link
Member

@hahnjo hahnjo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need

diff --git a/interpreter/CMakeLists.txt b/interpreter/CMakeLists.txt
index e6512a88828..014be83dc28 100644
--- a/interpreter/CMakeLists.txt
+++ b/interpreter/CMakeLists.txt
@@ -407,6 +407,9 @@ if (builtin_clang)
 else()
   find_package(Clang REQUIRED CONFIG)
   message(STATUS "Found Clang ${CLANG_PACKAGE_VERSION} in ${CLANG_CMAKE_DIR}")
+
+  # Forward CLANG_INSTALL_PREFIX so it can be used by core/clingutils/CMakeLists.txt
+  set(CLANG_INSTALL_PREFIX ${CLANG_INSTALL_PREFIX} PARENT_SCOPE)
 endif()
 
 # Reset the compiler flags after compiling LLVM and Clang

It might have worked by accident before if /lib/clang/ happened to contain files for the right Clang version...

@guitargeek
Copy link
Contributor Author

Hm wait, CLANG_INSTALL_PREFIX is not set for me with builtin_clang... Could be that we have to forward it

But the change is in the else branch of the if (builtin_clang) so it should be alright, no?

I have tested it for my setup: system LLVM without Clang and then standalone Clang in different directory, and it works

@hahnjo
Copy link
Member

hahnjo commented Apr 30, 2025

Hm wait, CLANG_INSTALL_PREFIX is not set for me with builtin_clang... Could be that we have to forward it

But the change is in the else branch of the if (builtin_clang) so it should be alright, no?

Yes sorry, my comment was supposed to say builtin_clang=OFF. It is set in interpreter/CMakeLists.txt, but not propagated to the parent directory.

I have tested it for my setup: system LLVM without Clang and then standalone Clang in different directory, and it works

Can you print the result of CLANG_RESOURCE_DIR_STEM? For me it was /lib/clang which is incorrect, but happened to work...

@guitargeek
Copy link
Contributor Author

Ok, I'll check. But I will also make some test with a full LLVM build including patched Clang so I'm more sure to understand all cases. So for me the PR is on hold anyway

@guitargeek
Copy link
Contributor Author

guitargeek commented May 4, 2025

Hi @hahnjo! I now tested this PR with two configurations:

  1. System LLVM with no Clang on the system, plus standalone build of patched Clang
  2. No LLVM on the system, but custom LLVM build with LLVM_ENABLE_PROJECTS=clang

Both works! By the way, what do you think about doing find_package(Clang) also in core, instead of the set(CLANG_INSTALL_PREFIX ${CLANG_INSTALL_PREFIX} PARENT_SCOPE)? Setting variables in the parent scope is more confusing IMO 🙂 But anyway, both works and I'm happy with how the PR currently is 👍

If Clang was installed standalone (in particular, not in the LLVM tree),
use the CLANG_INSTALL_PREFIX variable to indicate where it is.

Actually, we can always use `CLANG_INSTALL_PREFIX`. It's defined by
`ClangConfig.cmake`. To make sure that this works, `find_package(Clang)`
has to be called in `core/clingutils/CMakeLists.txt`.
@hahnjo
Copy link
Member

hahnjo commented May 5, 2025

By the way, what do you think about doing find_package(Clang) also in core, instead of the set(CLANG_INSTALL_PREFIX ${CLANG_INSTALL_PREFIX} PARENT_SCOPE)? Setting variables in the parent scope is more confusing IMO

Potentially, but we also compute many other variables in interpreter/CMakeLists.txt and having them all in one place might be the better choice

@guitargeek guitargeek merged commit 8f21acb into root-project:master May 5, 2025
40 of 41 checks passed
@guitargeek guitargeek deleted the clang_standalone branch August 5, 2025 17:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants