Skip to content

Make macOS SDL build portable, build script runnable locally #1393

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 27, 2024
Merged
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
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/audio/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

struct AudioSDL : AudioDriver {
AudioSDL& self = *this;
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 .