diff --git a/.gitignore b/.gitignore index be60c4a..499a304 100755 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,5 @@ /gmon.txt /cfg.txt /releases/ +/stickersolve-gui.app +.DS_Store \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 0f51b36..3a88bb4 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,7 @@ cmake_minimum_required(VERSION 3.16) +if(APPLE) +#set(CMAKE_OSX_ARCHITECTURES "arm64;x86_64" CACHE STRING "" FORCE) # comment out if you dont want a univeral binary +endif() project(stickersolve-gui) set(CMAKE_CXX_STANDARD 20) @@ -10,14 +13,21 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}) set(CMAKE_CXX_FLAGS_DEBUG "-g -O3 -Wall -pg") # gprof stickersolve-gui gmon.out > gmon.txt set(CMAKE_CXX_FLAGS_RELEASE "-O3") +if(APPLE) +find_package(Qt5 REQUIRED Core Widgets Gui PATHS /usr/local/opt/qt@5) # update path to qt cmake files here for MacOS +link_directories(/usr/local/opt/boost/lib/) # update path to boost cmake files here for MacOS +else() set(Qt5_DIR ./vendor/usr/lib/x86_64-linux-gnu/cmake/Qt5) find_package(Qt5 REQUIRED Core Widgets Gui PATHS ./vendor/lib/cmake) -include_directories(${PROJECT_SOURCE_DIR}/include/, ${PROJECT_SOURCE_DIR}/vendor/include/) set(CMAKE_BUILD_WITH_INSTALL_RPATH on) set(CMAKE_INSTALL_RPATH "./vendor/lib" "./lib") link_directories(${PROJECT_SOURCE_DIR}/vendor/lib) +endif() + +include_directories(${PROJECT_SOURCE_DIR}/include/, ${PROJECT_SOURCE_DIR}/vendor/include/) + file(GLOB_RECURSE APP_SOURCES CONFIGURE_DEPENDS "${PROJECT_SOURCE_DIR}/src/*" "${PROJECT_SOURCE_DIR}/include/*") file(GLOB_RECURSE VENDOR_SOURCES CONFIGURE_DEPENDS "${PROJECT_SOURCE_DIR}/vendor/src/*" "${PROJECT_SOURCE_DIR}/vendor/include/*") @@ -33,6 +43,21 @@ if(WIN32) Qt5::Widgets ${ADDITIONAL_LIBRARIES} ) +elseif(APPLE) + add_executable(${PROJECT_NAME} ${APP_SOURCES} ${VENDOR_SOURCES}) + target_compile_options(${PROJECT_NAME} PRIVATE -fPIC) + target_link_libraries(${PROJECT_NAME} + pthread + Qt5::Core + Qt5::Gui + Qt5::Widgets + -lboost_system + -lboost_iostreams + -lboost_filesystem + ) + set_target_properties(${PROJECT_NAME} PROPERTIES + MACOSX_BUNDLE TRUE + ) else() add_executable(${PROJECT_NAME} ${APP_SOURCES} ${VENDOR_SOURCES}) target_compile_options(${PROJECT_NAME} PRIVATE -fPIC) diff --git a/README.md b/README.md index 3b681c9..d344777 100644 --- a/README.md +++ b/README.md @@ -57,3 +57,17 @@ mkdir build && cd build && cmake -DCMAKE_BUILD_TYPE=Release .. && cmake --build # Building From Source On Windows On windows I recommend using the [dep-pull](https://github.com/TAR-ALEX/Cpp-Dependency-Manager.git) command to install only the git dependencies. (deb will not work on windows) Alternatively, files could be copied over manually from each git repo into the `./vendor/` directory. A build of Qt must be put into the vendor directory, and the same is true for the boost library. + +# Building From Source On MacOS + +Do a `brew install qt5` and a `brew install boost`. + +Feed the installed library directories to the cmake file (locations marked as comments in cmake). + +build the app using cmake but only the release target is supported. + +``` +mkdir build && cd build && cmake -DCMAKE_BUILD_TYPE=Release .. && cmake --build . --target stickersolve-gui --config Release && cd ../ +``` + +for distribution: to package the file into an app do a `macdeployqt stickersolve-gui.app` command. edit the plist as needed and create a dmg using `create-dmg` diff --git a/src/ConfigParser.h b/src/ConfigParser.h index 2f287ea..9ebfa21 100644 --- a/src/ConfigParser.h +++ b/src/ConfigParser.h @@ -1,10 +1,24 @@ #pragma once +#include #include #include #include class ConfigFile { +private: + std::string dirnameOf(const std::string& fname) + { + size_t pos = fname.find_last_of("\\/"); + return (std::string::npos == pos) + ? "" + : fname.substr(0, pos); + } + void createDir() { + boost::filesystem::path p = dirnameOf(path); + if (!(boost::filesystem::exists(p))) { boost::filesystem::create_directories(p); } + } + public: std::string path; double maxMemory = 9; @@ -12,16 +26,16 @@ class ConfigFile { ConfigFile(std::string path) : path(path) {} void parse() { - std::fstream file{path, std::ios::in | std::ios::app}; - if(!(file >> maxMemory)){ - maxMemory = 9; - } + createDir(); + std::ifstream file{path}; + if (!(file >> maxMemory)) { maxMemory = 9; } file.close(); } void save() { + createDir(); std::fstream file{path, std::ios::out | std::ios::trunc}; - file << maxMemory; + file << maxMemory << "\n"; file.close(); } }; \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 73182cd..800c3d6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -25,7 +25,15 @@ using namespace estd::shortnames; using namespace std; -ConfigFile cfgFile{"./cfg.txt"}; +#ifdef __APPLE__ +std::string tablesPath = (QDir::homePath()+"/Library/Application Support/stickersolve-gui/tables").toUtf8().constData(); +std::string cfgPath = (QDir::homePath()+"/Library/Application Support/stickersolve-gui/cfg.txt").toUtf8().constData(); +#else +std::string tablesPath = "./tables"; +std::string cfgPath = "./cfg.txt"; +#endif + +ConfigFile cfgFile{cfgPath}; int main(int argc, char** argv) { cfgFile.parse(); @@ -65,6 +73,7 @@ int main(int argc, char** argv) { puzzleColumn->addWidget(tlbx); auto configForm = new QFormLayout(); + configForm->setFieldGrowthPolicy(QFormLayout::AllNonFixedFieldsGrow); auto allowedMoves = new QLineEdit("U U2 U' R R2 R' F F2 F' D D2 D' L L2 L' B B2 B'"); auto applyMovesBtn = new QPushButton("apply"); @@ -184,7 +193,7 @@ int main(int argc, char** argv) { pzl.solvedState = solvedState->getState(); std::cout << "myState: " << pzl.toString() << endl; - solver.cfg->pruiningTablesPath = "./tables"; + solver.cfg->pruiningTablesPath = tablesPath; solver.cfg->maxMemoryInGb = maxMemoryLimitGb->value(); solver.progressCallback = [&](int progress) { QMetaObject::invokeMethod(app.get(), [=] { progressBar->setValue(progress); });