This is an archive of the discontinued LLVM Phabricator instance.

[CMake] Avoid `LLVM_BINARY_DIR` when other more specific variable are better-suited, part 2
ClosedPublic

Authored by Ericson2314 on Aug 20 2022, 3:39 PM.

Details

Summary

A simple sed doing these substitutions:

  • ${LLVM_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX}\> -> ${LLVM_LIBRARY_DIR}
  • ${LLVM_BINARY_DIR}/bin\> -> ${LLVM_TOOLS_BINARY_DIR}

where \> means "word boundary".

The only manual modifications were reverting changes in

  • runtimes/CMakeLists.txt

because these were "entry points" where we wanted to tread carefully not not introduce a "loop" which would end with an undefined variable being expanded to nothing.

There are some ${LLVM_BINARY_DIR}/lib without the ${LLVM_LIBDIR_SUFFIX}, but these refer to the lib subdirectory of the source (llvm/lib). That lib is automatically appended to make the local CMAKE_CURRENT_BINARY_DIR value by add_subdirectory; since the directory name in the source tree is fixed without any suffix, the corresponding CMAKE_CURRENT_BINARY_DIR will also be. We therefore do not replace it but leave it as-is.

This picks up where D133828 left off, getting the occurrences with*out* CMAKE_CFG_INTDIR. But this is difficult to do correctly and so not done in the (retroactively) previous diff.

This hopefully increases readability overall, and also decreases the usages of LLVM_LIBDIR_SUFFIX, preparing us for D130586.

Diff Detail

Event Timeline

