Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
run: sudo apt-get update && sudo apt-get install -y cmake libglfw3-dev libbz2-dev

- name: Configure
run: cmake -B build -DWERROR=ON -DDESKTOP_BACKEND=glfw3 -DCMAKE_BUILD_TYPE=Release "-DBUTTERSCOTCH_COMMIT_HASH=${{ steps.commit-info.outputs.hash }}" "-DBUTTERSCOTCH_COMMIT_DATE=${{ steps.commit-info.outputs.date }}"
run: cmake -B build -DWERROR=ON -DBACKEND=glfw3 -DCMAKE_BUILD_TYPE=Release "-DBUTTERSCOTCH_COMMIT_HASH=${{ steps.commit-info.outputs.hash }}" "-DBUTTERSCOTCH_COMMIT_DATE=${{ steps.commit-info.outputs.date }}"

- name: Build
run: cmake --build build -j$(nproc)
Expand Down Expand Up @@ -71,7 +71,7 @@ jobs:
sudo cp /tmp/bzip2-1.0.8/bzlib.h /usr/x86_64-w64-mingw32/include/

- name: Configure
run: cmake -B build -DCMAKE_TOOLCHAIN_FILE=cmake/mingw-w64.cmake -DWERROR=ON -DDESKTOP_BACKEND=glfw3 -DCMAKE_BUILD_TYPE=Release "-DBUTTERSCOTCH_COMMIT_HASH=${{ steps.commit-info.outputs.hash }}" "-DBUTTERSCOTCH_COMMIT_DATE=${{ steps.commit-info.outputs.date }}"
run: cmake -B build -DCMAKE_TOOLCHAIN_FILE=cmake/mingw-w64.cmake -DWERROR=ON -DBACKEND=glfw3 -DCMAKE_BUILD_TYPE=Release "-DBUTTERSCOTCH_COMMIT_HASH=${{ steps.commit-info.outputs.hash }}" "-DBUTTERSCOTCH_COMMIT_DATE=${{ steps.commit-info.outputs.date }}"

- name: Build
run: cmake --build build -j$(nproc)
Expand Down Expand Up @@ -114,7 +114,7 @@ jobs:
- name: Configure
run: |
export PKG_CONFIG_PATH=/usr/local/glfw-x86/lib/pkgconfig:/usr/lib/i386-linux-gnu/pkgconfig
cmake -B build -DWERROR=ON -DDESKTOP_BACKEND=glfw3 -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_FLAGS=-m32 -DCMAKE_EXE_LINKER_FLAGS=-m32 "-DBUTTERSCOTCH_COMMIT_HASH=${{ steps.commit-info.outputs.hash }}" "-DBUTTERSCOTCH_COMMIT_DATE=${{ steps.commit-info.outputs.date }}"
cmake -B build -DWERROR=ON -DBACKEND=glfw3 -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_FLAGS=-m32 -DCMAKE_EXE_LINKER_FLAGS=-m32 "-DBUTTERSCOTCH_COMMIT_HASH=${{ steps.commit-info.outputs.hash }}" "-DBUTTERSCOTCH_COMMIT_DATE=${{ steps.commit-info.outputs.date }}"

- name: Build
run: cmake --build build -j$(nproc)
Expand Down Expand Up @@ -166,7 +166,7 @@ jobs:
NO_COLOR=1 \
VERBOSE=1 \
CC='ccache i486-w64-mingw32-gcc' \
DESKTOP_BACKEND=glfw2 \
BACKEND=glfw2 \
GLFW2_LIBS='-lglfw -lopengl32' \
EXTRALIBS='-latomic' \
BUTTERSCOTCH_COMMIT_HASH=${{ steps.commit-info.outputs.hash }} \
Expand Down Expand Up @@ -398,7 +398,7 @@ jobs:
- name: Build
run: |
sudo mv butterscotch ~/woody
sudo chroot ~/woody /bin/sh --login -c 'make -C /butterscotch NO_COLOR=1 VERBOSE=1 CC="${{ matrix.compiler }} ${{ matrix.flags }}" DESKTOP_BACKEND=sdl1 AUDIO_BACKEND=none SDL1_LIBS='-lSDL' DISABLE_MMD=1'
sudo chroot ~/woody /bin/sh --login -c 'make -C /butterscotch NO_COLOR=1 VERBOSE=1 CC="${{ matrix.compiler }} ${{ matrix.flags }}" BACKEND=sdl1 AUDIO_BACKEND=none SDL1_LIBS='-lSDL' DISABLE_MMD=1'

