chore: got build working on mac (kind of)

This commit is contained in:
2025-12-18 01:29:32 +03:00
parent 57c3c55a94
commit 1a1747a472
8 changed files with 160 additions and 104 deletions

18
.vscode/launch.json vendored
View File

@@ -5,7 +5,7 @@
"version": "0.2.0", "version": "0.2.0",
"configurations": [ "configurations": [
{ {
"name": "Debug current target", "name": "Debug current target (GDB)",
"type": "cppdbg", "type": "cppdbg",
"request": "launch", "request": "launch",
"program": "${command:cmake.launchTargetPath}", "program": "${command:cmake.launchTargetPath}",
@@ -31,6 +31,22 @@
"ignoreFailures": true "ignoreFailures": true
} }
] ]
},
{
"name": "Debug current target (LLDB)",
"type": "cppdbg",
"request": "launch",
"program": "${command:cmake.launchTargetPath}",
"args": [
"--apply",
"--theme",
"dark"
],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "lldb",
}, },
] ]
} }

View File

@@ -8,6 +8,21 @@ if(WIN32)
URL https://download.savannah.gnu.org/releases/freetype/freetype-2.14.1.tar.gz URL https://download.savannah.gnu.org/releases/freetype/freetype-2.14.1.tar.gz
) )
FetchContent_MakeAvailable(freetype) FetchContent_MakeAvailable(freetype)
elseif(APPLE)
option(USE_SYSTEM_GLFW ON)
find_package(Freetype REQUIRED)
find_package(ZLIB REQUIRED)
find_package(BZip2 REQUIRED)
find_package(PNG REQUIRED)
find_library(BROTLIDEC_LIBRARY NAMES brotlidec)
find_library(BROTLICOMMON_LIBRARY NAMES brotlicommon)
find_package(PkgConfig QUIET)
if(PkgConfig_FOUND)
pkg_check_modules(HARFBUZZ harfbuzz)
endif()
else() else()
find_package(Freetype REQUIRED) find_package(Freetype REQUIRED)
find_package(PkgConfig REQUIRED) find_package(PkgConfig REQUIRED)
@@ -24,13 +39,24 @@ else()
pkg_check_modules(WAYLAND_EGL wayland-egl) pkg_check_modules(WAYLAND_EGL wayland-egl)
endif() endif()
if (LINUX) if(LINUX)
find_package(PkgConfig REQUIRED) find_package(PkgConfig REQUIRED)
pkg_check_modules(GTK3 REQUIRED gtk+-3.0) pkg_check_modules(GTK3 REQUIRED gtk+-3.0)
endif() endif()
if(USE_SYSTEM_GLFW) if(USE_SYSTEM_GLFW)
pkg_check_modules(GLFW REQUIRED glfw3) if(APPLE)
find_package(glfw3 QUIET)
if(glfw3_FOUND)
set(GLFW_FOUND TRUE)
set(GLFW_LIBRARIES glfw)
else()
find_package(PkgConfig REQUIRED)
pkg_check_modules(GLFW REQUIRED glfw3)
endif()
else()
pkg_check_modules(GLFW REQUIRED glfw3)
endif()
else() else()
include(FetchContent) include(FetchContent)
FetchContent_Declare( FetchContent_Declare(
@@ -62,12 +88,13 @@ if(HARFBUZZ_FOUND)
endif() endif()
set(WAYLAND_LIBS "") set(WAYLAND_LIBS "")
if(WAYLAND_CLIENT_FOUND) if(NOT APPLE)
list(APPEND WAYLAND_LIBS ${WAYLAND_CLIENT_LIBRARIES}) if(WAYLAND_CLIENT_FOUND)
message(STATUS "Found Wayland client") list(APPEND WAYLAND_LIBS ${WAYLAND_CLIENT_LIBRARIES})
endif() message(STATUS "Found Wayland client")
if(WAYLAND_EGL_FOUND) endif()
list(APPEND WAYLAND_LIBS ${WAYLAND_EGL_LIBRARIES}) if(WAYLAND_EGL_FOUND)
message(STATUS "Found Wayland EGL") list(APPEND WAYLAND_LIBS ${WAYLAND_EGL_LIBRARIES})
endif() message(STATUS "Found Wayland EGL")
endif()
endif()

View File

@@ -6,7 +6,7 @@
namespace clrsync::core namespace clrsync::core
{ {
const std::string GIT_SEMVER = "0.1.5+git.gd4ff415"; const std::string GIT_SEMVER = "0.1.6+git.g57c3c55";
const std::string version_string(); const std::string version_string();
} // namespace clrsync::core } // namespace clrsync::core

View File

@@ -15,6 +15,9 @@ set(GUI_SOURCES
file_browser.cpp file_browser.cpp
${CMAKE_SOURCE_DIR}/lib/color_text_edit/TextEditor.cpp ${CMAKE_SOURCE_DIR}/lib/color_text_edit/TextEditor.cpp
) )
if(APPLE)
list(APPEND GUI_SOURCES file_browser_macos.mm)
endif()
add_executable(clrsync_gui ${GUI_SOURCES}) add_executable(clrsync_gui ${GUI_SOURCES})

View File

@@ -138,85 +138,7 @@ std::string select_folder_dialog(const std::string& title,
} }
#else #elif !defined(__APPLE__)
#ifdef __APPLE__
#include <Cocoa/Cocoa.h>
namespace file_dialogs {
std::string open_file_dialog(const std::string& title,
const std::string& initial_path,
const std::vector<std::string>& filters) {
@autoreleasepool {
NSOpenPanel* panel = [NSOpenPanel openPanel];
[panel setTitle:[NSString stringWithUTF8String:title.c_str()]];
[panel setCanChooseFiles:YES];
[panel setCanChooseDirectories:NO];
[panel setAllowsMultipleSelection:NO];
if (!initial_path.empty()) {
NSURL* url = [NSURL fileURLWithPath:[NSString stringWithUTF8String:initial_path.c_str()]];
[panel setDirectoryURL:url];
}
if ([panel runModal] == NSModalResponseOK) {
NSURL* url = [[panel URLs] objectAtIndex:0];
return std::string([[url path] UTF8String]);
}
}
return "";
}
std::string save_file_dialog(const std::string& title,
const std::string& initial_path,
const std::vector<std::string>& filters) {
@autoreleasepool {
NSSavePanel* panel = [NSSavePanel savePanel];
[panel setTitle:[NSString stringWithUTF8String:title.c_str()]];
if (!initial_path.empty()) {
std::filesystem::path p(initial_path);
if (std::filesystem::exists(p.parent_path())) {
NSURL* url = [NSURL fileURLWithPath:[NSString stringWithUTF8String:p.parent_path().c_str()]];
[panel setDirectoryURL:url];
[panel setNameFieldStringValue:[NSString stringWithUTF8String:p.filename().c_str()]];
}
}
if ([panel runModal] == NSModalResponseOK) {
NSURL* url = [panel URL];
return std::string([[url path] UTF8String]);
}
}
return "";
}
std::string select_folder_dialog(const std::string& title,
const std::string& initial_path) {
@autoreleasepool {
NSOpenPanel* panel = [NSOpenPanel openPanel];
[panel setTitle:[NSString stringWithUTF8String:title.c_str()]];
[panel setCanChooseFiles:NO];
[panel setCanChooseDirectories:YES];
[panel setAllowsMultipleSelection:NO];
if (!initial_path.empty()) {
NSURL* url = [NSURL fileURLWithPath:[NSString stringWithUTF8String:initial_path.c_str()]];
[panel setDirectoryURL:url];
}
if ([panel runModal] == NSModalResponseOK) {
NSURL* url = [[panel URLs] objectAtIndex:0];
return std::string([[url path] UTF8String]);
}
}
return "";
}
}
#else
#include <gtk/gtk.h> #include <gtk/gtk.h>
@@ -338,6 +260,4 @@ std::string select_folder_dialog(const std::string& title,
} }
#endif
#endif #endif

