summaryrefslogtreecommitdiffstats
path: root/Modules/Compiler/Clang.cmake
diff options
context:
space:
mode:
authorMarc Chevrier <marc.chevrier@gmail.com>2018-10-02 15:34:57 (GMT)
committerMarc Chevrier <marc.chevrier@gmail.com>2018-11-11 16:34:09 (GMT)
commitc4b4d8b3a67718e29edb5676273e528dab566672 (patch)
treeddb8839ae8a5a15b5ffe8dd8190cf873841475da /Modules/Compiler/Clang.cmake
parent724a0346f7bd424ce0e5db246cee46db9f377a6f (diff)
downloadCMake-c4b4d8b3a67718e29edb5676273e528dab566672.zip
CMake-c4b4d8b3a67718e29edb5676273e528dab566672.tar.gz
CMake-c4b4d8b3a67718e29edb5676273e528dab566672.tar.bz2
POSITION_INDEPENDENT_CODE: Manage link flags for executables
Fixes: #14983, #16561
Diffstat (limited to 'Modules/Compiler/Clang.cmake')
-rw-r--r--Modules/Compiler/Clang.cmake20
1 files changed, 20 insertions, 0 deletions
diff --git a/Modules/Compiler/Clang.cmake b/Modules/Compiler/Clang.cmake
index e23470b..7cee9c7 100644
--- a/Modules/Compiler/Clang.cmake
+++ b/Modules/Compiler/Clang.cmake
@@ -21,6 +21,26 @@ else()
macro(__compiler_clang lang)
__compiler_gnu(${lang})
set(CMAKE_${lang}_COMPILE_OPTIONS_PIE "-fPIE")
+ # Link options for PIE are already set in 'Compiler/GNU.cmake'
+ # but clang may require alternate syntax on some platforms
+ if (NOT CMAKE_${lang}_FLAG_PIE)
+ cmake_check_compiler_flag(${lang} "${CMAKE_${lang}_COMPILE_OPTIONS_PIE};-Xlinker;-pie"
+ CMAKE_${lang}_FLAG_XLINKER_PIE)
+ if (CMAKE_${lang}_FLAG_XLINKER_PIE)
+ set(CMAKE_${lang}_LINK_OPTIONS_PIE ${CMAKE_${lang}_COMPILE_OPTIONS_PIE} "-Xlinker" "-pie")
+ else()
+ set(CMAKE_${lang}_LINK_OPTIONS_PIE "")
+ endif()
+ endif()
+ if (NOT CMAKE_${lang}_FLAG_NO_PIE)
+ cmake_check_compiler_flag(${lang} "-Xlinker;-no_pie"
+ CMAKE_${lang}_FLAG_XLINKER_NO_PIE)
+ if (CMAKE_${lang}_FLAG_XLINKER_NO_PIE)
+ set(CMAKE_${lang}_LINK_OPTIONS_NO_PIE "-Xlinker" "-no_pie")
+ else()
+ set(CMAKE_${lang}_LINK_OPTIONS_NO_PIE "")
+ endif()
+ endif()
set(CMAKE_INCLUDE_SYSTEM_FLAG_${lang} "-isystem ")
set(CMAKE_${lang}_COMPILE_OPTIONS_VISIBILITY "-fvisibility=")
if(CMAKE_${lang}_COMPILER_VERSION VERSION_LESS 3.4.0)