Skip to content

Commit

Permalink
Help macOS builds to get further before failing.
Browse files Browse the repository at this point in the history
  • Loading branch information
henricj committed Dec 22, 2023
1 parent 247d49b commit abaf333
Show file tree
Hide file tree
Showing 8 changed files with 125 additions and 24 deletions.
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ project(dunelegacy
VERSION 0.96.4
LANGUAGES CXX C
)
if(APPLE)
enable_language(OBJC)
endif()

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
Expand Down Expand Up @@ -53,6 +56,10 @@ if(MSVC)
include(setup/msvc-setup)
endif()

if(APPLE)
include(setup/macos-setup)
endif()

if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
include(setup/clang-gcc-setup)
endif()
Expand Down
59 changes: 37 additions & 22 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,14 @@
"hidden": true,
"inherits": "default",
"displayName": "Linux default",
"description": "Default Linux build"
"description": "Default Linux build",
"vendor": {
"microsoft.com/VisualStudioSettings/CMake/1.0": {
"hostOS": [
"Linux"
]
}
}
},
{
"name": "linux-debug",
Expand Down Expand Up @@ -352,17 +359,40 @@
}
},
{
"name": "macos-x64-release",
"inherits": "linux-base",
"displayName": "macOS x64 Release",
"name": "macos-base",
"hidden": true,
"inherits": "default",
"displayName": "macOS default",
"description": "Default macOS build",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release",
"VCPKG_TARGET_TRIPLET": "x64-osx-release"
"VCPKG_MANIFEST_DIR": "${sourceDir}/external/vcpkg/config-macos"
},
"vendor": {
"microsoft.com/VisualStudioSettings/CMake/1.0": {
"hostOS": [
"macOS"
]
}
}
},
{
"name": "macos-xcode",
"inherits": "macos-base",
"displayName": "macOS Xcode",
"generator": "Xcode"
},
{
"name": "macos-arm64-debug",
"inherits": "macos-base",
"displayName": "macOS arm64 Debug",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug",
"VCPKG_TARGET_TRIPLET": "arm64-osx"
}
},
{
"name": "macos-arm64-release",
"inherits": "linux-base",
"inherits": "macos-base",
"displayName": "macOS arm64 Release",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release",
Expand All @@ -379,10 +409,6 @@
"name": "linux-release",
"configurePreset": "linux-release"
},
{
"name": "macos-x64-release",
"configurePreset": "macos-x64-release"
},
{
"name": "macos-arm64-release",
"configurePreset": "macos-arm64-release"
Expand Down Expand Up @@ -411,17 +437,6 @@
"stopOnFailure": true
}
},
{
"name": "macos-x64-release",
"configurePreset": "macos-x64-release",
"output": {
"outputOnFailure": true
},
"execution": {
"noTestsAction": "error",
"stopOnFailure": true
}
},
{
"name": "macos-arm64-release",
"configurePreset": "macos-arm64-release",
Expand Down
16 changes: 16 additions & 0 deletions MacOSX/MacFunctions.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#ifndef MACFUNCTIONS_H
#define MACFUNCTIONS_H

#if __cplusplus
extern "C" {
#endif

const char* getMacLanguage();

void getMacApplicationSupportFolder(char* buffer, int len);

#if __cplusplus
}
#endif

#endif //MACFUNCTIONS_H
34 changes: 34 additions & 0 deletions MacOSX/MacFunctions.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@

#import <Cocoa/Cocoa.h>
#import "MacFunctions.h"

static char macLanguage[3] = " ";

const char* getMacLanguage() {
NSUserDefaults * userDefaults = [NSUserDefaults standardUserDefaults];
NSArray * languageArray = [userDefaults objectForKey:@"AppleLanguages"];
NSString * firstLanguage = [languageArray objectAtIndex:0];

macLanguage[0] = [firstLanguage characterAtIndex:0];
macLanguage[1] = [firstLanguage characterAtIndex:1];

return macLanguage;
}

void getMacApplicationSupportFolder(char* buffer, int len) {
FSRef appSupportFolder;
OSErr error = noErr;
NSString* appSupportFolderString;

error = FSFindFolder(kUserDomain, kApplicationSupportFolderType, true, &appSupportFolder);

if(error == noErr) {
CFURLRef url = CFURLCreateFromFSRef(kCFAllocatorDefault, &appSupportFolder);
appSupportFolderString = [(NSURL*) url path];
} else {
appSupportFolderString = [@"~/Library/Application Support" stringByExpandingTildeInPath];
}

[appSupportFolderString getCString:buffer maxLength:len-1 encoding:NSUTF8StringEncoding];
}

3 changes: 3 additions & 0 deletions cmake/setup/macos-setup.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
message(STATUS "Configuring macOS")
include_directories(AFTER "${CMAKE_CURRENT_LIST_DIR}../../../MacOSX")

8 changes: 8 additions & 0 deletions external/vcpkg/config-macos/vcpkg-configuration.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"overlay-ports": [
"../config/ports/sdl2"
],
"overlay-triplets": [
"../config/triplets"
]
}
13 changes: 13 additions & 0 deletions external/vcpkg/config-macos/vcpkg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"dependencies": [
"fmt",
"gtest",
"lodepng",
"ms-gsl",
"sdl2",
"sdl2-mixer",
"sdl2-ttf",
"soxr",
"openssl"
]
}
9 changes: 7 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ find_package(fmt CONFIG REQUIRED)
find_package(lodepng CONFIG REQUIRED)
find_package(Microsoft.GSL CONFIG REQUIRED)

if(UNIX)
if(UNIX AND NOT APPLE)
find_package(X11 REQUIRED)
endif()

Expand Down Expand Up @@ -73,7 +73,7 @@ if(WIN32)
list(APPEND EXE_SOURCES ../Windows/DuneLegacy.exe.manifest ../resource.rc)
endif()

if(UNIX)
if(UNIX AND NOT APPLE)
list(APPEND LIBS ${X11_LIBRARIES})
endif()

Expand Down Expand Up @@ -142,6 +142,11 @@ add_executable(dunelegacy ${EXE_SOURCES} ${EXE_HEADERS})
target_compile_options(dunelegacy PRIVATE ${dune_flags})
target_link_libraries(dunelegacy PRIVATE dune SDL2::SDL2main harden_interface)

if(APPLE)
target_sources(dunelegacy PRIVATE ../MacOSX/MacFunctions.m)
set_source_files_properties(../MacOSX/MacFunctions.m PROPERTIES SKIP_PRECOMPILE_HEADERS ON)
endif()

if(TARGET dune_gitversion)
target_link_libraries(dunelegacy PRIVATE "$<BUILD_INTERFACE:dune_gitversion>")
endif()
Expand Down

0 comments on commit abaf333

Please sign in to comment.