Generate and build macOS app bundles through CMake.

This uses the OpenLoco logo by Zcooger as the app icon.

Co-authored-by: Marijn van der Werf <marijn.vanderwerf@gmail.com>
Co-authored-by: Tom Lankhorst <hello@tomlankhorst.nl>
This commit is contained in:
Aaron van Geffen 2019-02-25 19:29:06 +01:00
parent 33b87992cb
commit fd764a1b62
11 changed files with 213 additions and 6 deletions

2
.gitignore vendored
View File

@ -1,6 +1,8 @@
artefacts/
bin.*/
boost/
lib/
vcpkg/
## Visual Studio Code
.vscode/

View File

@ -53,7 +53,9 @@ matrix:
- brew install https://raw.githubusercontent.com/OpenLoco/Dependencies/master/macos/boost.rb
script:
- curl -L https://github.com/OpenLoco/Dependencies/releases/download/v1.1.0/openloco.dependencies.macos.1.1.0.zip -o dependencies.zip
- unzip dependencies.zip -d vcpkg/
- unzip -q dependencies.zip -d vcpkg/
- curl -L https://github.com/OpenLoco/Dependencies/releases/download/v1.1.1/macos-x86-static-boost-1.68.0.zip -o boost.zip
- unzip -q boost.zip -d boost/
- mkdir build && cd build
- cmake .. "-DCMAKE_TOOLCHAIN_FILE=../vcpkg/scripts/buildsystems/vcpkg.cmake" -DVCPKG_TARGET_TRIPLET=x86-osx
- make -j2
@ -68,7 +70,9 @@ matrix:
- brew install https://raw.githubusercontent.com/OpenLoco/Dependencies/master/macos/boost.rb
script:
- curl -L https://github.com/OpenLoco/Dependencies/releases/download/v1.1.0/openloco.dependencies.macos.1.1.0.zip -o dependencies.zip
- unzip dependencies.zip -d vcpkg/
- unzip -q dependencies.zip -d vcpkg/
- curl -L https://github.com/OpenLoco/Dependencies/releases/download/v1.1.1/macos-x86-static-boost-1.68.0.zip -o boost.zip
- unzip -q boost.zip -d boost/
- mkdir build && cd build
- cmake .. "-DCMAKE_TOOLCHAIN_FILE=../vcpkg/scripts/buildsystems/vcpkg.cmake" -DVCPKG_TARGET_TRIPLET=x86-osx
- make -j2

View File

