This is an archive of the discontinued LLVM Phabricator instance.

[OpenMP][libomp] Copy OpenMP headers to clang build directory
Needs ReviewPublic

Authored by jlpeyton on Aug 1 2022, 11:56 AM.



This patch copies the OpenMP headers, omp.h, omp-tools.h to clang build directory to allow it use of OpenMP within a build directory prior to install phase.
The libraries seem to already be located in the correct place after building llvm/clang. The copying happens after building successfully.

Diff Detail

Event Timeline

jlpeyton created this revision.Aug 1 2022, 11:56 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 1 2022, 11:56 AM
jlpeyton requested review of this revision.Aug 1 2022, 11:56 AM
Meinersbur added a subscriber: Meinersbur.EditedAug 1 2022, 1:30 PM

Ideally, it would use the that comes with libomp (${CMAKE_BINARY_DIR}/runtime/src/omp.hin the build dir, generated from Only the install script copies it over to ${CMAKE_INSTALL_DIR}/lib/clang/15.0.0/include/omp.h where it can actually be found.

This is a similar problem to one cannot just use the Clang from the build directory for OpenMP since as well as omp.h are in non-standard locations in the build directory layout. For Clang itself, all the headers are copied ../lib/clang/include such that it is possible to use it (including in regression tests) without installing. It would be nice if we could do the same for OpenMP. However, it may not solve the problem for standalone where we still need to pass the search path to omp.h since none the standard header search paths do belong to the libomp's build dir.

jlpeyton updated this revision to Diff 449168.Aug 1 2022, 7:20 PM
jlpeyton retitled this revision from [OpenMP][libomp] Detect if test compiler has omp.h to [OpenMP][libomp] Copy OpenMP headers to clang build directory.
jlpeyton edited the summary of this revision. (Show Details)

Updated patch to copy headers to clang build directory so it can find omp.h and omp-tools.h before install phase.

mgorny added a comment.Aug 1 2022, 9:47 PM

Well, the new patch isn't going to change anything for me since I'm doing a standalone build.

@mgorny , I thought the fundamental issue, as noted by @Meinersbur, was the newly built (but not installed) clang's inability to find an accessible omp.h. You then use the newly built clang to standalone build OpenMP.

This is no longer directly fixing the standalone build by checking for omp.h existence, but instead "fixing" the initial ccache build of LLVM/clang by putting the omp.h where clang can find it.

mgorny added a comment.Aug 2 2022, 9:31 AM

Well, we are building clang *without* libomp, so I don't think this will work for us. I mean, I suppose we could work around that and install this file manually, however I'm getting a little confused what is the end goal here. After all, clang's openmp support isn't going to work without libomp, is it?

jlpeyton edited the summary of this revision. (Show Details)Aug 2 2022, 10:44 AM

I've created to address you issue specifically. It's just the same patch as before. I will leave this one open for review.

Meinersbur added inline comments.Aug 2 2022, 11:21 AM
221 ↗(On Diff #449168)

A non-standalone build doesn't mean that clang is built as well. LLVM_TOOL_CLANG_BUILD might be what you are looking for (like However, it will not be set in an LLVM_ENABLE_RUNTIMES=openmp build.

It not a big issue, at worst we have an unused omp.h in the build directory.

226 ↗(On Diff #449168)

In an LLVM_ENABLE_RUNTIMES=openmp configuration, does LLVM_LIBRARY_OUTPUT_INTDIR point to build the dir where clang is built?

I think it would be ok to only copy over omp.h/omp-tools.h in LLVM_ENABLE_PROJECTS=openmp builds for now.

237 ↗(On Diff #449168)

omp-tools.h is also installed as ompt.h

# install under legacy name ompt.h
jlpeyton updated this revision to Diff 449742.Aug 3 2022, 12:32 PM

Addressing comments

jlpeyton added inline comments.Aug 3 2022, 12:35 PM
221 ↗(On Diff #449168)

Thanks! I've added LLVM_TOOL_CLANG_BUILD and also a check for LLVM_RUNTIMES_BUILD which LLVM defines for the runtimes to know that LLVM_ENABLE_RUNTIMES=... is occurring.

226 ↗(On Diff #449168)

Conveniently, it does point to the correct directory for LLVM_ENABLE_RUNTIMES=openmp

237 ↗(On Diff #449168)

Added ompt.h to list of things to copy.