Skip to content

Commit 571832a

Browse files
jcm93jcm
and
jcm
authored
Make macOS SDL build portable, build script runnable locally (#1393)
Resubmission of #1389 with improvements. Now the SDL build script will not call `xcode-select`, which can have undesired effects on the user build environment, unless it is on CI (detected with the `$GITHUB_ACTIONS` env var). It will also not call ``cmake --install .``, which would previously replace the user's SDL installation. This second change required some minor changes to ruby's makefile. We now include the header directory from the cloned SDL source, and inform the linker correctly of the location of the SDL .dylib. Also added the cloned SDL repository and .dylib to the .gitignore for easier development workflow. To ensure compatibility with #1390, the `MACOS_COMPILED_SDL` flag is added so we can include the proper "SDL.h" header for compiled builds and `<SDL2/SDL.h>` header for system builds. Co-authored-by: jcm <[email protected]>
1 parent a04c215 commit 571832a

File tree

5 files changed

+30
-6
lines changed

5 files changed

+30
-6
lines changed

Diff for: .gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,6 @@ out/
99
obj-amd64/
1010
obj-arm64/
1111
out-amd64/
12-
out-arm64/
12+
out-arm64/
13+
thirdparty/SDL/SDL
14+
thirdparty/SDL/libSDL2-2.0.0.dylib

Diff for: ruby/GNUmakefile

+9-2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ ifeq ($(ruby),)
2626
ifeq ($(wildcard $(macsdl)),)
2727
$(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)
2828
endif
29+
flags += -DMACOS_COMPILED_SDL
2930
ruby += audio.sdl
3031
ruby += input.sdl
3132
endif
@@ -63,6 +64,9 @@ endif
6364

6465
ifeq ($(platform),macos)
6566
ruby.flags := $(flags.objcpp)
67+
ifeq ($(sdl2),true)
68+
ruby.flags += -I ../thirdparty/SDL/SDL/include/
69+
endif
6670
else
6771
ruby.flags := $(flags.cpp)
6872
endif
@@ -71,7 +75,7 @@ ruby.flags += -I../thirdparty
7175
ruby.flags += $(foreach c,$(subst .,_,$(call strupper,$(ruby))),-D$c)
7276
ifeq ($(pkg_config),)
7377
# TODO: add SDL2 cflags
74-
else
78+
else ifeq ($(wildcard $(macsdl)),)
7579
ruby.flags += $(if $(findstring input.sdl,$(ruby)),$(shell $(pkg_config) sdl2 --cflags))
7680
ruby.flags += $(if $(findstring audio.sdl,$(ruby)),$(shell $(pkg_config) sdl2 --cflags))
7781
endif
@@ -100,7 +104,7 @@ ifeq ($(platform),windows)
100104
ruby.options += $(if $(findstring input.sdl,$(ruby)),$(shell $(pkg_config) sdl2 --libs --static))
101105
ruby.options += $(if $(findstring audio.sdl,$(ruby)),$(shell $(pkg_config) sdl2 --libs --static))
102106
endif
103-
else
107+
else ifeq ($(wildcard $(macsdl)),)
104108
ruby.options += $(if $(findstring input.sdl,$(ruby)),$(shell $(pkg_config) sdl2 --libs))
105109
ruby.options += $(if $(findstring audio.sdl,$(ruby)),$(shell $(pkg_config) sdl2 --libs))
106110
endif
@@ -116,6 +120,9 @@ endif
116120
ifeq ($(platform),macos)
117121
ruby.options += -framework IOKit
118122
ruby.options += $(if $(findstring audio.openal,$(ruby)),-framework OpenAL)
123+
ifeq ($(sdl2),true)
124+
ruby.options += -L../thirdparty/SDL/ -lSDL2-2.0.0
125+
endif
119126
endif
120127

121128
ifeq ($(platform),linux)

Diff for: ruby/audio/sdl.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1+
#if defined(MACOS_COMPILED_SDL)
2+
#include "SDL.h"
3+
#else
14
#include <SDL2/SDL.h>
5+
#endif
26

37
struct AudioSDL : AudioDriver {
48
AudioSDL& self = *this;

Diff for: ruby/input/sdl.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1+
#if defined(MACOS_COMPILED_SDL)
2+
#include "SDL.h"
3+
#else
14
#include <SDL2/SDL.h>
5+
#endif
26

37
#if defined(PLATFORM_WINDOWS)
48
#include "shared/rawinput.cpp"

Diff for: thirdparty/SDL/build-sdl.sh

+10-3
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,18 @@ fi
99
git -C SDL reset --hard "$(cat HEAD)"
1010
mkdir -p SDL/build
1111
pushd SDL/build
12-
sudo xcode-select -s /Applications/Xcode.app/Contents/Developer
12+
13+
if [ -n "${GITHUB_ACTIONS+1}" ]; then
14+
sudo xcode-select -s /Applications/Xcode.app/Contents/Developer
15+
echo "Set Xcode version in order to target macOS 10.11 when building SDL."
16+
fi
1317
cmake .. "-DCMAKE_OSX_ARCHITECTURES=arm64;x86_64" \
1418
-DCMAKE_OSX_DEPLOYMENT_TARGET=10.11
1519
cmake --build .
16-
sudo cmake --install .
17-
sudo xcode-select -s /Applications/Xcode_14.2.app/Contents/Developer
20+
21+
if [ -n "${GITHUB_ACTIONS+1}" ]; then
22+
sudo xcode-select -s /Applications/Xcode_14.2.app/Contents/Developer
23+
echo "Set Xcode to 14.2 to continue build."
24+
fi
1825
popd
1926
cp SDL/build/libSDL2-2.0.0.dylib .

0 commit comments

Comments
 (0)