Skip to content

Commit 06e356d

Browse files
committed
Add devshell for nix under macOs
1 parent b5b5efb commit 06e356d

File tree

5 files changed

+167
-4
lines changed

5 files changed

+167
-4
lines changed

.envrc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
if ! has nix_direnv_version || ! nix_direnv_version 3.0.6; then
2+
source_url "https://raw.githubusercontent.com/nix-community/nix-direnv/3.0.6/direnvrc" "sha256-RYcUJaRMf8oF5LznDrlCXbkOQrywm0HDv1VjYGaJGdM="
3+
fi
4+
5+
use flake . --impure

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: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
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+
34+
buildInputs = with pkgs; [
35+
git
36+
pkg-config
37+
apple-sdk_15
38+
39+
# Need to use brew cmake since nix use old one 3.30.5
40+
# which has issues with copy libraries to macOs app
41+
cmake
42+
# use clang explicitly since don't use cmake
43+
clang_16
44+
# OpenXcom dependecies
45+
rapidyaml
46+
zlib
47+
#SDL_mixer
48+
# SDL_image
49+
# SDL_gfx
50+
# Try to build using SDL12_compat
51+
(SDL_compat.overrideAttrs (old: {
52+
postInstall = ''
53+
ln -s $out/lib/pkgconfig/sdl12_compat.pc $out/lib/pkgconfig/sdl.pc
54+
'';
55+
}))
56+
(SDL_mixer.override (old: {
57+
SDL = SDL_compat;
58+
smpeg = old.smpeg.override {
59+
SDL = SDL_compat;
60+
};
61+
}))
62+
(SDL_gfx.override (old: {
63+
SDL = SDL_compat;
64+
}))
65+
(
66+
(SDL_image.override (old: {
67+
SDL = SDL_compat;
68+
})).overrideAttrs
69+
(old: {
70+
propagatedBuildInputs = [ SDL_compat ];
71+
src = pkgs.fetchurl {
72+
url = "https://github.com/libsdl-org/SDL_image/archive/refs/heads/SDL-1.2.tar.gz";
73+
hash = "sha256-ytt87YL2zrvLun7bi5Jd4m5N7/UR09Y3I1kRDAqf6nQ=";
74+
};
75+
patches = [ ];
76+
})
77+
)
78+
];
79+
};
80+
}
81+
);
82+
};
83+
}

0 commit comments

Comments
 (0)