Skip to content

[CMake] Get Clang directory from CLANG_INSTALL_PREFIX #18460

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

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!

Copy link

github-actions bot commented Apr 22, 2025

Test Results

    17 files      17 suites   4d 0h 12m 13s ⏱️
 2 731 tests  2 731 ✅ 0 💤 0 ❌
45 307 runs  45 307 ✅ 0 💤 0 ❌

Results for commit 5807d94.

♻️ 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?

Comment on lines 88 to 94
# If Clang was installed standalone (in particular, not in the LLVM tree),
# use the CLANG_INSTALL_PREFIX variable to indicate where it is.
if(DEFINED CLANG_INSTALL_PREFIX)
set(CLANG_RESOURCE_DIR_STEM ${CLANG_INSTALL_PREFIX}/lib/clang)
else()
set(CLANG_RESOURCE_DIR_STEM ${LLVM_LIBRARY_DIR}/clang)
endif()
Copy link
Member

Choose a reason for hiding this comment

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

I think we can always use CLANG_INSTALL_PREFIX, it's defined by ClangConfig.cmake. We should also take into account LLVM_LIBDIR_SUFFIX (untested):

Suggested change
# If Clang was installed standalone (in particular, not in the LLVM tree),
# use the CLANG_INSTALL_PREFIX variable to indicate where it is.
if(DEFINED CLANG_INSTALL_PREFIX)
set(CLANG_RESOURCE_DIR_STEM ${CLANG_INSTALL_PREFIX}/lib/clang)
else()
set(CLANG_RESOURCE_DIR_STEM ${LLVM_LIBRARY_DIR}/clang)
endif()
set(CLANG_RESOURCE_DIR_STEM ${CLANG_INSTALL_PREFIX}/lib${LLVM_LIBDIR_SUFFIX}/clang)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the suggestion! I'll test it

Copy link
Member

Choose a reason for hiding this comment

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

For LLVM_LIBDIR_SUFFIX, we'll also need #18567

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`.
@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

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