Skip to content

Commit 19d8b74

Browse files
committed
macos tentative
1 parent 3ee2ff2 commit 19d8b74

9 files changed

Lines changed: 213 additions & 37 deletions

File tree

.github/workflows/macos.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: macOS SDL3 Build
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
- develop
8+
pull_request:
9+
branches:
10+
- master
11+
12+
jobs:
13+
build:
14+
runs-on: macos-latest
15+
16+
steps:
17+
- name: Checkout source
18+
uses: actions/checkout@v3
19+
20+
- name: Install dependencies
21+
run: |
22+
brew install cmake python libxmp zlib libogg libvorbis
23+
24+
- name: Verify Python
25+
run: |
26+
python3 --version
27+
#pip3 install --upgrade pip
28+
#pip3 install numpy pillow # example Python packages
29+
30+
- name: Configure and build
31+
run: |
32+
python3 packages/bin/macos-genc.py CMakeLists.txt
33+
ls -l
34+
pwd
35+
cmake -S . -B build -DCMAKE_OSX_ARCHITECTURES="arm64;x86_64"
36+
cmake --build build --config Release
37+
38+
- name: Upload binary
39+
uses: actions/upload-artifact@v4
40+
with:
41+
name: MyGame-macOS
42+
path: build/MyGame

bin/gen.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ def main():
220220
prefix = params.prefix if params.has_prefix() else "local/mingw"
221221
vars = [
222222
f"WINDRES={arch}-mingw32-windres",
223-
f"CXX={arch}-mingw32-g++",
223+
f"CXX={arch}-mingw32-g++", # -fno-exceptions -fno-rtti
224224
f"INC=-I{prefix}/include",
225225
f"LDFLAGS=-L{prefix}/lib -Wl,-t -mwindows {strip}",
226226
# "LIBS=-static-libstdc++ -static-libgcc -Wl,-Bstatic "

packages/bin/macos-genc.py

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
import sys
2+
import glob
3+
4+
APP_NAME = "MyGame"
5+
APP_ID = "com.cfrankb.creepspreadiii"
6+
APP_VERSION = "1.0"
7+
APP_LONGVERSION = "1.0.0"
8+
APP_LONGNAME = "Creepspread III"
9+
BUNDLE_NAME = APP_LONGNAME.replace(" ", "")
10+
11+
paths = ["src/*.cpp", "src/**/*.cpp", "src/**/**/*.cpp"]
12+
13+
src = []
14+
for pattern in paths:
15+
for f in glob.glob(pattern):
16+
src.append(f)
17+
18+
19+
CMAKEFILE_TEMPLATE = f"""
20+
cmake_minimum_required(VERSION 3.16)
21+
project({APP_NAME})
22+
23+
set(CMAKE_CXX_STANDARD 17)
24+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
25+
26+
# Enable macOS bundle
27+
set(MACOSX_BUNDLE_BUNDLE_NAME "{BUNDLE_NAME}")
28+
set(MACOSX_BUNDLE_GUI_IDENTIFIER "{APP_ID}")
29+
set(MACOSX_BUNDLE_SHORT_VERSION_STRING "{APP_VERSION}")
30+
set(MACOSX_BUNDLE_LONG_VERSION_STRING "{APP_LONGVERSION}")
31+
set(MACOSX_BUNDLE TRUE)
32+
33+
#add_subdirectory(SDL)
34+
#add_subdirectory(SDL_mixer)
35+
36+
#find_package(SDL3 REQUIRED)
37+
#find_package(SDL3_mixer REQUIRED)
38+
add_subdirectory(external/SDL3)
39+
add_subdirectory(external/SDL3_mixer)
40+
41+
find_library(XMP_LIBRARY xmp)
42+
find_library(ZLIB_LIBRARY z)
43+
find_library(OGG_LIBRARY ogg)
44+
find_library(VORBIS_LIBRARY vorbisfile)
45+
46+
add_executable({APP_NAME} MACOSX_BUNDLE
47+
{'\n\t'.join(src) + '\n'})
48+
49+
#target_link_libraries(MyGame PRIVATE SDL3::SDL3 SDL3_mixer::SDL3_mixer)
50+
51+
target_link_libraries({APP_NAME}
52+
PRIVATE SDL3::SDL3 SDL3_mixer::SDL3_mixer
53+
#SDL3::SDL3
54+
#SDL3_mixer::SDL3_mixer
55+
PUBLIC ${{XMP_LIBRARY}}
56+
${{ZLIB_LIBRARY}}
57+
${{OGG_LIBRARY}}
58+
${{VORBIS_LIBRARY}}
59+
)
60+
61+
# Copy entire assets directory into Resources
62+
set(ASSETS_DIR "${{CMAKE_SOURCE_DIR}}/data") # modified
63+
file(GLOB_RECURSE ASSET_FILES RELATIVE ${{ASSETS_DIR}} "${{ASSETS_DIR}}/*")
64+
65+
foreach(asset IN LISTS ASSET_FILES)
66+
set(source "${{ASSETS_DIR}}/${{asset}}")
67+
set(destination "Resources/${{asset}}")
68+
set_source_files_properties(${{source}} PROPERTIES MACOSX_PACKAGE_LOCATION ${{destination}})
69+
list(APPEND RESOURCE_FILES ${{source}})
70+
endforeach()
71+
72+
# Add assets to the bundle
73+
target_sources({APP_NAME} PRIVATE ${{RESOURCE_FILES}})
74+
75+
"""
76+
77+
PLIST_TEMPLATE = f"""<?xml version="1.0" encoding="UTF-8"?>
78+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
79+
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
80+
<plist version="1.0">
81+
<dict>
82+
<key>CFBundleExecutable</key>
83+
<string>{APP_NAME}</string>
84+
<key>CFBundleIdentifier</key>
85+
<string>{APP_ID}</string>
86+
<key>CFBundleName</key>
87+
<string>{APP_LONGNAME}</string>
88+
<key>CFBundleVersion</key>
89+
<string>{APP_VERSION}</string>
90+
<key>CFBundlePackageType</key>
91+
<string>APPL</string>
92+
</dict>
93+
</plist>"""
94+
95+
96+
argv = sys.argv
97+
filename = argv[1] if len(argv) > 1 else "CMakeLists.txt"
98+
99+
with open(filename, "w") as tfile:
100+
tfile.write(CMAKEFILE_TEMPLATE.strip() + "\n")
101+
102+
with open("packages/data/macos/Info.plist", "w") as tfile:
103+
tfile.write(PLIST_TEMPLATE.strip() + "\n")
104+
105+
"""
106+
MyGame.app/
107+
├── Contents/
108+
│ ├── MacOS/
109+
│ │ └── MyGame ← your compiled binary
110+
│ ├── Resources/
111+
│ │ ├── assets/ ← images, sounds, etc.
112+
│ │ └── config/ ← game settings, levels
113+
│ └── Info.plist ← metadata
114+
"""
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
cmake_minimum_required(VERSION 3.16)
2+
project(MyGame)
3+
4+
set(CMAKE_CXX_STANDARD 17)
5+
6+
find_package(SDL3 REQUIRED)
7+
find_package(SDL3_mixer REQUIRED)
8+
9+
find_library(XMP_LIBRARY xmp)
10+
find_library(ZLIB_LIBRARY z)
11+
find_library(OGG_LIBRARY ogg)
12+
find_library(VORBIS_LIBRARY vorbisfile)
13+
14+
add_executable(MyGame src/main.cpp)
15+
16+
target_link_libraries(MyGame
17+
SDL3::SDL3
18+
SDL3_mixer::SDL3_mixer
19+
${XMP_LIBRARY}
20+
${ZLIB_LIBRARY}
21+
${OGG_LIBRARY}
22+
${VORBIS_LIBRARY}
23+
)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
3+
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
4+
<plist version="1.0">
5+
<dict>
6+
<key>CFBundleExecutable</key>
7+
<string>MyGame</string>
8+
<key>CFBundleIdentifier</key>
9+
<string>com.frank.arcadegame</string>
10+
<key>CFBundleName</key>
11+
<string>Diamond Hunter</string>
12+
<key>CFBundleVersion</key>
13+
<string>1.0</string>
14+
<key>CFBundlePackageType</key>
15+
<string>APPL</string>
16+
</dict>
17+
</plist>

src/parseargs.cpp

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
*/
1818
#include <cstdio>
1919
#include <cstring>
20-
#include <filesystem>
2120
#include "parseargs.h"
2221
#include "skills.h"
2322
#include "runtime.h"
@@ -54,24 +53,6 @@ void initArgs(params_t &params)
5453
params.height = CRuntime::DEFAULT_HEIGHT;
5554
}
5655

