Skip to content

Commit

Permalink
CMake: Only enable fPic when building a .so
Browse files Browse the repository at this point in the history
  • Loading branch information
Ghabry committed Sep 28, 2020
1 parent f8028ff commit 7eeffa9
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,8 @@ set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

# Need fPIC when compiling a shared library (e.g. libretro.so)
# Must be at global scope, otherwise breaks -DPLAYER_BUILD_LIBLCF (see CMP0077)
option(BUILD_SHARED_LIBS "Build shared easyrpg_libretro core" ON)
if(BUILD_SHARED_LIBS)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
endif()

# Source Files
add_library(${PROJECT_NAME} STATIC
Expand Down Expand Up @@ -438,6 +434,12 @@ else()
message(FATAL_ERROR "Invalid target platform")
endif()

if(NOT PLAYER_BUILD_EXECUTABLE AND BUILD_SHARED_LIBS)
# Need fPIC when compiling a shared library (e.g. libretro.so)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set_property(TARGET ${PROJECT_NAME} PROPERTY POSITION_INDEPENDENT_CODE ON)
endif()

if(WIN32)
target_sources(${PROJECT_NAME} PRIVATE
src/registry.cpp
Expand Down Expand Up @@ -788,6 +790,7 @@ else()
src/platform/libretro/libretro_ui.cpp
src/platform/libretro/libretro_ui.h)
target_link_libraries(easyrpg_libretro ${PROJECT_NAME})
set_target_properties(easyrpg_libretro PROPERTIES PREFIX "")
else()
message(FATAL_ERROR "Unsupported library target platform ${PLAYER_TARGET_PLATFORM}")
endif()
Expand Down

0 comments on commit 7eeffa9

Please sign in to comment.