Skip to content

Commit 6ff84ea

Browse files
committed
Add devshell for nix under macOs
1 parent b5b5efb commit 6ff84ea

File tree

4 files changed

+163
-4
lines changed

4 files changed

+163
-4
lines changed

CMakeLists.txt

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ option ( ENABLE_CLANG_ANALYSIS "When building with clang, enable the static anal
2121
option ( CHECK_CCACHE "Check if ccache is installed and use it" OFF )
2222
set ( MSVC_WARNING_LEVEL 3 CACHE STRING "Visual Studio warning levels" )
2323
option ( FORCE_INSTALL_DATA_TO_BIN "Force installation of data to binary directory" OFF )
24+
if ( APPLE )
25+
# Use by default since brew doesn't have legacy SDL1, sdl12-compat avalaible
26+
option ( USE_SDL2 "Using SDL2 via SDL12 compatible layer" ON )
27+
else ()
28+
option ( USE_SDL2 "Using SDL2 via SDL12 compatible layer" OFF )
29+
endif ()
2430
set ( DATADIR "" CACHE STRING "Where to search for datafiles" )
2531

2632
if ( CHECK_CCACHE )
@@ -91,17 +97,30 @@ if(NOT UNIX AND IS_DIRECTORY ${DEPS_DIR})
9197
else ( )
9298
link_directories ( ${DEPS_DIR}/lib/Win32 )
9399
endif()
94-
set( SDL_LIBRARY SDL )
100+
set ( SDL_LIBRARY SDL )
101+
if ( USE_SDL2 )
102+
# explicitly added SDL2 as dependency since needed for runtime work
103+
set ( SDL2_LIBRARY SDL2 )
104+
message ( STATUS "Using SDL2 via SDL12 compatible layer" )
105+
else ( )
106+
set ( SDL2_LIBRARY "")
107+
endif ()
95108
set ( SDLGFX_LIBRARY SDL_gfx )
96109
set ( SDLMIXER_LIBRARY SDL_mixer )
97110
set ( SDLIMAGE_LIBRARY SDL_image )
98-
set ( PKG_DEPS_LDFLAGS ${SDLIMAGE_LIBRARY} ${SDLMIXER_LIBRARY} ${SDLGFX_LIBRARY} ${SDL_LIBRARY} ${OPENGL_LIBRARIES} )
111+
set ( PKG_DEPS_LDFLAGS ${SDLIMAGE_LIBRARY} ${SDLMIXER_LIBRARY} ${SDLGFX_LIBRARY} ${SDL_LIBRARY} ${SDL2_LIBRARY} ${OPENGL_LIBRARIES} )
99112
elseif(UNIX OR MINGW OR CYGWIN)
100113
if(IS_DIRECTORY ${DEPS_DIR})
101114
set(ENV{PKG_CONFIG_PATH} "${DEPS_DIR}/lib/pkgconfig/")
102115
endif()
103116

104117
include(FindPkgConfig)
118+
if ( USE_SDL2 )
119+
# explicitly added SDL2 as dependency since needed for runtime work
120+
pkg_check_modules(PKG_SDL2 REQUIRED sdl2)
121+
else ( )
122+
set ( PKG_SDLG2_LDFLAGS "" )
123+
endif ()
105124
pkg_check_modules(PKG_SDL REQUIRED sdl)
106125
pkg_check_modules(PKG_ZLIB REQUIRED zlib)
107126
pkg_check_modules(PKG_SDLIMAGE REQUIRED SDL_image)
@@ -110,7 +129,7 @@ elseif(UNIX OR MINGW OR CYGWIN)
110129

111130
include_directories(${PKG_SDL_INCLUDE_DIRS} ${PKG_ZLIB_INCLUDE_DIRS} ${PKG_SDLIMAGE_INCLUDE_DIRS})
112131
include_directories(${PKG_SDLGFX_INCLUDE_DIRS} ${PKG_SDLMIXER_INCLUDE_DIRS})
113-
set(PKG_DEPS_LDFLAGS ${PKG_SDL_LDFLAGS} ${PKG_ZLIB_LDFLAGS} ${PKG_SDLIMAGE_LDFLAGS} ${PKG_SDLGFX_LDFLAGS} ${PKG_SDLMIXER_LDFLAGS} ${OPENGL_LIBRARIES})
132+
set(PKG_DEPS_LDFLAGS ${PKG_SDL_LDFLAGS} ${PKG_SDL2_LDFLAGS} ${PKG_ZLIB_LDFLAGS} ${PKG_SDLIMAGE_LDFLAGS} ${PKG_SDLGFX_LDFLAGS} ${PKG_SDLMIXER_LDFLAGS} ${OPENGL_LIBRARIES})
114133

115134
if (UNIX)
116135
set(PKG_DEPS_LDFLAGS "${PKG_DEPS_LDFLAGS};dl")

README-OSX.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Building for MacOS
22

3-
## Dependencies
3+
## Using brew
4+
5+
### Dependencies
46
To successfully build an OpenXcom OSX bundle you will need to ensure all the relevant dependencies installed in /usr/local/.
57

68
The dependencies you require are following:
@@ -16,6 +18,17 @@ $ brew install cmake sdl sdl_gfx sdl_image sdl_mixer --with-flac --with-libmikmo
1618
```
1719
This should install all of these necessary dependencies to their appropriate place under /usr/local.
1820

21+
22+
## Using Nix
23+
24+
All needed stuff related to installing and configure shell already described at flake.nix, just execute
25+
26+
```
27+
$ nix develop -c $SHELL
28+
```
29+
30+
Note: After it all below building command are applicable
31+
1932
## Building
2033
This project has two ways to build: one with make and the other with Xcode. The make way is typically used for CI builds and produces a similar artifact as the Linux build. If you're just looking to get a quick build, this is a good way to do so. The Xcode way is useful if you're developing features (or bug fixes) and require the need for a debugger or an IDE experience.
2134

flake.lock

Lines changed: 43 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
{
2+
inputs = {
3+
systems.url = "github:nix-systems/default";
4+
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
5+
};
6+
7+
outputs =
8+
{
9+
self,
10+
nixpkgs,
11+
systems,
12+
}:
13+
let
14+
forEachSystem =
15+
f: nixpkgs.lib.genAttrs (import systems) (system: f { pkgs = import nixpkgs { inherit system; }; });
16+
in
17+
{
18+
devShells = forEachSystem (
19+
{ pkgs }:
20+
{
21+
default =
22+
pkgs.mkShell.override
23+
{
24+
# override clang 16 runtime
25+
stdenv = pkgs.lowPrio pkgs.llvmPackages_16.stdenv;
26+
}
27+
{
28+
propagatedBuildInputs = [
29+
pkgs.SDL_compat
30+
pkgs.SDL_image
31+
pkgs.libwebp
32+
];
33+
# when using SDL_compat instead of SDL_classic, SDL_mixer isn't correctly
34+
# detected, but there is no harm just specifying it
35+
buildInputs = with pkgs; [
36+
git
37+
pkg-config
38+
apple-sdk_15
39+
40+
# Need to use brew cmake since nix use old one 3.30.5
41+
# which has issues with copy libraries to macOs app
42+
#cmake
43+
# use clang explicitly since don't use cmake
44+
clang_16
45+
# OpenXcom dependecies
46+
rapidyaml
47+
zlib
48+
#SDL_mixer
49+
# SDL_image
50+
# SDL_gfx
51+
# Try to build using SDL12_compat
52+
(SDL_compat.overrideAttrs (old: {
53+
postInstall = ''
54+
ln -s $out/lib/pkgconfig/sdl12_compat.pc $out/lib/pkgconfig/sdl.pc
55+
'';
56+
}))
57+
(SDL_mixer.override (old: {
58+
SDL = SDL_compat;
59+
smpeg = old.smpeg.override {
60+
SDL = SDL_compat;
61+
};
62+
}))
63+
(SDL_gfx.override (old: {
64+
SDL = SDL_compat;
65+
}))
66+
(
67+
(SDL_image.override (old: {
68+
SDL = SDL_compat;
69+
})).overrideAttrs
70+
(old: {
71+
propagatedBuildInputs = [ SDL_compat ];
72+
src = pkgs.fetchurl {
73+
url = "https://github.com/libsdl-org/SDL_image/archive/refs/heads/SDL-1.2.tar.gz";
74+
hash = "sha256-0/s5eknEiqq/sOt3XTKWMdbEVQFOGmhVLQ9Vqthn5tU=";
75+
};
76+
patches = [ ];
77+
})
78+
)
79+
];
80+
};
81+
}
82+
);
83+
};
84+
}

0 commit comments

Comments
 (0)