1diff --git a/CMakeLists.txt b/CMakeLists.txt
2index 86ca2b3ef74b..555103bd97fe 100644
3--- a/CMakeLists.txt
4+++ b/CMakeLists.txt
5@@ -8,6 +8,7 @@ cmake_minimum_required(VERSION 3.4.3)
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 cd4c704fc824..5abcd1260381 100644
15--- a/cmake/Modules/AddCompilerRT.cmake
16+++ b/cmake/Modules/AddCompilerRT.cmake
17@@ -478,7 +478,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@@ -495,7 +495,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 04cc955980fa..a99f6dfb2f82 100644
37--- a/cmake/Modules/CompilerRTDarwinUtils.cmake
38+++ b/cmake/Modules/CompilerRTDarwinUtils.cmake
39@@ -377,7 +377,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 e5651718fa34..d95cfc984a85 100644
50--- a/cmake/Modules/CompilerRTUtils.cmake
51+++ b/cmake/Modules/CompilerRTUtils.cmake
52@@ -330,7 +330,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}/${target}/lib PARENT_SCOPE)
57+ set(${install_dir} ${COMPILER_RT_INSTALL_PATH}/${target}/${CMAKE_INSTALL_FULL_LIBDIR} 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 91fe2494b476..b59a0ffc69f4 100644
63--- a/cmake/base-config-ix.cmake
64+++ b/cmake/base-config-ix.cmake
65@@ -53,11 +53,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@@ -85,7 +85,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 c4b93b89a30c..3913dc3a1ee6 100644
91--- a/include/CMakeLists.txt
92+++ b/include/CMakeLists.txt
93@@ -48,12 +48,12 @@ 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 xray headers.
100 install(FILES ${XRAY_HEADERS}
101 COMPONENT compiler-rt-headers
102 PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
103- DESTINATION ${COMPILER_RT_INSTALL_PATH}/include/xray)
104+ DESTINATION ${COMPILER_RT_INSTALL_PATH}/${CMAKE_INSTALL_FULL_INCLUDEDIR}/xray)
105
106 if (NOT CMAKE_CONFIGURATION_TYPES) # don't add this for IDEs.
107 add_custom_target(install-compiler-rt-headers
108diff --git a/lib/dfsan/CMakeLists.txt b/lib/dfsan/CMakeLists.txt
109index b3ae713cf02c..52b364b900f5 100644
110--- a/lib/dfsan/CMakeLists.txt
111+++ b/lib/dfsan/CMakeLists.txt
112@@ -54,4 +54,4 @@ add_custom_command(OUTPUT ${dfsan_abilist_filename}
113 DEPENDS done_abilist.txt libc_ubuntu1404_abilist.txt)
114 add_dependencies(dfsan dfsan_abilist)
115 install(FILES ${dfsan_abilist_filename}
116- DESTINATION ${COMPILER_RT_INSTALL_PATH}/share)
117+ DESTINATION ${COMPILER_RT_INSTALL_PATH}/${CMAKE_INSTALL_FULL_DATADIR})