Skip to content

Commit 4c0beac

Browse files
committed
Enhance macOS support by embedding resource files and updating CMake configuration
1 parent 08ed34e commit 4c0beac

File tree

7 files changed

+168
-88
lines changed

7 files changed

+168
-88
lines changed

.DS_Store

6 KB
Binary file not shown.

.vscode/tasks.json

Lines changed: 90 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,91 @@
11
{
2-
"version": "2.0.0",
3-
"tasks": [
4-
{
5-
"type": "shell",
6-
"label": "Install Dependencies",
7-
"command": [
8-
"sudo apt-get update -y",
9-
"&& sudo apt install -y build-essential libasound2-dev libx11-dev libxrandr-dev libxi-dev libgl1-mesa-dev libglu1-mesa-dev libxcursor-dev libxinerama-dev",
10-
"&& wget https://github.com/Kitware/CMake/releases/download/v3.29.0-rc2/cmake-3.29.0-rc2.tar.gz && tar -xvf cmake-3.29.0-rc2.tar.gz && cd cmake-3.29.0-rc2 && ./bootstrap && make -j4 && sudo make install"
11-
],
12-
"group": "build"
13-
},
14-
{
15-
"type": "shell",
16-
"label": "Configure",
17-
"command": [
18-
"cmake -S . -B out --preset=${input:arch}-${input:type}-${input:platform}"
19-
],
20-
"options": {
21-
"cwd": "${workspaceFolder}"
22-
},
23-
"problemMatcher": ["$msCompile"],
24-
"group": "build"
25-
},
26-
{
27-
"type": "shell",
28-
"label": "Build Debug",
29-
"command": ["cmake --build out --config debug --target wispy"],
30-
"options": {
31-
"cwd": "${workspaceFolder}"
32-
},
33-
"problemMatcher": ["$msCompile"],
34-
"group": "build"
35-
},
36-
{
37-
"type": "shell",
38-
"label": "Build Release",
39-
"command": ["cmake --build out --config release --target wispy"],
40-
"options": {
41-
"cwd": "${workspaceFolder}"
42-
},
43-
"problemMatcher": ["$msCompile"],
44-
"group": "build"
45-
}
46-
],
47-
"inputs": [
48-
{
49-
"id": "arch",
50-
"type": "pickString",
51-
"options": ["x64", "x86"],
52-
"default": "x64",
53-
"description": "Architecture"
54-
},
55-
{
56-
"id": "type",
57-
"type": "pickString",
58-
"options": ["debug", "release", "relminsize"],
59-
"default": "debug",
60-
"description": "Build type"
61-
},
62-
{
63-
"id": "platform",
64-
"type": "pickString",
65-
"options": ["windows", "linux", "macos"],
66-
"default": "windows",
67-
"description": "Platform"
68-
}
69-
]
70-
}
2+
"version": "2.0.0",
3+
"tasks": [
4+
{
5+
"type": "shell",
6+
"label": "Install Dependencies",
7+
"command": [
8+
"sudo apt-get update -y",
9+
"&& sudo apt install -y build-essential libasound2-dev libx11-dev libxrandr-dev libxi-dev libgl1-mesa-dev libglu1-mesa-dev libxcursor-dev libxinerama-dev",
10+
"&& wget https://github.com/Kitware/CMake/releases/download/v3.29.0-rc2/cmake-3.29.0-rc2.tar.gz && tar -xvf cmake-3.29.0-rc2.tar.gz && cd cmake-3.29.0-rc2 && ./bootstrap && make -j4 && sudo make install"
11+
],
12+
"group": "build"
13+
},
14+
{
15+
"type": "shell",
16+
"label": "Configure",
17+
"command": [
18+
"cmake -S . -B out --preset=${input:arch}-${input:type}-${input:platform}"
19+
],
20+
"options": {
21+
"cwd": "${workspaceFolder}"
22+
},
23+
"problemMatcher": [
24+
"$msCompile"
25+
],
26+
"group": "build"
27+
},
28+
{
29+
"type": "shell",
30+
"label": "Build Debug",
31+
"command": [
32+
"cmake --build out --config debug --target wispy"
33+
],
34+
"options": {
35+
"cwd": "${workspaceFolder}"
36+
},
37+
"problemMatcher": [
38+
"$msCompile"
39+
],
40+
"group": "build"
41+
},
42+
{
43+
"type": "shell",
44+
"label": "Build Release",
45+
"command": [
46+
"cmake --build out --config release --target wispy"
47+
],
48+
"options": {
49+
"cwd": "${workspaceFolder}"
50+
},
51+
"problemMatcher": [
52+
"$msCompile"
53+
],
54+
"group": "build"
55+
}
56+
],
57+
"inputs": [
58+
{
59+
"id": "arch",
60+
"type": "pickString",
61+
"options": [
62+
"x64",
63+
"x86"
64+
],
65+
"default": "x64",
66+
"description": "Architecture"
67+
},
68+
{
69+
"id": "type",
70+
"type": "pickString",
71+
"options": [
72+
"debug",
73+
"release",
74+
"relminsize"
75+
],
76+
"default": "debug",
77+
"description": "Build type"
78+
},
79+
{
80+
"id": "platform",
81+
"type": "pickString",
82+
"options": [
83+
"windows",
84+
"linux",
85+
"macos"
86+
],
87+
"default": "windows",
88+
"description": "Platform"
89+
}
90+
]
91+
}

