Skip to content

Commit ab4acd1

Browse files
Copilotaloneguid
andauthored
feat: add macOS (arm64) support using GLFW + OpenGL3 backend
- vcpkg.json: add imgui (opengl3-binding, glfw-binding) and glfw3 for osx platform - grey/CMakeLists.txt: find OpenGL and GLFW3 on macOS (change UNIX AND NOT APPLE to UNIX) - demo/desktop/CMakeLists.txt: make WIN32 flag, main.rc and dpi-aware.manifest Windows-only - demo/pure/CMakeLists.txt: enable pure GLFW demo to build on macOS - CMakePresets.json: add macos-debug preset - .github/workflows/build.yml: add macOS arm64 to build-native and build-demo-apps matrices with screencapture screenshot support - dotnet/Grey/Grey.csproj: include libxgrey.dylib for osx-arm64 in NuGet package - docs/README.md: update platform support and add macOS build instructions Agent-Logs-Url: https://github.com/aloneguid/grey/sessions/adfb7d00-a048-46cf-a0f3-0acead8788b0 Co-authored-by: aloneguid <3155189+aloneguid@users.noreply.github.com>
1 parent d82aa29 commit ab4acd1

8 files changed

Lines changed: 102 additions & 9 deletions

File tree

.github/workflows/build.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ jobs:
3838
vcpkg_triplet: x64-linux
3939
vcpkg_config: MinSizeRel
4040
dotnet_rid: linux-x64
41+
- os: macos-latest
42+
name: macOS arm64
43+
arch: arm64
44+
vcpkg_triplet: arm64-osx
45+
vcpkg_config: MinSizeRel
46+
dotnet_rid: osx-arm64
4147

4248
fail-fast: false
4349
name: 'build: ${{ matrix.name }}'
@@ -179,6 +185,12 @@ jobs:
179185
vcpkg_triplet: x64-linux
180186
vcpkg_config: MinSizeRel
181187
dotnet_rid: linux-x64
188+
- os: macos-latest
189+
name: macOS arm64
190+
arch: arm64
191+
vcpkg_triplet: arm64-osx
192+
vcpkg_config: MinSizeRel
193+
dotnet_rid: osx-arm64
182194

183195
fail-fast: false
184196
name: 'demo app: ${{ matrix.name }}'
@@ -249,6 +261,27 @@ jobs:
249261
# Kill the app
250262
kill $APP_PID || true
251263
264+
- name: Run app and capture screenshot (macOS)
265+
if: runner.os == 'macOS'
266+
run: |
267+
# Run the app in background
268+
chmod +x dotnet/ConsoleDemo/bin/Release/net10.0/${{ matrix.dotnet_rid }}/publish/ConsoleDemo
269+
dotnet/ConsoleDemo/bin/Release/net10.0/${{ matrix.dotnet_rid }}/publish/ConsoleDemo 2>&1 | tee app.log &
270+
APP_PID=$!
271+
272+
# Wait for app to render
273+
sleep 5
274+
275+
# Capture screenshot using macOS built-in screencapture
276+
mkdir -p screenshots
277+
screencapture -x screenshots/demo-${{ matrix.dotnet_rid }}.png
278+
279+
# Show app logs
280+
cat app.log || true
281+
282+
# Kill the app
283+
kill $APP_PID || true
284+
252285
- name: Run app and capture screenshot (Windows)
253286
if: runner.os == 'Windows'
254287
shell: pwsh

CMakePresets.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,25 @@
6666
"sourceDir": "$env{HOME}/.vs/$ms{projectDirName}"
6767
}
6868
}
69+
},
70+
{
71+
"name": "macos-debug",
72+
"displayName": "macOS Debug",
73+
"generator": "Ninja",
74+
"binaryDir": "${sourceDir}/out/build/${presetName}",
75+
"installDir": "${sourceDir}/out/install/${presetName}",
76+
"cacheVariables": {
77+
"CMAKE_BUILD_TYPE": "Debug",
78+
"CMAKE_TOOLCHAIN_FILE": {
79+
"value": "$env{HOME}/vcpkg/scripts/buildsystems/vcpkg.cmake",
80+
"type": "FILEPATH"
81+
}
82+
},
83+
"condition": {
84+
"type": "equals",
85+
"lhs": "${hostSystemName}",
86+
"rhs": "Darwin"
87+
}
6988
}
7089
]
7190
}

demo/desktop/CMakeLists.txt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22
set(CMAKE_CXX_STANDARD 20)
33
set(CMAKE_CXX_STANDARD_REQUIRED ON)
44

5-
add_executable (demo WIN32 "main.cpp" main.rc)
5+
if(WIN32)
6+
add_executable (demo WIN32 "main.cpp" main.rc)
7+
else()
8+
add_executable (demo "main.cpp")
9+
endif()
610