57-
void verbose(const char *path)
58-
{
59-
printf("app:%s\n", path);
60-
try
61-
{
62-
// Get the current working directory
63-
std::filesystem::path currentPath = std::filesystem::current_path();
64-
65-
// Print the path to the console
66-
printf("Current folder (std::filesystem): %s\n", currentPath.c_str());
67-
}
68-
catch (const std::filesystem::filesystem_error &e)
69-
{
70-
// Handle potential errors (e.g., permissions issues)
71-
fprintf(stderr, "Filesystem error: %s\n", e.what());
72-
}
73-
}
74-
7556
bool parseArgs(const std::vector<std::string> &list, params_t &params, bool &appExit)
7657
{
7758
typedef struct

src/shared/helper.cpp

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
#include <ctype.h>
2020
#include <cstdio>
2121
#include <zlib.h>
22-
#include <filesystem>
2322
#include "helper.h"
2423
#ifdef USE_QFILE
2524
#define FILEWRAP QFileWrap
@@ -29,8 +28,6 @@
2928
#include "../shared/FileWrap.h"
3029
#endif
3130

32-
namespace fs = std::filesystem;
33-
3431
const char *toUpper(char *s)
3532
{
3633
for (unsigned int i = 0; i < strlen(s); ++i)
@@ -153,15 +150,3 @@ int compressData(unsigned char *in_data, unsigned long in_size, unsigned char **
153150
in_size,
154151
Z_DEFAULT_COMPRESSION);
155152
}
156-
157-
uint64_t getFileSize(const std::string &filename)
158-
{
159-
try
160-
{
161-
return fs::file_size(filename);
162-
}
163-
catch (const fs::filesystem_error &e)
164-
{
165-
throw std::runtime_error("Error accessing file: " + std::string(e.what()));
166-
}
167-
}

src/shared/helper.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,4 @@ int upperClean(int c);
3030
#include <stdlib.h>
3131
// #include <linux/limits.h>
3232
#endif
33-
int compressData(unsigned char *in_data, unsigned long in_size, unsigned char **out_data, unsigned long &out_size);
34-
uint64_t getFileSize(const std::string &filename);
33+
int compressData(unsigned char *in_data, unsigned long in_size, unsigned char **out_data, unsigned long &out_size);

tests/t_maparch.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
You should have received a copy of the GNU General Public License
1616
along with this program. If not, see <http://www.gnu.org/licenses/>.
1717
*/
18+
#include <filesystem>
1819
#include "t_maparch.h"
1920
#include "../src/maparch.h"
2021
#include "../src/map.h"
@@ -30,6 +31,20 @@
3031
#define OUT_FILE1 "tests/out/levels1.mapz"
3132
#define OUT_FILE2 "tests/out/levels2.mapz"
3233

34+
namespace fs = std::filesystem;
35+
36+
uint64_t getFileSize(const std::string &filename)
37+
{
38+
try
39+
{
40+
return fs::file_size(filename);
41+
}
42+
catch (const fs::filesystem_error &e)
43+
{
44+
throw std::runtime_error("Error accessing file: " + std::string(e.what()));
45+
}
46+
}
47+
3348
void injectStates(CMapArch &arch)
3449
{
3550
CMap *map = arch.at(0);

0 commit comments

Comments
 (0)