From 2058fb114468b6be941ba1ae4eb5317873fcce42 Mon Sep 17 00:00:00 2001 From: Daniel Bertalan Date: Fri, 16 May 2025 23:22:50 +0200 Subject: [PATCH] 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. --- Meta/CMake/lagom_compile_options.cmake | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Meta/CMake/lagom_compile_options.cmake b/Meta/CMake/lagom_compile_options.cmake index 6659e9aea25..18f3e3c2159 100644 --- a/Meta/CMake/lagom_compile_options.cmake +++ b/Meta/CMake/lagom_compile_options.cmake @@ -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)