I just tweaked one of the stock CMake files included in the Playdate SDK to fix some issues I was having with them, and figured I'd share the changes here.
The main issue I fixed was that pdc
wouldn't get re-run after changing assets -- it only got re-run when the game is compiled. So I'd be in situations where I would edit something like some graphics, audio or a font, rebuild and run my game, only to find that none of the assets were updated.
The other change is a small one I wrote about in an SDK feature request thread a while back, which is to provide a variable specifying where the pdx file you build will go (rather than the default of having it be in the source code directory).
Playdate devs: check it out! I think this is worth incorporating into the SDK.
I've attached the updated file, but here's a diff you can peruse in the thread:
playdate_game.cmake diff
9a10,16
> if (NOT DEFINED PLAYDATE_PDX_DIR)
> set(PLAYDATE_PDX_DIR "${CMAKE_CURRENT_SOURCE_DIR}" CACHE FILEPATH "Directory to create the pdx")
> endif ()
>
> set(PLAYDATE_PDX_PATH "${PLAYDATE_PDX_DIR}/${PLAYDATE_GAME_NAME}.pdx")
>
>
10a18,19
> set(PLAYDATE_TARGET ${PLAYDATE_GAME_DEVICE})
>
27c36
< ${CMAKE_CURRENT_SOURCE_DIR}/${PLAYDATE_GAME_NAME}.pdx
---
> ${PLAYDATE_PDX_PATH}
30,35d38
< add_custom_command(
< TARGET ${PLAYDATE_GAME_DEVICE} POST_BUILD
< COMMAND ${PDC} Source ${PLAYDATE_GAME_NAME}.pdx
< WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
< )
<
36a40
> set(PLAYDATE_TARGET ${PLAYDATE_GAME_NAME})
47c51
< file(TO_NATIVE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/${PLAYDATE_GAME_NAME}.pdx SIMGAMEPATH)
---
> file(TO_NATIVE_PATH ${PLAYDATE_PDX_PATH} SIMGAMEPATH)
64c68
< set_property(TARGET ${PLAYDATE_GAME_NAME} PROPERTY XCODE_SCHEME_ARGUMENTS \"${CMAKE_CURRENT_SOURCE_DIR}/${PLAYDATE_GAME_NAME}.pdx\")
---
> set_property(TARGET ${PLAYDATE_GAME_NAME} PROPERTY XCODE_SCHEME_ARGUMENTS \"${PLAYDATE_PDX_PATH}\")
104c108
< ${CMAKE_CURRENT_SOURCE_DIR}/${PLAYDATE_GAME_NAME}.pdx
---
> ${PLAYDATE_PDX_PATH}
105a110
> endif ()
107,110d111
< add_custom_command(
< TARGET ${PLAYDATE_GAME_NAME} POST_BUILD
< COMMAND ${PDC} ${CMAKE_CURRENT_SOURCE_DIR}/Source
< ${CMAKE_CURRENT_SOURCE_DIR}/${PLAYDATE_GAME_NAME}.pdx)
112c113,140
< endif ()
---
> # Get all the files that should trigger a call to pdc:
> file(GLOB_RECURSE PLAYDATE_SOURCE_FILES CONFIGURE_DEPENDS FOLLOW_SYMLINKS
> "${CMAKE_CURRENT_SOURCE_DIR}/Source/*.png"
> "${CMAKE_CURRENT_SOURCE_DIR}/Source/*.wav"
> "${CMAKE_CURRENT_SOURCE_DIR}/Source/*.fnt")
>
> # Detect adding or removing files in the Source directory:
> set(PLAYDATE_SOURCE_FILES_LIST ${CMAKE_CURRENT_BINARY_DIR}/Source_files_list.txt)
> if (EXISTS "${PLAYDATE_SOURCE_FILES_LIST}")
> file(READ "${PLAYDATE_SOURCE_FILES_LIST}" current_file_content)
> if (NOT current_file_content STREQUAL "${PLAYDATE_SOURCE_FILES}")
> file(WRITE "${PLAYDATE_SOURCE_FILES_LIST}" "${PLAYDATE_SOURCE_FILES}")
> endif()
> else()
> file(WRITE "${PLAYDATE_SOURCE_FILES_LIST}" "${PLAYDATE_SOURCE_FILES}")
> endif()
>
+ # This way we can have pdc run both as a post-build step and in case any library
> # files change:
> set(PLAYDATE_BUILT_STAMP "${CMAKE_CURRENT_BINARY_DIR}/built.stamp")
> add_custom_target(Playdate_Compile ALL DEPENDS ${PLAYDATE_BUILT_STAMP})
>
> add_custom_command(
> OUTPUT ${PLAYDATE_BUILT_STAMP}
> DEPENDS ${PLAYDATE_SOURCE_FILES} ${PLAYDATE_SOURCE_FILES_LIST} ${PLAYDATE_TARGET}
> COMMAND ${PDC} ${CMAKE_CURRENT_SOURCE_DIR}/Source ${PLAYDATE_PDX_PATH}
> COMMAND ${CMAKE_COMMAND} -E touch "${PLAYDATE_BUILT_STAMP}"
> )
playdate_game.cmake.zip (1.4 KB)