Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

macOS: Always link against Foundation framework #2267

Merged
merged 8 commits into from
Sep 15, 2020
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,6 @@ __MACOSX

# Android
*.iml

# libretro
easyrpg_libretro.*
32 changes: 15 additions & 17 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
cmake_minimum_required(VERSION 3.7)
cmake_policy(SET CMP0091 NEW) # Support MSVC_RUNTIME_LIBRARY

project(EasyRPG_Player VERSION 0.6.2 LANGUAGES CXX)

Expand Down Expand Up @@ -434,6 +435,11 @@ elseif(${PLAYER_TARGET_PLATFORM} STREQUAL "libretro")
set_target_properties(${PROJECT_NAME} PROPERTIES PREFIX "")
set_target_properties(${PROJECT_NAME} PROPERTIES OUTPUT_NAME "easyrpg_libretro")

SET(BUILD_SHARED_LIBS OFF CACHE BOOL "Build shared easyrpg_libretro core")
if(BUILD_SHARED_LIBS)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
endif()

add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/builds/libretro)
target_link_libraries(${PROJECT_NAME} retro_common)
elseif(${PLAYER_TARGET_PLATFORM} STREQUAL "3ds")
Expand Down Expand Up @@ -478,6 +484,9 @@ if(APPLE)
target_sources(${PROJECT_NAME} PRIVATE
src/platform/macos/utils.mm
src/platform/macos/utils.h)

find_library(MACOSFOUNDATION Foundation)
target_link_libraries(${PROJECT_NAME} ${MACOSFOUNDATION})
endif()

if(CMAKE_SYSTEM_NAME STREQUAL "Emscripten")
Expand Down Expand Up @@ -521,10 +530,14 @@ if(PLAYER_BUILD_LIBLCF)
"${PLAYER_BUILD_LIBLCF_GIT}"
"${LIBLCF_PATH}")
endif()
SET(BUILD_SHARED_LIBS OFF CACHE BOOL "Build liblcf shared library")
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/lib/liblcf/builds/cmake/Modules")

add_subdirectory(${LIBLCF_PATH})
# Always build static liblcf
function(add_liblcf)
set(BUILD_SHARED_LIBS OFF)
add_subdirectory(${LIBLCF_PATH})
endfunction()
add_liblcf()
target_link_libraries(${PROJECT_NAME} lcf)
else()
# Use system package
Expand Down Expand Up @@ -871,21 +884,6 @@ endif()
option(PLAYER_ENABLE_TESTS "Execute unit tests after compilation finishes" ON)

if(PLAYER_ENABLE_TESTS)
set(TEST_GAME_REPOSITORY_PATH "${CMAKE_CURRENT_SOURCE_DIR}/lib/TestGame")
if(NOT EXISTS ${TEST_GAME_REPOSITORY_PATH})
execute_process(COMMAND ${GIT_EXECUTABLE} clone "--depth=1"
"https://github.com/EasyRPG/TestGame.git"
"${TEST_GAME_REPOSITORY_PATH}")
endif()
set(TEST_GAME_PATH "${TEST_GAME_REPOSITORY_PATH}/TestGame-2000")

set(TEST_ENVS "RPG_TEST_GAME_PATH=${TEST_GAME_PATH}")
if(EXISTS $ENV{RPG_RTP_PATH})
get_filename_component(RPG_RTP_PATH "$ENV{RPG_RTP_PATH}" ABSOLUTE)
message(STATUS "using rtp path ${RPG_RTP_PATH}")
list(APPEND TEST_ENVS "RPG_RTP_PATH=${RPG_RTP_PATH}")
endif()

