C++ Setup Using CLion MacOS

Hello all! Ran into some trouble :sweat_smile:

I could not get the Playdate simulator nor proper device build properly working for the ‘Hello World CPP’ program. The steps are found in the ‘Inside Playdate with C’ section 2.2.

Device:
When the CMake file was reloading after setting the CMake option for the tool chain for the device build, I received errors pertaining to finding the compilers for C, CXX, and ASM.

Two more similar CMake errors popped up for the CMAKE_CXX_COMPILER and CMAKE_ASM_COMPILER. What do I need to do to ensure I properly locate these compilers?

Simulator:
I am using macOS 10.15. I set up the simulator with the proper macOS binary executable and the simulator displays when running my debug configuration but won’t display the proper program on the simulator. I don’t think my program arguments are correct here, I set them to the “Source” directory located within the working project (is that where the compiled pdx bundle discussed in the last step of section 2.2 is?). If my location is incorrect, where should the proper program argument located?

@chase These issues with the C++ examples should be fixed in the 0.11 SDK release. We don’t have anyone using C++ internally so this bug fell through the cracks. Apologies for that.

1 Like

This should fix it for you @chase

1 Like

Thank you! Your steps did help cMake properly set up the device build with no errors. C projects work no problem as I use the make file and a text editor.

Trying to build in C++ with CLion now produces problems with properly getting the pdx file when trying to test the game on the playdate simulator. The simulator opens a blank screen with the console saying “Couldn’t find pdx file”. (Probably me not properly entering the program arguments for the pdxinfo). I hope this is resolved in the 0.11 SDK release @james was talking about, with more insight on what is amiss.

TL;DR – you would need to build twice, once for each target, for a PDX to be compatible with both the simulator and the device.

The set of CMakeLists.txt and *.cmake files you find in the SDK define two targets for each project, e.g. hello_world and hello_world_DEVICE. These compile the .dylib and ARM binary respectively and place it inside the ./Source folder. If you look at $PLAYDATE_SDK/C_API/buildsupport/playdate_game.cmake you can see that there’s a post-build command that automatically invokes pdc after build either of these targets. Playdate’s command line tool pdc transforms assets to their proprietary format and copies the .dylib, arm binary, and any other assets to the hello_world.pdx folder which you then install to either the simulator or device.

Since pdc can only copy what it finds inside the Source folder, you basically always have to build both targets to avoid that one of the is stale or missing. This also has the side effect of running pdc twice.

CMake does not allow you to describe target dependencies across toolchains (arm.cmake vs. host) trivially. In my setup, I modified the build scripts significantly. This was also necessary to integrate it into a non-trivial set of build steps where I indeed have cross-dependencies between host and ARM targets. I am planning to share some of this here some time soon in the hope of Playdate incorporating it into the SDK but this will not solve this particular issue of needing to compile twice (as I am striving for compatibility with previous SDKs).

2 Likes