cmake_minimum_required(VERSION 3.12) if(PLAYDATE_DEVICE) set(PROJECT_LANGUAGES C ASM CXX) elseif(APPLE) set(PROJECT_LANGUAGES C OBJC CXX) else() # Some error needs to go here, and more platforms... endif() set(CMAKE_CXX_STANDARD 11) project(benzene ${PROJECT_LANGUAGES}) add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/third_party/sun/runtime EXCLUDE_FROM_ALL) if(PLAYDATE_DEVICE) # Playdate is software renderer elseif(APPLE) add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/third_party/sdl EXCLUDE_FROM_ALL) else() # Some error needs to go here, and more platforms... endif() set(BENZENE_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src) set(BENZENE_SOURCES ${BENZENE_SRC_DIR}/bz/impl.c ${BENZENE_SRC_DIR}/bz/audio/ogg.h ${BENZENE_SRC_DIR}/bz/audio/ogg.c ${BENZENE_SRC_DIR}/bz/audio/playback.h ${BENZENE_SRC_DIR}/bz/audio/playback_internal.h ${BENZENE_SRC_DIR}/bz/audio/playback.c ${BENZENE_SRC_DIR}/bz/audio/speech.h ${BENZENE_SRC_DIR}/bz/audio/speech.cpp ${BENZENE_SRC_DIR}/bz/audio/wav.h ${BENZENE_SRC_DIR}/bz/audio/wav.c ${BENZENE_SRC_DIR}/bz/collision/collision.h ${BENZENE_SRC_DIR}/bz/collision/collision.c ${BENZENE_SRC_DIR}/bz/collision/particle_collision.h ${BENZENE_SRC_DIR}/bz/collision/particle_collision.c ${BENZENE_SRC_DIR}/bz/debug/assert.h ${BENZENE_SRC_DIR}/bz/debug/assert.c ${BENZENE_SRC_DIR}/bz/debug/log.h ${BENZENE_SRC_DIR}/bz/debug/log.c ${BENZENE_SRC_DIR}/bz/debug/perfgraph.h ${BENZENE_SRC_DIR}/bz/debug/perfgraph.c ${BENZENE_SRC_DIR}/bz/fx/agent_simulation.h ${BENZENE_SRC_DIR}/bz/fx/agent_simulation_internal.h ${BENZENE_SRC_DIR}/bz/fx/agent_simulation.c ${BENZENE_SRC_DIR}/bz/fx/particle_simulation.h ${BENZENE_SRC_DIR}/bz/fx/particle_simulation_internal.h ${BENZENE_SRC_DIR}/bz/fx/particle_simulation.c ${BENZENE_SRC_DIR}/bz/fx/particle_system.h ${BENZENE_SRC_DIR}/bz/fx/particle_system_internal.h ${BENZENE_SRC_DIR}/bz/fx/particle_system.c ${BENZENE_SRC_DIR}/bz/game/actor.h ${BENZENE_SRC_DIR}/bz/game/actor_internal.h ${BENZENE_SRC_DIR}/bz/game/actor.c ${BENZENE_SRC_DIR}/bz/game/scene.h ${BENZENE_SRC_DIR}/bz/game/scene_internal.h ${BENZENE_SRC_DIR}/bz/game/scene.c ${BENZENE_SRC_DIR}/bz/game/scene_identifiers.cpp ${BENZENE_SRC_DIR}/bz/game/tilemap.h ${BENZENE_SRC_DIR}/bz/game/tilemap_internal.h ${BENZENE_SRC_DIR}/bz/game/tilemap.c ${BENZENE_SRC_DIR}/bz/gfx/aseprite.h ${BENZENE_SRC_DIR}/bz/gfx/aseprite_internal.h ${BENZENE_SRC_DIR}/bz/gfx/aseprite.c ${BENZENE_SRC_DIR}/bz/gfx/draw_queue.h ${BENZENE_SRC_DIR}/bz/gfx/draw_queue.c ${BENZENE_SRC_DIR}/bz/gfx/drawing.h ${BENZENE_SRC_DIR}/bz/gfx/drawing.c ${BENZENE_SRC_DIR}/bz/gfx/font.h ${BENZENE_SRC_DIR}/bz/gfx/font_internal.h ${BENZENE_SRC_DIR}/bz/gfx/font.c ${BENZENE_SRC_DIR}/bz/gfx/gfx.h ${BENZENE_SRC_DIR}/bz/gfx/gfx_internal.h ${BENZENE_SRC_DIR}/bz/gfx/gfx.c ${BENZENE_SRC_DIR}/bz/gfx/particle_drawing.h ${BENZENE_SRC_DIR}/bz/gfx/particle_drawing.c ${BENZENE_SRC_DIR}/bz/gfx/tilemap.h ${BENZENE_SRC_DIR}/bz/gfx/tilemap_internal.h ${BENZENE_SRC_DIR}/bz/gfx/tilemap.c ${BENZENE_SRC_DIR}/bz/input/input.h ${BENZENE_SRC_DIR}/bz/input/input_internal.h ${BENZENE_SRC_DIR}/bz/input/input.c ${BENZENE_SRC_DIR}/bz/input/input_id.h ${BENZENE_SRC_DIR}/bz/input/input_id_internal.h ${BENZENE_SRC_DIR}/bz/input/platform.h ${BENZENE_SRC_DIR}/bz/math/math.h ${BENZENE_SRC_DIR}/bz/math/math.c ${BENZENE_SRC_DIR}/bz/math/matrix.h ${BENZENE_SRC_DIR}/bz/math/matrix.c ${BENZENE_SRC_DIR}/bz/math/random.h ${BENZENE_SRC_DIR}/bz/math/random.c ${BENZENE_SRC_DIR}/bz/math/vector.h ${BENZENE_SRC_DIR}/bz/math/vector.c ${BENZENE_SRC_DIR}/bz/memory/allocator.h ${BENZENE_SRC_DIR}/bz/memory/allocator.c ${BENZENE_SRC_DIR}/bz/memory/arena.h ${BENZENE_SRC_DIR}/bz/memory/arena_internal.h ${BENZENE_SRC_DIR}/bz/memory/arena.c ${BENZENE_SRC_DIR}/bz/renderer/palette.h ${BENZENE_SRC_DIR}/bz/renderer/palette_internal.h ${BENZENE_SRC_DIR}/bz/renderer/palette.c ${BENZENE_SRC_DIR}/bz/renderer/render_pass.h ${BENZENE_SRC_DIR}/bz/renderer/render_pass_internal.h ${BENZENE_SRC_DIR}/bz/renderer/renderer.h ${BENZENE_SRC_DIR}/bz/renderer/renderer_internal.h ${BENZENE_SRC_DIR}/bz/renderer/renderer.c ${BENZENE_SRC_DIR}/bz/resources/resource.h ${BENZENE_SRC_DIR}/bz/resources/resource.c ${BENZENE_SRC_DIR}/bz/scripting/bindings.h ${BENZENE_SRC_DIR}/bz/scripting/bindings_internal.h ${BENZENE_SRC_DIR}/bz/scripting/bindings.cpp ${BENZENE_SRC_DIR}/bz/scripting/environment.h ${BENZENE_SRC_DIR}/bz/scripting/environment_internal.h ${BENZENE_SRC_DIR}/bz/scripting/environment.c ${BENZENE_SRC_DIR}/bz/scripting/script.h ${BENZENE_SRC_DIR}/bz/scripting/script_internal.h ${BENZENE_SRC_DIR}/bz/scripting/script.c ${BENZENE_SRC_DIR}/bz/scripting/static_crc32.hpp ${BENZENE_SRC_DIR}/bz/types/common.h ${BENZENE_SRC_DIR}/bz/types/identifier.h ${BENZENE_SRC_DIR}/bz/types/identifier.c ${BENZENE_SRC_DIR}/bz/types/point.h ${BENZENE_SRC_DIR}/bz/types/rect.h ${BENZENE_SRC_DIR}/bz/types/size.h ${BENZENE_SRC_DIR}/bz/types/user_parameter.h ) if(PLAYDATE_DEVICE) set(PLATFORM_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src_platform/playdate) set(BENZENE_PLATFORM_SOURCES ${PLATFORM_SRC_DIR}/bz/debug/assert.c ${PLATFORM_SRC_DIR}/bz/debug/log.c ${PLATFORM_SRC_DIR}/bz/debug/perfgraph.c ${PLATFORM_SRC_DIR}/bz/gfx/gfx_platform.h ${PLATFORM_SRC_DIR}/bz/gfx/gfx_platform.c ${PLATFORM_SRC_DIR}/bz/input/input.c ${PLATFORM_SRC_DIR}/bz/memory/arena.c ${PLATFORM_SRC_DIR}/bz/renderer/renderer.c ${PLATFORM_SRC_DIR}/bz/resources/resource.c ${PLATFORM_SRC_DIR}/playdate/entrypoint.h ${PLATFORM_SRC_DIR}/playdate/entrypoint.c ) else() set(PLATFORM_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src_platform/sdl) set(BENZENE_PLATFORM_SOURCES ${PLATFORM_SRC_DIR}/bz/audio/playback.c ${PLATFORM_SRC_DIR}/bz/debug/assert.c ${PLATFORM_SRC_DIR}/bz/debug/log.c ${PLATFORM_SRC_DIR}/bz/debug/perfgraph.c ${PLATFORM_SRC_DIR}/bz/gfx/gfx_platform.h ${PLATFORM_SRC_DIR}/bz/gfx/gfx_platform.c ${PLATFORM_SRC_DIR}/bz/input/input.c ${PLATFORM_SRC_DIR}/bz/memory/arena.c ${PLATFORM_SRC_DIR}/bz/renderer/renderer.c ${PLATFORM_SRC_DIR}/bz/resources/file_system_internal.h ${PLATFORM_SRC_DIR}/bz/resources/resource.c ${PLATFORM_SRC_DIR}/main.c ) endif() if(NOT PLAYDATE_DEVICE) set(PHYSFS_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/third_party/physfs/) set(PHYSFS_SOURCES ${PHYSFS_SRC_DIR}/src/physfs.c ${PHYSFS_SRC_DIR}/src/physfs.h ${PHYSFS_SRC_DIR}/src/physfs_archiver_7z.c ${PHYSFS_SRC_DIR}/src/physfs_archiver_dir.c ${PHYSFS_SRC_DIR}/src/physfs_archiver_grp.c ${PHYSFS_SRC_DIR}/src/physfs_archiver_hog.c ${PHYSFS_SRC_DIR}/src/physfs_archiver_iso9660.c ${PHYSFS_SRC_DIR}/src/physfs_archiver_mvl.c ${PHYSFS_SRC_DIR}/src/physfs_archiver_qpak.c ${PHYSFS_SRC_DIR}/src/physfs_archiver_slb.c ${PHYSFS_SRC_DIR}/src/physfs_archiver_unpacked.c ${PHYSFS_SRC_DIR}/src/physfs_archiver_vdf.c ${PHYSFS_SRC_DIR}/src/physfs_archiver_wad.c ${PHYSFS_SRC_DIR}/src/physfs_archiver_zip.c ${PHYSFS_SRC_DIR}/src/physfs_byteorder.c ${PHYSFS_SRC_DIR}/src/physfs_casefolding.h ${PHYSFS_SRC_DIR}/src/physfs_internal.h ${PHYSFS_SRC_DIR}/src/physfs_lzmasdk.h ${PHYSFS_SRC_DIR}/src/physfs_miniz.h ${PHYSFS_SRC_DIR}/src/physfs_platform_android.c ${PHYSFS_SRC_DIR}/src/physfs_platform_os2.c ${PHYSFS_SRC_DIR}/src/physfs_platform_posix.c ${PHYSFS_SRC_DIR}/src/physfs_platform_qnx.c ${PHYSFS_SRC_DIR}/src/physfs_platform_unix.c ${PHYSFS_SRC_DIR}/src/physfs_platform_windows.c ${PHYSFS_SRC_DIR}/src/physfs_platforms.h ${PHYSFS_SRC_DIR}/src/physfs_unicode.c ) if(APPLE) list(APPEND PHYSFS_SOURCES ${PHYSFS_SRC_DIR}/src/physfs_platform_apple.m) endif() endif() set(PARSON_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/third_party/parson/) set(PARSON_SOURCES ${PARSON_SRC_DIR}/parson.h ${PARSON_SRC_DIR}/parson.c ) set(PCG_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/third_party/pcg-c-basic/) set(PCG_SOURCES ${PCG_SRC_DIR}/pcg_basic.h ${PCG_SRC_DIR}/pcg_basic.c ) set(CRC_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/third_party/snippets_org_crc/) set(CRC_SOURCES ${CRC_SRC_DIR}/crc.h ${CRC_SRC_DIR}/crc.c ) set(SOLOUD_SPEECH_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/third_party/soloud_speech/) set(SOLOUD_SPEECH_SOURCES ${SOLOUD_SPEECH_SRC_DIR}/darray.h ${SOLOUD_SPEECH_SRC_DIR}/darray.cpp ${SOLOUD_SPEECH_SRC_DIR}/klatt.h ${SOLOUD_SPEECH_SRC_DIR}/klatt.cpp ${SOLOUD_SPEECH_SRC_DIR}/resonator.h ${SOLOUD_SPEECH_SRC_DIR}/resonator.cpp ${SOLOUD_SPEECH_SRC_DIR}/tts.h ${SOLOUD_SPEECH_SRC_DIR}/tts.cpp ) add_library(benzene STATIC ${BENZENE_SOURCES}) set_property(TARGET benzene PROPERTY C_STANDARD 11) if(PLAYDATE_DEVICE) # NB: This is copied out of the Playdate SDK. Check for correctness on update. 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() ## include_directories("${SDK}/C_API") set(PDC "${SDK}/bin/pdc" -sdkpath "${SDK}") add_compile_definitions(TARGET_EXTENSION=1) set(HEAP_SIZE 8388208) set(STACK_SIZE 61800) set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -x assembler-with-cpp -D__HEAP_SIZE=${HEAP_SIZE} -D__STACK_SIZE=${STACK_SIZE}") set(MCFLAGS -mthumb -mcpu=cortex-m7 -mfloat-abi=hard -mfpu=fpv5-sp-d16 -D__FPU_USED=1) target_compile_definitions(benzene PUBLIC TARGET_PLAYDATE=1) target_compile_options(benzene PUBLIC -Wall -Wno-unknown-pragmas -Wdouble-promotion) # target_compile_options(benzene PUBLIC $<$:-O2>) # target_compile_options(benzene PUBLIC $<$:-O2>) target_compile_options(benzene PUBLIC -O2) target_compile_options(benzene PUBLIC ${MCFLAGS}) target_compile_options(benzene PUBLIC -falign-functions=16 -fomit-frame-pointer) target_compile_options(benzene PUBLIC -gdwarf-2) target_compile_options(benzene PUBLIC -fverbose-asm) target_compile_options(benzene PUBLIC -ffunction-sections -fdata-sections) target_compile_options(benzene PUBLIC -mword-relocations -fno-common) #target_compile_options(benzene PUBLIC $<$:-fno-exceptions>) target_link_options(benzene PUBLIC ${MCFLAGS}) target_link_options(benzene PUBLIC -specs=nosys.specs) # target_compile_options(benzene PUBLIC "-funroll-loops") target_compile_options(benzene PUBLIC "-nostdlib") # target_compile_options(benzene PUBLIC "-nostdinc") target_compile_options(benzene PUBLIC "-nodefaultlibs") elseif(APPLE) endif() if(PLAYDATE_DEVICE) target_sources(benzene PRIVATE ${BENZENE_PLATFORM_SOURCES} ${PARSON_SOURCES} ${PCG_SOURCES} ${CRC_SOURCES}) else() target_sources(benzene PRIVATE ${BENZENE_PLATFORM_SOURCES} ${PHYSFS_SOURCES} ${PARSON_SOURCES} ${PCG_SOURCES} ${CRC_SOURCES} ${SOLOUD_SPEECH_SOURCES}) endif() target_precompile_headers(benzene PRIVATE ${BENZENE_SRC_DIR}/bz/common.pch) target_link_libraries(benzene PRIVATE sun) target_include_directories(benzene PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/third_party/sun/runtime/src) if(PLAYDATE_DEVICE) else() if(TARGET SDL2::SDL2main) target_link_libraries(benzene PRIVATE SDL2::SDL2main) endif() # FIXME, Ideally we want to use the DLLs so that Steam etc. can patch #target_link_libraries(benzene PRIVATE SDL2::SDL2) target_link_libraries(benzene PRIVATE SDL2::SDL2-static) endif() if(APPLE) target_link_libraries(benzene PRIVATE "-framework Foundation") target_link_libraries(benzene PRIVATE "-framework IOKit") endif() target_include_directories(benzene PRIVATE ${GAME_SRC_DIR}) target_include_directories(benzene PRIVATE ${BENZENE_SRC_DIR}) target_include_directories(benzene PRIVATE ${PLATFORM_SRC_DIR}) target_include_directories(benzene PRIVATE ${PARSON_SRC_DIR}) target_include_directories(benzene PRIVATE ${PCG_SRC_DIR}) target_include_directories(benzene PRIVATE ${CRC_SRC_DIR}) target_include_directories(benzene PRIVATE ${SOLOUD_SPEECH_SRC_DIR}) target_include_directories(benzene PRIVATE ${PHYSFS_SRC_DIR}/src) target_include_directories(benzene PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/third_party/stb)