Skip to content

Commit

Permalink
Merge pull request #2627 from carstene1ns/feature/dkp-cmake
Browse files Browse the repository at this point in the history
Build 3DS, Switch and Wii port with CMake
  • Loading branch information
Ghabry authored Mar 20, 2022
2 parents fec276e + 2a0b660 commit e773035
Show file tree
Hide file tree
Showing 74 changed files with 361 additions and 858 deletions.
17 changes: 17 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,20 @@ local.properties

# libretro
easyrpg_libretro.*

# switch
*.nacp
*.nro

# 3ds
*.3dsx
*.smdh
*.cia

# wii
*.dol

# psvita
eboot.bin
*.vpk
*.velf
207 changes: 143 additions & 64 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ project(EasyRPG_Player VERSION 0.7.0 LANGUAGES CXX)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/builds/cmake/Modules")
include(ConfigureWindows)
include(PlayerFindPackage)
include(PlayerBuildType)

# C++14 is required
set(CMAKE_CXX_STANDARD 14)
Expand Down Expand Up @@ -433,11 +434,6 @@ add_library(${PROJECT_NAME} STATIC
)

# These are actually unused when building in CMake
# src/sdl_ui.cpp
# src/sdl_ui.h
# src/platform/wii/wii_clock.cpp
# src/platform/wii/wii_clock.h
# src/platform/wii/wii_input_buttons.cpp
# src/platform/opendingux/opendingux_input_buttons.cpp
# src/platform/psp/psp_input_buttons.cpp

