Add platform variables for position independent code flags
Store in new platform variables CMAKE_${lang}_COMPILE_OPTIONS_PIC CMAKE_${lang}_COMPILE_OPTIONS_PIE flags for position independent code generation. In almost all cases, this means duplication of the CMAKE_SHARED_LIBRARY_${lang}_FLAGS for the _PIC case and using the assumed pie equivalent for the _PIE case. Note that the GNU compiler has supported -fPIE since 3.4 and that there is no -fPIC on GNU for Windows or Cygwin. There is a possibility that the _PIE variables are not correct. However, as there is no backwards compatibility to be concerned about (as the POSITION_INDEPENDENT_CODE property is not used anywhere yet), the current state suffices.
This commit is contained in:
parent
1ccbfdebb9
commit
31d7a0f2e3
|
@ -100,6 +100,14 @@ IF(NOT CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS)
|
|||
SET(CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS ${CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS})
|
||||
ENDIF(NOT CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS)
|
||||
|
||||
IF(NOT CMAKE_CXX_COMPILE_OPTIONS_PIC)
|
||||
SET(CMAKE_CXX_COMPILE_OPTIONS_PIC ${CMAKE_C_COMPILE_OPTIONS_PIC})
|
||||
ENDIF(NOT CMAKE_CXX_COMPILE_OPTIONS_PIC)
|
||||
|
||||
IF(NOT CMAKE_CXX_COMPILE_OPTIONS_PIE)
|
||||
SET(CMAKE_CXX_COMPILE_OPTIONS_PIE ${CMAKE_C_COMPILE_OPTIONS_PIE})
|
||||
ENDIF(NOT CMAKE_CXX_COMPILE_OPTIONS_PIE)
|
||||
|
||||
IF(NOT CMAKE_SHARED_LIBRARY_CXX_FLAGS)
|
||||
SET(CMAKE_SHARED_LIBRARY_CXX_FLAGS ${CMAKE_SHARED_LIBRARY_C_FLAGS})
|
||||
ENDIF(NOT CMAKE_SHARED_LIBRARY_CXX_FLAGS)
|
||||
|
|
|
@ -74,6 +74,14 @@ ENDIF()
|
|||
# catch any modules
|
||||
SET(CMAKE_NEEDS_REQUIRES_STEP_Fortran_FLAG 1)
|
||||
|
||||
IF(NOT CMAKE_Fortran_COMPILE_OPTIONS_PIC)
|
||||
SET(CMAKE_Fortran_COMPILE_OPTIONS_PIC ${CMAKE_C_COMPILE_OPTIONS_PIC})
|
||||
ENDIF(NOT CMAKE_Fortran_COMPILE_OPTIONS_PIC)
|
||||
|
||||
IF(NOT CMAKE_Fortran_COMPILE_OPTIONS_PIE)
|
||||
SET(CMAKE_Fortran_COMPILE_OPTIONS_PIE ${CMAKE_C_COMPILE_OPTIONS_PIE})
|
||||
ENDIF(NOT CMAKE_Fortran_COMPILE_OPTIONS_PIE)
|
||||
|
||||
# Create a set of shared library variable specific to Fortran
|
||||
# For 90% of the systems, these are the same flags as the C versions
|
||||
# so if these are not set just copy the flags from the c version
|
||||
|
|
|
@ -21,6 +21,10 @@ set(__COMPILER_GNU 1)
|
|||
macro(__compiler_gnu lang)
|
||||
# Feature flags.
|
||||
set(CMAKE_${lang}_VERBOSE_FLAG "-v")
|
||||
set(CMAKE_${lang}_COMPILE_OPTIONS_PIC "-fPIC")
|
||||
if(NOT CMAKE_${lang}_COMPILER_VERSION VERSION_LESS 3.4)
|
||||
set(CMAKE_${lang}_COMPILE_OPTIONS_PIE "-fPIE")
|
||||
endif()
|
||||
set(CMAKE_SHARED_LIBRARY_${lang}_FLAGS "-fPIC")
|
||||
set(CMAKE_SHARED_LIBRARY_CREATE_${lang}_FLAGS "-shared")
|
||||
|
||||
|
|
|
@ -20,6 +20,8 @@ set(__COMPILER_SCO 1)
|
|||
|
||||
macro(__compiler_sco lang)
|
||||
# Feature flags.
|
||||
set(CMAKE_${lang}_COMPILE_OPTIONS_PIC -Kpic)
|
||||
set(CMAKE_${lang}_COMPILE_OPTIONS_PIE -Kpie)
|
||||
set(CMAKE_SHARED_LIBRARY_${lang}_FLAGS "-Kpic -belf")
|
||||
set(CMAKE_SHARED_LIBRARY_CREATE_${lang}_FLAGS "-belf -Wl,-Bexport")
|
||||
endmacro()
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
SET(CMAKE_C_VERBOSE_FLAG "-#")
|
||||
|
||||
SET(CMAKE_C_COMPILE_OPTIONS_PIC -KPIC)
|
||||
SET(CMAKE_C_COMPILE_OPTIONS_PIE -KPIE)
|
||||
SET(CMAKE_SHARED_LIBRARY_C_FLAGS "-KPIC")
|
||||
SET(CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "-G")
|
||||
SET(CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG "-R")
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
SET(CMAKE_CXX_VERBOSE_FLAG "-v")
|
||||
|
||||
SET(CMAKE_CXX_COMPILE_OPTIONS_PIC -KPIC)
|
||||
SET(CMAKE_CXX_COMPILE_OPTIONS_PIE -KPIE)
|
||||
SET(CMAKE_SHARED_LIBRARY_CXX_FLAGS "-KPIC")
|
||||
SET(CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS "-G")
|
||||
SET(CMAKE_SHARED_LIBRARY_RUNTIME_CXX_FLAG "-R")
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
SET(BEOS 1)
|
||||
|
||||
SET(CMAKE_DL_LIBS root be)
|
||||
SET(CMAKE_C_COMPILE_OPTIONS_PIC "-fPIC")
|
||||
SET(CMAKE_C_COMPILE_OPTIONS_PIE "-fPIE")
|
||||
SET(CMAKE_SHARED_LIBRARY_C_FLAGS "-fPIC")
|
||||
SET(CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "-nostart")
|
||||
SET(CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG "-Wl,-rpath,")
|
||||
|
|
|
@ -85,11 +85,15 @@ set(CMAKE_DL_LIBS "dl")
|
|||
macro(__BlueGeneP_set_dynamic_flags compiler_id lang)
|
||||
if (${compiler_id} STREQUAL XL)
|
||||
# Flags for XL compilers if we explicitly detected XL
|
||||
set(CMAKE_${lang}_COMPILE_OPTIONS_PIC "-qpic")
|
||||
set(CMAKE_${lang}_COMPILE_OPTIONS_PIE "-qpie")
|
||||
set(CMAKE_SHARED_LIBRARY_${lang}_FLAGS "-qpic")
|
||||
set(CMAKE_SHARED_LIBRARY_CREATE_${lang}_FLAGS "-qmkshrobj -qnostaticlink")
|
||||
set(BGP_${lang}_DYNAMIC_EXE_FLAGS "-qnostaticlink -qnostaticlink=libgcc")
|
||||
else()
|
||||
# Assume flags for GNU compilers (if the ID is GNU *or* anything else).
|
||||
set(CMAKE_${lang}_COMPILE_OPTIONS_PIC "-fPIC")
|
||||
set(CMAKE_${lang}_COMPILE_OPTIONS_PIE "-fPIE")
|
||||
set(CMAKE_SHARED_LIBRARY_${lang}_FLAGS "-fPIC")
|
||||
set(CMAKE_SHARED_LIBRARY_CREATE_${lang}_FLAGS "-shared")
|
||||
set(BGP_${lang}_DYNAMIC_EXE_FLAGS "-dynamic")
|
||||
|
|
|
@ -35,7 +35,10 @@ macro(__cygwin_compiler_gnu lang)
|
|||
set(CMAKE_${lang}_LINK_EXECUTABLE
|
||||
"<CMAKE_${lang}_COMPILER> <FLAGS> <CMAKE_${lang}_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> -Wl,--out-implib,<TARGET_IMPLIB> ${CMAKE_GNULD_IMAGE_VERSION} <LINK_LIBRARIES>")
|
||||
|
||||
set(CMAKE_SHARED_LIBRARY_${lang}_FLAGS "") # No -fPIC on cygwin
|
||||
# No -fPIC on cygwin
|
||||
set(CMAKE_${lang}_COMPILE_OPTIONS_PIC "")
|
||||
set(CMAKE_${lang}_COMPILE_OPTIONS_PIE "")
|
||||
set(CMAKE_SHARED_LIBRARY_${lang}_FLAGS "")
|
||||
|
||||
# Initialize C link type selection flags. These flags are used when
|
||||
# building a shared library, shared module, or executable that links
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
IF(EXISTS /usr/include/dlfcn.h)
|
||||
SET(CMAKE_DL_LIBS "")
|
||||
SET(CMAKE_C_COMPILE_OPTIONS_PIC "-fPIC")
|
||||
SET(CMAKE_C_COMPILE_OPTIONS_PIE "-fPIE")
|
||||
SET(CMAKE_SHARED_LIBRARY_C_FLAGS "-fPIC") # -pic
|
||||
SET(CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "-shared") # -shared
|
||||
SET(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "") # +s, flag for exe link to use shared lib
|
||||
|
|
|
@ -19,6 +19,7 @@ endif()
|
|||
set(__HPUX_COMPILER_HP 1)
|
||||
|
||||
macro(__hpux_compiler_hp lang)
|
||||
set(CMAKE_${lang}_COMPILE_OPTIONS_PIC "+Z")
|
||||
set(CMAKE_SHARED_LIBRARY_${lang}_FLAGS "+Z")
|
||||
set(CMAKE_SHARED_LIBRARY_CREATE_${lang}_FLAGS "-Wl,-E,+nodefaultrpath -b -L/usr/lib")
|
||||
set(CMAKE_SHARED_LIBRARY_LINK_${lang}_FLAGS "-Wl,+s,-E,+nodefaultrpath")
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
SET(BEOS 1)
|
||||
|
||||
SET(CMAKE_DL_LIBS root be)
|
||||
SET(CMAKE_C_COMPILE_OPTIONS_PIC "-fPIC")
|
||||
SET(CMAKE_C_COMPILE_OPTIONS_PIE "-fPIE")
|
||||
SET(CMAKE_SHARED_LIBRARY_C_FLAGS "-fPIC")
|
||||
SET(CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "-nostart")
|
||||
SET(CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG "-Wl,-rpath,")
|
||||
|
|
|
@ -31,6 +31,8 @@ if(NOT XIAR)
|
|||
endif(NOT XIAR)
|
||||
|
||||
macro(__linux_compiler_intel lang)
|
||||
set(CMAKE_${lang}_COMPILE_OPTIONS_PIC "-fPIC")
|
||||
set(CMAKE_${lang}_COMPILE_OPTIONS_PIE "-fPIE")
|
||||
set(CMAKE_SHARED_LIBRARY_${lang}_FLAGS "-fPIC")
|
||||
set(CMAKE_SHARED_LIBRARY_CREATE_${lang}_FLAGS "-shared")
|
||||
|
||||
|
|
|
@ -20,6 +20,8 @@ set(__LINUX_COMPILER_PGI 1)
|
|||
|
||||
macro(__linux_compiler_pgi lang)
|
||||
# Shared library compile and link flags.
|
||||
set(CMAKE_${lang}_COMPILE_OPTIONS_PIC "-fPIC")
|
||||
set(CMAKE_${lang}_COMPILE_OPTIONS_PIE "-fPIE")
|
||||
set(CMAKE_SHARED_LIBRARY_${lang}_FLAGS "-fPIC")
|
||||
set(CMAKE_SHARED_LIBRARY_CREATE_${lang}_FLAGS "-shared")
|
||||
endmacro()
|
||||
|
|
|
@ -20,6 +20,8 @@ set(__LINUX_COMPILER_PATHSCALE 1)
|
|||
|
||||
macro(__linux_compiler_pathscale lang)
|
||||
# Shared library compile and link flags.
|
||||
set(CMAKE_${lang}_COMPILE_OPTIONS_PIC "-fPIC")
|
||||
set(CMAKE_${lang}_COMPILE_OPTIONS_PIE "-fPIE")
|
||||
set(CMAKE_SHARED_LIBRARY_${lang}_FLAGS "-fPIC")
|
||||
set(CMAKE_SHARED_LIBRARY_CREATE_${lang}_FLAGS "-shared")
|
||||
endmacro()
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
IF(CMAKE_SYSTEM MATCHES "MP-RAS-02*.")
|
||||
SET(CMAKE_C_COMPILE_OPTIONS_PIC -K PIC)
|
||||
SET(CMAKE_C_COMPILE_OPTIONS_PIE -K PIE)
|
||||
SET(CMAKE_SHARED_LIBRARY_C_FLAGS "-K PIC")
|
||||
ELSE(CMAKE_SYSTEM MATCHES "MP-RAS-02*.")
|
||||
SET(CMAKE_C_COMPILE_OPTIONS_PIC -K PIC)
|
||||
SET(CMAKE_C_COMPILE_OPTIONS_PIE -K PIE)
|
||||
SET(CMAKE_SHARED_LIBRARY_C_FLAGS "-K PIC")
|
||||
SET(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "-Wl,-Bexport")
|
||||
ENDIF(CMAKE_SYSTEM MATCHES "MP-RAS-02*.")
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
IF(EXISTS /usr/include/dlfcn.h)
|
||||
SET(CMAKE_DL_LIBS "")
|
||||
SET(CMAKE_C_COMPILE_OPTIONS_PIC "-fPIC")
|
||||
SET(CMAKE_C_COMPILE_OPTIONS_PIE "-fPIE")
|
||||
SET(CMAKE_SHARED_LIBRARY_C_FLAGS "-fPIC") # -pic
|
||||
SET(CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "-shared") # -shared
|
||||
SET(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "") # +s, flag for exe link to use shared lib
|
||||
|
|
|
@ -4,6 +4,8 @@ IF(CMAKE_SYSTEM MATCHES "OSF1-1.[012]")
|
|||
ENDIF(CMAKE_SYSTEM MATCHES "OSF1-1.[012]")
|
||||
IF(CMAKE_SYSTEM MATCHES "OSF1-1.*")
|
||||
# OSF/1 1.3 from OSF using ELF, and derivatives, including AD2
|
||||
SET(CMAKE_C_COMPILE_OPTIONS_PIC "-fpic")
|
||||
SET(CMAKE_C_COMPILE_OPTIONS_PIE "-fpie")
|
||||
SET(CMAKE_SHARED_LIBRARY_C_FLAGS "-fpic") # -pic
|
||||
SET(CMAKE_SHARED_LIBRARY_CXX_FLAGS "-fpic") # -pic
|
||||
ENDIF(CMAKE_SYSTEM MATCHES "OSF1-1.*")
|
||||
|
|
|
@ -1,2 +1,4 @@
|
|||
SET(CMAKE_C_COMPILE_OPTIONS_PIC -K PIC)
|
||||
SET(CMAKE_C_COMPILE_OPTIONS_PIE "")
|
||||
SET(CMAKE_SHARED_LIBRARY_C_FLAGS "-K PIC")
|
||||
INCLUDE(Platform/UnixPaths)
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
IF(CMAKE_SYSTEM MATCHES "SunOS-4.*")
|
||||
SET(CMAKE_C_COMPILE_OPTIONS_PIC "-PIC")
|
||||
SET(CMAKE_C_COMPILE_OPTIONS_PIE "-PIE")
|
||||
SET(CMAKE_SHARED_LIBRARY_C_FLAGS "-PIC")
|
||||
SET(CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "-shared -Wl,-r")
|
||||
SET(CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG "-Wl,-R")
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
SET(CMAKE_C_COMPILE_OPTIONS_PIC -K PIC)
|
||||
SET(CMAKE_C_COMPILE_OPTIONS_PIE "")
|
||||
SET(CMAKE_SHARED_LIBRARY_C_FLAGS "-K PIC")
|
||||
SET(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "-Wl,-Bexport")
|
||||
INCLUDE(Platform/UnixPaths)
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
SET(CMAKE_C_COMPILE_OPTIONS_PIC -K PIC)
|
||||
SET(CMAKE_C_COMPILE_OPTIONS_PIE "")
|
||||
SET(CMAKE_SHARED_LIBRARY_C_FLAGS "-K PIC")
|
||||
SET(CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "-Wl,-Bexport")
|
||||
INCLUDE(Platform/UnixPaths)
|
||||
|
|
|
@ -77,7 +77,11 @@ macro(__windows_compiler_gnu lang)
|
|||
endforeach(type)
|
||||
endif()
|
||||
|
||||
set(CMAKE_SHARED_LIBRARY_${lang}_FLAGS "") # No -fPIC on Windows
|
||||
# No -fPIC on Windows
|
||||
set(CMAKE_${lang}_COMPILE_OPTIONS_PIC "")
|
||||
set(CMAKE_${lang}_COMPILE_OPTIONS_PIE "")
|
||||
set(CMAKE_SHARED_LIBRARY_${lang}_FLAGS "")
|
||||
|
||||
set(CMAKE_${lang}_USE_RESPONSE_FILE_FOR_OBJECTS ${__WINDOWS_GNU_LD_RESPONSE})
|
||||
set(CMAKE_${lang}_USE_RESPONSE_FILE_FOR_INCLUDES 1)
|
||||
|
||||
|
|
|
@ -10,6 +10,8 @@
|
|||
|
||||
|
||||
SET(CMAKE_DL_LIBS "dl")
|
||||
SET(CMAKE_C_COMPILE_OPTIONS_PIC "-fPIC")
|
||||
SET(CMAKE_C_COMPILE_OPTIONS_PIE "-fPIE")
|
||||
SET(CMAKE_SHARED_LIBRARY_C_FLAGS "-fPIC") # -pic
|
||||
SET(CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "-shared") # -shared
|
||||
SET(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "") # +s, flag for exe link to use shared lib
|
||||
|
|
|
@ -30,6 +30,8 @@ CMAKE_SHARED_LIBRARY_RUNTIME_FLAG == "${CMAKE_SHARED_LIBRARY_RUNTIME_FLAG}"
|
|||
CMAKE_SHARED_LIBRARY_RUNTIME_FLAG_SEP == "${CMAKE_SHARED_LIBRARY_RUNTIME_FLAG_SEP}"
|
||||
CMAKE_SHARED_LIBRARY_LINK_STATIC_C_FLAGS == "${CMAKE_SHARED_LIBRARY_LINK_STATIC_C_FLAGS}"
|
||||
CMAKE_SHARED_LIBRARY_LINK_DYNAMIC_C_FLAGS == "${CMAKE_SHARED_LIBRARY_LINK_DYNAMIC_C_FLAGS}"
|
||||
CMAKE_C_COMPILE_OPTIONS_PIC == "${CMAKE_C_COMPILE_OPTIONS_PIC}"
|
||||
CMAKE_C_COMPILE_OPTIONS_PIE == "${CMAKE_C_COMPILE_OPTIONS_PIE}"
|
||||
|
||||
// C shared module flags
|
||||
CMAKE_SHARED_MODULE_C_FLAGS == "${CMAKE_SHARED_MODULE_C_FLAGS}"
|
||||
|
@ -49,6 +51,8 @@ CMAKE_SHARED_LIBRARY_RUNTIME_CXX_FLAG == "${CMAKE_SHARED_LIBRARY_RUNTIME_CXX_FLA
|
|||
CMAKE_SHARED_LIBRARY_RUNTIME_CXX_FLAG_SEP == "${CMAKE_SHARED_LIBRARY_RUNTIME_CXX_FLAG_SEP}"
|
||||
CMAKE_SHARED_LIBRARY_LINK_STATIC_CXX_FLAGS == "${CMAKE_SHARED_LIBRARY_LINK_STATIC_CXX_FLAGS}"
|
||||
CMAKE_SHARED_LIBRARY_LINK_DYNAMIC_CXX_FLAGS == "${CMAKE_SHARED_LIBRARY_LINK_DYNAMIC_CXX_FLAGS}"
|
||||
CMAKE_CXX_COMPILE_OPTIONS_PIC == "${CMAKE_CXX_COMPILE_OPTIONS_PIC}"
|
||||
CMAKE_CXX_COMPILE_OPTIONS_PIE == "${CMAKE_CXX_COMPILE_OPTIONS_PIE}"
|
||||
|
||||
// CXX shared module flags
|
||||
CMAKE_SHARED_MODULE_CREATE_CXX_FLAGS == "${CMAKE_SHARED_MODULE_CREATE_CXX_FLAGS}"
|
||||
|
|
Loading…
Reference in New Issue