View File

@@ -0,0 +1,80 @@
#include "file_browser.hpp"
#include <filesystem>
#ifdef __APPLE__
#include <Cocoa/Cocoa.h>
namespace file_dialogs {
std::string open_file_dialog(const std::string& title,
const std::string& initial_path,
const std::vector<std::string>& filters) {
@autoreleasepool {
NSOpenPanel* panel = [NSOpenPanel openPanel];
[panel setTitle:[NSString stringWithUTF8String:title.c_str()]];
[panel setCanChooseFiles:YES];
[panel setCanChooseDirectories:NO];
[panel setAllowsMultipleSelection:NO];
if (!initial_path.empty()) {
NSURL* url = [NSURL fileURLWithPath:[NSString stringWithUTF8String:initial_path.c_str()]];
[panel setDirectoryURL:url];
}
if ([panel runModal] == NSModalResponseOK) {
NSURL* url = [[panel URLs] objectAtIndex:0];
return std::string([[url path] UTF8String]);
}
}
return "";
}
std::string save_file_dialog(const std::string& title,
const std::string& initial_path,
const std::vector<std::string>& filters) {
@autoreleasepool {
NSSavePanel* panel = [NSSavePanel savePanel];
[panel setTitle:[NSString stringWithUTF8String:title.c_str()]];
if (!initial_path.empty()) {
std::filesystem::path p(initial_path);
if (std::filesystem::exists(p.parent_path())) {
NSURL* url = [NSURL fileURLWithPath:[NSString stringWithUTF8String:p.parent_path().c_str()]];
[panel setDirectoryURL:url];
[panel setNameFieldStringValue:[NSString stringWithUTF8String:p.filename().c_str()]];
}
}
if ([panel runModal] == NSModalResponseOK) {
NSURL* url = [panel URL];
return std::string([[url path] UTF8String]);
}
}
return "";
}
std::string select_folder_dialog(const std::string& title,
const std::string& initial_path) {
@autoreleasepool {
NSOpenPanel* panel = [NSOpenPanel openPanel];
[panel setTitle:[NSString stringWithUTF8String:title.c_str()]];
[panel setCanChooseFiles:NO];
[panel setCanChooseDirectories:YES];
[panel setAllowsMultipleSelection:NO];
if (!initial_path.empty()) {
NSURL* url = [NSURL fileURLWithPath:[NSString stringWithUTF8String:initial_path.c_str()]];
[panel setDirectoryURL:url];
}
if ([panel runModal] == NSModalResponseOK) {
NSURL* url = [[panel URLs] objectAtIndex:0];
return std::string([[url path] UTF8String]);
}
}
return "";
}
}
#endif

