1diff --git a/CMakeLists.txt b/CMakeLists.txt
2index b44ad2c2118e..d42f5664d448 100644
3--- a/CMakeLists.txt
4+++ b/CMakeLists.txt
5@@ -8,6 +8,7 @@ cmake_minimum_required(VERSION 3.13.4)
6 # Check if compiler-rt is built as a standalone project.
7 if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR OR COMPILER_RT_STANDALONE_BUILD)
8 project(CompilerRT C CXX ASM)
9+ include(GNUInstallDirs)
10 set(COMPILER_RT_STANDALONE_BUILD TRUE)
11 set_property(GLOBAL PROPERTY USE_FOLDERS ON)
12 endif()
13diff --git a/cmake/Modules/AddCompilerRT.cmake b/cmake/Modules/AddCompilerRT.cmake
14index 361538a58e47..f0d8d9ab80f1 100644
15--- a/cmake/Modules/AddCompilerRT.cmake
16+++ b/cmake/Modules/AddCompilerRT.cmake
17@@ -495,7 +495,7 @@ macro(add_compiler_rt_resource_file target_name file_name component)
18 add_custom_target(${target_name} DEPENDS ${dst_file})
19 # Install in Clang resource directory.
20 install(FILES ${file_name}
21- DESTINATION ${COMPILER_RT_INSTALL_PATH}/share
22+ DESTINATION ${COMPILER_RT_INSTALL_PATH}/${CMAKE_INSTALL_FULL_DATADIR}
23 COMPONENT ${component})
24 add_dependencies(${component} ${target_name})
25
26@@ -512,7 +512,7 @@ macro(add_compiler_rt_script name)
27 add_custom_target(${name} DEPENDS ${dst})
28 install(FILES ${dst}
29 PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
30- DESTINATION ${COMPILER_RT_INSTALL_PATH}/bin)
31+ DESTINATION ${COMPILER_RT_INSTALL_PATH}/${CMAKE_INSTALL_FULL_BINDIR})
32 endmacro(add_compiler_rt_script src name)
33
34 # Builds custom version of libc++ and installs it in <prefix>.
35diff --git a/cmake/Modules/CompilerRTDarwinUtils.cmake b/cmake/Modules/CompilerRTDarwinUtils.cmake
36index 456a8dcda59f..7a09e74c7c79 100644
37--- a/cmake/Modules/CompilerRTDarwinUtils.cmake
38+++ b/cmake/Modules/CompilerRTDarwinUtils.cmake
39@@ -508,7 +508,7 @@ macro(darwin_add_embedded_builtin_libraries)
40 set(DARWIN_macho_embedded_LIBRARY_OUTPUT_DIR
41 ${COMPILER_RT_OUTPUT_DIR}/lib/macho_embedded)
42 set(DARWIN_macho_embedded_LIBRARY_INSTALL_DIR
43- ${COMPILER_RT_INSTALL_PATH}/lib/macho_embedded)
44+ ${COMPILER_RT_INSTALL_PATH}/${CMAKE_INSTALL_FULL_LIBDIR}/macho_embedded)
45
46 set(CFLAGS_armv7 "-target thumbv7-apple-darwin-eabi")
47 set(CFLAGS_i386 "-march=pentium")
48diff --git a/cmake/Modules/CompilerRTUtils.cmake b/cmake/Modules/CompilerRTUtils.cmake
49index f61d487e93a0..f1f46fb9599c 100644
50--- a/cmake/Modules/CompilerRTUtils.cmake
51+++ b/cmake/Modules/CompilerRTUtils.cmake
52@@ -378,7 +378,7 @@ endfunction()
53 function(get_compiler_rt_install_dir arch install_dir)
54 if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE)
55 get_compiler_rt_target(${arch} target)
56- set(${install_dir} ${COMPILER_RT_INSTALL_PATH}/lib/${target} PARENT_SCOPE)
57+ set(${install_dir} ${COMPILER_RT_INSTALL_PATH}/${CMAKE_INSTALL_FULL_LIBDIR}/${target} PARENT_SCOPE)
58 else()
59 set(${install_dir} ${COMPILER_RT_LIBRARY_INSTALL_DIR} PARENT_SCOPE)
60 endif()
61diff --git a/cmake/base-config-ix.cmake b/cmake/base-config-ix.cmake
62index 1edab43e7c0d..1aac6b73ff82 100644
63--- a/cmake/base-config-ix.cmake
64+++ b/cmake/base-config-ix.cmake
65@@ -65,11 +65,11 @@ if (LLVM_TREE_AVAILABLE)
66 else()
67 # Take output dir and install path from the user.
68 set(COMPILER_RT_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR} CACHE PATH
69- "Path where built compiler-rt libraries should be stored.")
70+ "Path where built compiler-rt build artifacts should be stored.")
71 set(COMPILER_RT_EXEC_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR}/bin CACHE PATH
72 "Path where built compiler-rt executables should be stored.")
73- set(COMPILER_RT_INSTALL_PATH ${CMAKE_INSTALL_PREFIX} CACHE PATH
74- "Path where built compiler-rt libraries should be installed.")
75+ set(COMPILER_RT_INSTALL_PATH "" CACHE PATH
76+ "Prefix where built compiler-rt artifacts should be installed, comes before CMAKE_INSTALL_PREFIX.")
77 option(COMPILER_RT_INCLUDE_TESTS "Generate and build compiler-rt unit tests." OFF)
78 option(COMPILER_RT_ENABLE_WERROR "Fail and stop if warning is triggered" OFF)
79 # Use a host compiler to compile/link tests.
80@@ -97,7 +97,7 @@ else(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR)
81 set(COMPILER_RT_LIBRARY_OUTPUT_DIR
82 ${COMPILER_RT_OUTPUT_DIR}/lib/${COMPILER_RT_OS_DIR})
83 set(COMPILER_RT_LIBRARY_INSTALL_DIR
84- ${COMPILER_RT_INSTALL_PATH}/lib/${COMPILER_RT_OS_DIR})
85+ ${COMPILER_RT_INSTALL_PATH}/${CMAKE_INSTALL_FULL_LIBDIR}/${COMPILER_RT_OS_DIR})
86 endif()
87
88 if(APPLE)
89diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt
90index b00e8caa1ddd..0fe64e4862c9 100644
91--- a/include/CMakeLists.txt
92+++ b/include/CMakeLists.txt
93@@ -69,22 +69,22 @@ set_target_properties(compiler-rt-headers PROPERTIES FOLDER "Compiler-RT Misc")
94 install(FILES ${SANITIZER_HEADERS}
95 COMPONENT compiler-rt-headers
96 PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
97- DESTINATION ${COMPILER_RT_INSTALL_PATH}/include/sanitizer)
98+ DESTINATION ${COMPILER_RT_INSTALL_PATH}/${CMAKE_INSTALL_FULL_INCLUDEDIR}/sanitizer)
99 # Install fuzzer headers.
100 install(FILES ${FUZZER_HEADERS}
101 COMPONENT compiler-rt-headers
102 PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
103- DESTINATION ${COMPILER_RT_INSTALL_PATH}/include/fuzzer)
104+ DESTINATION ${COMPILER_RT_INSTALL_PATH}/${CMAKE_INSTALL_FULL_INCLUDEDIR}/fuzzer)
105 # Install xray headers.
106 install(FILES ${XRAY_HEADERS}
107 COMPONENT compiler-rt-headers
108 PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
109- DESTINATION ${COMPILER_RT_INSTALL_PATH}/include/xray)
110+ DESTINATION ${COMPILER_RT_INSTALL_PATH}/${CMAKE_INSTALL_FULL_INCLUDEDIR}/xray)
111 # Install profile headers.
112 install(FILES ${PROFILE_HEADERS}
113 COMPONENT compiler-rt-headers
114 PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
115- DESTINATION ${COMPILER_RT_INSTALL_PATH}/include/profile)
116+ DESTINATION ${COMPILER_RT_INSTALL_PATH}/${CMAKE_INSTALL_FULL_INCLUDEDIR}/profile)
117
118 if (NOT CMAKE_CONFIGURATION_TYPES) # don't add this for IDEs.
119 add_custom_target(install-compiler-rt-headers
120diff --git a/lib/dfsan/CMakeLists.txt b/lib/dfsan/CMakeLists.txt
121index a29de8deff1b..d39ff01613d2 100644
122--- a/lib/dfsan/CMakeLists.txt
123+++ b/lib/dfsan/CMakeLists.txt
124@@ -57,4 +57,4 @@ add_custom_command(OUTPUT ${dfsan_abilist_filename}
125 DEPENDS done_abilist.txt libc_ubuntu1404_abilist.txt)
126 add_dependencies(dfsan dfsan_abilist)
127 install(FILES ${dfsan_abilist_filename}
128- DESTINATION ${COMPILER_RT_INSTALL_PATH}/share)
129+ DESTINATION ${COMPILER_RT_INSTALL_PATH}/${CMAKE_INSTALL_FULL_DATADIR})