diff --git a/clang/tools/scan-build/CMakeLists.txt b/clang/tools/scan-build/CMakeLists.txt --- a/clang/tools/scan-build/CMakeLists.txt +++ b/clang/tools/scan-build/CMakeLists.txt @@ -66,16 +66,16 @@ endforeach() foreach(ManPage ${ManPages}) - add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_MANDIR}/man1/${ManPage} + add_custom_command(OUTPUT "${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_MANDIR}/man1/${ManPage}" COMMAND ${CMAKE_COMMAND} -E make_directory - ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_MANDIR}/man1 + "${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_MANDIR}/man1" COMMAND ${CMAKE_COMMAND} -E copy - ${CMAKE_CURRENT_SOURCE_DIR}/man/${ManPage} - ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_MANDIR}/man1/ + "${CMAKE_CURRENT_SOURCE_DIR}/man/${ManPage}" + "${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_MANDIR}/man1/" DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/man/${ManPage}) - list(APPEND Depends ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_MANDIR}/man1/${ManPage}) + list(APPEND Depends "${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_MANDIR}/man1/${ManPage}") install(PROGRAMS man/${ManPage} - DESTINATION ${CMAKE_INSTALL_MANDIR}/man1 + DESTINATION "${CMAKE_INSTALL_MANDIR}/man1" COMPONENT scan-build) endforeach() diff --git a/libclc/CMakeLists.txt b/libclc/CMakeLists.txt --- a/libclc/CMakeLists.txt +++ b/libclc/CMakeLists.txt @@ -183,8 +183,8 @@ # pkg-config file configure_file( libclc.pc.in libclc.pc @ONLY ) -install( FILES ${CMAKE_CURRENT_BINARY_DIR}/libclc.pc DESTINATION ${CMAKE_INSTALL_DATADIR}/pkgconfig ) -install( DIRECTORY generic/include/clc DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} ) +install( FILES ${CMAKE_CURRENT_BINARY_DIR}/libclc.pc DESTINATION "${CMAKE_INSTALL_DATADIR}/pkgconfig" ) +install( DIRECTORY generic/include/clc DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" ) if( ENABLE_RUNTIME_SUBNORMAL ) add_library( subnormal_use_default STATIC @@ -192,7 +192,7 @@ add_library( subnormal_disable STATIC generic/lib/subnormal_disable.ll ) install( TARGETS subnormal_use_default subnormal_disable ARCHIVE - DESTINATION ${CMAKE_INSTALL_DATADIR}/clc ) + DESTINATION "${CMAKE_INSTALL_DATADIR}/clc" ) endif() find_package( Python3 REQUIRED COMPONENTS Interpreter ) @@ -343,7 +343,7 @@ add_custom_target( "prepare-${spv_suffix}" ALL DEPENDS "${spv_suffix}" ) install( FILES ${CMAKE_CURRENT_BINARY_DIR}/${spv_suffix} - DESTINATION ${CMAKE_INSTALL_DATADIR}/clc ) + DESTINATION "${CMAKE_INSTALL_DATADIR}/clc" ) else() # Add prepare target @@ -366,7 +366,7 @@ PROPERTIES ENVIRONMENT "LLVM_CONFIG=${LLVM_CONFIG}" ) endif() - install( FILES ${CMAKE_CURRENT_BINARY_DIR}/${obj_suffix} DESTINATION ${CMAKE_INSTALL_DATADIR}/clc ) + install( FILES ${CMAKE_CURRENT_BINARY_DIR}/${obj_suffix} DESTINATION "${CMAKE_INSTALL_DATADIR}/clc" ) foreach( a ${${d}_aliases} ) set( alias_suffix "${a}-${t}.bc" ) add_custom_target( ${alias_suffix} ALL @@ -374,7 +374,7 @@ create_symlink ${obj_suffix} ${alias_suffix} DEPENDS "prepare-${obj_suffix}" ) - install( FILES ${CMAKE_CURRENT_BINARY_DIR}/${alias_suffix} DESTINATION ${CMAKE_INSTALL_DATADIR}/clc ) + install( FILES ${CMAKE_CURRENT_BINARY_DIR}/${alias_suffix} DESTINATION "${CMAKE_INSTALL_DATADIR}/clc" ) endforeach( a ) endif() endforeach( d ) diff --git a/lldb/cmake/modules/FindLibEdit.cmake b/lldb/cmake/modules/FindLibEdit.cmake --- a/lldb/cmake/modules/FindLibEdit.cmake +++ b/lldb/cmake/modules/FindLibEdit.cmake @@ -25,14 +25,14 @@ HINTS ${PC_LIBEDIT_INCLUDEDIR} ${PC_LIBEDIT_INCLUDE_DIRS} - ${CMAKE_INSTALL_FULL_INCLUDEDIR}) + "${CMAKE_INSTALL_FULL_INCLUDEDIR}") find_library(LibEdit_LIBRARIES NAMES edit libedit HINTS ${PC_LIBEDIT_LIBDIR} ${PC_LIBEDIT_LIBRARY_DIRS} - ${CMAKE_INSTALL_FULL_LIBDIR}) + "${CMAKE_INSTALL_FULL_LIBDIR}") if(LibEdit_INCLUDE_DIRS AND EXISTS "${LibEdit_INCLUDE_DIRS}/histedit.h") file(STRINGS "${LibEdit_INCLUDE_DIRS}/histedit.h" diff --git a/llvm/CMakeLists.txt b/llvm/CMakeLists.txt --- a/llvm/CMakeLists.txt +++ b/llvm/CMakeLists.txt @@ -270,9 +270,12 @@ message(FATAL_ERROR "Invalid value for CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}") endif() +include(GNUInstallDirs) + set(LLVM_LIBDIR_SUFFIX "" CACHE STRING "Define suffix of library directory name (32/64)" ) -set(LLVM_TOOLS_INSTALL_DIR "bin" CACHE STRING "Path for binary subdirectory (defaults to 'bin')") +set(LLVM_TOOLS_INSTALL_DIR "${CMAKE_INSTALL_BINDIR}" CACHE STRING + "Path for binary subdirectory (defaults to 'bin')") mark_as_advanced(LLVM_TOOLS_INSTALL_DIR) set(LLVM_UTILS_INSTALL_DIR "${LLVM_TOOLS_INSTALL_DIR}" CACHE STRING @@ -581,9 +584,9 @@ option (LLVM_ENABLE_OCAMLDOC "Build OCaml bindings documentation." ON) option (LLVM_ENABLE_BINDINGS "Build bindings." ON) -set(LLVM_INSTALL_DOXYGEN_HTML_DIR "share/doc/llvm/doxygen-html" +set(LLVM_INSTALL_DOXYGEN_HTML_DIR "${CMAKE_INSTALL_DOCDIR}/${project}/doxygen-html" CACHE STRING "Doxygen-generated HTML documentation install directory") -set(LLVM_INSTALL_OCAMLDOC_HTML_DIR "share/doc/llvm/ocaml-html" +set(LLVM_INSTALL_OCAMLDOC_HTML_DIR "${CMAKE_INSTALL_DOCDIR}/${project}/ocaml-html" CACHE STRING "OCamldoc-generated HTML documentation install directory") option (LLVM_BUILD_EXTERNAL_COMPILER_RT @@ -1066,7 +1069,7 @@ if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) install(DIRECTORY include/llvm include/llvm-c - DESTINATION include + DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" COMPONENT llvm-headers FILES_MATCHING PATTERN "*.def" @@ -1077,7 +1080,7 @@ ) install(DIRECTORY ${LLVM_INCLUDE_DIR}/llvm ${LLVM_INCLUDE_DIR}/llvm-c - DESTINATION include + DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" COMPONENT llvm-headers FILES_MATCHING PATTERN "*.def" @@ -1091,13 +1094,13 @@ if (LLVM_INSTALL_MODULEMAPS) install(DIRECTORY include/llvm include/llvm-c - DESTINATION include + DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" COMPONENT llvm-headers FILES_MATCHING PATTERN "module.modulemap" ) install(FILES include/llvm/module.install.modulemap - DESTINATION include/llvm + DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/llvm" COMPONENT llvm-headers RENAME "module.extern.modulemap" ) diff --git a/llvm/cmake/modules/AddLLVM.cmake b/llvm/cmake/modules/AddLLVM.cmake --- a/llvm/cmake/modules/AddLLVM.cmake +++ b/llvm/cmake/modules/AddLLVM.cmake @@ -823,7 +823,7 @@ ${export_to_llvmexports} LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX} COMPONENT ${name} ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX} COMPONENT ${name} - RUNTIME DESTINATION bin COMPONENT ${name}) + RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" COMPONENT ${name}) if (NOT LLVM_ENABLE_IDE) add_llvm_install_targets(install-${name} @@ -1253,7 +1253,7 @@ endif() add_llvm_executable(${name} ${ARGN}) if( LLVM_BUILD_EXAMPLES ) - install(TARGETS ${name} RUNTIME DESTINATION examples) + install(TARGETS ${name} RUNTIME DESTINATION "${CMAKE_INSTALL_DOCDIR}/examples") endif() set_target_properties(${name} PROPERTIES FOLDER "Examples") endmacro(add_llvm_example name) diff --git a/llvm/cmake/modules/AddSphinxTarget.cmake b/llvm/cmake/modules/AddSphinxTarget.cmake --- a/llvm/cmake/modules/AddSphinxTarget.cmake +++ b/llvm/cmake/modules/AddSphinxTarget.cmake @@ -74,7 +74,7 @@ if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) if (builder STREQUAL man) if (CMAKE_INSTALL_MANDIR) - set(INSTALL_MANDIR ${CMAKE_INSTALL_MANDIR}/) + set(INSTALL_MANDIR "${CMAKE_INSTALL_MANDIR}/") else() set(INSTALL_MANDIR share/man/) endif() @@ -90,7 +90,7 @@ endif() elseif (builder STREQUAL html) string(TOUPPER "${project}" project_upper) - set(${project_upper}_INSTALL_SPHINX_HTML_DIR "share/doc/${project}/html" + set(${project_upper}_INSTALL_SPHINX_HTML_DIR "${CMAKE_INSTALL_DOCDIR}/${project}/html" CACHE STRING "HTML documentation install directory for ${project}") # '/.' indicates: copy the contents of the directory directly into diff --git a/llvm/cmake/modules/CMakeLists.txt b/llvm/cmake/modules/CMakeLists.txt --- a/llvm/cmake/modules/CMakeLists.txt +++ b/llvm/cmake/modules/CMakeLists.txt @@ -1,6 +1,6 @@ include(LLVMDistributionSupport) -set(LLVM_INSTALL_PACKAGE_DIR lib${LLVM_LIBDIR_SUFFIX}/cmake/llvm) +set(LLVM_INSTALL_PACKAGE_DIR lib${LLVM_LIBDIR_SUFFIX}/cmake/llvm CACHE STRING "Path for CMake subdirectory (defaults to 'cmake/llvm')") set(llvm_cmake_builddir "${LLVM_BINARY_DIR}/${LLVM_INSTALL_PACKAGE_DIR}") # First for users who use an installed LLVM, create the LLVMExports.cmake file. @@ -109,13 +109,13 @@ set(LLVM_CONFIG_CODE "${LLVM_CONFIG_CODE} get_filename_component(LLVM_INSTALL_PREFIX \"\${LLVM_INSTALL_PREFIX}\" PATH)") endforeach(p) -set(LLVM_CONFIG_INCLUDE_DIRS "\${LLVM_INSTALL_PREFIX}/include") +set(LLVM_CONFIG_INCLUDE_DIRS "\${LLVM_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}") set(LLVM_CONFIG_INCLUDE_DIR "${LLVM_CONFIG_INCLUDE_DIRS}") set(LLVM_CONFIG_MAIN_INCLUDE_DIR "${LLVM_CONFIG_INCLUDE_DIRS}") set(LLVM_CONFIG_LIBRARY_DIRS "\${LLVM_INSTALL_PREFIX}/lib\${LLVM_LIBDIR_SUFFIX}") set(LLVM_CONFIG_CMAKE_DIR "\${LLVM_INSTALL_PREFIX}/${LLVM_INSTALL_PACKAGE_DIR}") set(LLVM_CONFIG_BINARY_DIR "\${LLVM_INSTALL_PREFIX}") -set(LLVM_CONFIG_TOOLS_BINARY_DIR "\${LLVM_INSTALL_PREFIX}/bin") +set(LLVM_CONFIG_TOOLS_BINARY_DIR "\${LLVM_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}") # Generate a default location for lit if (LLVM_INSTALL_UTILS AND LLVM_BUILD_UTILS) diff --git a/llvm/cmake/modules/LLVMInstallSymlink.cmake b/llvm/cmake/modules/LLVMInstallSymlink.cmake --- a/llvm/cmake/modules/LLVMInstallSymlink.cmake +++ b/llvm/cmake/modules/LLVMInstallSymlink.cmake @@ -4,7 +4,7 @@ function(install_symlink name target outdir) set(DESTDIR $ENV{DESTDIR}) - set(bindir "${DESTDIR}${CMAKE_INSTALL_PREFIX}/${outdir}/") + set(bindir "${DESTDIR}${outdir}/") message(STATUS "Creating ${name}") diff --git a/llvm/docs/CMake.rst b/llvm/docs/CMake.rst --- a/llvm/docs/CMake.rst +++ b/llvm/docs/CMake.rst @@ -252,6 +252,22 @@ Sets the C++ standard to conform to when building LLVM. Possible values are 14, 17, 20. LLVM Requires C++ 14 or higher. This defaults to 14. +**CMAKE_INSTALL_BINDIR**:STRING + The path to install binary tools, relative to the ``CMAKE_INSTALL_PREFIX``. + Defaults to ``bin``. + +**CMAKE_INSTALL_INCLUDEDIR**:STRING + The path to install header files, relative to the ``CMAKE_INSTALL_PREFIX``. + Defaults to ``include``. + +**CMAKE_INSTALL_DOCDIR**:STRING + The path to install documentation, relative to the ``CMAKE_INSTALL_PREFIX``. + Defaults to ``share/doc``. + +**CMAKE_INSTALL_MANDIR**:STRING + The path to install manpage files, relative to the ``CMAKE_INSTALL_PREFIX``. + Defaults to ``share/man``. + .. _LLVM-related variables: LLVM-related variables @@ -563,12 +579,12 @@ **LLVM_INSTALL_OCAMLDOC_HTML_DIR**:STRING The path to install OCamldoc-generated HTML documentation to. This path can either be absolute or relative to the CMAKE_INSTALL_PREFIX. Defaults to - `share/doc/llvm/ocaml-html`. + ``${CMAKE_INSTALL_DOCDIR}/${project}/ocaml-html``. **LLVM_INSTALL_SPHINX_HTML_DIR**:STRING The path to install Sphinx-generated HTML documentation to. This path can either be absolute or relative to the CMAKE_INSTALL_PREFIX. Defaults to - `share/doc/llvm/html`. + ``${CMAKE_INSTALL_DOCDIR}/${project}/html``. **LLVM_INSTALL_UTILS**:BOOL If enabled, utility binaries like ``FileCheck`` and ``not`` will be installed @@ -592,8 +608,8 @@ **LLVM_INSTALL_DOXYGEN_HTML_DIR**:STRING The path to install Doxygen-generated HTML documentation to. This path can - either be absolute or relative to the CMAKE_INSTALL_PREFIX. Defaults to - `share/doc/llvm/doxygen-html`. + either be absolute or relative to the ``CMAKE_INSTALL_PREFIX``. Defaults to + ``${CMAKE_INSTALL_DOCDIR}/${project}/doxygen-html``. **LLVM_LINK_LLVM_DYLIB**:BOOL If enabled, tools will be linked with the libLLVM shared library. Defaults diff --git a/llvm/examples/Bye/CMakeLists.txt b/llvm/examples/Bye/CMakeLists.txt --- a/llvm/examples/Bye/CMakeLists.txt +++ b/llvm/examples/Bye/CMakeLists.txt @@ -14,6 +14,6 @@ BUILDTREE_ONLY ) - install(TARGETS ${name} RUNTIME DESTINATION examples) + install(TARGETS ${name} RUNTIME DESTINATION "${CMAKE_INSTALL_DOCDIR}/examples") set_target_properties(${name} PROPERTIES FOLDER "Examples") endif() diff --git a/llvm/include/llvm/CMakeLists.txt b/llvm/include/llvm/CMakeLists.txt --- a/llvm/include/llvm/CMakeLists.txt +++ b/llvm/include/llvm/CMakeLists.txt @@ -5,5 +5,5 @@ # If we're doing an out-of-tree build, copy a module map for generated # header files into the build area. if (NOT "${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}") - configure_file(module.modulemap.build module.modulemap COPYONLY) + configure_file(module.modulemap.build ${LLVM_INCLUDE_DIR}/module.modulemap COPYONLY) endif (NOT "${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}") diff --git a/llvm/tools/llvm-config/BuildVariables.inc.in b/llvm/tools/llvm-config/BuildVariables.inc.in --- a/llvm/tools/llvm-config/BuildVariables.inc.in +++ b/llvm/tools/llvm-config/BuildVariables.inc.in @@ -23,6 +23,8 @@ #define LLVM_CXXFLAGS "@LLVM_CXXFLAGS@" #define LLVM_BUILDMODE "@LLVM_BUILDMODE@" #define LLVM_LIBDIR_SUFFIX "@LLVM_LIBDIR_SUFFIX@" +#define LLVM_INSTALL_BINDIR "@CMAKE_INSTALL_BINDIR@" +#define LLVM_INSTALL_INCLUDEDIR "@CMAKE_INSTALL_INCLUDEDIR@" #define LLVM_TARGETS_BUILT "@LLVM_TARGETS_BUILT@" #define LLVM_SYSTEM_LIBS "@LLVM_SYSTEM_LIBS@" #define LLVM_BUILD_SYSTEM "@LLVM_BUILD_SYSTEM@" diff --git a/llvm/tools/llvm-config/llvm-config.cpp b/llvm/tools/llvm-config/llvm-config.cpp --- a/llvm/tools/llvm-config/llvm-config.cpp +++ b/llvm/tools/llvm-config/llvm-config.cpp @@ -357,10 +357,16 @@ ("-I" + ActiveIncludeDir + " " + "-I" + ActiveObjRoot + "/include"); } else { ActivePrefix = CurrentExecPrefix; - ActiveIncludeDir = ActivePrefix + "/include"; - SmallString<256> path(StringRef(LLVM_TOOLS_INSTALL_DIR)); - sys::fs::make_absolute(ActivePrefix, path); - ActiveBinDir = std::string(path.str()); + { + SmallString<256> Path(StringRef(LLVM_INSTALL_INCLUDEDIR)); + sys::fs::make_absolute(ActivePrefix, Path); + ActiveIncludeDir = std::string(Path.str()); + } + { + SmallString<256> Path(StringRef(LLVM_INSTALL_BINDIR)); + sys::fs::make_absolute(ActivePrefix, Path); + ActiveBinDir = std::string(Path.str()); + } ActiveLibDir = ActivePrefix + "/lib" + LLVM_LIBDIR_SUFFIX; ActiveCMakeDir = ActiveLibDir + "/cmake/llvm"; ActiveIncludeOption = "-I" + ActiveIncludeDir; diff --git a/llvm/tools/lto/CMakeLists.txt b/llvm/tools/lto/CMakeLists.txt --- a/llvm/tools/lto/CMakeLists.txt +++ b/llvm/tools/lto/CMakeLists.txt @@ -33,7 +33,7 @@ ${SOURCES} DEPENDS intrinsics_gen) install(FILES ${LLVM_MAIN_INCLUDE_DIR}/llvm-c/lto.h - DESTINATION include/llvm-c + DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/llvm-c" COMPONENT LTO) if (APPLE) diff --git a/llvm/tools/opt-viewer/CMakeLists.txt b/llvm/tools/opt-viewer/CMakeLists.txt --- a/llvm/tools/opt-viewer/CMakeLists.txt +++ b/llvm/tools/opt-viewer/CMakeLists.txt @@ -8,7 +8,7 @@ foreach (file ${files}) install(PROGRAMS ${file} - DESTINATION share/opt-viewer + DESTINATION "${CMAKE_INSTALL_DATADIR}/opt-viewer" COMPONENT opt-viewer) endforeach (file) diff --git a/llvm/tools/remarks-shlib/CMakeLists.txt b/llvm/tools/remarks-shlib/CMakeLists.txt --- a/llvm/tools/remarks-shlib/CMakeLists.txt +++ b/llvm/tools/remarks-shlib/CMakeLists.txt @@ -19,7 +19,7 @@ endif() install(FILES ${LLVM_MAIN_INCLUDE_DIR}/llvm-c/Remarks.h - DESTINATION include/llvm-c + DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/llvm-c" COMPONENT Remarks) if (APPLE) diff --git a/openmp/runtime/src/CMakeLists.txt b/openmp/runtime/src/CMakeLists.txt --- a/openmp/runtime/src/CMakeLists.txt +++ b/openmp/runtime/src/CMakeLists.txt @@ -323,7 +323,7 @@ install(CODE "execute_process(COMMAND \"\${CMAKE_COMMAND}\" -E copy \"${LIBOMP_LIB_FILE}\" \"${alias}${LIBOMP_LIBRARY_SUFFIX}\" WORKING_DIRECTORY \${CMAKE_INSTALL_PREFIX}/bin)") install(CODE "execute_process(COMMAND \"\${CMAKE_COMMAND}\" -E copy \"${LIBOMP_IMP_LIB_FILE}\" - \"${alias}${CMAKE_STATIC_LIBRARY_SUFFIX}\" WORKING_DIRECTORY \${CMAKE_INSTALL_PREFIX}/${OPENMP_INSTALL_LIBDIR})") + \"${alias}${CMAKE_STATIC_LIBRARY_SUFFIX}\" WORKING_DIRECTORY \"\${CMAKE_INSTALL_PREFIX}/${OPENMP_INSTALL_LIBDIR}\")") endforeach() else() @@ -335,7 +335,7 @@ foreach(alias IN LISTS LIBOMP_ALIASES) install(CODE "execute_process(COMMAND \"\${CMAKE_COMMAND}\" -E create_symlink \"${LIBOMP_LIB_FILE}\" \"${alias}${LIBOMP_LIBRARY_SUFFIX}\" WORKING_DIRECTORY - \$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/${OPENMP_INSTALL_LIBDIR})") + \"\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/${OPENMP_INSTALL_LIBDIR}\")") endforeach() endif() endif()