Skip to content
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

Feature/mac os saves directory correct fix #36

Merged
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
43 changes: 39 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ cmake_minimum_required(VERSION 3.0)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

if(${CMAKE_HOST_SYSTEM_NAME} MATCHES "Darwin" AND APPLE)
message("Building for Mac OS...")
set(MAC_OS TRUE)
endif()

# Project
project(Stronghold)
set(Stronghold_VERSION, 0.1.2)
Expand Down Expand Up @@ -35,24 +40,47 @@ find_package(Threads REQUIRED)
# SDL2
find_package(SDL2 REQUIRED)

# OpenAL
# OpenAL
find_package(OpenAL REQUIRED)
add_library(OpenAL::OpenAL UNKNOWN IMPORTED)

# Mac OS frameworks should be handled in a special way.
# See more info about cmake issues with Mac OS frameworks here:
# https://cmake.org/pipermail/cmake/2016-April/063179.html
# and here
# https://gitlab.kitware.com/cmake/cmake/-/issues/19410
if(MAC_OS AND OPENAL_LIBRARY MATCHES "\\.framework$")
add_library(OpenAL::OpenAL INTERFACE IMPORTED)
set_target_properties(OpenAL::OpenAL PROPERTIES
INTERFACE_LINK_LIBRARIES "${OPENAL_LIBRARY}")
else()
add_library(OpenAL::OpenAL UNKNOWN IMPORTED)
set_target_properties(OpenAL::OpenAL PROPERTIES
IMPORTED_LOCATION ${OPENAL_LIBRARY})
endif()

set_target_properties(OpenAL::OpenAL PROPERTIES
IMPORTED_LOCATION ${OPENAL_LIBRARY}
INTERFACE_INCLUDE_DIRECTORIES ${OPENAL_INCLUDE_DIR})

# FFmpeg
find_package(FFmpeg REQUIRED COMPONENTS
AVCODEC AVFORMAT AVUTIL SWSCALE)


# swresample
find_package(Libswresample REQUIRED)
add_library(SWRESAMPLE::SWRESAMPLE UNKNOWN IMPORTED)
set_target_properties(SWRESAMPLE::SWRESAMPLE PROPERTIES
IMPORTED_LOCATION ${LIBSWRESAMPLE_LIBRARIES}
INTERFACE_INCLUDE_DIRECTORIES ${LIBSWRESAMPLE_INCLUDE_DIRS})

# MacOSUtils
if(MAC_OS)
add_library(MacOSUtils macos/src/PathUtils.m)
set_target_properties(MacOSUtils PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_SOURCE_DIR}/macos/src)
target_link_libraries(MacOSUtils
PRIVATE "-framework Foundation"
)
endif()

# Include sources / headers
file(
Expand Down Expand Up @@ -88,11 +116,18 @@ else()
-fno-fast-math)
endif()


set_target_properties(Stronghold PROPERTIES
CXX_STANDARD 11
CXX_STANDARD_REQUIRED YES
CXX_EXTENSIONS NO
)

if(MAC_OS)
target_link_libraries(Stronghold
PRIVATE MacOSUtils
)
endif()

