From 55760ca7b7cd7bbb064947f44a7ca5434d9603e4 Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Mon, 30 Dec 2024 19:00:20 +0100 Subject: [PATCH] cmake: build hardened dll game with sub cmake to use different compilation flags --- cmake/DaemonFlags.cmake | 12 +++++++++--- cmake/DaemonGame.cmake | 24 ++++++++++++++++++++++-- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/cmake/DaemonFlags.cmake b/cmake/DaemonFlags.cmake index 7baa84efa6..74f5a2a831 100644 --- a/cmake/DaemonFlags.cmake +++ b/cmake/DaemonFlags.cmake @@ -337,9 +337,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 (NOT APPLE) - try_linker_flag(LINKER_PIE "-pie") + if (FORK EQUAL 2 AND BUILD_GAME_NATIVE_DLL) + try_c_cxx_flag(FPIC "-fPIC") + try_linker_flag(LINKER_PIC "-pic") + else() + try_c_cxx_flag(FPIE "-fPIE") + + if (NOT APPLE) + try_linker_flag(LINKER_PIE "-pie") + endif() endif() endif() diff --git a/cmake/DaemonGame.cmake b/cmake/DaemonGame.cmake index 3bbc090b7d..98ff1e139b 100644 --- a/cmake/DaemonGame.cmake +++ b/cmake/DaemonGame.cmake @@ -157,7 +157,11 @@ function(GAMEMODULE) endif() if (BUILD_GAME_NATIVE_DLL) - buildGameModule("native-dll") + if (USE_HARDENING) + set(FORK 1 PARENT_SCOPE) + else() + buildGameModule("native-dll") + endif() endif() if (BUILD_GAME_NATIVE_EXE) @@ -180,6 +184,17 @@ function(GAMEMODULE) "-D${inherited_option}=${${inherited_option}}") endforeach(inherited_option) + if (BUILD_GAME_NATIVE_DLL AND USE_HARDENING) + set(VMS_PROJECT dll-vms) + set(VMS_PROJECTS ${VMS_PROJECT}) + + gameSubProject( + -DBUILD_GAME_NACL=OFF + -DBUILD_GAME_NATIVE_DLL=ON + -DBUILD_GAME_NATIVE_EXE=OFF + ) + endif() + if (BUILD_GAME_NACL) if (USE_NACL_SAIGO) add_custom_target(nacl-vms ALL) @@ -229,7 +244,12 @@ function(GAMEMODULE) set(VMS_PROJECTS ${VMS_PROJECTS} PARENT_SCOPE) elseif (FORK EQUAL 2) - if (BUILD_GAME_NACL) + if (BUILD_GAME_NATIVE_DLL) + # Put the .dll and .so files in the same directory as the engine. + set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/..) + + buildGameModule("native-dll") + elseif (BUILD_GAME_NACL) if (USE_NACL_SAIGO) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}) else()