Prefer CMake's built-in -fPIC and -fpie support
CMake has a built-in property, `POSITION_INDEPENDENT_CODE`, that determines if code will be built with `-fPIC`. This property is `True` by default for `SHARED` and `MODULE` library targets and `False` otherwise. Previously, we were always passing the `-fPIC` flag manually. With this change, we set the appropriate CMake variable that will enable the property for all compile jobs. Furthermore, with CMake policy CMP0083 set to "new" (which happens by default when the `cmake_minimum_required` version is >=3.14), CMake has built-in support for passing the `-fpie` flag when building executables. It uses the same property, `POSITION_INDEPENDENT_CODE`, so setting this property (and enabling it with the CMake `CheckPIESupported` module) allows us to use CMake's built-in support for these flags. Signed-off-by: Chris Burel <burelc@amazon.com>
This commit is contained in:
@@ -20,8 +20,6 @@ ly_append_configurations_options(
|
||||
-Wall
|
||||
-Werror
|
||||
|
||||
-fpie # Position-Independent Executables
|
||||
|
||||
###################
|
||||
# Disabled warnings (please do not disable any others without first consulting sig-build)
|
||||
###################
|
||||
|
||||
@@ -62,3 +62,8 @@ if(CMAKE_GENERATOR MATCHES "Ninja")
|
||||
ly_set(CMAKE_JOB_POOL_LINK link_job_pool)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
set(CMAKE_POSITION_INDEPENDENT_CODE True)
|
||||
|
||||
include(CheckPIESupported)
|
||||
check_pie_supported()
|
||||
|
||||
@@ -16,7 +16,6 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
|
||||
__linux__
|
||||
LINUX64
|
||||
COMPILATION
|
||||
-fPIC
|
||||
-msse4.1
|
||||
LINK_NON_STATIC
|
||||
-Wl,-undefined,error
|
||||
@@ -47,7 +46,6 @@ elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
|
||||
__linux__
|
||||
LINUX64
|
||||
COMPILATION
|
||||
-fPIC
|
||||
-msse4.1
|
||||
LINK_NON_STATIC
|
||||
${LY_GCC_GCOV_LFLAGS}
|
||||
|
||||
Reference in New Issue
Block a user