build-cxx:
name: Build as C++
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
run: sudo apt-get update && sudo apt-get install -y cmake libglfw3-dev libbz2-dev

- name: Configure
run: cmake -B build -DDESKTOP_BACKEND=glfw3 -DCMAKE_BUILD_TYPE=Release "-DBUTTERSCOTCH_COMMIT_HASH=${{ steps.commit-info.outputs.hash }}" "-DBUTTERSCOTCH_COMMIT_DATE=${{ steps.commit-info.outputs.date }}"
run: cmake -B build -DBACKEND=glfw3 -DCMAKE_BUILD_TYPE=Release "-DBUTTERSCOTCH_COMMIT_HASH=${{ steps.commit-info.outputs.hash }}" "-DBUTTERSCOTCH_COMMIT_DATE=${{ steps.commit-info.outputs.date }}"

- name: Build Butterscotch
run: cmake --build build -j$(nproc)
Expand Down
22 changes: 11 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ else()
endif()
endif()

set(PLATFORM "desktop" CACHE STRING "Platform backend")
set(DESKTOP_BACKEND "" CACHE STRING "Desktop platform backend")
set(PLATFORM "cli" CACHE STRING "Platform backend")
set(BACKEND "" CACHE STRING "Desktop platform backend")
set(AUDIO_BACKEND "" CACHE STRING "Audio backend")

if(PLATFORM STREQUAL "desktop" AND DESKTOP_BACKEND STREQUAL "")
message(FATAL_ERROR "You need to set a DESKTOP_BACKEND!")
if(PLATFORM STREQUAL "cli" AND BACKEND STREQUAL "")
message(FATAL_ERROR "You need to set a BACKEND!")
endif()

# Build metadata
Expand Down Expand Up @@ -203,7 +203,7 @@ if(ENABLE_VM_EXCEPTIONS_LOGS)
add_compile_definitions(ENABLE_VM_EXCEPTIONS_LOGS)
endif()

if(PLATFORM STREQUAL "desktop")
if(PLATFORM STREQUAL "cli")
# Matches the GitHub Actions container flags (FORTIFY requires building with optimizations enabled!)
target_compile_options(butterscotch PRIVATE "$<$<CONFIG:Release,RelWithDebInfo>:-U_FORTIFY_SOURCE;-D_FORTIFY_SOURCE=2>")

Expand Down Expand Up @@ -269,7 +269,7 @@ if(PLATFORM STREQUAL "desktop")
set(PLATFORM_LIBRARIES ${PLATFORM_LIBRARIES} ${CMAKE_DL_LIBS})
endif()

if(DESKTOP_BACKEND STREQUAL "glfw3")
if(BACKEND STREQUAL "glfw3")
add_compile_definitions(USE_GLFW3)

if(MINGW)
Expand All @@ -291,29 +291,29 @@ if(PLATFORM STREQUAL "desktop")
target_link_directories(butterscotch PRIVATE ${GLFW3_LIBRARY_DIRS})
set(BACKEND_LIBRARIES ${GLFW3_LIBRARIES})
endif()
elseif(DESKTOP_BACKEND STREQUAL "glfw2")
elseif(BACKEND STREQUAL "glfw2")
add_compile_definitions(USE_GLFW2)

