[clang][cmake] Use `GNUInstallDirs` to support custom installation dirs

I am breaking apart D99484 so the cause of build failures is easier to
understand.

Differential Revision: https://reviews.llvm.org/D117419
This commit is contained in:
John Ericson 2022-01-16 06:14:24 +00:00
parent efa15f4178
commit 10d0d8c0c1
12 changed files with 35 additions and 28 deletions

View File

@ -4,7 +4,13 @@ cmake_minimum_required(VERSION 3.13.4)
# standalone project, using LLVM as an external library:
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
project(Clang)
set(CLANG_BUILT_STANDALONE TRUE)
endif()
# Must go below project(..)
include(GNUInstallDirs)
if(CLANG_BUILT_STANDALONE)
set(CMAKE_CXX_STANDARD 14 CACHE STRING "C++ standard to conform to")
set(CMAKE_CXX_STANDARD_REQUIRED YES)
set(CMAKE_CXX_EXTENSIONS NO)
@ -185,8 +191,6 @@ if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
endif()
endif()
set(CLANG_BUILT_STANDALONE TRUE)
set(BACKEND_PACKAGE_STRING "LLVM ${LLVM_PACKAGE_VERSION}")
else()
set(BACKEND_PACKAGE_STRING "${PACKAGE_STRING}")
@ -424,7 +428,7 @@ include_directories(BEFORE
if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
install(DIRECTORY include/clang include/clang-c
DESTINATION include
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
COMPONENT clang-headers
FILES_MATCHING
PATTERN "*.def"
@ -433,7 +437,7 @@ if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
)
install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include/clang
DESTINATION include
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
COMPONENT clang-headers
FILES_MATCHING
PATTERN "CMakeFiles" EXCLUDE
@ -453,7 +457,7 @@ if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
add_custom_target(bash-autocomplete DEPENDS utils/bash-autocomplete.sh)
install(PROGRAMS utils/bash-autocomplete.sh
DESTINATION share/clang
DESTINATION "${CMAKE_INSTALL_DATADIR}/clang"
COMPONENT bash-autocomplete)
if(NOT LLVM_ENABLE_IDE)
add_llvm_install_targets(install-bash-autocomplete

View File

@ -1,3 +1,4 @@
include(GNUInstallDirs)
include(LLVMDistributionSupport)
function(clang_tablegen)
@ -120,7 +121,7 @@ macro(add_clang_library name)
${export_to_clangtargets}
LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX}
ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX}
RUNTIME DESTINATION bin)
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")
if (NOT LLVM_ENABLE_IDE)
add_llvm_install_targets(install-${lib}
@ -159,7 +160,7 @@ macro(add_clang_tool name)
get_target_export_arg(${name} Clang export_to_clangtargets)
install(TARGETS ${name}
${export_to_clangtargets}
RUNTIME DESTINATION bin
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
COMPONENT ${name})
if(NOT LLVM_ENABLE_IDE)

View File

@ -1,3 +1,4 @@
include(ExtendPath)
include(LLVMDistributionSupport)
include(FindPrefixFromConfig)
@ -42,8 +43,9 @@ find_prefix_from_config(CLANG_CONFIG_CODE CLANG_INSTALL_PREFIX "${CLANG_INSTALL_
set(CLANG_CONFIG_CMAKE_DIR "\${CLANG_INSTALL_PREFIX}/${CLANG_INSTALL_PACKAGE_DIR}")
set(CLANG_CONFIG_LLVM_CMAKE_DIR "\${CLANG_INSTALL_PREFIX}/${LLVM_INSTALL_PACKAGE_DIR}")
get_config_exports_includes(Clang CLANG_CONFIG_INCLUDE_EXPORTS)
extend_path(base_includedir "\${CLANG_INSTALL_PREFIX}" "${CMAKE_INSTALL_INCLUDEDIR}")
set(CLANG_CONFIG_INCLUDE_DIRS
"\${CLANG_INSTALL_PREFIX}/include"
"${base_includedir}"
)
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/ClangConfig.cmake.in

View File

@ -49,7 +49,7 @@ if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
set_property(TARGET c-index-test APPEND PROPERTY INSTALL_RPATH
"@executable_path/../../lib")
else()
set(INSTALL_DESTINATION bin)
set(INSTALL_DESTINATION "${CMAKE_INSTALL_BINDIR}")
endif()
install(TARGETS c-index-test

View File

@ -21,20 +21,20 @@ if( LLVM_LIB_FUZZING_ENGINE OR LLVM_USE_SANITIZE_COVERAGE )
endif()
install(PROGRAMS clang-format-bbedit.applescript
DESTINATION share/clang
DESTINATION "${CMAKE_INSTALL_DATADIR}/clang"
COMPONENT clang-format)
install(PROGRAMS clang-format-diff.py
DESTINATION share/clang
DESTINATION "${CMAKE_INSTALL_DATADIR}/clang"
COMPONENT clang-format)
install(PROGRAMS clang-format-sublime.py
DESTINATION share/clang
DESTINATION "${CMAKE_INSTALL_DATADIR}/clang"
COMPONENT clang-format)
install(PROGRAMS clang-format.el
DESTINATION share/clang
DESTINATION "${CMAKE_INSTALL_DATADIR}/clang"
COMPONENT clang-format)
install(PROGRAMS clang-format.py
DESTINATION share/clang
DESTINATION "${CMAKE_INSTALL_DATADIR}/clang"
COMPONENT clang-format)
install(PROGRAMS git-clang-format
DESTINATION bin
DESTINATION "${CMAKE_INSTALL_BINDIR}"
COMPONENT clang-format)

View File

@ -22,4 +22,4 @@ target_link_libraries(clang-nvlink-wrapper
${CLANG_NVLINK_WRAPPER_LIB_DEPS}
)
install(TARGETS clang-nvlink-wrapper RUNTIME DESTINATION bin)
install(TARGETS clang-nvlink-wrapper RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")

View File

@ -19,8 +19,8 @@ clang_target_link_libraries(clang-rename
)
install(PROGRAMS clang-rename.py
DESTINATION share/clang
DESTINATION "${CMAKE_INSTALL_DATADIR}/clang"
COMPONENT clang-rename)
install(PROGRAMS clang-rename.el
DESTINATION share/clang
DESTINATION "${CMAKE_INSTALL_DATADIR}/clang"
COMPONENT clang-rename)

View File

@ -186,7 +186,7 @@ endif()
if(INTERNAL_INSTALL_PREFIX)
set(LIBCLANG_HEADERS_INSTALL_DESTINATION "${INTERNAL_INSTALL_PREFIX}/include")
else()
set(LIBCLANG_HEADERS_INSTALL_DESTINATION include)
set(LIBCLANG_HEADERS_INSTALL_DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
endif()
install(DIRECTORY ../../include/clang-c

View File

@ -43,7 +43,7 @@ foreach(BinFile ${BinFiles})
${CMAKE_BINARY_DIR}/bin/scan-build-py
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/bin/scan-build)
install (PROGRAMS "bin/scan-build"
DESTINATION bin
DESTINATION "${CMAKE_INSTALL_BINDIR}"
RENAME scan-build-py
COMPONENT scan-build-py)
list(APPEND Depends ${CMAKE_BINARY_DIR}/bin/scan-build-py)
@ -56,7 +56,7 @@ foreach(BinFile ${BinFiles})
${CMAKE_BINARY_DIR}/bin/
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/bin/${BinFile})
install(PROGRAMS bin/${BinFile}
DESTINATION bin
DESTINATION "${CMAKE_INSTALL_BINDIR}"
COMPONENT scan-build-py)
list(APPEND Depends ${CMAKE_BINARY_DIR}/bin/${BinFile})
endif()
@ -72,7 +72,7 @@ foreach(lib ${LibExecs})
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/libexec/${lib})
list(APPEND Depends ${CMAKE_BINARY_DIR}/libexec/${lib})
install(PROGRAMS libexec/${lib}
DESTINATION libexec
DESTINATION "${CMAKE_INSTALL_LIBEXECDIR}"
COMPONENT scan-build-py)
endforeach()

View File

@ -47,7 +47,7 @@ if(CLANG_INSTALL_SCANBUILD)
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/bin/${BinFile})
list(APPEND Depends ${CMAKE_BINARY_DIR}/bin/${BinFile})
install(PROGRAMS bin/${BinFile}
DESTINATION bin
DESTINATION "${CMAKE_INSTALL_BINDIR}"
COMPONENT scan-build)
endforeach()
@ -61,7 +61,7 @@ if(CLANG_INSTALL_SCANBUILD)
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/libexec/${LibexecFile})
list(APPEND Depends ${CMAKE_BINARY_DIR}/libexec/${LibexecFile})
install(PROGRAMS libexec/${LibexecFile}
DESTINATION libexec
DESTINATION "${CMAKE_INSTALL_LIBEXECDIR}"
COMPONENT scan-build)
endforeach()
@ -89,7 +89,7 @@ if(CLANG_INSTALL_SCANBUILD)
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/share/scan-build/${ShareFile})
list(APPEND Depends ${CMAKE_BINARY_DIR}/share/scan-build/${ShareFile})
install(FILES share/scan-build/${ShareFile}
DESTINATION share/scan-build
DESTINATION "${CMAKE_INSTALL_DATADIR}/scan-build"
COMPONENT scan-build)
endforeach()

View File

@ -20,7 +20,7 @@ if(CLANG_INSTALL_SCANVIEW)
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/bin/${BinFile})
list(APPEND Depends ${CMAKE_BINARY_DIR}/bin/${BinFile})
install(PROGRAMS bin/${BinFile}
DESTINATION bin
DESTINATION "${CMAKE_INSTALL_BINDIR}"
COMPONENT scan-view)
endforeach()
@ -34,7 +34,7 @@ if(CLANG_INSTALL_SCANVIEW)
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/share/${ShareFile})
list(APPEND Depends ${CMAKE_BINARY_DIR}/share/scan-view/${ShareFile})
install(FILES share/${ShareFile}
DESTINATION share/scan-view
DESTINATION "${CMAKE_INSTALL_DATADIR}/scan-view"
COMPONENT scan-view)
endforeach()

View File

@ -10,7 +10,7 @@ add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin/${CLANG_HM
list(APPEND Depends ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin/${CLANG_HMAPTOOL})
install(PROGRAMS ${CLANG_HMAPTOOL}
DESTINATION bin
DESTINATION "${CMAKE_INSTALL_BINDIR}"
COMPONENT hmaptool)
add_custom_target(hmaptool ALL DEPENDS ${Depends})