Hello!
I've been having a nightmare of a time trying to get C working on the Playdate. I have successfully got it building for the Simulator on Windows using a slightly modified Hello World program in Visual Studio 2019 using the cmake tools built in.
This is the CMakeLists.txt that I have been successfully using.
cmake_minimum_required(VERSION 3.14)
set(CMAKE_C_STANDARD 11)
set(ENVSDK $ENV{PLAYDATE_SDK_PATH})
if (NOT ${ENVSDK} STREQUAL "")
# Convert path from Windows
file(TO_CMAKE_PATH ${ENVSDK} SDK)
else()
execute_process(
COMMAND bash -c "egrep '^\\s*SDKRoot' $HOME/.Playdate/config"
COMMAND head -n 1
COMMAND cut -c9-
OUTPUT_VARIABLE SDK
OUTPUT_STRIP_TRAILING_WHITESPACE
)
endif()
if (NOT EXISTS ${SDK})
message(FATAL_ERROR "SDK Path not found; set ENV value PLAYDATE_SDK_PATH")
return()
endif()
set(CMAKE_CONFIGURATION_TYPES "Debug;Release")
set(CMAKE_XCODE_GENERATE_SCHEME TRUE)
# Game Name Customization
set(PLAYDATE_GAME_NAME hello_world)
set(PLAYDATE_GAME_DEVICE hello_world_DEVICE)
project(${PLAYDATE_GAME_NAME} C ASM)
if (TOOLCHAIN STREQUAL "armgcc")
add_executable(${PLAYDATE_GAME_DEVICE} ${SDK}/C_API/buildsupport/setup.c src/main.c)
else()
add_library(${PLAYDATE_GAME_NAME} SHARED src/main.c )
endif()
include(${SDK}/C_API/buildsupport/playdate_game.cmake)
As well as this configuration in CMakeSettings.json
{
"name": "x64-Debug (default)",
"generator": "Ninja",
"configurationType": "Debug",
"inheritEnvironments": [ "msvc_x64_x64" ],
"buildRoot": "${projectDir}\\out\\build\\${name}",
"installRoot": "${projectDir}\\out\\install\\${name}",
"cmakeCommandArgs": "",
"buildCommandArgs": "",
"ctestCommandArgs": "",
"variables": []
},
I just right click on the CMakeLists in Visual Studio 2019, click Build and its good to go. Open the simulator, new changes are loaded automatically.
However, when I want to build to the Playdate device itself is when I run into issues.
I've attempted these two configurations in CMakeSettings.json
{
"name": "gcc-arm-release",
"generator": "Ninja",
"configurationType": "Release",
"buildRoot": "${projectDir}\\out\\build\\${name}",
"installRoot": "${projectDir}\\out\\install\\${name}",
"cmakeCommandArgs": "",
"buildCommandArgs": "",
"ctestCommandArgs": "",
"inheritEnvironments": [ "gcc-arm" ],
"variables": []
},
{
"name": "arm-buildsupport-Debug",
"generator": "Ninja",
"configurationType": "Debug",
"buildRoot": "${projectDir}\\out\\build\\${name}",
"installRoot": "${projectDir}\\out\\install\\${name}",
"cmakeCommandArgs": "",
"buildCommandArgs": "",
"ctestCommandArgs": "",
"inheritEnvironments": [ "..\\..\\..\\buildsupport\\arm.cmake" ],
"variables": []
}
and am met with the same error
Line Suppression State Error CMake Error at C:\<myusernamehere>\Visual Studio 2019\Projects\PlaydateHelloWorld\CMakeLists.txt:31 (project):
No CMAKE_C_COMPILER could be found.
Tell CMake where to find the compiler by setting either the environment
variable "CC" or the CMake cache entry CMAKE_C_COMPILER to the full path to
the compiler, or to the compiler name if it is in the PATH.
I have also attempted to use nmake through the command line using the tips on the Inside Playdate with C page
4.4. Building for the Simulator using NMake
If you’d like to use VSCode or a different IDE you can also build using NMake.
Navigate into the project directory and create a build folder, this is where cmake will generate its project files
Open a Visual Studio Developer Command Prompt from the Start Menu or from within Visual Studio
In the developer command prompt window, navigate into build directory and type cmake .. -G "NMake Makefiles"
Type nmake to build the project. This will create a .pdx file at the root level of the project directory which can be run in the Simulator.
4.5. Building for the Playdate using NMake
Navigate into the project directory and create a build folder, this is where cmake will generate its project files
Open a Visual Studio Developer Command Prompt from the Start Menu or from within Visual Studio
In the developer command prompt window, navigate into build directory and type cmake .. -G "NMake Makefiles" --toolchain=..\..\..\buildsupport\arm.cmake
Type nmake to build the project. This will create a .pdx file at the root level of the project directory which can be run on the Playdate.
Building for Release
When you’re ready to do a release build, regenerate the build targets by passing -DCMAKE_BUILD_TYPE=Release argument to CMake.
but each time I try, I get a .pdx folder that works with the simulator but still holds a completely empty pdx.bin (like 0 bits, it is completely blank when I open it up in Notepad). I've been lead to believe that this is what the Playdate device needs in order to boot the game because I get a "CAPI handler function wasn’t located in loaded data" error on the device itself when I attempt to sideload these .pdx folders.
I've really tried to get this running on my own and clearly people are having success but after several multiple hour long debugging sessions, I am asking for all of your help in trying to get a proper build made. I've tried to give everything I have that would be useful but if you need anything else that would help you debug, let me know!
Thank you all for your help in advance!