Skip to content

Commit

Permalink
cmake: allow static PIC builds with new optional WICKED_PIC_CODE (#1010)
Browse files Browse the repository at this point in the history
  • Loading branch information
metaleap authored Jan 11, 2025
1 parent 93b351a commit acd31d6
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 6 deletions.
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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} $<$<NOT:$<WICKED_DYNAMIC_LIBRARY>>:--for-linker=-no-pie>" )
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} $<$<NOT:$<WICKED_PIC>>:--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")
Expand Down
2 changes: 1 addition & 1 deletion Samples/Tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
11 changes: 10 additions & 1 deletion WickedEngine/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion WickedEngine/LUA/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
2 changes: 1 addition & 1 deletion WickedEngine/Utility/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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}
)
1 change: 0 additions & 1 deletion WickedEngine/Utility/FAudio/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit acd31d6

Please sign in to comment.