find_package(PkgConfig REQUIRED)
pkg_check_modules(GLFW2 REQUIRED libglfw)
target_include_directories(butterscotch PRIVATE ${GLFW2_INCLUDE_DIRS})
target_link_directories(butterscotch PRIVATE ${GLFW2_LIBRARY_DIRS})
set(BACKEND_LIBRARIES ${GLFW2_LIBRARIES})
elseif(DESKTOP_BACKEND STREQUAL "sdl1")
elseif(BACKEND STREQUAL "sdl1")
add_compile_definitions(USE_SDL1)

find_package(SDL REQUIRED)
target_include_directories(butterscotch PUBLIC ${SDL_INCLUDE_DIR})
set(BACKEND_LIBRARIES ${SDL_LIBRARY})
elseif(DESKTOP_BACKEND STREQUAL "sdl2")
elseif(BACKEND STREQUAL "sdl2")
add_compile_definitions(USE_SDL2)

find_package(PkgConfig REQUIRED)
pkg_check_modules(SDL2 REQUIRED sdl2)
target_include_directories(butterscotch PRIVATE ${SDL2_INCLUDE_DIRS})
target_link_directories(butterscotch PRIVATE ${SDL2_LIBRARY_DIRS})
set(BACKEND_LIBRARIES ${SDL2_LIBRARIES})
elseif(DESKTOP_BACKEND STREQUAL "sdl3")
elseif(BACKEND STREQUAL "sdl3")
add_compile_definitions(USE_SDL3)

find_package(PkgConfig REQUIRED)
Expand All @@ -323,7 +323,7 @@ if(PLATFORM STREQUAL "desktop")
set(BACKEND_LIBRARIES ${SDL3_LIBRARIES})
endif()
target_link_libraries(butterscotch PRIVATE ${BACKEND_LIBRARIES} ${AUDIO_LIBRARIES} ${PLATFORM_LIBRARIES})
target_sources(butterscotch PRIVATE src/desktop/backends/${DESKTOP_BACKEND}.c)
target_sources(butterscotch PRIVATE src/backends/${BACKEND}.c)

