diff --git a/flang/CMakeLists.txt b/flang/CMakeLists.txt --- a/flang/CMakeLists.txt +++ b/flang/CMakeLists.txt @@ -7,6 +7,8 @@ set(CMAKE_CXX_STANDARD_REQUIRED TRUE) set(CMAKE_CXX_EXTENSIONS OFF) +include(GNUInstallDirs) + set(FLANG_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) if (CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR AND NOT MSVC_IDE) @@ -444,7 +446,7 @@ if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) install(DIRECTORY include/flang - DESTINATION include + DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" COMPONENT flang-headers FILES_MATCHING PATTERN "*.def" @@ -456,7 +458,7 @@ PATTERN "CMakeFiles" EXCLUDE) install(DIRECTORY ${FLANG_INCLUDE_DIR}/flang - DESTINATION include + DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" COMPONENT flang-headers FILES_MATCHING PATTERN "*.inc" diff --git a/flang/cmake/modules/AddFlang.cmake b/flang/cmake/modules/AddFlang.cmake --- a/flang/cmake/modules/AddFlang.cmake +++ b/flang/cmake/modules/AddFlang.cmake @@ -1,3 +1,4 @@ +include(GNUInstallDirs) include(LLVMDistributionSupport) macro(set_flang_windows_version_resource_properties name) @@ -71,7 +72,7 @@ ${export_to_flangtargets} 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-${name} @@ -108,7 +109,7 @@ get_target_export_arg(${name} Flang export_to_flangtargets) install(TARGETS ${name} ${export_to_flangtargets} - RUNTIME DESTINATION bin + RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" COMPONENT ${name}) if(NOT LLVM_ENABLE_IDE) diff --git a/flang/cmake/modules/CMakeLists.txt b/flang/cmake/modules/CMakeLists.txt --- a/flang/cmake/modules/CMakeLists.txt +++ b/flang/cmake/modules/CMakeLists.txt @@ -26,6 +26,18 @@ set(FLANG_CONFIG_CMAKE_DIR) set(FLANG_CONFIG_LLVM_CMAKE_DIR) +function(extend_delayed_install_path joined_path current_segment) + if("${current_segment}" STREQUAL "") + set(temp_path "\${FLANG_INSTALL_PREFIX}") + elseif(IS_ABSOLUTE "${current_segment}") + message(WARNING "Since \"${current_segment}\" is absolute, it overrides FLANG_INSTALL_PREFIX") + set(temp_path "${current_segment}") + else() + set(temp_path "\${FLANG_INSTALL_PREFIX}/${current_segment}") + endif() + set(${joined_path} "${temp_path}" PARENT_SCOPE) +endfunction() + # Generate FlangConfig.cmake for the install tree. set(FLANG_CONFIG_CODE " # Compute the installation prefix from this LLVMConfig.cmake file location. @@ -41,7 +53,7 @@ set(FLANG_CONFIG_CMAKE_DIR "\${FLANG_INSTALL_PREFIX}/${FLANG_INSTALL_PACKAGE_DIR}") set(FLANG_CONFIG_LLVM_CMAKE_DIR "\${FLANG_INSTALL_PREFIX}/${LLVM_INSTALL_PACKAGE_DIR}") get_config_exports_includes(Flang FLANG_CONFIG_INCLUDE_EXPORTS) -set(FLANG_CONFIG_INCLUDE_DIRS "\${FLANG_INSTALL_PREFIX}/include") +extend_delayed_install_path(FLANG_CONFIG_INCLUDE_DIRS "${CMAKE_INCLUDE_DIR}") configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/FlangConfig.cmake.in diff --git a/flang/tools/f18/CMakeLists.txt b/flang/tools/f18/CMakeLists.txt --- a/flang/tools/f18/CMakeLists.txt +++ b/flang/tools/f18/CMakeLists.txt @@ -38,7 +38,7 @@ DEPENDS ${base}.mod COMMAND ${CMAKE_COMMAND} -E copy ${base}.mod ${base}.f18.mod) list(APPEND MODULE_FILES ${base}.mod ${base}.f18.mod) - install(FILES ${base}.mod ${base}.f18.mod DESTINATION include/flang) + install(FILES ${base}.mod ${base}.f18.mod DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/flang") endforeach() add_custom_target(module_files ALL DEPENDS ${MODULE_FILES}) @@ -48,5 +48,5 @@ file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/flang DESTINATION ${CMAKE_BINARY_DIR}/bin FILE_PERMISSIONS OWNER_EXECUTE OWNER_READ OWNER_WRITE) - install(PROGRAMS ${CMAKE_BINARY_DIR}/bin/flang DESTINATION bin) + install(PROGRAMS ${CMAKE_BINARY_DIR}/bin/flang DESTINATION "${CMAKE_INSTALL_BINDIR}") endif() diff --git a/flang/tools/flang-driver/CMakeLists.txt b/flang/tools/flang-driver/CMakeLists.txt --- a/flang/tools/flang-driver/CMakeLists.txt +++ b/flang/tools/flang-driver/CMakeLists.txt @@ -34,4 +34,4 @@ export_executable_symbols_for_plugins(flang-new) endif() -install(TARGETS flang-new DESTINATION bin) +install(TARGETS flang-new DESTINATION "${CMAKE_INSTALL_BINDIR}")