View File

@@ -123,25 +123,27 @@ std::vector<unsigned char> font_loader::load_font_macos(const char* font_name)
if (!desc) if (!desc)
return out; return out;
CTFontRef font = CTFontCreateWithFontDescriptor(desc, 0, nullptr); CFURLRef url = (CFURLRef)CTFontDescriptorCopyAttribute(desc, kCTFontURLAttribute);
CFRelease(desc); CFRelease(desc);
if (!font) if (!url)
return out; return out;
CFDataRef data = CTFontCopyTable(font, kCTFontTableCFF, 0); CFDataRef data = nullptr;
if (!data) Boolean success = CFURLCreateDataAndPropertiesFromResource(kCFAllocatorDefault, url, &data, nullptr, nullptr, nullptr);
data = CTFontCopyTable(font, kCTFontTableHead, 0); CFRelease(url);
if (data) if (success && data)
{ {
CFIndex size = CFDataGetLength(data); CFIndex size = CFDataGetLength(data);
out.resize(size); if (size > 100)
CFDataGetBytes(data, CFRangeMake(0, size), out.data()); {
out.resize(size);
CFDataGetBytes(data, CFRangeMake(0, size), out.data());
}
CFRelease(data); CFRelease(data);
} }
CFRelease(font);
return out; return out;
} }

View File

@@ -23,7 +23,11 @@ GLFWwindow * init_glfw()
} }
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
#ifdef __APPLE__
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
#else
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);
#endif
glfwWindowHint(GLFW_TRANSPARENT_FRAMEBUFFER, GLFW_TRUE); glfwWindowHint(GLFW_TRANSPARENT_FRAMEBUFFER, GLFW_TRUE);
GLFWwindow* w = glfwCreateWindow(1280, 720, "clrsync", nullptr, nullptr); GLFWwindow* w = glfwCreateWindow(1280, 720, "clrsync", nullptr, nullptr);
@@ -49,7 +53,11 @@ void init_imgui(GLFWwindow* window, const std::string& ini_path)
ImGui::StyleColorsDark(); ImGui::StyleColorsDark();
ImGui_ImplGlfw_InitForOpenGL(window, true); ImGui_ImplGlfw_InitForOpenGL(window, true);
ImGui_ImplOpenGL3_Init("#version 130"); #ifdef __APPLE__
ImGui_ImplOpenGL3_Init("#version 150");
#else
ImGui_ImplOpenGL3_Init("#version 120");
#endif
} }
void begin_frame() void begin_frame()