# Enable AddressSanitizer by default in Debug builds
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
Expand Down
4 changes: 2 additions & 2 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
"generator": "Ninja",
"binaryDir": "${sourceDir}/build",
"cacheVariables": {
"PLATFORM": "desktop",
"DESKTOP_BACKEND": "glfw3",
"PLATFORM": "cli",
"BACKEND": "glfw3",
"ENABLE_ASAN": false,
"CMAKE_TOOLCHAIN_FILE": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake"
}
Expand Down
28 changes: 19 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ INCLUDES += $(INCLUDE). \
HEADERS += $(wildcard src/*.h) $(shell find vendor -name '*.h')
SRCS += $(wildcard src/*.c) $(wildcard src/image/*.c) $(wildcard vendor/bzip2/*.c) vendor/md5/md5.c vendor/sha1/sha1.c vendor/base64/base64.c

DESKTOP_BACKEND := glfw3
PLATFORM := cli
BACKEND := glfw3
AUDIO_BACKEND := miniaudio

ifdef BUTTERSCOTCH_COMMIT_DATE
Expand All @@ -69,35 +70,44 @@ ifndef DISABLE_WAD17
DEFINES += $(DEFINE)ENABLE_WAD17
endif

# TODO: add support for non-desktop backends
SRCS += $(wildcard src/desktop/*.c) src/desktop/backends/$(DESKTOP_BACKEND).c
ifeq ($(PLATFORM),cli)
SRCS += $(wildcard src/cli/*.c)
else
ifeq ($(PLATFORM),embedded)
SRCS += $(wildcard src/embedded/*.c)
else
$(error unknown platform)
endif
endif

SRCS += src/backends/$(BACKEND).c
ifeq ($(OS),Windows)
PKG_CONFIG_FLAGS := --static
endif
INCLUDES += $(INCLUDE)src/desktop
ifeq ($(DESKTOP_BACKEND),glfw3)
INCLUDES += $(INCLUDE)src/cli
ifeq ($(BACKEND),glfw3)
GLFW3_LIBS += $(shell $(PKG_CONFIG) $(PKG_CONFIG_FLAGS) --libs glfw3)
LIBS += $(GLFW3_LIBS)
DEFINES += $(DEFINE)USE_GLFW3
ENABLE_GLAD := 1
endif
ifeq ($(DESKTOP_BACKEND),glfw2)
ifeq ($(BACKEND),glfw2)
GLFW2_LIBS += $(shell $(PKG_CONFIG) $(PKG_CONFIG_FLAGS) --libs libglfw)
LIBS += $(GLFW2_LIBS)
DEFINES += $(DEFINE)USE_GLFW2
ENABLE_GLAD := 1
endif
ifeq ($(DESKTOP_BACKEND),sdl1)
ifeq ($(BACKEND),sdl1)
SDL1_LIBS += $(shell $(PKG_CONFIG) $(PKG_CONFIG_FLAGS) --libs sdl)
LIBS += $(SDL1_LIBS)
DEFINES += $(DEFINE)USE_SDL1
endif
ifeq ($(DESKTOP_BACKEND),sdl2)
ifeq ($(BACKEND),sdl2)
SDL2_LIBS += $(shell $(PKG_CONFIG) $(PKG_CONFIG_FLAGS) --libs sdl2)
LIBS += $(SDL2_LIBS)
DEFINES += $(DEFINE)USE_SDL2
endif
ifeq ($(DESKTOP_BACKEND),sdl3)
ifeq ($(BACKEND),sdl3)
SDL3_LIBS += $(shell $(PKG_CONFIG) $(PKG_CONFIG_FLAGS) --libs sdl3)
LIBS += $(SDL3_LIBS)
DEFINES += $(DEFINE)USE_SDL3
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ The following compilers have been tested to successfully build butterscotch, old

```bash
mkdir build && cd build
cmake -DPLATFORM=desktop -DDESKTOP_BACKEND=glfw3 -DCMAKE_BUILD_TYPE=Debug ..
cmake -DPLATFORM=desktop -DBACKEND=glfw3 -DCMAKE_BUILD_TYPE=Debug ..
make
```

Expand Down
3 changes: 0 additions & 3 deletions src/android/stb_impl.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,3 @@

#define STB_IMAGE_WRITE_IMPLEMENTATION
#include "stb_image_write.h"

#define STB_DS_IMPLEMENTATION
#include "stb_ds.h"
2 changes: 1 addition & 1 deletion src/desktop/backends/glfw2.c → src/backends/glfw2.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

#include "common.h"
#include "input_recording.h"
#include "desktop/platformdefs.h"
#include "platformdefs.h"
#include "gettime.h"
#include "runner_mouse.h"

Expand Down
2 changes: 1 addition & 1 deletion src/desktop/backends/glfw3.c → src/backends/glfw3.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

#include "common.h"
#include "input_recording.h"
#include "desktop/platformdefs.h"
#include "platformdefs.h"
#include "gettime.h"
#include "runner_mouse.h"

Expand Down
2 changes: 1 addition & 1 deletion src/desktop/backends/sdl1.c → src/backends/sdl1.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#include "common.h"
#include "input_recording.h"
#include "desktop/platformdefs.h"
#include "platformdefs.h"
#include "gettime.h"

#ifndef SDL_BUTTON_WHEELUP
Expand Down
2 changes: 1 addition & 1 deletion src/desktop/backends/sdl2.c → src/backends/sdl2.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

#include "common.h"
#include "input_recording.h"
#include "desktop/platformdefs.h"
#include "platformdefs.h"
#include "gettime.h"
#include "runner_mouse.h"

Expand Down
2 changes: 1 addition & 1 deletion src/desktop/backends/sdl3.c → src/backends/sdl3.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

#include "common.h"
#include "input_recording.h"
#include "desktop/platformdefs.h"
#include "platformdefs.h"
#include "gettime.h"
#include <ctype.h>
#include "runner_mouse.h"
Expand Down
Loading
Loading