From 7c9f56cd3b72727b8d111b4dcde782aabf4151b6 Mon Sep 17 00:00:00 2001 From: Anthony Rabine Date: Mon, 22 Jan 2024 16:56:14 +0100 Subject: [PATCH] Add MacOS bundle generation (WIP) + Macos build fixes --- .gitignore | 8 ++++++ .vscode/launch.json | 10 +++++++- story-editor/CMakeLists.txt | 25 ++++++++++++++++++ story-editor/bundle.plist.in | 34 +++++++++++++++++++++++++ story-editor/src/gui.cpp | 20 +++++++++++---- story-editor/src/gui.h | 2 +- story-editor/src/media_node.cpp | 2 ++ story-editor/src/node_editor_window.cpp | 1 + story-editor/src/platform_folders.cpp | 18 +++++++++++++ story-editor/src/platform_folders.h | 2 ++ 10 files changed, 115 insertions(+), 7 deletions(-) create mode 100644 story-editor/bundle.plist.in diff --git a/.gitignore b/.gitignore index f65b305..426b82c 100644 --- a/.gitignore +++ b/.gitignore @@ -69,3 +69,11 @@ docs/.vitepress/cache/ docs/.vitepress/dist/ software/.cache/ + +.DS_Store + +story-editor/.idea/ + +story-editor/buildxcode/ + +story-editor/cmake-build-debug/ diff --git a/.vscode/launch.json b/.vscode/launch.json index dfe57fc..2290ea5 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -14,7 +14,15 @@ "cwd": "${workspaceFolder}/story-editor", "environment": [], "externalConsole": false, - "MIMode": "gdb", + "linux": { + "MIMode": "gdb", + "miDebuggerPath": "/usr/bin/gdb" + }, + "osx": { + "MIMode": "lldb", + "miDebuggerPath": "/Users/user936511/.vscode/extensions/ms-vscode.cpptools-1.18.5-darwin-arm64/debugAdapters/lldb-mi/bin/lldb-mi" + }, + "setupCommands": [ { "description": "Enable pretty-printing for gdb", diff --git a/story-editor/CMakeLists.txt b/story-editor/CMakeLists.txt index 0acdcc7..5de20ad 100644 --- a/story-editor/CMakeLists.txt +++ b/story-editor/CMakeLists.txt @@ -203,6 +203,27 @@ target_include_directories(${STORY_EDITOR_PROJECT} PUBLIC add_definitions(-DIMGUI_USE_WCHAR32 -DVERSION_MAJOR=${PROJECT_VERSION_MAJOR} -DVERSION_MINOR=${PROJECT_VERSION_MINOR} -DVERSION_PATCH=${PROJECT_VERSION_PATCH}) add_link_options(-static-libgcc -static-libstdc++) +if (APPLE) +set_target_properties(${PROJECT_NAME} PROPERTIES + LINKER_LANGUAGE CXX + LINK_FLAGS "-Wl,-rpath,@executable_path" + MACOSX_RPATH TRUE + SKIP_BUILD_RPATH FALSE + BUILD_WITH_INSTALL_RPATH TRUE + INSTALL_RPATH_USE_LINK_PATH TRUE +) + +set_target_properties(${PROJECT_NAME} PROPERTIES + BUNDLE True + MACOSX_BUNDLE_GUI_IDENTIFIER eu.d8s.OpenStoryTeller.StoryEditor.${CUR_TARGET} + MACOSX_BUNDLE_BUNDLE_NAME ${CUR_TARGET} + MACOSX_BUNDLE_BUNDLE_VERSION "0.1" + MACOSX_BUNDLE_SHORT_VERSION_STRING "0.1" + MACOSX_BUNDLE_INFO_PLIST ${CMAKE_SOURCE_DIR}/bundle.plist.in +) + +endif() + target_compile_definitions(${STORY_EDITOR_PROJECT} PUBLIC cimg_display=0) target_compile_definitions(${STORY_EDITOR_PROJECT} PUBLIC "$<$:DEBUG>") @@ -255,4 +276,8 @@ if(WIN32) set(CPACK_NSIS_MUI_ICON "${CMAKE_SOURCE_DIR}/story-editor-logo.ico") endif() +if (APPLE) + install_files("." FILES "${SDL2_BIN_DIR}/libSDL2-2.0.0.dylib") +endif() + include(CPack) diff --git a/story-editor/bundle.plist.in b/story-editor/bundle.plist.in new file mode 100644 index 0000000..a4009bc --- /dev/null +++ b/story-editor/bundle.plist.in @@ -0,0 +1,34 @@ + + + + + CFBundleDevelopmentRegion + English + CFBundleExecutable + ${MACOSX_BUNDLE_EXECUTABLE_NAME} + CFBundleGetInfoString + ${MACOSX_BUNDLE_INFO_STRING} + CFBundleIconFile + ${MACOSX_BUNDLE_ICON_FILE} + CFBundleIdentifier + ${MACOSX_BUNDLE_GUI_IDENTIFIER} + CFBundleInfoDictionaryVersion + 6.0 + CFBundleLongVersionString + ${MACOSX_BUNDLE_LONG_VERSION_STRING} + CFBundleName + ${MACOSX_BUNDLE_BUNDLE_NAME} + CFBundlePackageType + APPL + CFBundleShortVersionString + ${MACOSX_BUNDLE_SHORT_VERSION_STRING} + CFBundleSignature + ???? + CFBundleVersion + ${MACOSX_BUNDLE_BUNDLE_VERSION} + CSResourcesFileMapped + + NSHumanReadableCopyright + ${MACOSX_BUNDLE_COPYRIGHT} + + diff --git a/story-editor/src/gui.cpp b/story-editor/src/gui.cpp index 474bafe..7885d65 100644 --- a/story-editor/src/gui.cpp +++ b/story-editor/src/gui.cpp @@ -8,7 +8,7 @@ your use of the corresponding standard functions. #include "gui.h" #include - +#include #include "imgui_impl_sdl2.h" #include "imgui_impl_sdlrenderer2.h" @@ -24,6 +24,9 @@ your use of the corresponding standard functions. #include "IconsFontAwesome5_c.h" #include "qoi.h" + +#include "platform_folders.h" + static void glfw_error_callback(int error, const char* description) { fprintf(stderr, "GLFW Error %d: %s\n", error, description); @@ -110,9 +113,16 @@ bool LoadTextureFromFile(const char* filename, Gui::Image &img) #define MANOLAB_VERSION "1.0" +std::string GetDirectory (const std::string& path) +{ + size_t found = path.find_last_of("/\\"); + return(path.substr(0, found)); +} + Gui::Gui() { - + m_executablePath = GetDirectory(pf::getExecutablePath()); + std::cout << "PATH: " << m_executablePath << std::endl; } @@ -161,7 +171,7 @@ bool Gui::Initialize() io.ConfigFlags |= ImGuiConfigFlags_DockingEnable; - io.Fonts->AddFontFromFileTTF( "fonts/roboto.ttf", 20); + io.Fonts->AddFontFromFileTTF( std::string(m_executablePath + "/fonts/roboto.ttf").c_str(), 20); { ImFontConfig config; @@ -169,7 +179,7 @@ bool Gui::Initialize() // config.GlyphMinAdvanceX = 20.0f; // Use if you want to make the icon monospaced // config.GlyphOffset.y += 1.0; static const ImWchar icon_ranges[] = { ICON_MIN_FA, ICON_MAX_FA, 0 }; - io.Fonts->AddFontFromFileTTF("fonts/fa-solid-900.ttf", 16.0f, &config, icon_ranges); + io.Fonts->AddFontFromFileTTF(std::string(m_executablePath + "/fonts/fa-solid-900.ttf").c_str(), 16.0f, &config, icon_ranges); io.Fonts->Build(); } @@ -179,7 +189,7 @@ bool Gui::Initialize() config.MergeMode = true; // ATTENTION, MERGE AVEC LA FONT PRECEDENTE !! static const ImWchar icon_ranges_mdi[] = { ICON_MIN_MDI, ICON_MAX_MDI, 0 }; - io.Fonts->AddFontFromFileTTF("fonts/materialdesignicons-webfont.ttf", 16.0f, &config, icon_ranges_mdi); + io.Fonts->AddFontFromFileTTF(std::string(m_executablePath + "/fonts/materialdesignicons-webfont.ttf").c_str(), 16.0f, &config, icon_ranges_mdi); io.Fonts->Build(); } diff --git a/story-editor/src/gui.h b/story-editor/src/gui.h index 604283f..78321cb 100644 --- a/story-editor/src/gui.h +++ b/story-editor/src/gui.h @@ -50,7 +50,7 @@ public: static Size GetWindowSize(); private: - + std::string m_executablePath; }; namespace ImGui { diff --git a/story-editor/src/media_node.cpp b/story-editor/src/media_node.cpp index d510181..188f977 100644 --- a/story-editor/src/media_node.cpp +++ b/story-editor/src/media_node.cpp @@ -1,3 +1,5 @@ + +#include #include "media_node.h" namespace ed = ax::NodeEditor; diff --git a/story-editor/src/node_editor_window.cpp b/story-editor/src/node_editor_window.cpp index ee93daa..f2bd969 100644 --- a/story-editor/src/node_editor_window.cpp +++ b/story-editor/src/node_editor_window.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include "IconsFontAwesome5_c.h" #include "media_node.h" diff --git a/story-editor/src/platform_folders.cpp b/story-editor/src/platform_folders.cpp index 8c6ef33..d070c51 100644 --- a/story-editor/src/platform_folders.cpp +++ b/story-editor/src/platform_folders.cpp @@ -164,6 +164,24 @@ static std::string GetAppDataLocal() return GetKnownWindowsFolder(FOLDERID_LocalAppData, "LocalAppData could not be found"); } #elif defined(__APPLE__) + + +#include +#include + +namespace pf { +std::string getExecutablePath() +{ + std::string path; + char buf [PATH_MAX]; + uint32_t bufsize = PATH_MAX; + if(!_NSGetExecutablePath(buf, &bufsize)) + path.assign(buf); + + return path; +} +} + #else #include #include diff --git a/story-editor/src/platform_folders.h b/story-editor/src/platform_folders.h index 953e726..9623ce1 100644 --- a/story-editor/src/platform_folders.h +++ b/story-editor/src/platform_folders.h @@ -61,6 +61,8 @@ std::string win32_utf16_to_utf8(const wchar_t* wstr); std::string getDataHome(); +std::string getExecutablePath(); + std::string getUserHome(); /**