This is an archive of the discontinued LLVM Phabricator instance.

[lld][CMake] Use `GNUInstallDirs` to support custom installation dirs
ClosedPublic

Authored by Ericson2314 on Dec 10 2021, 7:15 PM.

Details

Summary

Extracted from D99484. My new plan is to start from the outside and work
inward.

Diff Detail

Event Timeline

Ericson2314 created this revision.Dec 10 2021, 7:15 PM
Ericson2314 requested review of this revision.Dec 10 2021, 7:15 PM
Herald added a project: Restricted Project. · View Herald TranscriptDec 10 2021, 7:15 PM

Fix installed include dir

  1. Updating D115568: [lld] Use GNUInstallDirs to support custom installation dirs. #
  2. Enter a brief description of the changes included in this update.
  3. The first line is used as subject, next lines as comment. #
  4. If you intended to create a new revision, use:
  5. $ arc diff --create

Fix typo

  1. Updating D115568: [lld] Use GNUInstallDirs to support custom installation dirs. #
  2. Enter a brief description of the changes included in this update.
  3. The first line is used as subject, next lines as comment. #
  4. If you intended to create a new revision, use:
  5. $ arc diff --create

fix typo and simplify

phosek added inline comments.Dec 13 2021, 11:44 PM
lld/cmake/modules/CMakeLists.txt
31–41

Could we move this to a top-level CMake module in https://github.com/llvm/llvm-project/tree/main/cmake/Modules so we can avoid duplicating this logic in every subproject?

Ericson2314 added inline comments.Dec 14 2021, 8:10 AM
lld/cmake/modules/CMakeLists.txt
31–41

Oh I didn't realize there was such a top-level dir, great!

  1. Updating D115568: [lld] Use GNUInstallDirs to support custom installation dirs. #
  2. Enter a brief description of the changes included in this update.
  3. The first line is used as subject, next lines as comment. #
  4. If you intended to create a new revision, use:
  5. $ arc diff --create

factor out functions

Ericson2314 marked an inline comment as done.Dec 14 2021, 12:08 PM
Ericson2314 added inline comments.
lld/cmake/modules/CMakeLists.txt
31–41

This is now done, and I rebased it atop D115746 which does something similar.

(we removed similar project-wide prefix variables in libc++, libc++abi, and libc++ before, but I suppose now that we have this function, if someone were to chime in that they wanted them back after all, it wouldn't be such a nuisance to support.)

  1. Updating D115568: [lld] Use GNUInstallDirs to support custom installation dirs. #
  2. Enter a brief description of the changes included in this update.
  3. The first line is used as subject, next lines as comment. #
  4. If you intended to create a new revision, use:
  5. $ arc diff --create

rebase on arc diff of the other

Ericson2314 retitled this revision from [lld] Use `GNUInstallDirs` to support custom installation dirs. to [lld][cmake] Use `GNUInstallDirs` to support custom installation dirs..Dec 14 2021, 12:14 PM
  1. Updating D115568: [lld][cmake] Use GNUInstallDirs to support custom installation dirs. #
  2. Enter a brief description of the changes included in this update.
  3. The first line is used as subject, next lines as comment. #
  4. If you intended to create a new revision, use:
  5. $ arc diff --create

Rebase to hopefully fix pre-merge CI

  1. Updating D115568: [lld][cmake] Use GNUInstallDirs to support custom installation dirs. #
  2. Enter a brief description of the changes included in this update.
  3. The first line is used as subject, next lines as comment. #
  4. If you intended to create a new revision, use:
  5. $ arc diff --create

Fix mod inc path

Rebase, no longer need new function

  1. Updating D115568: [lld][cmake] Use GNUInstallDirs to support custom installation dirs. #
  2. Enter a brief description of the changes included in this update.
  3. The first line is used as subject, next lines as comment. #
  4. If you intended to create a new revision, use:
  5. $ arc diff --create

rebase

Ericson2314 retitled this revision from [lld][cmake] Use `GNUInstallDirs` to support custom installation dirs. to [lld] Use `GNUInstallDirs` to support custom installation dirs..Dec 29 2021, 11:03 PM
  1. Updating D115568: [lld] Use GNUInstallDirs to support custom installation dirs. #
  2. Enter a brief description of the changes included in this update.
  3. The first line is used as subject, next lines as comment. #
  4. If you intended to create a new revision, use:
  5. $ arc diff --create

fix base cmake import

MaskRay added a reviewer: Restricted Project.Dec 30 2021, 12:42 AM
MaskRay retitled this revision from [lld] Use `GNUInstallDirs` to support custom installation dirs. to [lld][CMake] Use `GNUInstallDirs` to support custom installation dirs.
This revision is now accepted and ready to land.Dec 31 2021, 1:30 AM
mstorsjo added inline comments.
lld/CMakeLists.txt
159

This broke building in my setups.

In my setups, I still symlink the clang/lld directories into llvm/tools instead of invoking them via LLVM_ENABLE_PROJECTS. Thus referring to ${LLD_SOURCE_DIR}/.. ends up at llvm-project/llvm/tools instead of at llvm-project.

Is there some better cmake variable we could use here for unambiguously referring to the monorepo root?

(As backstory - a condition for me for getting away from building in that legacy setup, would be to be able to build things with the main llvm-project directory as main target directory for the cmake invocation. When pointing cmake at llvm-project/llvm, cmake uses relative paths for all files under the llvm subdir, but uses absolute paths for files under e.g. llvm-project/lld. With those tools symlinked under llvm-project/llvm/tools, it ends up using relative paths for all files. Using relative paths for compiling files is vital for being able to use ccache across different source trees, otherwise all built object files are unique for each source tree, due to e.g. paths in assert messages.)

mstorsjo added inline comments.Dec 31 2021, 4:08 PM
lld/CMakeLists.txt
159

I guess a working, but inelegant, solution would be to use ${LLVM_MAIN_SRC_DIR}/../cmake if it happens to exist, otherwise fall back on ${LLD_SOURCE_DIR}/../cmake. The former would normally work, but could maybe fail if building lld standalone without being invoked from the main llvm tree, and the llvm-project source tree has been moved since llvm itself was built.

Ericson2314 added inline comments.Dec 31 2021, 4:58 PM
lld/CMakeLists.txt
159

Sorry about this. The runtime libraries (compile-rt, libunwind, libcxxabi, etc.) do this already, so I figured it was OK.

As a temp hack, you can symlink the repo-root cmake as llvm/tools/cmake. That should fix the ../cmake, right?

I think the better thing to do is simply make a new CACHE PATH for "shared cmake utils" in each of these projects, so you can set that one however you like.