@ -1,4 +1,5 @@
cmake_minimum_required(VERSION 3.8)
cmake_minimum_required(VERSION 3.9)
cmake_policy(VERSION 3.9)
set (PROJECT openloco)
@ -230,6 +231,54 @@ endif()
if (APPLE)
target_link_libraries(${PROJECT} "-framework Cocoa")
set_target_properties(${PROJECT} PROPERTIES
MACOSX_BUNDLE ON
MACOSX_BUNDLE_INFO_PLIST ${CMAKE_CURRENT_SOURCE_DIR}/distribution/macos/Info.plist.in)
set(MACOSX_BUNDLE_BUNDLE_NAME "OpenLoco")
set(MACOSX_BUNDLE_BUNDLE_VERSION "${OPENRCT2_COMMIT_SHA1_SHORT}")
set(MACOSX_BUNDLE_COPYRIGHT "OpenLoco is licensed under the MIT License")
set(MACOSX_BUNDLE_GUI_IDENTIFIER "io.openloco.OpenLoco")
set(MACOSX_BUNDLE_ICON_FILE "AppIcon")
if(${OPENLOCO_BRANCH} EQUAL master)
set(MACOSX_BUNDLE_SHORT_VERSION_STRING "${OPENLOCO_VERSION_TAG}")
else()
set(MACOSX_BUNDLE_SHORT_VERSION_STRING "${OPENLOCO_VERSION_TAG} ${OPENLOCO_BRANCH}")
endif()
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/distribution/macos/AppIcon.iconset DESTINATION ${CMAKE_BINARY_DIR})
set(ICON_TARGET "${CMAKE_BINARY_DIR}/AppIcon.iconset")
set(ICON_OUTPUT "${CMAKE_BINARY_DIR}/AppIcon.icns")
set(SOURCE_ICON_DIR "${CMAKE_CURRENT_SOURCE_DIR}/resources/logo")
add_custom_command(OUTPUT ${ICON_OUTPUT}
COMMAND cp icon_x16.png ${ICON_TARGET}/icon_16x16.png
COMMAND cp icon_x32.png ${ICON_TARGET}/icon_16x16@2x.png
COMMAND cp icon_x32.png ${ICON_TARGET}/icon_32x32.png
COMMAND cp icon_x64.png ${ICON_TARGET}/icon_32x32@2x.png
COMMAND cp icon_x128.png ${ICON_TARGET}/icon_128x128.png
COMMAND cp icon_x256.png ${ICON_TARGET}/icon_128x128@2x.png
COMMAND cp icon_x256.png ${ICON_TARGET}/icon_256x256.png
COMMAND cp icon_x512.png ${ICON_TARGET}/icon_256x256@2x.png
COMMAND cp icon_x512.png ${ICON_TARGET}/icon_512x512.png
COMMAND cp icon_x1024.png ${ICON_TARGET}/icon_512x512@2x.png
COMMAND iconutil -c icns ${ICON_TARGET}
WORKING_DIRECTORY ${SOURCE_ICON_DIR})
set(BUNDLE_RESOURCES ${ICON_OUTPUT})
list(APPEND BUNDLE_RESOURCES ${CMAKE_CURRENT_SOURCE_DIR}/CHANGELOG.md)
list(APPEND BUNDLE_RESOURCES ${CMAKE_CURRENT_SOURCE_DIR}/CONTRIBUTORS.MD)
set_target_properties(${PROJECT} PROPERTIES RESOURCE "${BUNDLE_RESOURCES}")
target_sources(${PROJECT} PUBLIC ${BUNDLE_RESOURCES})
file(GLOB BUNDLE_LANGUAGES "${CMAKE_CURRENT_SOURCE_DIR}/data/language/*")
target_sources(${PROJECT} PUBLIC ${BUNDLE_LANGUAGES})
set_property(
SOURCE ${BUNDLE_LANGUAGES}
PROPERTY MACOSX_PACKAGE_LOCATION "Resources/language"
)
try_compile(SUPPORT_STD_BYTE ${CMAKE_BINARY_DIR} ${CMAKE_SOURCE_DIR}/cmake/std_byte.cpp CXX_STANDARD 17)
if (NOT SUPPORT_STD_BYTE)
message(STATUS "std::byte is not supported.")

View File