target_link_libraries(Stronghold
PRIVATE Threads::Threads
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ data
├── jester.ani
└── sword.ani
```
Also you should create `saves` directory near your `data` folder.

## Configuration
This is either done by reading an existing Stronghold config file, found in your documents folder
Expand Down
54 changes: 44 additions & 10 deletions macos/Sourcehold.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@
6D6C457D25D03F94009A45DF /* World.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6D6C454D25D03F93009A45DF /* World.cpp */; };
6D6C457E25D03F94009A45DF /* Game.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6D6C454E25D03F93009A45DF /* Game.cpp */; };
6D6C459225D05B9B009A45DF /* OpenAL.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6D6C459125D05B9B009A45DF /* OpenAL.framework */; };
6D6C45AA25D07B28009A45DF /* blast.c in Sources */ = {isa = PBXBuildFile; fileRef = 6D6C45A925D07B28009A45DF /* blast.c */; };
6D6C45B025D09F57009A45DF /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6D6C45AF25D09F57009A45DF /* Foundation.framework */; };
6D6C496325D1C2B3009A45DF /* blast.c in Sources */ = {isa = PBXBuildFile; fileRef = 6D6C496225D1C2B3009A45DF /* blast.c */; };
6D6C496A25D1C3A6009A45DF /* PathUtils.m in Sources */ = {isa = PBXBuildFile; fileRef = 6D6C496925D1C3A6009A45DF /* PathUtils.m */; };
/* End PBXBuildFile section */

/* Begin PBXCopyFilesBuildPhase section */
Expand Down Expand Up @@ -178,14 +180,18 @@
6D6C454D25D03F93009A45DF /* World.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = World.cpp; sourceTree = "<group>"; };
6D6C454E25D03F93009A45DF /* Game.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Game.cpp; sourceTree = "<group>"; };
6D6C459125D05B9B009A45DF /* OpenAL.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OpenAL.framework; path = System/Library/Frameworks/OpenAL.framework; sourceTree = SDKROOT; };
6D6C45A925D07B28009A45DF /* blast.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = blast.c; path = ../../../thirdparty/blast/blast.c; sourceTree = "<group>"; };
6D6C45AF25D09F57009A45DF /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
6D6C496225D1C2B3009A45DF /* blast.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = blast.c; path = ../../thirdparty/blast/blast.c; sourceTree = "<group>"; };
6D6C496825D1C3A6009A45DF /* PathUtils.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PathUtils.h; sourceTree = "<group>"; };
6D6C496925D1C3A6009A45DF /* PathUtils.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = PathUtils.m; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
6D6C44D025D03EE8009A45DF /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
6D6C45B025D09F57009A45DF /* Foundation.framework in Frameworks */,
6D6C459225D05B9B009A45DF /* OpenAL.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand All @@ -196,8 +202,8 @@
6D6C44CA25D03EE7009A45DF = {
isa = PBXGroup;
children = (
6D6C44DF25D03F93009A45DF /* src */,
6D6C45A025D063DF009A45DF /* thirdparty */,
6D6C496525D1C2F5009A45DF /* Common */,
6D6C496625D1C319009A45DF /* MacOS */,
6D6C44D425D03EE9009A45DF /* Products */,
6D6C459025D05B9B009A45DF /* Frameworks */,
);
Expand Down Expand Up @@ -382,27 +388,54 @@
6D6C459025D05B9B009A45DF /* Frameworks */ = {
isa = PBXGroup;
children = (
6D6C45AF25D09F57009A45DF /* Foundation.framework */,
6D6C459125D05B9B009A45DF /* OpenAL.framework */,
);
name = Frameworks;
sourceTree = "<group>";
};
6D6C45A025D063DF009A45DF /* thirdparty */ = {
6D6C496025D1C297009A45DF /* thidparty */ = {
isa = PBXGroup;
children = (
6D6C45A425D06404009A45DF /* blast */,
6D6C496125D1C2A2009A45DF /* blast */,
);
path = thirdparty;
name = thidparty;
sourceTree = "<group>";
};
6D6C45A425D06404009A45DF /* blast */ = {
6D6C496125D1C2A2009A45DF /* blast */ = {
isa = PBXGroup;
children = (
6D6C45A925D07B28009A45DF /* blast.c */,
6D6C496225D1C2B3009A45DF /* blast.c */,
);
path = blast;
sourceTree = "<group>";
};
6D6C496525D1C2F5009A45DF /* Common */ = {
isa = PBXGroup;
children = (
6D6C44DF25D03F93009A45DF /* src */,
6D6C496025D1C297009A45DF /* thidparty */,
);
name = Common;
sourceTree = "<group>";
};
6D6C496625D1C319009A45DF /* MacOS */ = {
isa = PBXGroup;
children = (
6D6C496725D1C344009A45DF /* src */,
);
name = MacOS;
sourceTree = "<group>";
};
6D6C496725D1C344009A45DF /* src */ = {
isa = PBXGroup;
children = (
6D6C496825D1C3A6009A45DF /* PathUtils.h */,
6D6C496925D1C3A6009A45DF /* PathUtils.m */,
);
path = src;
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXNativeTarget section */
Expand Down Expand Up @@ -484,6 +517,7 @@
6D6C455325D03F94009A45DF /* Gm1File.cpp in Sources */,
6D6C455725D03F94009A45DF /* AniFile.cpp in Sources */,
6D6C457E25D03F94009A45DF /* Game.cpp in Sources */,
6D6C496A25D1C3A6009A45DF /* PathUtils.m in Sources */,
6D6C457125D03F94009A45DF /* Camera.cpp in Sources */,
6D6C457725D03F94009A45DF /* Renderer.cpp in Sources */,
6D6C456025D03F94009A45DF /* Audio.cpp in Sources */,
Expand Down Expand Up @@ -526,7 +560,7 @@
6D6C457425D03F94009A45DF /* Display.cpp in Sources */,
6D6C455825D03F94009A45DF /* Parser.cpp in Sources */,
6D6C455425D03F94009A45DF /* MlbFile.cpp in Sources */,
6D6C45AA25D07B28009A45DF /* blast.c in Sources */,
6D6C496325D1C2B3009A45DF /* blast.c in Sources */,
6D6C456125D03F94009A45DF /* Effect.cpp in Sources */,
6D6C457525D03F94009A45DF /* Surface.cpp in Sources */,
);
Expand Down
3 changes: 0 additions & 3 deletions macos/install-tools.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ which -s brew
if [[ $? != 0 ]] ; then
echo "Installing Homebrew..."
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
else
echo "Updating Homebrew..."
brew update
fi

echo "Installing cmake..."
Expand Down
1 change: 0 additions & 1 deletion macos/set-up-n-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@
./install-tools.sh
./install-dependencies.sh
./build.sh
./set-up.sh
10 changes: 0 additions & 10 deletions macos/set-up.sh

This file was deleted.

16 changes: 16 additions & 0 deletions macos/src/PathUtils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// PathUtils.h
// Sourcehold
//
// Created by apodrugin on 08.02.2021.
//

#ifdef __cplusplus
extern "C" {
#endif

bool GetUserDocumentsDirectoryPath(char *buffer, unsigned long bufferSize);

#ifdef __cplusplus
}
#endif
36 changes: 36 additions & 0 deletions macos/src/PathUtils.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//
// PathUtils.m
// Sourcehold
//
// Created by apodrugin on 08.02.2021.
//

#import <Foundation/Foundation.h>
#import "PathUtils.h"


bool GetUserDocumentsDirectoryPath(char *buffer, unsigned long bufferSize) {
if (NULL == buffer) {
return false;
}

@autoreleasepool {
NSArray<NSString *> *pathsList = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
NSUserDomainMask,
YES);

if (0 == pathsList.count) {
return false;
}

NSString *path = pathsList.firstObject;
const NSUInteger pathLength = [path lengthOfBytesUsingEncoding:NSUTF8StringEncoding] + 1 /*+1 for '\0'*/;

if (bufferSize < pathLength) {
return false;
}

strcpy(buffer, path.UTF8String);
return true;
}
}
17 changes: 17 additions & 0 deletions src/System/Config.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
#pragma once

#if defined(__APPLE__)
#include <TargetConditionals.h>
#endif

#define SOURCEHOLD_VERSION_MAJOR 0
#define SOURCEHOLD_VERSION_MINOR 1
#define SOURCEHOLD_VERSION_STRING "0.1.4"

#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) || defined(win32)

#if defined(__GNUC__) || defined(__MINGW32__)
#define SOURCEHOLD_BUILD "MinGW"
#define SOURCEHOLD_MINGW 1
Expand All @@ -14,7 +19,9 @@
#define SOURCEHOLD_WINDOWS 1
#define ATTRIB_PACKED
#endif

#elif defined(linux) || defined(__linux)

#define SOURCEHOLD_BUILD "Linux"
#define SOURCEHOLD_LINUX 1
#define SOURCEHOLD_UNIX 1
Expand All @@ -23,10 +30,20 @@
#define SOURCEHOLD_BUILD "Android"
#define SOURCEHOLD_ANDROID 1
#endif

#elif TARGET_OS_MAC

#define SOURCEHOLD_BUILD "Mac OS"
#define SOURCEHOLD_MAC_OS 1
#define SOURCEHOLD_UNIX 1
#define ATTRIB_PACKED __attribute__((packed))

#else /* assume unix */

#define SOURCEHOLD_BUILD "Generic unix"
#define SOURCEHOLD_UNIX 1
#define ATTRIB_PACKED __attribute__((packed))

#endif

/* Configuration of hardcoded stuff */
Expand Down
13 changes: 10 additions & 3 deletions src/System/FileUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@

#include "System/filesystem.h"

#if SOURCEHOLD_MAC_OS
#include "../macos/src/PathUtils.h"
#endif


using namespace Sourcehold;
using namespace System;

Expand Down Expand Up @@ -55,13 +60,16 @@ void System::CreateFolder(ghc::filesystem::path path)

ghc::filesystem::path System::GetDocumentsPath()
{
char path[512];
static const unsigned int maxPathLength = 512;
char path[maxPathLength];

/**
* TODO: better way to do this
* Why the f*** isn't this part of boost?
*/
#ifdef SOURCEHOLD_UNIX
#if SOURCEHOLD_MAC_OS
GetUserDocumentsDirectoryPath(path, maxPathLength);
#elif SOURCEHOLD_UNIX
/* Requires ~/.config/user-dirs.dirs from the FreeDesktop xdg standard */
const char *home = getenv("HOME");
strcpy(path, home);
Expand Down Expand Up @@ -95,7 +103,6 @@ ghc::filesystem::path System::GetDocumentsPath()
else {
*path = '\0';
}

#elif SOURCEHOLD_WINDOWS || SOURCEHOLD_MINGW
LPITEMIDLIST pidl;
SHGetSpecialFolderLocation(NULL, CSIDL_PERSONAL, &pidl);
Expand Down