file(GLOB TEST_FILES ${CMAKE_CURRENT_SOURCE_DIR}/tests/*.cpp)
add_executable(test_runner_player EXCLUDE_FROM_ALL ${TEST_FILES})
set_target_properties(test_runner_player PROPERTIES OUTPUT_NAME "test_runner")
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ Read more detailed instructions at:

https://wiki.easyrpg.org/development/compiling/player/cmake

CMake is the only supported way to build liblcf for Windows. All dependencies
CMake is the only supported way to build Player for Windows. All dependencies
must be installed with [vcpkg].

### Building a libretro core:
Expand Down
60 changes: 34 additions & 26 deletions builds/cmake/Modules/ConfigureWindows.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,33 +12,41 @@ if(WIN32)
endif()

if(MSVC)
option(SHARED_RUNTIME "Windows: Build using the shared runtime library (/MD), disable for static runtime (/MT)" ON)

# Set compiler options.
set(variables
CMAKE_C_FLAGS_DEBUG
CMAKE_C_FLAGS_MINSIZEREL
CMAKE_C_FLAGS_RELEASE
CMAKE_C_FLAGS_RELWITHDEBINFO
CMAKE_CXX_FLAGS_DEBUG
CMAKE_CXX_FLAGS_MINSIZEREL
CMAKE_CXX_FLAGS_RELEASE
CMAKE_CXX_FLAGS_RELWITHDEBINFO
)
if(SHARED_RUNTIME)
message(STATUS "Windows: Using dynamic runtime library (/MD)")
foreach(variable ${variables})
if(${variable} MATCHES "/MT")
string(REGEX REPLACE "/MT" "/MD" ${variable} "${${variable}}")
endif()
endforeach()
if(${CMAKE_VERSION} VERSION_LESS "3.15.0")
message(WARNING "Your CMake version is older than 3.15")
message(WARNING "For proper MSVC runtime library support upgrade to a newer version")

option(SHARED_RUNTIME "Windows: Build using the shared runtime library (/MD), disable for static runtime (/MT)" ON)

# Set compiler options.
set(variables
CMAKE_C_FLAGS_DEBUG
CMAKE_C_FLAGS_MINSIZEREL
CMAKE_C_FLAGS_RELEASE
CMAKE_C_FLAGS_RELWITHDEBINFO
CMAKE_CXX_FLAGS_DEBUG
CMAKE_CXX_FLAGS_MINSIZEREL
CMAKE_CXX_FLAGS_RELEASE
CMAKE_CXX_FLAGS_RELWITHDEBINFO
)
if(SHARED_RUNTIME)
message(STATUS "Windows: Using dynamic runtime library (/MD)")
foreach(variable ${variables})
if(${variable} MATCHES "/MT")
string(REGEX REPLACE "/MT" "/MD" ${variable} "${${variable}}")
endif()
endforeach()
else()
message(STATUS "Windows: Using static runtime library (/MT)")
foreach(variable ${variables})
if(${variable} MATCHES "/MD")
string(REGEX REPLACE "/MD" "/MT" ${variable} "${${variable}}")
endif()
endforeach()
endif()
else()
message(STATUS "Windows: Using static runtime library (/MT)")
foreach(variable ${variables})
if(${variable} MATCHES "/MD")
string(REGEX REPLACE "/MD" "/MT" ${variable} "${${variable}}")
endif()
endforeach()
# Depends on vcpkg but we don't support anything else
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>$<$<STREQUAL:${VCPKG_CRT_LINKAGE},dynamic>:DLL>" CACHE STRING "")
endif()

option(MSVC_MULTICORE "MSVC: Build using multiple cores (/MP)" ON)
Expand Down
1 change: 1 addition & 0 deletions builds/libretro/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Makefile
10 changes: 8 additions & 2 deletions builds/libretro/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ cmake_minimum_required(VERSION 3.7)

project(retro_common VERSION 1.0 LANGUAGES C)

# Only for ugly MD-MT patching on old versions, new CMAKE_MSVC_RUNTIME_LIBRARY is inherited
if(${CMAKE_VERSION} VERSION_LESS "3.15.0")
include(ConfigureWindows)
endif()

# Check availability of libretro-common submodule
file(GLOB RETRO_COMMON_DIR ${CMAKE_CURRENT_SOURCE_DIR}/libretro-common/*)
list(LENGTH RETRO_COMMON_DIR RETRO_COMMON_DIR_LEN)
Expand All @@ -16,7 +21,8 @@ add_library(retro_common STATIC
target_include_directories(retro_common PUBLIC
libretro-common/include)

# FIXME: Likely won't work on all platforms
target_link_libraries(retro_common "pthread")
if(NOT MSVC)
target_link_libraries(retro_common "pthread")
endif()

mark_as_advanced(RETRO_COMMON_DIR RETRO_COMMON_DIR_LEN)
2 changes: 1 addition & 1 deletion builds/libretro/libretro-common
Submodule libretro-common updated 285 files