Skip to content

Commit

Permalink
Make macOS SDL build portable, build script runnable locally
Browse files Browse the repository at this point in the history
  • Loading branch information
jcm committed Mar 27, 2024
1 parent a04c215 commit b3e12fc
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 6 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ out/
obj-amd64/
obj-arm64/
out-amd64/
out-arm64/
out-arm64/
thirdparty/SDL/SDL
thirdparty/SDL/libSDL2-2.0.0.dylib
11 changes: 9 additions & 2 deletions ruby/GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ ifeq ($(ruby),)
ifeq ($(wildcard $(macsdl)),)
$(error Tried to compile ruby for macOS with SDL2 linked, but no SDL2 library was found. Compile it with thirdparty/SDL/build-sdl.sh, or disable SDL by compiling ares with sdl2=false)
endif
flags += -DMACOS_COMPILED_SDL
ruby += audio.sdl
ruby += input.sdl
endif
Expand Down Expand Up @@ -63,6 +64,9 @@ endif

ifeq ($(platform),macos)
ruby.flags := $(flags.objcpp)
ifeq ($(sdl2),true)
ruby.flags += -I ../thirdparty/SDL/SDL/include/
endif
else
ruby.flags := $(flags.cpp)
endif
Expand All @@ -71,7 +75,7 @@ ruby.flags += -I../thirdparty
ruby.flags += $(foreach c,$(subst .,_,$(call strupper,$(ruby))),-D$c)
ifeq ($(pkg_config),)
# TODO: add SDL2 cflags
else
else ifeq ($(wildcard $(macsdl)),)
ruby.flags += $(if $(findstring input.sdl,$(ruby)),$(shell $(pkg_config) sdl2 --cflags))
ruby.flags += $(if $(findstring audio.sdl,$(ruby)),$(shell $(pkg_config) sdl2 --cflags))
endif
Expand Down Expand Up @@ -100,7 +104,7 @@ ifeq ($(platform),windows)
ruby.options += $(if $(findstring input.sdl,$(ruby)),$(shell $(pkg_config) sdl2 --libs --static))
ruby.options += $(if $(findstring audio.sdl,$(ruby)),$(shell $(pkg_config) sdl2 --libs --static))
endif
else
else ifeq ($(wildcard $(macsdl)),)
ruby.options += $(if $(findstring input.sdl,$(ruby)),$(shell $(pkg_config) sdl2 --libs))
ruby.options += $(if $(findstring audio.sdl,$(ruby)),$(shell $(pkg_config) sdl2 --libs))
endif
Expand All @@ -116,6 +120,9 @@ endif
ifeq ($(platform),macos)
ruby.options += -framework IOKit
ruby.options += $(if $(findstring audio.openal,$(ruby)),-framework OpenAL)
ifeq ($(sdl2),true)
ruby.options += -L../thirdparty/SDL/ -lSDL2-2.0.0
endif
endif

ifeq ($(platform),linux)
Expand Down
4 changes: 4 additions & 0 deletions ruby/input/sdl.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#if defined(MACOS_COMPILED_SDL)
#include "SDL.h"
#else
#include <SDL2/SDL.h>
#endif

#if defined(PLATFORM_WINDOWS)
#include "shared/rawinput.cpp"
Expand Down
13 changes: 10 additions & 3 deletions thirdparty/SDL/build-sdl.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,18 @@ fi
git -C SDL reset --hard "$(cat HEAD)"
mkdir -p SDL/build
pushd SDL/build
sudo xcode-select -s /Applications/Xcode.app/Contents/Developer

if [ -n "${GITHUB_ACTIONS+1}" ]; then
sudo xcode-select -s /Applications/Xcode.app/Contents/Developer
echo "Set Xcode version in order to target macOS 10.11 when building SDL."
fi
cmake .. "-DCMAKE_OSX_ARCHITECTURES=arm64;x86_64" \
-DCMAKE_OSX_DEPLOYMENT_TARGET=10.11
cmake --build .
sudo cmake --install .
sudo xcode-select -s /Applications/Xcode_14.2.app/Contents/Developer

if [ -n "${GITHUB_ACTIONS+1}" ]; then
sudo xcode-select -s /Applications/Xcode_14.2.app/Contents/Developer
echo "Set Xcode to 14.2 to continue build."
fi
popd
cp SDL/build/libSDL2-2.0.0.dylib .

0 comments on commit b3e12fc

Please sign in to comment.