CMake workflow basic questions

This feels like a FAQ, but everything I've been able to find has been either "it should all just work" or a very esoteric question that assumes I understand the basics.

I'm working on a Lua project and trying to add a single C library to it. (James's port of the SAM speech synthesizer, which already comes with its own CMake setup and example project).

After following the basic instructions, I've got a Makefile in my build directory that works to generate a .pdx in my main directory, and that works in the Simulator.

Here are my issues/confusions/frustrations:

  1. Make doesn't detect files have been touched when I change Lua files, so it does nothing. Do I need to explicitly run pdc every time I change the Lua source? (On my last mostly-Lua project with a single C function, make seemed to recognize changes to C or to Lua and call pdc as needed, but I can't even find where pdc is invoked in the Cmake-generated files).
  2. Choosing Device -> Upload Game to Device from the Simulator crashes on entry, because my library isn't getting called to register my C functions. Is this to be expected, or is there a step missing from my process, and I'm only building a Simulator-only pdx?
  3. Is it possible to build hybrid pdx that works on both Simulator and device if I'm using C?
  4. How often do I need to run CMake? I'm assuming it's only generating the Makefile, so I only need to run it once unless I make a dramatic change to the number of C source files or libraries I'm including. Do I need to re-run it to generate device builds vs simulator builds, for instance?
  5. Is there an existing setup, or instructions on how to setup, for Nova to use a build like what I'm describing? Do I need to explicitly set up the commands for build/run?

Thanks in advance for any enlightenment,
Chuck

1 Like

Following up on this after getting some help in Discord:

I'd missed the step that the build folder needed to be deleted in between running CMake for simulator, making the project, and then running CMake for the device. (Or else have 2 separate build folders). Is this still the best option we have available now?

Is it possible for the generated Makefile to recognize when only the Lua code changes and remake? Or do I just need to make clean in between every execution?

And I'd still be curious if there's a guide for Nova to make the process as straightforward as Lua-only projects.

I think one of your issues is because there are two different types of binaries being built. The one that works in Simulator is built for the type of CPU in your computer and the one you need for device needs to be compiled for a different type of CPU.

I can't help any further as I've not done it myself. But hopefully that gives you more to go on. Playdate Squad C section will probably have the answer.

1 Like

Thanks, in my case at least, I postponed the problem by ignoring CMake and just using a Makefile. This has the added advantage of working well with Nova using the "Make (C/Lua)" toolchain.

If anybody's in the same boat as me, there's a sample in the PlaydateSDK/C_API/Examples/3DLibrary project, showing how to use a Makefile to build a Lua project with a C library.

3 Likes

What/where is the “playdate squad”? I’m just getting started and that sounds pretty useful! Thank you for any info!

1 Like

Here we go https://discord.com/invite/zFKagQ2

1 Like