This is an archive of the discontinued LLVM Phabricator instance.

[cmake] Make include(GNUInstallDirs) always below project(..)
ClosedPublic

Authored by Ericson2314 on Jan 18 2022, 10:54 PM.

Details

Reviewers
arichardson
compnerd
phosek
beanz
bollu
ldionne
sscalpone
Group Reviewers
Restricted Project
Restricted Project
Restricted Project
Commits
rGdf31ff1b29bc: [cmake] Make include(GNUInstallDirs) always below project(..)
Summary

Its defaulting logic must go after project(..) to work correctly, but project(..) is often in a standalone condition making this
awkward, since the rest of the condition code may also need GNUInstallDirs.

The good thing is there are the various standalone booleans, which I had missed before. This makes splitting the conditional blocks less awkward.

Diff Detail

Event Timeline

Ericson2314 created this revision.Jan 18 2022, 10:54 PM
Herald added a reviewer: ldionne. · View Herald Transcript
Herald added projects: Restricted Project, Restricted Project. · View Herald Transcript
Herald added a reviewer: Restricted Project. · View Herald Transcript
Ericson2314 requested review of this revision.Jan 18 2022, 10:54 PM
Herald added projects: Restricted Project, Restricted Project, Restricted Project, Restricted Project. · View Herald TranscriptJan 18 2022, 10:54 PM
Herald added a reviewer: Restricted Project. · View Herald Transcript
Herald added a reviewer: Restricted Project. · View Herald Transcript

Don't forget compiler-rt

Herald added a project: Restricted Project. · View Herald TranscriptJan 18 2022, 11:00 PM
Herald added subscribers: Restricted Project, JDevlieghere. · View Herald Transcript

I believe LLVM_LIBDIR_SUFFIX was added as a workaround for not being able to use GNUInstallDirs (which will automatically detect the right suffixed e.g. for SuSE) in rG46fed3b475ddd92d02d9b72d0d77c5a939f132d1. Would it be possible to move the include() below the project()/enable_language() calls so that CMake can detect the expected libdir suffix and then use something like the following:

# If LLVM_LIBDIR_SUFFIX is defined, we use that to override the libdir, otherwise GNUInstallDirs defaults should be correct.
if(DEFINED LLVM_LIBDIR_SUFFIX)
  message(DEPRECATION "LLVM_LIBDIR_SUFFIX is deprecated, set CMAKE_INSTALL_LIBDIR to lib${LLVM_LIBDIR_SUFFIX} instead")
  set(CMAKE_INSTALL_LIBDIR lib${LLVM_LIBDIR_SUFFIX})
endif()
include(GNUInstallDirs)

I can't see anywhere where the GNUInstallDirs variables are used before project(), so can't we just move the includes further down?

I see AddLLVM already includes GNUInstallDirs, can we add the LLVM_LIBDIR_SUFFIX check to that file and avoid including GNUInstallDirs explicitly in all the projects? The standalone builds will pull in GNUInstallDirs via AddLLVM, and the non-standalone builds should already have the variables defined?

I believe LLVM_LIBDIR_SUFFIX was added as a workaround for not being able to use GNUInstallDirs (which will automatically detect the right suffixed e.g. for SuSE) in rG46fed3b475ddd92d02d9b72d0d77c5a939f132d1. Would it be possible to move the include() below the project()/enable_language() calls so that CMake can detect the expected libdir suffix and then use something like the following:

# If LLVM_LIBDIR_SUFFIX is defined, we use that to override the libdir, otherwise GNUInstallDirs defaults should be correct.
if(DEFINED LLVM_LIBDIR_SUFFIX)
  message(DEPRECATION "LLVM_LIBDIR_SUFFIX is deprecated, set CMAKE_INSTALL_LIBDIR to lib${LLVM_LIBDIR_SUFFIX} instead")
  set(CMAKE_INSTALL_LIBDIR lib${LLVM_LIBDIR_SUFFIX})
endif()
include(GNUInstallDirs)

I would love to do this, but I was unsure whether that was acceptable.

It gets even more complicated downstream when other *_LIBDIR_SUFFIX variable are defaulted from LLVM_LIBDIR_SUFFIX. Can we deprecate that too?

Ericson2314 updated this revision to Diff 401296.EditedJan 19 2022, 9:52 AM

Just move them

@arichardson as the description now indicates, I found the STANDALONE variables, which made doing what was originally asked less awkard than I feared.

I do also prefer splitting the blocks to putting the logic further below. as I rather not get clever with questions of "does this include transitively reference gnu install dirs?" etc.

Herald added a project: Restricted Project. · View Herald Transcript
Ericson2314 retitled this revision from [cmake] Avoid warning or extra suffix for CMAKE_INSTALL_LIBDIR to [cmake] Make include(GNUInstallDirs) always below project(..).Jan 19 2022, 9:54 AM
Ericson2314 edited the summary of this revision. (Show Details)
Ericson2314 edited the summary of this revision. (Show Details)

Rebase after D117617 landed

arichardson accepted this revision.Jan 19 2022, 3:39 PM

This LGTM, but please wait for someone else to review before committing it.

lldb/CMakeLists.txt
21

Could keep this in the first if then you won't have to duplicate setting LLDB_BUILT_STANDALONE?

beanz accepted this revision.Jan 19 2022, 3:41 PM

LGTM.

phosek accepted this revision.Jan 19 2022, 7:48 PM

LGTM

ldionne accepted this revision.Jan 20 2022, 8:18 AM
This revision is now accepted and ready to land.Jan 20 2022, 8:18 AM