Skip to content

Commit 4a678f8

Browse files
committed
[cmake] Use GNUInstallDirs to support custom installation dirs.
This is the original patch in my GNUInstallDirs series, now last to merge as the final piece! It arose as a new draft of D28234. I initially did the unorthodox thing of pushing to that when I wasn't the original author, but since I ended up - Using `GNUInstallDirs`, rather than mimicking it, as the original author was hesitant to do but others requested. - Converting all the packages, not just LLVM, effecting many more projects than LLVM itself. I figured it was time to make a new revision. I have used this patch series (and many back-ports) as the basis of NixOS/nixpkgs#111487 for my distro (NixOS), which was merged last spring (2021). It looked like people were generally on board in D28234, but I make note of this here in case extra motivation is useful. --- As pointed out in the original issue, a central tension is that LLVM already has some partial support for these sorts of things. Variables like `COMPILER_RT_INSTALL_PATH` have already been dealt with. Variables like `LLVM_LIBDIR_SUFFIX` however, will require further work, so that we may use `CMAKE_INSTALL_LIBDIR`. These remaining items will be addressed in further patches. What is here is now rote and so we should get it out of the way before dealing more intricately with the remainder. Reviewed By: #libunwind, #libc, #libc_abi, compnerd Differential Revision: https://reviews.llvm.org/D99484
1 parent 1088c78 commit 4a678f8

File tree

36 files changed

+96
-68
lines changed

36 files changed

+96
-68
lines changed

clang-tools-extra/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
include(CMakeDependentOption)
2+
include(GNUInstallDirs)
23

34
option(CLANG_TIDY_ENABLE_STATIC_ANALYZER
45
"Include static analyzer checks in clang-tidy" ON)

clang-tools-extra/clang-doc/tool/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ target_link_libraries(clang-doc
1919
)
2020

2121
install(FILES ../assets/clang-doc-default-stylesheet.css
22-
DESTINATION share/clang
22+
DESTINATION "${CMAKE_INSTALL_DATADIR}/clang"
2323
COMPONENT clang-doc)
2424

2525
install(FILES ../assets/index.js
26-
DESTINATION share/clang
26+
DESTINATION "${CMAKE_INSTALL_DATADIR}/clang"
2727
COMPONENT clang-doc)

clang-tools-extra/clang-include-fixer/find-all-symbols/tool/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@ target_link_libraries(find-all-symbols
2020
)
2121

2222
install(PROGRAMS run-find-all-symbols.py
23-
DESTINATION share/clang
23+
DESTINATION "${CMAKE_INSTALL_DATADIR}/clang"
2424
COMPONENT find-all-symbols)

clang-tools-extra/clang-include-fixer/tool/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ target_link_libraries(clang-include-fixer
2121
)
2222

2323
install(PROGRAMS clang-include-fixer.el
24-
DESTINATION share/clang
24+
DESTINATION "${CMAKE_INSTALL_DATADIR}/clang"
2525
COMPONENT clang-include-fixer)
2626
install(PROGRAMS clang-include-fixer.py
27-
DESTINATION share/clang
27+
DESTINATION "${CMAKE_INSTALL_DATADIR}/clang"
2828
COMPONENT clang-include-fixer)

clang-tools-extra/clang-tidy/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ add_subdirectory(utils)
113113

114114
if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
115115
install(DIRECTORY .
116-
DESTINATION include/clang-tidy
116+
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/clang-tidy"
117117
COMPONENT clang-tidy-headers
118118
FILES_MATCHING
119119
PATTERN "*.h"

clang-tools-extra/clang-tidy/tool/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ target_link_libraries(clang-tidy
5252

5353

5454
install(PROGRAMS clang-tidy-diff.py
55-
DESTINATION share/clang
55+
DESTINATION "${CMAKE_INSTALL_DATADIR}/clang"
5656
COMPONENT clang-tidy)
5757
install(PROGRAMS run-clang-tidy.py
58-
DESTINATION bin
58+
DESTINATION "${CMAKE_INSTALL_BINDIR}"
5959
COMPONENT clang-tidy
6060
RENAME run-clang-tidy)

clang-tools-extra/modularize/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,5 @@ clang_target_link_libraries(modularize
2323
)
2424

2525
install(TARGETS modularize
26-
RUNTIME DESTINATION bin
26+
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
2727
COMPONENT clang-extras)

clang/CMakeLists.txt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
cmake_minimum_required(VERSION 3.13.4)
22

3+
include(GNUInstallDirs)
4+
35
# If we are not building as a part of LLVM, build Clang as an
46
# standalone project, using LLVM as an external library:
57
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
@@ -424,7 +426,7 @@ include_directories(BEFORE
424426

425427
if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
426428
install(DIRECTORY include/clang include/clang-c
427-
DESTINATION include
429+
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
428430
COMPONENT clang-headers
429431
FILES_MATCHING
430432
PATTERN "*.def"
@@ -433,7 +435,7 @@ if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
433435
)
434436

435437
install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include/clang
436-
DESTINATION include
438+
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
437439
COMPONENT clang-headers
438440
FILES_MATCHING
439441
PATTERN "CMakeFiles" EXCLUDE
@@ -453,7 +455,7 @@ if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
453455

454456
add_custom_target(bash-autocomplete DEPENDS utils/bash-autocomplete.sh)
455457
install(PROGRAMS utils/bash-autocomplete.sh
456-
DESTINATION share/clang
458+
DESTINATION "${CMAKE_INSTALL_DATADIR}/clang"
457459
COMPONENT bash-autocomplete)
458460
if(NOT LLVM_ENABLE_IDE)
459461
add_llvm_install_targets(install-bash-autocomplete

clang/cmake/modules/AddClang.cmake

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
include(GNUInstallDirs)
12
include(LLVMDistributionSupport)
23

34
function(clang_tablegen)
@@ -120,7 +121,7 @@ macro(add_clang_library name)
120121
${export_to_clangtargets}
121122
LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX}
122123
ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX}
123-
RUNTIME DESTINATION bin)
124+
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")
124125

125126
if (NOT LLVM_ENABLE_IDE)
126127
add_llvm_install_targets(install-${lib}
@@ -159,7 +160,7 @@ macro(add_clang_tool name)
159160
get_target_export_arg(${name} Clang export_to_clangtargets)
160161
install(TARGETS ${name}
161162
${export_to_clangtargets}
162-
RUNTIME DESTINATION bin
163+
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
163164
COMPONENT ${name})
164165

165166
if(NOT LLVM_ENABLE_IDE)

clang/tools/c-index-test/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
4949
set_property(TARGET c-index-test APPEND PROPERTY INSTALL_RPATH
5050
"@executable_path/../../lib")
5151
else()
52-
set(INSTALL_DESTINATION bin)
52+
set(INSTALL_DESTINATION "${CMAKE_INSTALL_BINDIR}")
5353
endif()
5454

5555
install(TARGETS c-index-test

0 commit comments

Comments
 (0)