@ -0,0 +1,68 @@
{
"images" : [
{
"size" : "16x16",
"idiom" : "mac",
"filename" : "icon_16x16.png",
"scale" : "1x"
},
{
"size" : "16x16",
"idiom" : "mac",
"filename" : "icon_16x16@2x.png",
"scale" : "2x"
},
{
"size" : "32x32",
"idiom" : "mac",
"filename" : "icon_32x32.png",
"scale" : "1x"
},
{
"size" : "32x32",
"idiom" : "mac",
"filename" : "icon_32x32@2x.png",
"scale" : "2x"
},
{
"size" : "128x128",
"idiom" : "mac",
"filename" : "icon_128x128.png",
"scale" : "1x"
},
{
"size" : "128x128",
"idiom" : "mac",
"filename" : "icon_128x128@2x.png",
"scale" : "2x"
},
{
"size" : "256x256",
"idiom" : "mac",
"filename" : "icon_256x256.png",
"scale" : "1x"
},
{
"size" : "256x256",
"idiom" : "mac",
"filename" : "icon_256x256@2x.png",
"scale" : "2x"
},
{
"size" : "512x512",
"idiom" : "mac",
"filename" : "icon_512x512.png",
"scale" : "1x"
},
{
"size" : "512x512",
"idiom" : "mac",
"filename" : "icon_512x512@2x.png",
"scale" : "2x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}

View File

@ -0,0 +1,55 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<!-- Executable file -->
<key>CFBundleExecutable</key>
<string>${MACOSX_BUNDLE_EXECUTABLE_NAME}</string>
<key>CFBundleGetInfoString</key>
<string>${MACOSX_BUNDLE_INFO_STRING}</string>
<!-- Icon file -->
<key>CFBundleIconFile</key>
<string>${MACOSX_BUNDLE_ICON_FILE}</string>
<!-- Bundle identifier -->
<key>CFBundleIdentifier</key>
<string>${MACOSX_BUNDLE_GUI_IDENTIFIER}</string>
<!-- InfoDictionary version -->
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<!-- Bundle name -->
<key>CFBundleName</key>
<string>${MACOSX_BUNDLE_BUNDLE_NAME}</string>
<!-- Bundle OS Type code -->
<key>CFBundlePackageType</key>
<string>APPL</string>
<!-- Bundle versions string, short -->
<key>CFBundleShortVersionString</key>
<string>${MACOSX_BUNDLE_SHORT_VERSION_STRING}</string>
<key>CFBundleSignature</key>
<string>????</string>
<!-- Bundle version -->
<key>CFBundleVersion</key>
<string>${MACOSX_BUNDLE_BUNDLE_VERSION}</string>
<!-- Resources should be file-mapped -->
<key>CSResourcesFileMapped</key>
<true/>
<!--High Resolution Capable-->
<key>NSHighResolutionCapable</key>
<true/>
<!--Copyright (human-readable)-->
<key>NSHumanReadableCopyright</key>
<string>${MACOSX_BUNDLE_COPYRIGHT}</string>
</dict>
</plist>

View File

@ -207,6 +207,12 @@ namespace openloco::environment
case path_id::scores:
case path_id::openloco_yml:
return platform::get_user_directory();
case path_id::language_files:
#if defined(__APPLE__) && defined(__MACH__)
return platform::GetBundlePath();
#else
return platform::GetCurrentExecutablePath().parent_path() / "data";
#endif
default:
return get_loco_install_path();
}
@ -263,7 +269,8 @@ namespace openloco::environment
"Data/TUT800_1.DAT",
"Data/TUT800_2.DAT",
"Data/TUT800_3.DAT",
"openloco.yml"
"openloco.yml",
"language",
};
size_t index = (size_t)id;

View File

@ -65,6 +65,7 @@ namespace openloco::environment
tut800_2,
tut800_3,
openloco_yml,
language_files,
};
fs::path get_path(path_id id);

View File

@ -260,7 +260,7 @@ namespace openloco::localisation
void loadLanguageFile()
{
// First, load en-GB for fallback strings.
fs::path languageDir = platform::GetCurrentExecutablePath().parent_path() / "data" / "language";
fs::path languageDir = environment::get_path(environment::path_id::language_files);
fs::path languageFile = languageDir / "en-GB.yml";
if (!loadLanguageStringTable(languageFile))
throw std::runtime_error("Could not load the en-GB language file!");

View File

@ -1,4 +1,5 @@
#include "languages.h"
#include "../environment.h"
#include "../platform/platform.h"
#include "../utility/yaml.hpp"
#include "conversion.h"
@ -26,7 +27,7 @@ namespace openloco::localisation
language_descriptors.emplace_back(undefinedLanguage);
// Search the languages dir for YAML language files.
fs::path languageDir = platform::GetCurrentExecutablePath().parent_path() / "data" / "language";
fs::path languageDir = environment::get_path(environment::path_id::language_files);
for (auto& entry : fs::directory_iterator(languageDir))
{
auto filename = entry.path().string();

View File

@ -16,4 +16,7 @@ namespace openloco::platform
std::string prompt_directory(const std::string& title);
fs::path GetCurrentExecutablePath();
std::vector<fs::path> get_drives();
#if defined(__APPLE__) && defined(__MACH__)
fs::path GetBundlePath();
#endif
}

View File

@ -53,4 +53,21 @@ fs::path openloco::platform::GetCurrentExecutablePath()
}
}
fs::path openloco::platform::GetBundlePath()
{
@autoreleasepool
{
NSBundle * bundle = [NSBundle mainBundle];
if (bundle)
{
auto resources = bundle.resourcePath.UTF8String;
if (fs::exists(resources))
{
return resources;
}
}
return fs::path();
}
}
#endif