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.
For standalone clang build, keep the actual value as libclc cannot be built that way.

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.
For standalone clang build, keep the actual value as libclc cannot be
built that way.
@llvmbot llvmbot added the clang Clang issues not falling into any other category label Sep 29, 2025
@llvmbot
Copy link
Member

llvmbot commented Sep 29, 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.
For standalone clang build, keep the actual value as libclc cannot be built that way.


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

1 Files Affected:

  • (modified) clang/cmake/modules/CMakeLists.txt (+8-4)
diff --git a/clang/cmake/modules/CMakeLists.txt b/clang/cmake/modules/CMakeLists.txt
index d2d68121371bf..9ad2f984f0e27 100644
--- a/clang/cmake/modules/CMakeLists.txt
+++ b/clang/cmake/modules/CMakeLists.txt
@@ -8,15 +8,19 @@ 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")
+if(CLANG_BUILT_STANDALONE)
+  # CMAKE_INSTALL_PACKAGEDIR might be absolute, so don't reuse below.
+  set(clang_cmake_builddir "${CMAKE_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX}/cmake/clang")
+else()
+  set(clang_cmake_builddir "${llvm_builddir}/cmake/clang")
+endif()
 
 get_property(CLANG_EXPORTS GLOBAL PROPERTY CLANG_EXPORTS)
 export(TARGETS ${CLANG_EXPORTS} FILE ${clang_cmake_builddir}/ClangTargets.cmake)

@rjodinchr
Copy link
Contributor Author

This is a following on #155844
cc @tstellar @Keenuts @peterwaller-arm

@peterwaller-arm
Copy link
Contributor

cc @RossComputerGuy

Copy link
Member

@RossComputerGuy RossComputerGuy left a comment

Choose a reason for hiding this comment

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

I was able to build this in nixpkgs which does standalone packaging of LLVM components so this should be good.

@rjodinchr
Copy link
Contributor Author

@tstellar please take a look. If you approve, please merge it (I cannot do it myself)
Thank you

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.

LGTM, since this is mostly the same as the previous change & people impacted by the previous PR have confirmed this is OK, I'll move ahead and merge. We can always revert if we find a new issue.

@Keenuts Keenuts merged commit 88b7707 into llvm:main Oct 16, 2025
11 checks passed
@rjodinchr rjodinchr deleted the pr/clang-cmake branch October 16, 2025 12:36
@llvm-ci
Copy link
Collaborator

llvm-ci commented Oct 16, 2025

LLVM Buildbot has detected a new failure on builder clang-ppc64le-linux-test-suite running on ppc64le-clang-test-suite while building clang at step 6 "test-build-unified-tree-check-all".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/95/builds/18795

Here is the relevant piece of the build log for the reference
Step 6 (test-build-unified-tree-check-all) failure: 1200 seconds without output running [b'ninja', b'check-all'], attempting to kill
...
PASS: MemorySanitizer-POWERPC64LE :: allocator_padding.cpp (102770 of 102779)
PASS: Profile-powerpc64le :: Posix/instrprof-value-prof-shared.test (102771 of 102779)
PASS: lit :: shtest-define.py (102772 of 102779)
PASS: ThreadSanitizer-powerpc64le :: deadlock_detector_stress_test.cpp (102773 of 102779)
PASS: ThreadSanitizer-powerpc64le :: restore_stack.cpp (102774 of 102779)
PASS: SanitizerCommon-asan-powerpc64le-Linux :: Linux/signal_segv_handler.cpp (102775 of 102779)
PASS: SanitizerCommon-tsan-powerpc64le-Linux :: Linux/signal_segv_handler.cpp (102776 of 102779)
PASS: SanitizerCommon-ubsan-powerpc64le-Linux :: Linux/signal_segv_handler.cpp (102777 of 102779)
PASS: SanitizerCommon-msan-powerpc64le-Linux :: Linux/signal_segv_handler.cpp (102778 of 102779)
PASS: SanitizerCommon-lsan-powerpc64le-Linux :: Linux/signal_segv_handler.cpp (102779 of 102779)
command timed out: 1200 seconds without output running [b'ninja', b'check-all'], attempting to kill
process killed by signal 9
program finished with exit code -1
elapsedTime=4425.090010

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.

6 participants