Skip to content

Commit

Permalink
Added MacOS build support
Browse files Browse the repository at this point in the history
  • Loading branch information
TAR-ALEX committed May 12, 2024
1 parent 3433ef5 commit 5f301e2
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 8 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@
/gmon.txt
/cfg.txt
/releases/
/stickersolve-gui.app
.DS_Store
27 changes: 26 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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/*")
Expand All @@ -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)
Expand Down
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
24 changes: 19 additions & 5 deletions src/ConfigParser.h
Original file line number Diff line number Diff line change
@@ -1,27 +1,41 @@
#pragma once

#include <boost/filesystem.hpp>
#include <fstream>
#include <iostream>
#include <string>

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;

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();
}
};
13 changes: 11 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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); });
Expand Down

0 comments on commit 5f301e2

Please sign in to comment.