CMakeLists.txt

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -108,21 +108,37 @@ elseif(UNIX)
108108
add_library(${PROJECT_NAME} SHARED ${SOURCES})
109109
target_link_libraries(${PROJECT_NAME} raylib zlibstatic json-c android log)
110110
elseif(APPLE)
111-
add_executable(${PROJECT_NAME} ${SOURCES})
111+
set(RESOURCE_C "${CMAKE_BINARY_DIR}/resource.c")
112+
add_custom_command(
113+
OUTPUT ${RESOURCE_C}
114+
COMMAND xxd -i ${RESOURCE_PACK_DIR}resource.pack > ${RESOURCE_C}
115+
DEPENDS ${RESOURCE_PACK_DIR}resource.pack
116+
COMMENT "Embedding resource.pack into C source (xxd)"
117+
)
118+
add_custom_target(generate_resource ALL DEPENDS ${RESOURCE_C})
119+
list(APPEND SOURCES ${RESOURCE_C})
112120

113-
target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_BINARY_DIR})
121+
add_executable(${PROJECT_NAME} MACOSX_BUNDLE ${SOURCES})
122+
add_dependencies(${PROJECT_NAME} generate_resource)
114123

115-
find_library(COCOA_LIBRARY Cocoa)
116-
find_library(IOKIT_LIBRARY IOKit)
117-
find_library(COREVIDEO_LIBRARY CoreVideo)
118-
find_library(OPENGL_LIBRARY OpenGL)
119-
find_library(COREAUDIO_LIBRARY CoreAudio)
120-
find_library(COREFOUNDATION_LIBRARY CoreFoundation)
121124

122125
target_link_libraries(${PROJECT_NAME} PRIVATE
123-
raylib zlibstatic json-c pthread
124-
${COCOA_LIBRARY} ${IOKIT_LIBRARY} ${COREVIDEO_LIBRARY} ${OPENGL_LIBRARY} ${COREAUDIO_LIBRARY} ${COREFOUNDATION_LIBRARY}
126+
raylib
127+
zlibstatic
128+
json-c
129+
"-framework Cocoa"
130+
"-framework IOKit"
131+
"-framework CoreVideo"
132+
"-framework CoreAudio"
133+
"-framework AudioToolbox"
134+
"-framework OpenGL"
125135
)
136+
set_target_properties(${PROJECT_NAME} PROPERTIES
137+
MACOSX_BUNDLE_BUNDLE_NAME ${PROJECT_NAME}
138+
MACOSX_BUNDLE_GUI_IDENTIFIER "com.julesgrc0.${PROJECT_NAME}"
139+
MACOSX_BUNDLE_INFO_PLIST "${CMAKE_SOURCE_DIR}/Info.plist"
140+
)
141+
126142
else()
127143
add_executable(${PROJECT_NAME} ${SOURCES})
128144
if(CMAKE_SIZEOF_VOID_P EQUAL 8)

