From c92edbe28b954005c6ad6ee0a289e69028f4aa3f Mon Sep 17 00:00:00 2001 From: Yousef Khadadeh Date: Thu, 2 Oct 2025 14:30:11 +0300 Subject: [PATCH] Added an option to make a portable executable --- CMakeLists.txt | 5 +++++ src/main.cpp | 7 +++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 82773d0..8760934 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,6 +24,7 @@ option(USE_MEMORYSAN "Enable Memory Sanitizer" OFF) option(LINK_SKIA_MANUALLY "Link skia not as a package, but as separate libraries for non-Conan builds" OFF) option(EMSCRIPTEN_SINGLE_HTML_FILE "Building with emscripten generates a single HTML file" OFF) option(TBB_NOT_ONETBB "Use TBB::tbb package and not onetbb::onetbb package from conan" OFF) +option(CONFIG_NEXT_TO_EXECUTABLE "Place configuration folder next to executable (portable executable)" OFF) # Setting sources set(sources "src/main.cpp" @@ -250,6 +251,10 @@ if(WIN32) target_compile_definitions(infinipaint PRIVATE WIN32_LEAN_AND_MEAN NOMINMAX) endif() +if(CONFIG_NEXT_TO_EXECUTABLE) + target_compile_definitions(infinipaint PRIVATE CONFIG_NEXT_TO_EXECUTABLE) +endif() + if(NOT EMSCRIPTEN AND ((GRAPHICS_BACKEND STREQUAL "OpenGL3.3") OR (GRAPHICS_BACKEND STREQUAL "OpenGLES3.0") OR (GRAPHICS_BACKEND STREQUAL "OpenGL2.1"))) find_package(OpenGL REQUIRED) if(GRAPHICS_BACKEND STREQUAL "OpenGLES3.0") diff --git a/src/main.cpp b/src/main.cpp index e9b645e..f006816 100755 --- a/src/main.cpp +++ b/src/main.cpp @@ -333,8 +333,6 @@ const char* emscripten_before_unload(int eventType, const void *reserved, void * #endif void init_logs(MainStruct& mS) { - std::string CONFIG_FOLDER_NAME = "infinipaint"; - mS.homePath = std::filesystem::current_path(); #ifdef __EMSCRIPTEN__ EM_ASM( @@ -352,7 +350,12 @@ void init_logs(MainStruct& mS) { ); mS.homePath = std::filesystem::path("/"); mS.configPath = std::filesystem::path("/infinipaint"); +#elif CONFIG_NEXT_TO_EXECUTABLE + std::string CONFIG_FOLDER_NAME = "config"; + std::filesystem::create_directory(CONFIG_FOLDER_NAME); + mS.configPath = mS.homePath / CONFIG_FOLDER_NAME; #else + std::string CONFIG_FOLDER_NAME = "infinipaint"; std::filesystem::path configHome(sago::getConfigHome()); std::filesystem::create_directory(configHome); mS.configPath = configHome / CONFIG_FOLDER_NAME;