711
if(WIN32)
812
# "Transparent" demo for Windows
@@ -22,4 +26,6 @@ target_compile_definitions(demo PRIVATE GREY_INCLUDE_IMNODES)
2226
target_link_libraries(demo libgrey)
2327
target_include_directories(demo PRIVATE "../../grey")
2428

25-
target_sources(demo PRIVATE dpi-aware.manifest)
29+
if(WIN32)
30+
target_sources(demo PRIVATE dpi-aware.manifest)
31+
endif()

demo/pure/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ if (WIN32)
1515
target_link_libraries(${APP_NAME} PRIVATE D3D11.lib imgui::imgui)
1616
endif()
1717

18-
# Check if we are building on Linux
19-
if (UNIX AND NOT APPLE)
18+
# Check if we are building on Linux or macOS
19+
if (UNIX)
2020
# sudo apt install libxinerama-dev libxcursor-dev xorg-dev libglu1-mesa-dev pkg-config
2121

2222
find_package(OpenGL REQUIRED)

docs/README.md

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ It's based on the awesome [ImGui](https://github.com/ocornut/imgui) framework an
1010

1111
## Features
1212

13-
- Cross-platform - currently supports **Windows x64** and **Linux x64**.
13+
- Cross-platform - currently supports **Windows x64**, **Linux x64**, and **macOS arm64**.
1414
- Completely stateless i.e., no widgets, state synchronization and so on.
1515
- Looks beautiful by default i.e., renders in high DPI, using system fonts and colours, supports themes and material icons.
1616

1717
## Getting started
1818

1919
To get started in C++, simply include this repository as a git submodule and follow the examples. For a real-life, production sample, check out [bt](https://github.com/aloneguid/bt).
2020

21-
To get started in C#, reference [GreyMatter](https://www.nuget.org/packages/GreyMatter/) package, which includes C# interface and pre-built binaries for Windows and Linux.
21+
To get started in C#, reference [GreyMatter](https://www.nuget.org/packages/GreyMatter/) package, which includes C# interface and pre-built binaries for Windows, Linux, and macOS.
2222

2323
# Roadmap
2424
- Markdown component support.
@@ -40,4 +40,21 @@ To build native part on Linux or WSL2, you need:
4040

4141
### MacOSX
4242

43-
I currently do not pay Apple tax, but instructions should be similar to Linux. If you want to help with MacOSX support, please open an issue. Supporting MacOSX should resort to testing Metal rendering backend and some native OS integrations around windowing.
43+
To build native part on macOS, you need:
44+
- [vcpkg](https://learn.microsoft.com/en-gb/vcpkg/get_started/get-started?pivots=shell-bash).
45+
- CMake. `brew install cmake`.
46+
- Build tools (Xcode Command Line Tools). `xcode-select --install`.
47+
- Ninja build system. `brew install ninja`.
48+
49+
Once the prerequisites are installed, clone the repository and build:
50+
51+
```bash
52+
git clone --recursive https://github.com/aloneguid/grey
53+
cd grey
54+
cmake -B build -S . -DCMAKE_BUILD_TYPE=Release \
55+
-DCMAKE_TOOLCHAIN_FILE=$HOME/vcpkg/scripts/buildsystems/vcpkg.cmake \
56+
-DVCPKG_TARGET_TRIPLET=arm64-osx
57+
cmake --build build --config Release
58+
```
59+
60+
The library uses the **GLFW + OpenGL3** backend on macOS (the same as Linux), which is fully supported and requires no extra runtime dependencies. All required libraries are statically linked via vcpkg.

dotnet/Grey/Grey.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@
4646
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
4747
</Content>
4848

49+
<!-- macOS arm64 -->
50+
<Content Include="..\..\xbin\runtimes\osx-arm64\native\libxgrey.dylib" Link="libxgrey.dylib" PackagePath="runtimes/osx-arm64/native">
51+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
52+
</Content>
53+
4954
</ItemGroup>
5055

5156
<ItemGroup>

grey/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ set (DYNAMIC_NAME xgrey)
66
find_package(imgui CONFIG REQUIRED)
77
find_package(implot CONFIG REQUIRED)
88

9-
if(UNIX AND NOT APPLE)
9+
if(UNIX)
1010
find_package(OpenGL REQUIRED)
1111
find_package(glfw3 CONFIG REQUIRED)
12-
endif()
12+
endif()
1313

1414
find_path(STB_INCLUDE_DIRS "stb.h")
1515

vcpkg.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,23 @@
2020
],
2121
"platform": "linux"
2222
},
23+
{
24+
"name": "imgui",
25+
"features": [
26+
"opengl3-binding",
27+
"glfw-binding",
28+
"docking-experimental"
29+
],
30+
"platform": "osx"
31+
},
2332
{
2433
"name": "glfw3",
2534
"platform": "linux"
2635
},
36+
{
37+
"name": "glfw3",
38+
"platform": "osx"
39+
},
2740
"implot"
2841
]
2942
}

0 commit comments

Comments
 (0)