Info.plist

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>CFBundleDevelopmentRegion</key>
6+
<string>en</string>
7+
<key>CFBundleExecutable</key>
8+
<string>${EXECUTABLE_NAME}</string>
9+
<key>CFBundleIdentifier</key>
10+
<string>com.julesgrc0.wispy</string>
11+
<key>CFBundleInfoDictionaryVersion</key>
12+
<string>6.0</string>
13+
<key>CFBundleName</key>
14+
<string>Wispy</string>
15+
<key>CFBundlePackageType</key>
16+
<string>APPL</string>
17+
<key>CFBundleShortVersionString</key>
18+
<string>1.0</string>
19+
<key>CFBundleVersion</key>
20+
<string>1</string>
21+
<key>LSRequiresIPhoneOS</key>
22+
<true/>
23+
<key>UILaunchStoryboardName</key>
24+
<string>LaunchScreen</string>
25+
<key>UIMainStoryboardFile</key>
26+
<string>Main</string>
27+
<key>UIRequiredDeviceCapabilities</key>
28+
<array>
29+
<string>armv7</string>
30+
</array>
31+
<key>UISupportedInterfaceOrientations</key>
32+
<array>
33+
<string>UIInterfaceOrientationPortrait</string>
34+
<string>UIInterfaceOrientationLandscapeLeft</string>
35+
<string>UIInterfaceOrientationLandscapeRight</string>
36+
</array>
37+
</dict>
38+
</plist>

src/unpack/unpack.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,21 @@ w_asset *unpack_assets(size_t *size)
3030
{
3131
*size = 0;
3232
size_t in_size = 0;
33-
33+
3434
#if defined(WISPY_WINDOWS)
3535
if (hInstance == NULL)
3636
return NULL;
3737
char *in_buffer = load_resource(hInstance, &in_size);
3838
#elif defined(WISPY_LINUX)
3939
char *in_buffer = &w_binary___tools_resource_pack_start;
40-
in_size = &w_binary___tools_resource_pack_end - &w_binary___tools_resource_pack_start;
40+
in_size = &w_binary___tools_resource_pack_end -
41+
&w_binary___tools_resource_pack_start;
4142
#elif defined(WISPY_MACOS)
42-
char* in_buffer = (char*)resource_pack;
43+
44+
char *in_buffer = (char *)resource_pack;
4345
in_size = resource_pack_len;
44-
#elif defined(WISPY_ANDROID)
45-
char *in_buffer = (char *)LoadFileData(RESOURCE_NAME, (int*)&in_size);
46+
#elif defined(WISPY_ANDROID)
47+
char *in_buffer = (char *)LoadFileData(RESOURCE_NAME, (int *)&in_size);
4648
#endif
4749

4850
if (in_buffer == NULL)
@@ -55,8 +57,8 @@ w_asset *unpack_assets(size_t *size)
5557

5658
size_t try_index = 0;
5759
for (; try_index < MAX_UNCOMPRESSE_TRY; try_index++) {
58-
if (uncompress((Bytef*)out_buffer, (uLongf *)&out_size, (const Bytef*)in_buffer,
59-
(uLong)in_size) != Z_OK) {
60+
if (uncompress((Bytef *)out_buffer, (uLongf *)&out_size,
61+
(const Bytef *)in_buffer, (uLong)in_size) != Z_OK) {
6062
out_size *= 2;
6163
void *new_outbuff = realloc(out_buffer, out_size);
6264
if (new_outbuff == NULL) {

src/unpack/unpack.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@
1010
extern char w_binary___tools_resource_pack_start;
1111
extern char w_binary___tools_resource_pack_end;
1212
#elif defined(WISPY_MACOS)
13-
#include "resource.pack.h"
13+
extern unsigned char _Users_julesgrc0_pc_Dev_wispy_tools_resource_pack[];
14+
extern unsigned int _Users_julesgrc0_pc_Dev_wispy_tools_resource_pack_len;
15+
#define resource_pack _Users_julesgrc0_pc_Dev_wispy_tools_resource_pack
16+
#define resource_pack_len _Users_julesgrc0_pc_Dev_wispy_tools_resource_pack_len
1417
#elif defined(WISPY_ANDROID)
1518
#define RESOURCE_NAME "resource.pack"
1619
#endif

tools/pack_assets.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def main(args: list[str]):
9696
f"(from {total_size} to {gz_size} bytes)")
9797
print(f"[PACK]: Generated file: {pack_path}")
9898

99-
create_header_file(pack_path)
99+
# create_header_file(pack_path)
100100
print("[PACK]: End")
101101

102102

0 commit comments

Comments
 (0)