Skip to content

Commit

Permalink
Add devshell for nix under macOs
Browse files Browse the repository at this point in the history
  • Loading branch information
vkravets committed Jan 6, 2025
1 parent b5b5efb commit 6e12068
Show file tree
Hide file tree
Showing 5 changed files with 167 additions and 4 deletions.
25 changes: 22 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ option ( ENABLE_CLANG_ANALYSIS "When building with clang, enable the static anal
option ( CHECK_CCACHE "Check if ccache is installed and use it" OFF )
set ( MSVC_WARNING_LEVEL 3 CACHE STRING "Visual Studio warning levels" )
option ( FORCE_INSTALL_DATA_TO_BIN "Force installation of data to binary directory" OFF )
if ( APPLE )
# Use by default since brew doesn't have legacy SDL1, sdl12-compat avalaible
option ( USE_SDL2 "Using SDL2 via SDL12 compatible layer" ON )
else ()
option ( USE_SDL2 "Using SDL2 via SDL12 compatible layer" OFF )
endif ()
set ( DATADIR "" CACHE STRING "Where to search for datafiles" )

if ( CHECK_CCACHE )
Expand Down Expand Up @@ -91,17 +97,30 @@ if(NOT UNIX AND IS_DIRECTORY ${DEPS_DIR})
else ( )
link_directories ( ${DEPS_DIR}/lib/Win32 )
endif()
set( SDL_LIBRARY SDL )
set ( SDL_LIBRARY SDL )
if ( USE_SDL2 )
# explicitly added SDL2 as dependency since needed for runtime work
set ( SDL2_LIBRARY SDL2 )
message ( STATUS "Using SDL2 via SDL12 compatible layer" )
else ( )
set ( SDL2_LIBRARY "")
endif ()
set ( SDLGFX_LIBRARY SDL_gfx )
set ( SDLMIXER_LIBRARY SDL_mixer )
set ( SDLIMAGE_LIBRARY SDL_image )
set ( PKG_DEPS_LDFLAGS ${SDLIMAGE_LIBRARY} ${SDLMIXER_LIBRARY} ${SDLGFX_LIBRARY} ${SDL_LIBRARY} ${OPENGL_LIBRARIES} )
set ( PKG_DEPS_LDFLAGS ${SDLIMAGE_LIBRARY} ${SDLMIXER_LIBRARY} ${SDLGFX_LIBRARY} ${SDL_LIBRARY} ${SDL2_LIBRARY} ${OPENGL_LIBRARIES} )
elseif(UNIX OR MINGW OR CYGWIN)
if(IS_DIRECTORY ${DEPS_DIR})
set(ENV{PKG_CONFIG_PATH} "${DEPS_DIR}/lib/pkgconfig/")
endif()

include(FindPkgConfig)
if ( USE_SDL2 )
# explicitly added SDL2 as dependency since needed for runtime work
pkg_check_modules(PKG_SDL2 REQUIRED sdl2)
else ( )
set ( PKG_SDLG2_LDFLAGS "" )
endif ()
pkg_check_modules(PKG_SDL REQUIRED sdl)
pkg_check_modules(PKG_ZLIB REQUIRED zlib)
pkg_check_modules(PKG_SDLIMAGE REQUIRED SDL_image)
Expand All @@ -110,7 +129,7 @@ elseif(UNIX OR MINGW OR CYGWIN)

include_directories(${PKG_SDL_INCLUDE_DIRS} ${PKG_ZLIB_INCLUDE_DIRS} ${PKG_SDLIMAGE_INCLUDE_DIRS})
include_directories(${PKG_SDLGFX_INCLUDE_DIRS} ${PKG_SDLMIXER_INCLUDE_DIRS})
set(PKG_DEPS_LDFLAGS ${PKG_SDL_LDFLAGS} ${PKG_ZLIB_LDFLAGS} ${PKG_SDLIMAGE_LDFLAGS} ${PKG_SDLGFX_LDFLAGS} ${PKG_SDLMIXER_LDFLAGS} ${OPENGL_LIBRARIES})
set(PKG_DEPS_LDFLAGS ${PKG_SDL_LDFLAGS} ${PKG_SDL2_LDFLAGS} ${PKG_ZLIB_LDFLAGS} ${PKG_SDLIMAGE_LDFLAGS} ${PKG_SDLGFX_LDFLAGS} ${PKG_SDLMIXER_LDFLAGS} ${OPENGL_LIBRARIES})

if (UNIX)
set(PKG_DEPS_LDFLAGS "${PKG_DEPS_LDFLAGS};dl")
Expand Down
15 changes: 14 additions & 1 deletion README-OSX.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Building for MacOS

## Dependencies
## Using brew

### Dependencies
To successfully build an OpenXcom OSX bundle you will need to ensure all the relevant dependencies installed in /usr/local/.

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


## Using Nix

All needed stuff related to installing and configure shell already described at flake.nix, just execute

```
$ nix develop -c $SHELL
```

Note: After it all below building command are applicable

## Building
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.

Expand Down
43 changes: 43 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

84 changes: 84 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
{
inputs = {
systems.url = "github:nix-systems/default";
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
};

outputs =
{
self,
nixpkgs,
systems,
}:
let
forEachSystem =
f: nixpkgs.lib.genAttrs (import systems) (system: f { pkgs = import nixpkgs { inherit system; }; });
in
{
devShells = forEachSystem (
{ pkgs }:
{
default =
pkgs.mkShell.override
{
# override clang 16 runtime
stdenv = pkgs.lowPrio pkgs.llvmPackages_16.stdenv;
}
{
propagatedBuildInputs = [
pkgs.SDL_compat
pkgs.SDL_image
pkgs.libwebp
];
# when using SDL_compat instead of SDL_classic, SDL_mixer isn't correctly
# detected, but there is no harm just specifying it
buildInputs = with pkgs; [
git
pkg-config
apple-sdk_15

# Need to use brew cmake since nix use old one 3.30.5
# which has issues with copy libraries to macOs app
#cmake
# use clang explicitly since don't use cmake
clang_16
# OpenXcom dependecies
rapidyaml
zlib
#SDL_mixer
# SDL_image
# SDL_gfx
# Try to build using SDL12_compat
(SDL_compat.overrideAttrs (old: {
postInstall = ''
ln -s $out/lib/pkgconfig/sdl12_compat.pc $out/lib/pkgconfig/sdl.pc
'';
}))
(SDL_mixer.override (old: {
SDL = SDL_compat;
smpeg = old.smpeg.override {
SDL = SDL_compat;
};
}))
(SDL_gfx.override (old: {
SDL = SDL_compat;
}))
(
(SDL_image.override (old: {
SDL = SDL_compat;
})).overrideAttrs
(old: {
propagatedBuildInputs = [ SDL_compat ];
src = pkgs.fetchurl {
url = "https://github.com/libsdl-org/SDL_image/archive/refs/heads/SDL-1.2.tar.gz";
hash = "sha256-0/s5eknEiqq/sOt3XTKWMdbEVQFOGmhVLQ9Vqthn5tU=";
};
patches = [ ];
})
)
];
};
}
);
};
}
4 changes: 4 additions & 0 deletions src/Engine/Options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,11 @@ void createOptionsOXC()
_info.push_back(OptionInfo(OPTION_OXC, "useScaleFilter", &useScaleFilter, false));
_info.push_back(OptionInfo(OPTION_OXC, "useHQXFilter", &useHQXFilter, false));
_info.push_back(OptionInfo(OPTION_OXC, "useXBRZFilter", &useXBRZFilter, false));
#ifdef __APPLE__
_info.push_back(OptionInfo(OPTION_OXC, "useOpenGL", &useOpenGL, true));
#else
_info.push_back(OptionInfo(OPTION_OXC, "useOpenGL", &useOpenGL, false));
#endif
_info.push_back(OptionInfo(OPTION_OXC, "checkOpenGLErrors", &checkOpenGLErrors, false));
_info.push_back(OptionInfo(OPTION_OXC, "useOpenGLShader", &useOpenGLShader, "Shaders/Raw.OpenGL.shader"));
_info.push_back(OptionInfo(OPTION_OXC, "useOpenGLSmoothing", &useOpenGLSmoothing, true));
Expand Down

0 comments on commit 6e12068

Please sign in to comment.