Expand All @@ -452,8 +448,8 @@ if (NOT CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
endif()

# Platform setup
set(PLAYER_TARGET_PLATFORM "SDL2" CACHE STRING "Platform to compile for. Options: SDL2 libretro psvita")
set_property(CACHE PLAYER_TARGET_PLATFORM PROPERTY STRINGS SDL2 libretro psvita)
set(PLAYER_TARGET_PLATFORM "SDL2" CACHE STRING "Platform to compile for. Options: SDL2 libretro psvita 3ds switch wii")
set_property(CACHE PLAYER_TARGET_PLATFORM PROPERTY STRINGS SDL2 libretro psvita 3ds switch wii)
set(PLAYER_BUILD_EXECUTABLE ON)
set(PLAYER_TEST_LIBRARIES ${PROJECT_NAME})

Expand Down Expand Up @@ -486,21 +482,31 @@ elseif(${PLAYER_TARGET_PLATFORM} STREQUAL "libretro")
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/builds/libretro)
target_link_libraries(${PROJECT_NAME} retro_common)
elseif(${PLAYER_TARGET_PLATFORM} STREQUAL "3ds")
if(NOT NINTENDO_3DS)
message(FATAL_ERROR "Missing toolchain file! Use '-DCMAKE_TOOLCHAIN_FILE=$DEVKITPRO/cmake/3DS.cmake' option.")
endif()
target_compile_options(${PROJECT_NAME} PUBLIC -Wno-psabi) # Remove abi warning after devkitarm ships newer gcc
# generate gfx assets
enable_language(ASM)
ctr_add_graphics_target(keyboard IMAGE
INPUTS ${CMAKE_CURRENT_SOURCE_DIR}/resources/3ds/keyboard.png
OPTIONS -f rgba)
dkp_generate_binary_embed_sources(PLAYER_3DS_ASSETS keyboard)
target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_BINARY_DIR})
target_sources(${PROJECT_NAME} PRIVATE
src/platform/3ds/3ds_audio.cpp
src/platform/3ds/3ds_audio.h
src/platform/3ds/3ds_clock.cpp
src/platform/3ds/3ds_clock.h
src/platform/3ds/3ds_ui.cpp
src/platform/3ds/3ds_ui.h)
src/platform/3ds/3ds_ui.h
${PLAYER_3DS_ASSETS})
elseif(${PLAYER_TARGET_PLATFORM} STREQUAL "psvita")
if(NOT VITA)
message(FATAL_ERROR "Missing toolchain file! Use '-DCMAKE_TOOLCHAIN_FILE=$VITASDK/share/vita.toolchain.cmake' option.")
endif()
include("$ENV{VITASDK}/share/vita.cmake" REQUIRED)
set(CMAKE_DL_LIBS "") # hack4icu!
set(PLAYER_ENABLE_TESTS OFF)
target_compile_options(${PROJECT_NAME} PUBLIC -fno-exceptions -fno-rtti -Wno-psabi) # Remove abi warning after vitasdk ships newer gcc
target_compile_options(${PROJECT_NAME} PUBLIC -Wno-psabi) # Remove abi warning after vitasdk ships newer gcc
target_sources(${PROJECT_NAME} PRIVATE
src/platform/psvita/psp2_audio.cpp
src/platform/psvita/psp2_audio.h
Expand All @@ -509,24 +515,55 @@ elseif(${PLAYER_TARGET_PLATFORM} STREQUAL "psvita")
src/platform/psvita/psp2_ui.cpp
src/platform/psvita/psp2_ui.h)
elseif(${PLAYER_TARGET_PLATFORM} STREQUAL "switch")
if(NOT NINTENDO_SWITCH)
message(FATAL_ERROR "Missing toolchain file! Use '-DCMAKE_TOOLCHAIN_FILE=$DEVKITPRO/cmake/Switch.cmake' option.")
endif()
find_package(OpenGL CONFIG REQUIRED)
find_library(GLAD glad REQUIRED)
target_link_libraries(${PROJECT_NAME} OpenGL::EGL)
# generate gfx assets
enable_language(ASM)
dkp_generate_binary_embed_sources(PLAYER_SWITCH_ASSETS "${CMAKE_CURRENT_SOURCE_DIR}/resources/switch/touch_ui.png")
target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_BINARY_DIR})
target_sources(${PROJECT_NAME} PRIVATE
src/platform/switch/switch_audio.cpp
src/platform/switch/switch_audio.h
src/platform/switch/switch_clock.cpp
src/platform/switch/switch_clock.h
src/platform/switch/switch_ui.cpp
src/platform/switch/switch_ui.h)
src/platform/switch/switch_ui.h
${PLAYER_SWITCH_ASSETS})
elseif(${PLAYER_TARGET_PLATFORM} STREQUAL "wii")
if(NOT NINTENDO_WII)
message(FATAL_ERROR "Missing toolchain file! Use '-DCMAKE_TOOLCHAIN_FILE=$DEVKITPRO/cmake/Wii.cmake' option.")
endif()
find_package(SDL REQUIRED)
target_compile_definitions(${PROJECT_NAME} PUBLIC USE_SDL=1)
target_include_directories(${PROJECT_NAME} PUBLIC ${SDL_INCLUDE_DIR})
target_sources(${PROJECT_NAME} PRIVATE
src/platform/wii/wii_clock.cpp
src/platform/wii/wii_clock.h
src/platform/wii/wii_input_buttons.cpp
src/sdl_ui.cpp
src/sdl_ui.h)
else()
message(FATAL_ERROR "Invalid target platform")
endif()

# These are shared by libretro and native builds
if(N3DS)
target_compile_definitions(${PROJECT_NAME} PUBLIC _3DS)
elseif(VITA)
target_compile_definitions(${PROJECT_NAME} PUBLIC PSP2)
elseif(NSWITCH)
target_compile_definitions(${PROJECT_NAME} PUBLIC __SWITCH__)
# Shared by homebrew platforms
if(${PLAYER_TARGET_PLATFORM} MATCHES "^(3ds|psvita|switch|wii)$")
target_compile_options(${PROJECT_NAME} PUBLIC -fno-exceptions -fno-rtti)
set(CMAKE_DL_LIBS "") # hack4icu!
set(PLAYER_ENABLE_TESTS OFF)
endif()
# Make romfs available
if(${PLAYER_TARGET_PLATFORM} MATCHES "^(3ds|switch)$")
option(PLAYER_ROMFS "Embedd a directory in the executable" OFF)
set(PLAYER_ROMFS_PATH "romfs" CACHE PATH "Directory to include in executable as romfs:/ path")
set(ROMFS_ARG "NO_ROMFS_IGNORE_ME")
if(PLAYER_ROMFS)
set(ROMFS_ARG "ROMFS")
endif()
endif()

