Compilation Errors in Playdate SDK on Windows with Visual Studio 2022 using CMake

I'm encountering syntax errors related to the Playdate SDK when building a project using Visual Studio and CMake on Windows. Specifically, I'm getting errors related to missing or improperly defined types such as LCDColor, LCDBitmapFlip, and PDStringEncoding in pd_api_gfx.h. Additionally, Visual Studio is reporting that the PDSystemEvent type is undefined. The build stops with over 100 errors, many of which are syntax-related, indicating that the compiler does not recognize the SDK types correctly.

Here’s an example of some of the errors I’m encountering:

${PLAYDATE_SDK_PATH}/C_API/pd_api_gfx.h(127): error C2146: syntax error: missing ')' before identifier 'color'
${PLAYDATE_SDK_PATH}/C_API/pd_api_gfx.h(127): error C2061: syntax error: identifier 'color'
${PLAYDATE_SDK_PATH}/C_API/pd_api_gfx.h(140): error C2081: 'LCDBitmapFlip': name in formal parameter list illegal
${PLAYDATE_SDK_PATH}/C_API/pd_api_gfx.h(152): error C2081: 'LCDColor': name in formal parameter list illegal

Additionally, the IDE highlights the PDSystemEvent type as undefined in the code:

What I've Tried So Far:

  • Verified that pd_api.h is included correctly in main.c.
  • Ensured that the PLAYDATE_SDK_PATH environment variable is set and included in CMakeLists.txt.
  • Added MSVC-specific compile options to suppress warnings and ensure compatibility.
  • Tested with the C11 standard enabled using set(CMAKE_C_STANDARD 11).
  • Checked that the types like LCDColor and LCDBitmapFlip are defined in pd_api_gfx.h, and they seem to be present.

Despite these efforts, the errors persist, particularly when using the MSVC compiler in Visual Studio. I suspect there might be an issue with how MSVC handles the SDK’s headers, but I’m unsure how to resolve it.

Has anyone experienced similar issues when working with the Playdate SDK on Windows using Visual Studio? Any help would be greatly appreciated!

what version of cmake?
did you use cmake command line (I am using CMake 3.22.1 GUI and it generates valid solutions)?

If it helps, my CMakeLists.txt file:

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 snow)
set(PLAYDATE_GAME_DEVICE snow_DEVICE)

project(${PLAYDATE_GAME_NAME} C ASM)

file(GLOB LIB3D_GLOB
     "lib3d/*.c"
     "lib3d/*.h"
)

file(GLOB LUA_CODE
	"source/*.lua"
)

include_directories("lib3d")

if (TOOLCHAIN STREQUAL "armgcc")
	add_executable(${PLAYDATE_GAME_DEVICE} ${LIB3D_GLOB} )
else()
	add_library(${PLAYDATE_GAME_NAME} SHARED ${LIB3D_GLOB} ${LUA_CODE})
endif()

include(${SDK}/C_API/buildsupport/playdate_game.cmake)

Thanks, this helped a lot!