CMake: Set CMAKE_POSITION_INDEPENDENT_CODE instead of manual -fPIC

If we are doing a statically linked build, there is no need for full
`-fPIC`, just `-fpie` is enough (which lets the compiler assume that
global variables can be accessed directly without the GOT, etc.). CMake
does the right thing already when we set the `POSITION_INDEPENDENT_CODE`
property.
This commit is contained in:
Daniel Bertalan 2025-05-16 23:22:50 +02:00 committed by Andrew Kaster
parent ffdf0268dd
commit 2058fb1144

View File

@ -13,8 +13,10 @@ else()
add_cxx_compile_options(/Z7)
endif()
if (NOT WIN32)
add_cxx_compile_options(-fPIC)
include(CheckPIESupported)
check_pie_supported(LANGUAGES CXX)
if(CMAKE_CXX_LINK_PIE_SUPPORTED)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
endif()
if (LINUX)