if(NOT PLAYER_BUILD_EXECUTABLE AND BUILD_SHARED_LIBS)
Expand Down Expand Up @@ -569,10 +606,6 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Emscripten")
target_sources(${PROJECT_NAME} PRIVATE src/external/picojson.h)
endif()

if(CMAKE_BUILD_TYPE STREQUAL "Debug")
target_compile_definitions(${PROJECT_NAME} PUBLIC _DEBUG=1)
endif()

# Endianess check
if(NOT DEFINED CMAKE_TOOLCHAIN_FILE)
include(TestBigEndian)
Expand Down Expand Up @@ -614,7 +647,7 @@ if(PLAYER_BUILD_LIBLCF)
target_link_libraries(${PROJECT_NAME} lcf)
else()
# Use system package
find_package(liblcf REQUIRED)
find_package(liblcf REQUIRED CONFIG)
target_link_libraries(${PROJECT_NAME} liblcf::liblcf)
endif()

Expand All @@ -629,7 +662,7 @@ find_package(fmt REQUIRED)
target_link_libraries(${PROJECT_NAME} fmt::fmt)

# Always enable Wine registry support on non-Windows, but not for console ports
if(NOT CMAKE_SYSTEM_NAME STREQUAL "Windows" AND NOT ${PLAYER_TARGET_PLATFORM} MATCHES "^(psvita|3ds|switch)$")
if(NOT CMAKE_SYSTEM_NAME STREQUAL "Windows" AND NOT ${PLAYER_TARGET_PLATFORM} MATCHES "^(psvita|3ds|switch|wii)$")
target_compile_definitions(${PROJECT_NAME} PUBLIC HAVE_WINE=1)
endif()

Expand Down Expand Up @@ -669,7 +702,7 @@ else()
endif()

# Configure Audio backends
if(${PLAYER_AUDIO_BACKEND} MATCHES "^(SDL2|libretro|psvita)$")
if(${PLAYER_AUDIO_BACKEND} MATCHES "^(SDL2|libretro|psvita|3ds|switch|wii)$")
set(PLAYER_HAS_AUDIO ON)
target_compile_definitions(${PROJECT_NAME} PUBLIC SUPPORT_AUDIO=1)

Expand Down Expand Up @@ -730,7 +763,7 @@ CMAKE_DEPENDENT_OPTION(PLAYER_WITH_FLUIDLITE "Play MIDI audio with fluidlite" ON
CMAKE_DEPENDENT_OPTION(PLAYER_WITH_XMP "Play MOD audio with libxmp" ON "PLAYER_HAS_AUDIO" OFF)
CMAKE_DEPENDENT_OPTION(PLAYER_ENABLE_DRWAV "Play WAV audio with dr_wav (built-in). Unsupported files are played by libsndfile." ON "PLAYER_HAS_AUDIO" OFF)

if(${PLAYER_AUDIO_BACKEND} MATCHES "^(SDL2|libretro|psvita)$")
if(${PLAYER_AUDIO_BACKEND} MATCHES "^(SDL2|libretro|psvita|3ds|switch|wii)$")
set(PLAYER_AUDIO_RESAMPLER "Auto" CACHE STRING "Audio resampler to use. Options: Auto speexdsp samplerate OFF")
set_property(CACHE PLAYER_AUDIO_RESAMPLER PROPERTY STRINGS Auto speexdsp samplerate OFF)

Expand Down Expand Up @@ -787,6 +820,13 @@ if(${PLAYER_AUDIO_BACKEND} MATCHES "^(SDL2|libretro|psvita)$")
DEFINITION HAVE_OGGVORBIS
TARGET Vorbisfile::Vorbisfile)

if(NOT VORBISFILE_FOUND)
player_find_package(NAME Tremor
CONDITION PLAYER_WITH_OGGVORBIS
DEFINITION HAVE_TREMOR
TARGET Tremor::Tremor)
endif()

