From acd31d6dfc9484f8aec722d8dc3b31c27fad3b51 Mon Sep 17 00:00:00 2001 From: Phil Schumann Date: Sat, 11 Jan 2025 22:16:41 +0100 Subject: [PATCH] cmake: allow static PIC builds with new optional WICKED_PIC_CODE (#1010) --- CMakeLists.txt | 4 +++- Samples/Tests/CMakeLists.txt | 2 +- WickedEngine/CMakeLists.txt | 11 ++++++++++- WickedEngine/LUA/CMakeLists.txt | 2 +- WickedEngine/Utility/CMakeLists.txt | 2 +- WickedEngine/Utility/FAudio/CMakeLists.txt | 1 - 6 files changed, 16 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f6129ef853..170a4b4100 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,6 +12,7 @@ endif() set(WICKED_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}) option(WICKED_DYNAMIC_LIBRARY "Build WickedEngine as a dynamic library" OFF) +option(WICKED_PIC "Build WickedEngine as position-independent code" WICKED_DYNAMIC_LIBRARY) option(USE_LIBCXX "Link WickedEngine to llvm libc++ library - only available with the Clang compiler" OFF) option(WICKED_EDITOR "Build WickedEngine editor" ON) @@ -30,6 +31,7 @@ endif() set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) +set(CMAKE_POSITION_INDEPENDENT_CODE WICKED_PIC) # Use solution folders to organize projects set_property(GLOBAL PROPERTY USE_FOLDERS ON) @@ -50,7 +52,7 @@ endif() if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fdeclspec -fms-extensions") - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} $<$>:--for-linker=-no-pie>" ) + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} $<$>:--for-linker=-no-pie>" ) if (USE_LIBCXX) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++") set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -stdlib=libc++ -lc++abi") diff --git a/Samples/Tests/CMakeLists.txt b/Samples/Tests/CMakeLists.txt index 2be247ede4..971a736bcc 100644 --- a/Samples/Tests/CMakeLists.txt +++ b/Samples/Tests/CMakeLists.txt @@ -50,6 +50,6 @@ add_custom_command( # Copy font test resources COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_SOURCE_DIR}/yumin.ttf ${CMAKE_CURRENT_BINARY_DIR}/ - COMMENT Copying Tests resources + COMMENT "Copying Tests resources" VERBATIM ) diff --git a/WickedEngine/CMakeLists.txt b/WickedEngine/CMakeLists.txt index d890e3893e..1914bd6910 100644 --- a/WickedEngine/CMakeLists.txt +++ b/WickedEngine/CMakeLists.txt @@ -55,6 +55,9 @@ add_subdirectory(Utility) add_compile_definitions(JPH_DEBUG_RENDERER=1) set(PHYSICS_REPO_ROOT ${CMAKE_CURRENT_SOURCE_DIR}) include(${PHYSICS_REPO_ROOT}/Jolt/Jolt.cmake) +set_target_properties(Jolt PROPERTIES + POSITION_INDEPENDENT_CODE ${WICKED_PIC} +) file(GLOB HEADER_FILES CONFIGURE_DEPENDS *.h) @@ -71,7 +74,10 @@ if(MSVC) endif() add_library(WickedEngine ALIAS ${TARGET_NAME}) -set_target_properties(${TARGET_NAME} PROPERTIES PUBLIC_HEADER "${HEADER_FILES}") +set_target_properties(${TARGET_NAME} PROPERTIES + PUBLIC_HEADER "${HEADER_FILES}" + POSITION_INDEPENDENT_CODE ${WICKED_PIC} +) target_include_directories(${TARGET_NAME} SYSTEM PUBLIC $ @@ -83,6 +89,9 @@ set(WICKEDENGINE_STATIC_LIBRARIES LUA Utility ) +set_target_properties(FAudio PROPERTIES + POSITION_INDEPENDENT_CODE ${WICKED_PIC} +) if (WIN32) target_compile_definitions(${TARGET_NAME} PUBLIC diff --git a/WickedEngine/LUA/CMakeLists.txt b/WickedEngine/LUA/CMakeLists.txt index 3657a1a9e6..dded200df3 100644 --- a/WickedEngine/LUA/CMakeLists.txt +++ b/WickedEngine/LUA/CMakeLists.txt @@ -13,7 +13,7 @@ endif() set_target_properties(LUA PROPERTIES FOLDER "ThirdParty" - POSITION_INDEPENDENT_CODE ${WICKED_DYNAMIC_LIBRARY} + POSITION_INDEPENDENT_CODE ${WICKED_PIC} ) install(FILES ${LUA_HEADERS} diff --git a/WickedEngine/Utility/CMakeLists.txt b/WickedEngine/Utility/CMakeLists.txt index 26e6c0a459..b2366c6ea3 100644 --- a/WickedEngine/Utility/CMakeLists.txt +++ b/WickedEngine/Utility/CMakeLists.txt @@ -55,5 +55,5 @@ add_library(Utility STATIC set_target_properties("Utility" PROPERTIES FOLDER "ThirdParty" - POSITION_INDEPENDENT_CODE ${WICKED_DYNAMIC_LIBRARY} + POSITION_INDEPENDENT_CODE ${WICKED_PIC} ) diff --git a/WickedEngine/Utility/FAudio/CMakeLists.txt b/WickedEngine/Utility/FAudio/CMakeLists.txt index f103fe43fe..d576afe822 100644 --- a/WickedEngine/Utility/FAudio/CMakeLists.txt +++ b/WickedEngine/Utility/FAudio/CMakeLists.txt @@ -90,7 +90,6 @@ set_target_properties(FAudio PROPERTIES OUTPUT_NAME "FAudio" VERSION ${LIB_VERSION} SOVERSION ${LIB_MAJOR_VERSION} - POSITION_INDEPENDENT_CODE ${WICKED_DYNAMIC_LIBRARY} ) # SDL2 Dependency