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

Build 3DS, Switch and Wii port with CMake #2627

Merged
merged 7 commits into from
Mar 20, 2022

Conversation

carstene1ns
Copy link
Member

@carstene1ns carstene1ns commented Aug 30, 2021

No description provided.

@Ghabry
Copy link
Member

Ghabry commented Aug 30, 2021

I'm pleasantly surprised how small the changes are, somehow I expected this to be much worse (okay, most of the ugliness is probably hidden behind these functions :))

@@ -602,7 +643,7 @@ if(PLAYER_BUILD_LIBLCF)
target_link_libraries(${PROJECT_NAME} lcf)
else()
# Use system package
find_package(liblcf REQUIRED)
find_package(liblcf REQUIRED CONFIG)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is actually an unrelated change: We always want a recent liblcf and we always ship a config file, so we can skip all Findliblcf stuff.

@Ghabry
Copy link
Member

Ghabry commented Sep 16, 2021

Is https://github.com/devkitPro/pacman-packages even maintained anymore? So many open pr, no feedback 🤔

@Ghabry Ghabry modified the milestones: 0.7.0, 0.7.1 Sep 28, 2021
@Ghabry
Copy link
Member

Ghabry commented Feb 5, 2022

Well the PR by c1 is "merged"/integrated (kinda) so this can likely progress now?

Will do a build test :)

@Ghabry
Copy link
Member

Ghabry commented Feb 5, 2022

Rebased it and added some fixes to make it compile.

After patching devkitpro to use BOTH instead of ONLY I get a 3dsx and a nro with the following cmake line:

Switch:

cmake . -Bswitch-build -DPLAYER_TARGET_PLATFORM=switch \
  -DCMAKE_PREFIX_PATH="$PWD/../easyrpg-buildscripts/switch" \
  -DCMAKE_TOOLCHAIN_FILE=/opt/devkitpro/cmake/Switch.cmake \
  -DPLAYER_BUILD_LIBLCF=ON \
  -DPLAYER_WITH_FREETYPE=OFF

3DS:

cmake . -B3ds-build -DPLAYER_TARGET_PLATFORM=3ds \
  -DCMAKE_PREFIX_PATH="$PWD/../easyrpg-buildscripts/3ds" \
  -DCMAKE_TOOLCHAIN_FILE=/opt/devkitpro/cmake/3DS.cmake  \
  -DPLAYER_BUILD_LIBLCF=ON \
  -DPLAYER_WITH_FREETYPE=OFF

There is something broken in the Harfbuzz CMake config file and OPUS has some linker error because of tremor.

The tremor issue should be fixable. Fixed

@Ghabry
Copy link
Member

Ghabry commented Feb 5, 2022

The 3DS build work 🥳 . Only issue I see is that the consoleInit is wrapped into NDEBUG so the console is always displayed now. Maybe just use a define in the ui-file that can be commented out to enable this.

For the switch: Here is the NRO, cannot test this one:

easyrpg-player.nro.zip

@carstene1ns
Copy link
Member Author

carstene1ns commented Feb 6, 2022

Use -DCMAKE_BUILD_TYPE=RelWithDebInfo to achieve the same as the Makefile. ;)

CMakeLists.txt Outdated
@@ -938,6 +939,8 @@ elseif(${PLAYER_TARGET_PLATFORM} MATCHES "^(3ds|switch|psvita)$")
ctr_create_3dsx(easyrpg-player
SMDH easyrpg-player.smdh)
elseif(NINTENDO_SWITCH)
target_include_directories(${PROJECT_NAME} PUBLIC
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should already be set by the toolchain I guess.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The toolchain only sets -L but not -I.
The proper way would be to request all the libraries through pkg-config (as we can be certain pkg-config is available due to devkitpro). That was the first thing I tried but CMake dislikes the pc files because some of them contain prefix=$(devkitpro)... instead of prefix=/opt/devkitpro.

So would require asking DKP maintainers to patch all the pc files :/

Copy link
Member

@Ghabry Ghabry Feb 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually there is a CMake config file for use with find_package(OpenGL CONFIG REQUIRED) but the config file is not found because it is not in one of the search directories used by CMake. Only looks in usr/lib but not in lib.

I'm not sure if this is a CMake bug or not. The same happens with SYSTEM_NAME=Generic.

I asked for clarification here: https://gitlab.kitware.com/cmake/cmake/-/issues/23192

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The find_package problem was resolved in the recent dkp cmake update. Solving the last blocker.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interestingly enough it works locally, but not on my ports jenkins agent.

CMakeLists.txt Outdated Show resolved Hide resolved
@Ghabry
Copy link
Member

Ghabry commented Feb 28, 2022

They also added a CMake Toolchain for Wii now.

@carstene1ns could you update dkp on your buildbot to the latest version?

Looks all pretty good now to give this the final push and then we can go all cmake :)