# opusfile
player_find_package(NAME Opusfile
CONDITION PLAYER_WITH_OPUS
Expand Down Expand Up @@ -848,15 +888,13 @@ if(${PLAYER_BUILD_EXECUTABLE} AND ${PLAYER_TARGET_PLATFORM} STREQUAL "SDL2")
set_target_properties("${EXE_NAME}" PROPERTIES OUTPUT_NAME "EasyRPG Player")
else()
set(EXE_NAME ${PROJECT_NAME}_exe)
add_executable(${EXE_NAME} WIN32 "src/main.cpp")
add_executable(${EXE_NAME} "src/main.cpp")
set_target_properties(${EXE_NAME} PROPERTIES OUTPUT_NAME "easyrpg-player")
endif()

if(WIN32)
# Open console for Debug builds
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
set_target_properties(${EXE_NAME} PROPERTIES WIN32_EXECUTABLE FALSE)
endif()
set_target_properties(${EXE_NAME} PROPERTIES WIN32_EXECUTABLE $<NOT:CONFIG:Debug>)

# Add resources
target_sources(${EXE_NAME} PRIVATE "resources/player.rc")
Expand Down Expand Up @@ -904,40 +942,76 @@ if(${PLAYER_BUILD_EXECUTABLE} AND ${PLAYER_TARGET_PLATFORM} STREQUAL "SDL2")
endif()
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PLAYER_JS_OUTPUT_NAME}.wasm DESTINATION ${CMAKE_INSTALL_BINDIR})
endif()
elseif(${PLAYER_TARGET_PLATFORM} STREQUAL "psvita")
elseif(${PLAYER_TARGET_PLATFORM} MATCHES "^(psvita|3ds|switch|wii)$")
add_executable(easyrpg-player "src/main.cpp")
target_link_libraries(easyrpg-player
${PROJECT_NAME}
vita2d
-Wl,--whole-archive pthread -Wl,--no-whole-archive
SceLibKernel_stub
SceDisplay_stub
SceGxm_stub
vitashaders
SceSysmodule_stub
SceCtrl_stub
SceTouch_stub
ScePgf_stub
ScePower_stub
SceCommonDialog_stub
SceAudio_stub)
vita_create_self(eboot.bin easyrpg-player $<$<NOT:CONFIG:Debug>:STRIPPED>)
set(VITA_MKSFOEX_FLAGS "-d ATTRIBUTE2=12")
# a kludge to match the valid version format
if(NOT PROJECT_VERSION_PATCH)
set(PROJECT_VERSION_PATCH 0)
endif()
if(NOT PROJECT_VERSION_TWEAK)
set(PROJECT_VERSION_TWEAK 0)
if(NINTENDO_3DS)
target_link_libraries(easyrpg-player
${PROJECT_NAME}
-lcitro2d
-lcitro3d)
ctr_generate_smdh(easyrpg-player.smdh
NAME "EasyRPG Player"
DESCRIPTION "Play your RPG Maker 2000/2003 games everywhere"
AUTHOR "EasyRPG Team"
ICON ${CMAKE_CURRENT_SOURCE_DIR}/resources/3ds/icon.png)
ctr_create_3dsx(easyrpg-player
SMDH easyrpg-player.smdh
${ROMFS_ARG} ${PLAYER_ROMFS_PATH})
elseif(NINTENDO_SWITCH)
target_link_libraries(easyrpg-player
${PROJECT_NAME}
${GLAD})
nx_generate_nacp(easyrpg-player.nacp
NAME "EasyRPG Player"
AUTHOR "EasyRPG Team"
VERSION "${PROJECT_VERSION}")
nx_create_nro(easyrpg-player
NACP easyrpg-player.nacp
ICON "${PROJECT_SOURCE_DIR}/resources/switch/icon.jpg"
${ROMFS_ARG} ${PLAYER_ROMFS_PATH})
elseif(NINTENDO_WII)
target_link_libraries(easyrpg-player
${PROJECT_NAME}
${SDL_LIBRARIES}
-laesnd
-lfat
-lwiikeyboard)
ogc_create_dol(easyrpg-player)
elseif(VITA)
set(CMAKE_EXECUTABLE_SUFFIX .elf)
target_link_libraries(easyrpg-player
${PROJECT_NAME}
vita2d
-Wl,--whole-archive pthread -Wl,--no-whole-archive
SceLibKernel_stub
SceDisplay_stub
SceGxm_stub
vitashaders
SceSysmodule_stub
SceCtrl_stub
SceTouch_stub
ScePgf_stub
ScePower_stub
SceCommonDialog_stub
SceAudio_stub)
vita_create_self(eboot.bin easyrpg-player.elf $<$<NOT:CONFIG:Debug>:STRIPPED>)
set(VITA_MKSFOEX_FLAGS "-d ATTRIBUTE2=12")
# a kludge to match the valid version format
if(NOT PROJECT_VERSION_PATCH)
set(PROJECT_VERSION_PATCH 0)
endif()
if(NOT PROJECT_VERSION_TWEAK)
set(PROJECT_VERSION_TWEAK 0)
endif()
vita_create_vpk(EasyRPG-Player.vpk "EASYRPG01" eboot.bin
VERSION "${PROJECT_VERSION_MAJOR}${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}${PROJECT_VERSION_TWEAK}"
NAME "EasyRPG Player"
FILE "${CMAKE_CURRENT_SOURCE_DIR}/resources/psvita/icon0.png" sce_sys/icon0.png
FILE "${CMAKE_CURRENT_SOURCE_DIR}/resources/psvita/bg.png" sce_sys/livearea/contents/bg.png
FILE "${CMAKE_CURRENT_SOURCE_DIR}/resources/psvita/startup.png" sce_sys/livearea/contents/startup.png
FILE "${CMAKE_CURRENT_SOURCE_DIR}/resources/psvita/template.xml" sce_sys/livearea/contents/template.xml
FILE "${CMAKE_CURRENT_SOURCE_DIR}/resources/psvita/touch_ui.png" touch_ui.png)
endif()
vita_create_vpk(EasyRPG-Player.vpk "EASYRPG01" eboot.bin
VERSION "${PROJECT_VERSION_MAJOR}${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}${PROJECT_VERSION_TWEAK}"
NAME "EasyRPG Player"
FILE "${CMAKE_CURRENT_SOURCE_DIR}/resources/psvita/icon0.png" sce_sys/icon0.png
FILE "${CMAKE_CURRENT_SOURCE_DIR}/resources/psvita/bg.png" sce_sys/livearea/contents/bg.png
FILE "${CMAKE_CURRENT_SOURCE_DIR}/resources/psvita/startup.png" sce_sys/livearea/contents/startup.png
FILE "${CMAKE_CURRENT_SOURCE_DIR}/resources/psvita/template.xml" sce_sys/livearea/contents/template.xml
FILE "${CMAKE_CURRENT_SOURCE_DIR}/resources/psvita/touch_ui.png" touch_ui.png)
else()
if(${PLAYER_TARGET_PLATFORM} STREQUAL "libretro")
add_library(easyrpg_libretro
Expand Down Expand Up @@ -1090,6 +1164,9 @@ endif()
# Print summary
message(STATUS "")
message(STATUS "Target system: ${PLAYER_TARGET_PLATFORM}")
if(PLAYER_ROMFS)
message(STATUS "RomFS: Embedding directory \"${PLAYER_ROMFS_PATH}\"")
endif()
message(STATUS "")

if(PLAYER_BUILD_LIBLCF)
Expand All @@ -1098,7 +1175,7 @@ if(PLAYER_BUILD_LIBLCF)
endif()

message(STATUS "Audio backend: ${PLAYER_AUDIO_BACKEND}")
if(${PLAYER_AUDIO_BACKEND} MATCHES "^(SDL2|libretro|psvita)$")
if(${PLAYER_AUDIO_BACKEND} MATCHES "^(SDL2|libretro|psvita|3ds|switch|wii)$")
message(STATUS "")

set(WAV_LIBS)
Expand Down Expand Up @@ -1146,6 +1223,8 @@ if(${PLAYER_AUDIO_BACKEND} MATCHES "^(SDL2|libretro|psvita)$")

if(VORBISFILE_FOUND)
message(STATUS "Ogg Vorbis playback: libvorbis")
elseif(TREMOR_FOUND)
message(STATUS "Ogg Vorbis playback: tremor")
else()
message(STATUS "Ogg Vorbis playback: None")
endif()
Expand Down
Loading

0 comments on commit e773035

Please sign in to comment.