Ericson2314 created this revision.Aug 20 2022, 3:39 PM
Herald added a reviewer: andreadb. · View Herald Transcript
Herald added a reviewer: rafauler. · View Herald Transcript
Herald added a reviewer: Amir. · View Herald Transcript
Herald added a reviewer: maksfb. · View Herald Transcript
Herald added projects: Restricted Project, Restricted Project. · View Herald Transcript
Ericson2314 requested review of this revision.Aug 20 2022, 3:39 PM
Herald added projects: Restricted Project, Restricted Project, Restricted Project, Restricted Project. · View Herald TranscriptAug 20 2022, 3:39 PM
sebastian-ne added inline comments.Aug 22 2022, 1:56 AM
llvm/tools/llvm-shlib/CMakeLists.txt
89 ↗(On Diff #454256)

The lib here is not used as a folder, so this should probably not be replaced?
It should probably include CMAKE_CFG_INTDIR though (i.e. ${LLVM_BINARY_DIR}/${CMAKE_CFG_INTDIR}/libllvm-c.exports), to be consistent with other places, though this only affects the ninja multi-config build. I’m not sure if that works at all and it’s outside of the scope of this patch anyway.

91 ↗(On Diff #454256)

Should this be set(LIB_DIR ${LLVM_LIBRARY_DIR})?

139 ↗(On Diff #454256)

This should probably use LLVM_LIBRARY_DIR as well.

Redo sed mandating ending on word boundary

Ericson2314 marked an inline comment as done.Aug 23 2022, 7:08 AM
Ericson2314 added inline comments.
llvm/tools/llvm-shlib/CMakeLists.txt
91 ↗(On Diff #454256)

I am not sure what is up with CMAKE_CFG_INTDIR, so I rather leave that for a later revision.

139 ↗(On Diff #454256)

Ditto, rather tackle things with CMAKE_CFG_INTDIR separately.

sebastian-ne added inline comments.Aug 23 2022, 7:13 AM
llvm/tools/llvm-shlib/CMakeLists.txt
91 ↗(On Diff #454256)

LLVM_LIBRARY_DIR includes CMAKE_CFG_INTDIR as it’s set through

set(LLVM_LIBRARY_OUTPUT_INTDIR ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib${LLVM_LIBDIR_SUFFIX})
set(LLVM_LIBRARY_DIR      ${LLVM_LIBRARY_OUTPUT_INTDIR})

As far as I understand, CMAKE_CFG_INTDIR is set to ., unless one does a multi-config build, i.e. one build directory for debug and release builds. multi-config builds are the default when creating Visual Studio solutions and ninja supports multi-config builds since some time (rather recently).

Convert CMAKE_CFG_INTDIR as @sebastian-ne suggests, also .../bin

Ericson2314 marked 3 inline comments as done.Aug 23 2022, 3:10 PM
Ericson2314 added inline comments.
llvm/tools/llvm-shlib/CMakeLists.txt
91 ↗(On Diff #454256)

Oh I see. Silly me. That is a fine reason to convert then.

Ericson2314 retitled this revision from [CMake] `${LLVM_BINARY_DIR}/lib(${LLVM_LIBDIR_SUFFIX})?` -> `${LLVM_LIBRARY_DIR}` to [CMake] Avoid `LLVM_BINARY_DIR` when other more specific variable are better-suited.Aug 23 2022, 3:15 PM
Ericson2314 edited the summary of this revision. (Show Details)
sebastian-ne accepted this revision.Aug 24 2022, 1:39 AM
This revision is now accepted and ready to land.Aug 24 2022, 1:39 AM

The build afterwards succeeded again. Seems like every ~20th build on that windows machine fails.

@Ericson2314 It seems that these changes break building on Windows using Visual Studio 2019.
There are 2 issues:

  • CMake now creates a directory $(Configuration) in the root build directory.
Location before the changes: lib\cmake\llvm
Location after the changes:  $(Configuration)\lib\cmake\llvm
  • The build fails with the errors:
Error C1083 Cannot open include file: 'PPCGenRegisterInfo.inc': No such file or directory	LLVMExegesisPowerPC	llvm-project\llvm\lib\Target\PowerPC\MCTargetDesc\PPCMCTargetDesc.h
Error C1083 Cannot open include file: 'MipsGenRegisterInfo.inc': No such file or directory	LLVMExegesisMips	llvm-project\llvm\lib\Target\Mips\MCTargetDesc\MipsMCTargetDesc.h
Error C1083 Cannot open include file: 'X86GenRegisterInfo.inc': No such file or directory	LLVMExegesisX86	        llvm-project\llvm\lib\Target\X86\MCTargetDesc\X86MCTargetDesc.h
Error C1083 Cannot open include file: 'AArch64GenRegisterInfo.inc': No such file or directory	LLVMExegesisAArch64	llvm-project\llvm\lib\Target\AArch64\MCTargetDesc\AArch64MCTargetDesc.h

This is probably caused by using CMAKE_CFG_INTDIR (indirectly) in more places. Seems like it expands to $(Configuration) for Visual Studio.
Searching more about it, it’s only set at build time, but not at install time, which is a problem as well.
On top of all, CMAKE_CFG_INTDIR is deprecated and superseded by generator expression: https://cmake.org/cmake/help/latest/variable/CMAKE_CFG_INTDIR.html

It also broke llvm-exegesis for 32 bits targets, see https://github.com/llvm/llvm-project/issues/57348
Reverting changes for the files in tools/llvm-exegesis/ solves the compilation issue.

Let's just revert this. I'll do it later today if no one beats me to it.

Let's just revert this. I'll do it later today if no one beats me to it.

Thanks

Ericson2314 reopened this revision.Sep 13 2022, 8:33 PM
This revision is now accepted and ready to land.Sep 13 2022, 8:33 PM
Ericson2314 retitled this revision from [CMake] Avoid `LLVM_BINARY_DIR` when other more specific variable are better-suited to [CMake] Avoid `LLVM_BINARY_DIR` when other more specific variable are better-suited, part 2.Sep 13 2022, 8:43 PM
Ericson2314 edited the summary of this revision. (Show Details)
Ericson2314 edited the summary of this revision. (Show Details)Sep 13 2022, 9:24 PM

Require LLVM_LIBDIR_SUFFIX in the sed

I think I fixed the issue: I was confusing /lib stemming from lib subdirs in the source and /lib stemming from building things in a lib directory that will later be installed also to a lib directory. It is just the latter case that uses the suffix, and so just the latter case will be so seded.