diff --git a/llvm/CMakeLists.txt b/llvm/CMakeLists.txt --- a/llvm/CMakeLists.txt +++ b/llvm/CMakeLists.txt @@ -256,9 +256,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 @@ -567,9 +570,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 @@ -1032,7 +1035,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" @@ -1043,7 +1046,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" @@ -1057,13 +1060,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 @@ -804,7 +804,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} @@ -1240,7 +1240,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) @@ -1875,7 +1875,7 @@ endfunction() -function(llvm_install_symlink name dest) +function(llvm_install_symlink name dest output_dir) cmake_parse_arguments(ARG "ALWAYS_GENERATE" "COMPONENT" "" ${ARGN}) foreach(path ${CMAKE_MODULE_PATH}) if(EXISTS ${path}/LLVMInstallSymlink.cmake) @@ -1898,7 +1898,7 @@ set(full_dest ${dest}${CMAKE_EXECUTABLE_SUFFIX}) install(SCRIPT ${INSTALL_SYMLINK} - CODE "install_symlink(${full_name} ${full_dest} ${LLVM_TOOLS_INSTALL_DIR})" + CODE "install_symlink(${full_name} ${full_dest} ${output_dir})" COMPONENT ${component}) if (NOT LLVM_ENABLE_IDE AND NOT ARG_ALWAYS_GENERATE) @@ -1981,7 +1981,8 @@ endif() if ((TOOL_IS_TOOLCHAIN OR NOT LLVM_INSTALL_TOOLCHAIN_ONLY) AND LLVM_BUILD_TOOLS) - llvm_install_symlink(${link_name} ${target}) + GNUInstallDirs_get_absolute_install_dir(output_dir LLVM_TOOLS_INSTALL_DIR) + llvm_install_symlink(${link_name} ${target} ${output_dir}) endif() endif() endfunction() 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 @@ -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,4 +1,4 @@ -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. @@ -107,13 +107,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 @@ -550,8 +550,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_ENABLE_SPHINX**:BOOL If specified, CMake will search for the ``sphinx-build`` executable and will make @@ -582,13 +582,29 @@ **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`. + either be absolute or relative to the ``CMAKE_INSTALL_PREFIX``. Defaults to + `${CMAKE_INSTALL_DOCDIR}/${project}/html`. **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`. + either be absolute or relative to the ``CMAKE_INSTALL_PREFIX``. Defaults to + `${CMAKE_INSTALL_DOCDIR}/${project}/ocaml-html`. + +**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_CREATE_XCODE_TOOLCHAIN**:BOOL macOS Only: If enabled CMake will generate a target named 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 @@ -25,7 +25,7 @@ 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)