summaryrefslogtreecommitdiffstats
path: root/Modules/Compiler/GNU.cmake
diff options
context:
space:
mode:
Diffstat (limited to 'Modules/Compiler/GNU.cmake')
-rw-r--r--Modules/Compiler/GNU.cmake16
1 files changed, 16 insertions, 0 deletions
diff --git a/Modules/Compiler/GNU.cmake b/Modules/Compiler/GNU.cmake
index 4491d4b..688a1b5 100644
--- a/Modules/Compiler/GNU.cmake
+++ b/Modules/Compiler/GNU.cmake
@@ -9,6 +9,7 @@ endif()
set(__COMPILER_GNU 1)
include(Compiler/CMakeCommonCompilerMacros)
+include(Internal/CMakeCheckCompilerFlag)
macro(__compiler_gnu lang)
# Feature flags.
@@ -16,6 +17,21 @@ macro(__compiler_gnu lang)
set(CMAKE_${lang}_COMPILE_OPTIONS_PIC "-fPIC")
if(NOT CMAKE_${lang}_COMPILER_VERSION VERSION_LESS 3.4)
set(CMAKE_${lang}_COMPILE_OPTIONS_PIE "-fPIE")
+ # Support of PIE at link stage depends on various elements : platform, compiler, linker
+ # so the easiest way is to check if compiler supports these flags
+ cmake_check_compiler_flag(${lang} "${CMAKE_${lang}_COMPILE_OPTIONS_PIE};-pie"
+ CMAKE_${lang}_FLAG_PIE)
+ if (CMAKE_${lang}_FLAG_PIE)
+ set(CMAKE_${lang}_LINK_OPTIONS_PIE ${CMAKE_${lang}_COMPILE_OPTIONS_PIE} "-pie")
+ else()
+ set(CMAKE_${lang}_LINK_OPTIONS_PIE "")
+ endif()
+ cmake_check_compiler_flag(${lang} "-no-pie" CMAKE_${lang}_FLAG_NO_PIE)
+ if (CMAKE_${lang}_FLAG_NO_PIE)
+ set(CMAKE_${lang}_LINK_OPTIONS_NO_PIE "-no-pie")
+ else()
+ set(CMAKE_${lang}_LINK_OPTIONS_NO_PIE "")
+ endif()
endif()
if(NOT CMAKE_${lang}_COMPILER_VERSION VERSION_LESS 4.0)
set(CMAKE_${lang}_COMPILE_OPTIONS_VISIBILITY "-fvisibility=")