@carstene1ns carstene1ns changed the title Build 3DS and Switch port with CMake Build 3DS, Switch and Wii port with CMake Mar 1, 2022
Copy link
Member Author

@carstene1ns carstene1ns left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw. Wii is untested, need to setup the toolchain locally tonight.

src/platform/3ds/3ds_ui.cpp Outdated Show resolved Hide resolved
@carstene1ns
Copy link
Member Author

carstene1ns commented Mar 2, 2022

my make_wii.sh:

#!/bin/sh

set -e

toolchaindir="/home/carsten/projects/easyrpg/buildscripts/wii"
lcfdir="/home/carsten/projects/easyrpg/liblcf/wii"

#export PKG_CONFIG="pkg-config --static"

if [ "x$1" == "xclean" ]; then
  rm -rf build-wii
  exit
fi

cmake -B build-wii . -G Ninja -DCMAKE_TOOLCHAIN_FILE=$DEVKITPRO/cmake/Wii.cmake \
  -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DCMAKE_BUILD_TYPE=Release -DPLAYER_TARGET_PLATFORM=wii \
  -DCMAKE_PREFIX_PATH="$toolchaindir;$lcfdir" -DPLAYER_WITH_FREETYPE=NO
cmake --build build-wii

Currently the dol is 12 mb, which seems a bit too much. Need to investigate.

Edit: Here are the biggest 50 entries in the elf:

nm output
8070a48c 00002c84 T _svfprintf_r
8071230c 00002d44 T _vfprintf_r
80945198 00002e68 R icudt58b_windows_950_2000_cnv
801285a8 00003060 T Transition::Draw(Bitmap&)
80507764 00003138 T png_do_read_transformations
80633f24 000032e0 T sfload_file	/home/carsten/projects/easyrpg/buildscripts/wii/FluidLite-57a0e74e708f699b13d7c85b28a4e1ff5b71887c/src/fluid_defsfont.c:2010
80792fc8 00003368 r BITMAPFONT_RMG2000
8059a914 00003414 T INT123_do_layer3
8099f5f2 00003528 r categories
8078fa68 00003560 r SHINONOME_MINCHO
8013cf1c 00003758 t void lcf::rpg::ForEachString<Translation::RewriteDatabase()::{lambda(lcf::DBString&, auto:1&)#1}, lcf::Context<lcf::rpg::Database, lcf::Context<void, void> > >(lcf::rpg::Terms&, Translation::RewriteDatabase()::{lambda(lcf::DBString&, auto:1&)#1} const&, lcf::Context<lcf::rpg::Database, lcf::Context<void, void> > const*)
80d0eb60 00004000 b __conf_buffer	/home/carsten/projects/wii/libogc/libogc/conf.c:41
80c324e0 00004000 b _kbd_buf_stack	/home/carsten/projects/wii/libogc/libwiikeyboard/keyboard.c:107
80c364e0 00004000 b _kbd_stack	/home/carsten/projects/wii/libogc/libwiikeyboard/keyboard.c:106
8097d368 00004000 r vwin8192
8084c994 00004eac R RTP::rtp_table_2k
808518b8 000054a0 R RTP::rtp_table_2k3
8087a094 00005a00 r ucase_props_trieIndex
80b9f190 00005dd8 B Window_Keyboard::layouts
80ca3c20 00007274 b __wpdcb	/home/carsten/projects/wii/libogc/wiiuse/wpad.c:97
80cfbd10 00008000 b __ppc_btstack1	/home/carsten/projects/wii/libogc/lwbt/physbusif.c:42
80d03d10 00008000 b __ppc_btstack2	/home/carsten/projects/wii/libogc/lwbt/physbusif.c:43
80cad478 00008000 b ppc_stack	/home/carsten/projects/wii/libogc/lwbt/bte.c:94
8095d10c 0000803c r ispow
80b96750 00008404 b palette
808941b0 0000ada8 R icudt58b_confusables_cfu
80340bc0 0000c4bc t __static_initialization_and_destruction_0(int, int)
80925d80 0000ca08 R icudt58b_nfkc_cf_nrm
80918a78 0000d308 R icudt58b_nfkc_nrm
80932788 0000ed08 R icudt58b_uts46_nrm
808847b8 0000f9f8 R icudt58b_cnvalias_icu
80730b85 00010000 r hard_light
80bcb170 00010000 b midisynth::(anonymous namespace)::vibrato_table
80cb96f8 00010010 b ram_block	/home/carsten/projects/wii/libogc/lwbt/btmemr.c:20
80c204c0 00012000 b stream_buffer	/home/carsten/projects/wii/libogc/libaesnd/aesndlib.c:237
80374778 00014918 T FmMidiDecoder::load_programs()
80796330 00015038 r BITMAPFONT_TTYP0
808ffc48 00016378 R icudt58b_ibm_943_P15A_2003_cnv
808deae0 0001c7e8 R icudt58b_ibm_1386_P100_2001_cnv
80102410 0001ce6c T TilemapLayer::TilemapLayer(int)
80102410 0001ce6c T TilemapLayer::TilemapLayer(int)
808c0528 0001e5b8 R icudt58b_ibm_1373_P100_2002_cnv
8089f9f0 00020b38 R icudt58b_ibm_1363_P11B_1998_cnv
80ba8f70 00022200 b midisynth::(anonymous namespace)::envelope_table
80cc9708 00032280 b memb_mem_pool_pbufs	/home/carsten/projects/wii/libogc/lwbt/btpbuf.c:14
80bdcf60 00040000 b gp_fifo	/home/davem/projects/devkitpro/pacman-packages/wii/SDL/src/SDL-1.2.15/./src/video/ogc/SDL_ogc_video.c:87
80743f84 0004bae4 r SHINONOME_GOTHIC
80c3d86c 0005dc00 b rand_table	/home/carsten/projects/easyrpg/buildscripts/wii/FluidLite-57a0e74e708f699b13d7c85b28a4e1ff5b71887c/src/fluid_synth.c:2074
807ab368 0008f26c r BITMAPFONT_WQY

@carstene1ns carstene1ns marked this pull request as ready for review March 2, 2022 12:17
@carstene1ns
Copy link
Member Author

One thing currently missing is romfs support, but this can be added later.

@Ghabry Ghabry self-requested a review March 14, 2022 17:21
@Ghabry
Copy link
Member

Ghabry commented Mar 14, 2022

@carstene1ns
Works great except for one minor thing:
The Switch section needs the following change, otherwise the EGL.h header is not found in switch_ui.cpp

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 109d066c..c3ac39b3 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -532,6 +532,7 @@ elseif(${PLAYER_TARGET_PLATFORM} STREQUAL "switch")
 		src/platform/switch/switch_ui.cpp
 		src/platform/switch/switch_ui.h
 		${PLAYER_SWITCH_ASSETS})
+	target_link_libraries(${PROJECT_NAME} OpenGL::EGL)
 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.")
@@ -955,8 +956,7 @@ elseif(${PLAYER_TARGET_PLATFORM} MATCHES "^(psvita|3ds|switch|wii)$")
 	elseif(NINTENDO_SWITCH)
 		target_link_libraries(easyrpg-player
 			${PROJECT_NAME}
-			${GLAD}
-			OpenGL::EGL)
+			${GLAD})
 		nx_generate_nacp(easyrpg-player.nacp
 			NAME "EasyRPG Player"
 			AUTHOR "EasyRPG Team"

@Ghabry Ghabry merged commit e773035 into EasyRPG:master Mar 20, 2022
@carstene1ns carstene1ns deleted the feature/dkp-cmake branch March 20, 2022 19:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

3 participants