diff --git a/cmake/DaemonFlags.cmake b/cmake/DaemonFlags.cmake index fadca6635d..c284ffa6d6 100644 --- a/cmake/DaemonFlags.cmake +++ b/cmake/DaemonFlags.cmake @@ -68,10 +68,19 @@ macro(set_c_cxx_flag FLAG) set_c_flag(${FLAG} ${ARGN}) set_cxx_flag(${FLAG} ${ARGN}) endmacro() + +macro(set_kind_linker_flag KIND FLAG) + if (KIND STREQUAL "exe") + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${FLAG}") + set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} ${FLAG}") + else() + set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${FLAG}") + endif() +endmacro() + macro(set_linker_flag FLAG) - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${FLAG}") - set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${FLAG}") - set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} ${FLAG}") + set_kind_linker_flag("exe" FLAG) + set_kind_linker_flag("shared" FLAG) endmacro() function(try_flag LIST FLAG) @@ -142,6 +151,16 @@ macro(try_linker_flag PROP FLAG) endif() endmacro() +macro(try_kind_linker_flag KIND PROP FLAG) + # Check it with the C compiler + set(CMAKE_REQUIRED_FLAGS ${FLAG}) + check_C_compiler_flag(${FLAG} FLAG_${KIND}_${PROP}) + set(CMAKE_REQUIRED_FLAGS "") + if (FLAG_${KIND}_${PROP}) + set_kind_linker_flag(${KIND} ${FLAG} ${ARGN}) + endif() +endmacro() + if (BE_VERBOSE) set(WARNMODE "no-error=") else() @@ -335,13 +354,19 @@ else() try_c_cxx_flag(WSTACK_PROTECTOR "-Wstack-protector") if (NOT NACL OR (NACL AND GAME_PIE)) - try_c_cxx_flag(FPIE "-fPIE") + if (BUILD_GAME_NATIVE_DLL AND (BUILD_CGAME OR BUILD_SGAME)) + try_c_cxx_flag(FPIC "-fPIC") + else() + try_c_cxx_flag(FPIE "-fPIE") + endif() + if (NOT APPLE) - try_linker_flag(LINKER_PIE "-pie") + try_kind_linker_flag("shared" LINKER_PIC "-pic") + try_kind_linker_flag("exe" LINKER_PIE "-pie") endif() endif() - if ("${FLAG_LINKER_PIE}" AND MINGW) + if ("${FLAG_shared_LINKER_PIE}" AND MINGW) # https://github.com/msys2/MINGW-packages/issues/4100 if (ARCH STREQUAL "i686") set_linker_flag("-Wl,-e,_mainCRTStartup")