From 2220bfb5de3614d77e6918dbb90c157cf60a13d7 Mon Sep 17 00:00:00 2001 From: Daniel Dada Date: Mon, 8 Dec 2025 16:00:35 +0300 Subject: [PATCH] create windows installed with nsis --- CMakeLists.txt | 55 +++++++++++++++++++++++++++++++++- LICENSE => LICENSE.txt | 0 src/core/config/config.cpp | 18 ++++++++++- src/core/config/config.hpp | 1 + src/gui/palette_controller.cpp | 2 +- 5 files changed, 73 insertions(+), 3 deletions(-) rename LICENSE => LICENSE.txt (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index a3d68b1..696b7bd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,6 +6,14 @@ include(GNUInstallDirs) set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) +if(WIN32) + set(CMAKE_INSTALL_PREFIX "C:/Program Files/clrsync") + set(CMAKE_INSTALL_BINDIR "bin") + set(CMAKE_INSTALL_LIBDIR "lib") + set(CMAKE_INSTALL_DATADIR "share") + set(CMAKE_INSTALL_FULL_DATADIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATADIR}") +endif() + set(CMAKE_SKIP_BUILD_RPATH FALSE) set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE) set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) @@ -122,33 +130,78 @@ target_compile_definitions(imgui PUBLIC IMGUI_ENABLE_FREETYPE) install(TARGETS clrsync_core LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + COMPONENT Core ) install(TARGETS clrsync_cli RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + COMPONENT CLI ) install(TARGETS clrsync_gui RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + COMPONENT GUI ) install(FILES example_config/config.toml DESTINATION ${CMAKE_INSTALL_DATADIR}/clrsync + COMPONENT Core ) install(DIRECTORY example_config/templates DESTINATION ${CMAKE_INSTALL_DATADIR}/clrsync + COMPONENT Core FILES_MATCHING PATTERN "*" ) install(DIRECTORY example_config/palettes DESTINATION ${CMAKE_INSTALL_DATADIR}/clrsync + COMPONENT Core FILES_MATCHING PATTERN "*.toml" ) if(UNIX AND NOT APPLE) install(FILES resources/clrsync.desktop DESTINATION ${CMAKE_INSTALL_DATADIR}/applications + COMPONENT Core ) -endif() \ No newline at end of file +endif() + +set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/LICENSE.txt") +set(CPACK_COMPONENTS_ALL Core GUI CLI) + +set(CPACK_PACKAGE_NAME "clrsync") +set(CPACK_PACKAGE_VENDOR "Daniel Dada") +set(CPACK_PACKAGE_VERSION ${PROJECT_VERSION}) +set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Color scheme manager") + +set(CPACK_COMPONENTS_ALL Core GUI CLI) +set(CPACK_COMPONENT_CORE_DISPLAY_NAME "Core Library") +set(CPACK_COMPONENT_CORE_DESCRIPTION "clrsync core library and default configs (required)") +set(CPACK_COMPONENT_CORE_REQUIRED ON) +set(CPACK_COMPONENT_GUI_DISPLAY_NAME "GUI Application") +set(CPACK_COMPONENT_GUI_DESCRIPTION "clrsync GUI app") +set(CPACK_COMPONENT_GUI_DEPENDS Core) +set(CPACK_COMPONENT_CLI_DISPLAY_NAME "Command Line Tool") +set(CPACK_COMPONENT_CLI_DESCRIPTION "clrsync CLI app") +set(CPACK_COMPONENT_CLI_DEPENDS Core) + +set(CPACK_GENERATOR "NSIS") + +set(CPACK_NSIS_INSTALLED_NAME "clrsync") +set(CPACK_NSIS_INSTALL_ROOT "$PROGRAMFILES64") + +set(CPACK_NSIS_MODIFY_PATH ON) +set(CPACK_NSIS_ENABLE_UNINSTALL_BEFORE_INSTALL ON) + +set(CPACK_NSIS_MENU_LINKS "bin/clrsync_gui.exe" "clrsync") +set(CPACK_NSIS_CREATE_DESKTOP_LINKS "bin/clrsync_gui.exe;clrsync") + +message(STATUS "CMAKE_INSTALL_PREFIX: ${CMAKE_INSTALL_PREFIX}") +message(STATUS "CMAKE_INSTALL_DATADIR: ${CMAKE_INSTALL_DATADIR}") +message(STATUS "CMAKE_INSTALL_FULL_DATADIR: ${CMAKE_INSTALL_FULL_DATADIR}") +message(STATUS "CMAKE_SIZEOF_VOID_P: ${CMAKE_SIZEOF_VOID_P}") + +include(CPack) diff --git a/LICENSE b/LICENSE.txt similarity index 100% rename from LICENSE rename to LICENSE.txt diff --git a/src/core/config/config.cpp b/src/core/config/config.cpp index 4058553..2e74e0f 100644 --- a/src/core/config/config.cpp +++ b/src/core/config/config.cpp @@ -5,6 +5,10 @@ #include #include +#ifdef _WIN32 +#include "windows.h" +#endif + namespace clrsync::core { config &config::instance() @@ -33,10 +37,22 @@ std::filesystem::path config::get_user_config_dir() #endif } +std::filesystem::path config::get_data_dir() { +#ifdef _WIN32 + char buffer[MAX_PATH]; + GetModuleFileNameA(nullptr, buffer, MAX_PATH); + std::filesystem::path exe_path(buffer); + std::filesystem::path data_dir = exe_path.parent_path().parent_path() / "share" / "clrsync"; + return data_dir; +#else + return {CLRSYNC_DATADIR}; +#endif +} + void config::copy_default_configs() { std::filesystem::path user_config = get_user_config_dir(); - std::filesystem::path default_dir = CLRSYNC_DATADIR; + std::filesystem::path default_dir = get_data_dir(); if (!std::filesystem::exists(user_config)) { diff --git a/src/core/config/config.hpp b/src/core/config/config.hpp index 84604f7..ecc0fd3 100644 --- a/src/core/config/config.hpp +++ b/src/core/config/config.hpp @@ -32,6 +32,7 @@ class config void update_template(const std::string &key, const clrsync::core::theme_template &theme_template); + static std::filesystem::path get_data_dir(); private: config() = default; diff --git a/src/gui/palette_controller.cpp b/src/gui/palette_controller.cpp index db55a9f..7f64651 100644 --- a/src/gui/palette_controller.cpp +++ b/src/gui/palette_controller.cpp @@ -28,7 +28,7 @@ void palette_controller::select_palette(const std::string& name) void palette_controller::create_palette(const std::string& name) { - clrsync::core::palette new_palette = m_palette_manager.load_palette_from_file(std::string(CLRSYNC_DATADIR) + "/palettes/cursed.toml"); + clrsync::core::palette new_palette = m_palette_manager.load_palette_from_file(clrsync::core::config::get_data_dir().string() + "/palettes/cursed.toml"); new_palette.set_name(name); auto dir = clrsync::core::config::instance().palettes_path();