Skip to content

Commit

Permalink
cmake: make possible to enable LTO when compiling dll games
Browse files Browse the repository at this point in the history
  • Loading branch information
illwieckz committed Dec 30, 2024
1 parent af2ba5a commit 0ed3c26
Showing 1 changed file with 30 additions and 5 deletions.
35 changes: 30 additions & 5 deletions cmake/DaemonFlags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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_${PROP})
set(CMAKE_REQUIRED_FLAGS "")
if (FLAG_${PROP})
set_kind_linker_flag(${KIND} ${FLAG} ${ARGN})
endif()
endmacro()

if (BE_VERBOSE)
set(WARNMODE "no-error=")
else()
Expand Down Expand Up @@ -335,9 +354,15 @@ 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(FPIE "-fPIC")
else()
try_c_cxx_flag(FPIE "-fPIE")
endif()

if (NOT APPLE)
try_linker_flag(LINKER_PIE "-pie")
try_kind_linker_flag("shared" LINKER_PIE "-pic")
try_kind_linker_flag("exe" LINKER_PIE "-pie")
endif()
endif()

Expand Down

0 comments on commit 0ed3c26

Please sign in to comment.