Skip to content

Conversation

rjodinchr
Copy link
Contributor

When building llvm from a subdirectory (like clspv does) CMAKE_BINARY_DIR is at the top of the build directory.

When building runtimes (libclc for example), the build fails looking for clang (through find_package looking at LLVM_BINARY_DIR with NO_DEFAULT_PATH & NO_CMAKE_FIND_ROOT_PATH) because clang is not in LLVM_BINARY_DIR.

Fix that issue by setting clang_cmake_builddir the same way we set llvm_cmake_builddir from LLVM_BINARY_DIR.

For default llvm build (using llvm as the main cmake project), it should not change anything.

@llvmbot llvmbot added the clang Clang issues not falling into any other category label Aug 28, 2025
@llvmbot
Copy link
Member

llvmbot commented Aug 28, 2025

@llvm/pr-subscribers-clang

Author: Romaric Jodin (rjodinchr)

Changes

When building llvm from a subdirectory (like clspv does) CMAKE_BINARY_DIR is at the top of the build directory.

When building runtimes (libclc for example), the build fails looking for clang (through find_package looking at LLVM_BINARY_DIR with NO_DEFAULT_PATH & NO_CMAKE_FIND_ROOT_PATH) because clang is not in LLVM_BINARY_DIR.

Fix that issue by setting clang_cmake_builddir the same way we set llvm_cmake_builddir from LLVM_BINARY_DIR.

For default llvm build (using llvm as the main cmake project), it should not change anything.


Full diff: https://github.com/llvm/llvm-project/pull/155844.diff

1 Files Affected:

  • (modified) clang/cmake/modules/CMakeLists.txt (+3-4)
diff --git a/clang/cmake/modules/CMakeLists.txt b/clang/cmake/modules/CMakeLists.txt
index d2d68121371bf..b3b4a74f6d470 100644
--- a/clang/cmake/modules/CMakeLists.txt
+++ b/clang/cmake/modules/CMakeLists.txt
@@ -8,15 +8,14 @@ include(FindPrefixFromConfig)
 # the usual CMake convention seems to be ${Project}Targets.cmake.
 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 "${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
   "Path for CMake subdirectory for LLVM (defaults to '${CMAKE_INSTALL_PACKAGEDIR}/llvm')")
 # CMAKE_INSTALL_PACKAGEDIR might be absolute, so don't reuse below.
-string(REPLACE "${CMAKE_CFG_INTDIR}" "." llvm_cmake_builddir "${LLVM_LIBRARY_DIR}")
-set(llvm_cmake_builddir "${llvm_cmake_builddir}/cmake/llvm")
+string(REPLACE "${CMAKE_CFG_INTDIR}" "." llvm_builddir "${LLVM_LIBRARY_DIR}")
+set( llvm_cmake_builddir "${llvm_builddir}/cmake/llvm")
+set(clang_cmake_builddir "${llvm_builddir}/cmake/clang")
 
 get_property(CLANG_EXPORTS GLOBAL PROPERTY CLANG_EXPORTS)
 export(TARGETS ${CLANG_EXPORTS} FILE ${clang_cmake_builddir}/ClangTargets.cmake)

@rjodinchr
Copy link
Contributor Author

@frasercrmck please take a look

@rjodinchr rjodinchr changed the title [clang] clang_cmake_builddir [clang] fix clang_cmake_builddir Aug 28, 2025
When building llvm from a subdirectory (like clspv does)
`CMAKE_BINARY_DIR` is at the top of the build directory.

When building runtimes (libclc for example), the build fails looking
for clang (through `find_package` looking at `LLVM_BINARY_DIR` with
`NO_DEFAULT_PATH` & `NO_CMAKE_FIND_ROOT_PATH`) because clang is not in
`LLVM_BINARY_DIR`.

Fix that issue by setting `clang_cmake_builddir` the same way we set
`llvm_cmake_builddir` from `LLVM_BINARY_DIR`.

For default llvm build (using llvm as the main cmake project), it
should not change anything.
@rjodinchr rjodinchr force-pushed the pr/clang-cmake-builddir branch from 420b284 to bc8040d Compare August 28, 2025 14:30
Copy link
Contributor

@Keenuts Keenuts left a comment

Choose a reason for hiding this comment

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

Looks ok to me. So far seems like even on main, setting -DLLVM_LIBDIR_SUFFIX seem to have the same effect so seems like this is ok
Adding @kwk in case I'm missing something

@Keenuts Keenuts requested a review from kwk September 1, 2025 12:39
@kwk
Copy link
Contributor

kwk commented Sep 1, 2025

Looks ok to me. So far seems like even on main, setting -DLLVM_LIBDIR_SUFFIX has no effect so seems like this is ok Adding @kwk in case I'm missing something

@Keenuts am I really the person you had in mind when asking for a review?

@Keenuts
Copy link
Contributor

Keenuts commented Sep 1, 2025

@Keenuts am I really the person you had in mind when asking for a review?

Was searching for somebody who could double-check, saw you were part of the release status team, so guessed maybe you were familiar with the importants bits around those build directories bits? Do you know a better contact point?

@kwk
Copy link
Contributor

kwk commented Sep 1, 2025

@Keenuts am I really the person you had in mind when asking for a review?

Was searching for somebody who could double-check, saw you were part of the release status team, so guessed maybe you were familiar with the importants bits around those build directories bits? Do you know a better contact point?

Ah I see. @tru and @tstellar are probably more familiar with these bits.

@kwk kwk requested review from tru and tstellar and removed request for kwk September 1, 2025 15:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants