From ff45d73e10094bf67f20628fa5a5c02826e14bb6 Mon Sep 17 00:00:00 2001 From: bialger Date: Wed, 14 Aug 2024 16:29:30 +0300 Subject: [PATCH 01/12] Added help argument --- main.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/main.cpp b/main.cpp index b75c19c..51af4c7 100644 --- a/main.cpp +++ b/main.cpp @@ -1,9 +1,15 @@ #include +#include #include "lib/basic/basic_functions.hpp" #include "lib/parser/arguments_parser.hpp" #include "lib/sand_pile/sand_pile.hpp" int main(int32_t argc, char** argv) { + if (argc == 2 && (strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "--help") == 0)) { + PrintHelp(); + return 0; + } + constexpr size_t kArgumentCount = 6; ArgumentInformation* arguments = new ArgumentInformation[kArgumentCount]; arguments[0] = {"-i", "--input=", "Path to input file", From 60bfe24b6d1cc22a1c75f5d94928439962d7759d Mon Sep 17 00:00:00 2001 From: bialger Date: Wed, 14 Aug 2024 16:29:42 +0300 Subject: [PATCH 02/12] Updated version --- CMakeLists.txt | 2 +- lib/basic/basic_functions.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b656e99..99ca85f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.12) project( SandPile - VERSION 0.1.0 + VERSION 1.0 DESCRIPTION "C++ Year 2023 Labwork3 - SandPile by bialger" LANGUAGES C CXX ) diff --git a/lib/basic/basic_functions.cpp b/lib/basic/basic_functions.cpp index e69d84a..0cfa49a 100644 --- a/lib/basic/basic_functions.cpp +++ b/lib/basic/basic_functions.cpp @@ -148,7 +148,7 @@ bool IsDirectory(char* dirname) { } void PrintHelp() { - std::cout << "SandPile model version 0.1 by bialger.\n" + std::cout << "SandPile model version 1.0 by bialger.\n" << "SandPile model help page.\n" << "Usage: SandPile [OPTIONS]...\n" << "SandPile models an Abelian sandpile model. " From 5804693fa4ea87c92d514ef8b209c0c6bbfb8424 Mon Sep 17 00:00:00 2001 From: bialger Date: Wed, 14 Aug 2024 16:29:55 +0300 Subject: [PATCH 03/12] Added installation script --- PrintOS.cmake | 13 ++++++++ install.sh | 90 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 103 insertions(+) create mode 100644 PrintOS.cmake create mode 100755 install.sh diff --git a/PrintOS.cmake b/PrintOS.cmake new file mode 100644 index 0000000..d3ae2b2 --- /dev/null +++ b/PrintOS.cmake @@ -0,0 +1,13 @@ +cmake_minimum_required(VERSION 3.12) + +if (UNIX AND NOT APPLE) + set(LINUX TRUE) +endif () + +if (WIN32) + message("Windows") +elseif (LINUX) + message("Linux") +else () + message("MacOS") +endif () diff --git a/install.sh b/install.sh new file mode 100755 index 0000000..9d5ba52 --- /dev/null +++ b/install.sh @@ -0,0 +1,90 @@ +#!/bin/sh + +OS_NAME="$(cmake -P ./PrintOS.cmake 2>&1)" +PROJECT_NAME="SandPile" +CMAKE_BUILD_DIR="$HOME/CMakeBuilds" +CMAKE_PROJECT_DIR="$CMAKE_BUILD_DIR/$PROJECT_NAME" + +if [ "x$SAVE_PREV" = "x" ]; then + if [ -e "$CMAKE_PROJECT_DIR" ]; then + rm -rf "$CMAKE_PROJECT_DIR" + fi +fi + +EXEC_EXTENSION=".exe" +EXEC_PATH="$CMAKE_PROJECT_DIR/$PROJECT_NAME$EXEC_EXTENSION" + +if [ "$OS_NAME" = "Linux" ]; then + EXEC_EXTENSION=".run" + EXEC_PATH="$CMAKE_PROJECT_DIR/$PROJECT_NAME" +elif [ "$OS_NAME" = "MacOS" ]; then + EXEC_EXTENSION=".run" + EXEC_PATH="$CMAKE_PROJECT_DIR/$PROJECT_NAME" +fi + +EXEC_LINK_PATH="$HOME/$PROJECT_NAME$EXEC_EXTENSION" + +if (cmake -S . -B "$CMAKE_PROJECT_DIR" -DCMAKE_BUILD_TYPE=Release -G "Unix Makefiles" && cmake --build "$CMAKE_PROJECT_DIR" --target "$PROJECT_NAME"); then + rm -f "$EXEC_LINK_PATH" + ln -s "$EXEC_PATH" "$EXEC_LINK_PATH" + echo '' + + if ("$EXEC_LINK_PATH" -h >/dev/null 2>/dev/null); then + echo "Congratulations! $PROJECT_NAME was compiled successfully." + echo '' + "$EXEC_LINK_PATH" -h + echo '' + + if [ "$OS_NAME" = "Linux" ]; then + printf 'Do you want to add this utility to /usr/bin (y/n)? ' && read -r CHOISE + COMMON_LINK_PATH="/usr/bin/${PROJECT_NAME:?}" + COMMON_PROJECT_DIR="/opt/${PROJECT_NAME:?}" + COMMON_EXEC_PATH="$COMMON_PROJECT_DIR/$PROJECT_NAME" + + if [ "$CHOISE" = "y" ]; then + sudo -S rm -f "$COMMON_LINK_PATH" + + if (sudo ln -s "$EXEC_PATH" "$COMMON_LINK_PATH"); then + if [ -e "$COMMON_PROJECT_DIR" ]; then + sudo rm -rf "$COMMON_PROJECT_DIR" + fi + + sudo rm -f "$COMMON_LINK_PATH" + sudo cp -r "$CMAKE_PROJECT_DIR" "$COMMON_PROJECT_DIR" + sudo ln -s "$COMMON_EXEC_PATH" "$COMMON_LINK_PATH" + echo "Accepted, run utility with $PROJECT_NAME" + else + echo 'Please try again later.' + echo "Declined, run utility with $EXEC_LINK_PATH" + fi + else + echo "Declined, run utility with $EXEC_LINK_PATH" + fi + else + echo "Run utility with $EXEC_LINK_PATH" + fi + + exit 0 + elif (cd "$CMAKE_PROJECT_DIR" && "./$PROJECT_NAME$EXEC_EXTENSION" -h >/dev/null 2>/dev/null); then + rm -f "$EXEC_LINK_PATH" + rm -rf "$HOME/${PROJECT_NAME:?}" + echo "Congratulations! $PROJECT_NAME was compiled successfully." + echo "Because of Windows-specific limitations, it is not possible to create a link to it." + echo "You can run it from $HOME/$PROJECT_NAME as .\\$PROJECT_NAME$EXEC_EXTENSION" + echo "Or you can run CMD.EXE with administrative privileges and type: " + echo 'mklink "%userprofile%\SandPile.exe" "%userprofile%\SandPile\SandPile.exe"' + echo '' + mkdir "$HOME/$PROJECT_NAME" + cp "$CMAKE_PROJECT_DIR/$PROJECT_NAME$EXEC_EXTENSION" "$HOME/$PROJECT_NAME/$PROJECT_NAME$EXEC_EXTENSION" + # ALso copy all *dll files like following: + # cp -r "$CMAKE_PROJECT_DIR/liblib.dll" "$HOME/$PROJECT_NAME/liblib.dll" + cd "$HOME/$PROJECT_NAME" && "./$PROJECT_NAME$EXEC_EXTENSION" -h + exit 0 + else + echo 'Oops! Could not execute the program.' + exit 1 + fi +else + echo 'Error occurred during running CMake. Make sure that it is installed and configured properly.' + exit 1 +fi From c7158118304a871395c118a62dd5b9657223af80 Mon Sep 17 00:00:00 2001 From: bialger Date: Wed, 14 Aug 2024 16:40:16 +0300 Subject: [PATCH 04/12] Added CI/CD build test --- .github/workflows/ci_tests.yml | 72 ++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 .github/workflows/ci_tests.yml diff --git a/.github/workflows/ci_tests.yml b/.github/workflows/ci_tests.yml new file mode 100644 index 0000000..5dc88e2 --- /dev/null +++ b/.github/workflows/ci_tests.yml @@ -0,0 +1,72 @@ +name: "CI tests" + +on: [ push, workflow_dispatch ] + +jobs: + build-mingw: + name: Application run on Windows Latest MinGW + runs-on: windows-latest + + steps: + - uses: actions/checkout@v4 + + - name: Create CMake cache + run: | + cmake -S . -B cmake-build-release -DCMAKE_BUILD_TYPE=Release -G "Unix Makefiles" + + - name: Build main target + shell: bash + run: | + cmake --build cmake-build-release --target SandPile || echo Built with errors + + - name: Run program + working-directory: .\cmake-build-release + run: | + .\SandPile.exe --help + + build-matrix: + name: Application run on ${{ matrix.config.name }} + runs-on: ${{ matrix.config.os }} + strategy: + fail-fast: false + matrix: + config: + - { + name: "Windows Latest MSVC", artifact: "Windows-MSVC.tar.xz", + os: windows-latest, + build_type: "Release", cc: "cl", cxx: "cl", + environment_script: "C:/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise/VC/Auxiliary/Build/vcvars64.bat" + } + - { + name: "Ubuntu Latest GCC", artifact: "Linux.tar.xz", + os: ubuntu-latest, + build_type: "Release", cc: "gcc", cxx: "g++" + } + - { + name: "macOS Latest Clang", artifact: "macOS.tar.xz", + os: macos-latest, + build_type: "Release", cc: "clang", cxx: "clang++" + } + + steps: + - uses: actions/checkout@v4 + + - name: Create CMake cache + shell: bash + run: | + cmake -S . -B cmake-build-release -DCMAKE_BUILD_TYPE=Release + + - name: Build main target + shell: bash + run: | + cmake --build cmake-build-release --target SandPile || echo "Built with errors" + + - name: Run program + shell: bash + working-directory: ./cmake-build-release + run: | + if [ "$RUNNER_OS" == "Windows" ]; then + ./SandPile.exe --help + else + ./SandPile --help + fi From 5c9a8796dd54eb666de290f44dbbce67f72f62ef Mon Sep 17 00:00:00 2001 From: bialger Date: Wed, 14 Aug 2024 16:43:31 +0300 Subject: [PATCH 05/12] Determined standard version --- CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 99ca85f..088a8d9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,6 +8,7 @@ project( ) set(CMAKE_CXX_COMPILER_VERSION 20) +set(CMAKE_CXX_STANDARD 20) add_compile_options( -Werror From cb80ca43c623fcd97b4aa687624f134652791237 Mon Sep 17 00:00:00 2001 From: bialger Date: Wed, 14 Aug 2024 16:45:50 +0300 Subject: [PATCH 06/12] Added if-clause on compilation options --- CMakeLists.txt | 52 ++++++++++++++++++++++++++------------------------ 1 file changed, 27 insertions(+), 25 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 088a8d9..90ab87e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,35 +1,37 @@ cmake_minimum_required(VERSION 3.12) project( - SandPile - VERSION 1.0 - DESCRIPTION "C++ Year 2023 Labwork3 - SandPile by bialger" - LANGUAGES C CXX + SandPile + VERSION 1.0 + DESCRIPTION "C++ Year 2023 Labwork3 - SandPile by bialger" + LANGUAGES C CXX ) - + set(CMAKE_CXX_COMPILER_VERSION 20) set(CMAKE_CXX_STANDARD 20) -add_compile_options( - -Werror - - -Wall - -Wextra - -Wpedantic - - -Wcast-align - -Wcast-qual - -Wconversion - -Wctor-dtor-privacy - -Wenum-compare - -Wfloat-equal - -Wnon-virtual-dtor - -Wold-style-cast - -Woverloaded-virtual - -Wredundant-decls - -Wsign-conversion - -Wsign-promo -) +if (CMAKE_CXX_COMPILER_ID NOT STREQUAL "MSVC") + add_compile_options( + -Werror + + -Wall + -Wextra + -Wpedantic + + -Wcast-align + -Wcast-qual + -Wconversion + -Wctor-dtor-privacy + -Wenum-compare + -Wfloat-equal + -Wnon-virtual-dtor + -Wold-style-cast + -Woverloaded-virtual + -Wredundant-decls + -Wsign-conversion + -Wsign-promo + ) +endif () add_subdirectory(lib) From 4f720178706bed599a3607849d05c7b3d821b648 Mon Sep 17 00:00:00 2001 From: bialger Date: Wed, 14 Aug 2024 16:56:36 +0300 Subject: [PATCH 07/12] Fixed main cmake --- CMakeLists.txt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 90ab87e..64dbf25 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,7 +10,11 @@ project( set(CMAKE_CXX_COMPILER_VERSION 20) set(CMAKE_CXX_STANDARD 20) -if (CMAKE_CXX_COMPILER_ID NOT STREQUAL "MSVC") +if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") + add_compile_options( + /Wall + ) +else () add_compile_options( -Werror @@ -31,6 +35,7 @@ if (CMAKE_CXX_COMPILER_ID NOT STREQUAL "MSVC") -Wsign-conversion -Wsign-promo ) + endif () add_subdirectory(lib) From cfa42a95b8d5c74bbaf6d571357da5eb6ea8ead1 Mon Sep 17 00:00:00 2001 From: bialger Date: Wed, 14 Aug 2024 16:59:27 +0300 Subject: [PATCH 08/12] Removed redundant flags --- CMakeLists.txt | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 64dbf25..8166e79 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,24 +16,7 @@ if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") ) else () add_compile_options( - -Werror - -Wall - -Wextra - -Wpedantic - - -Wcast-align - -Wcast-qual - -Wconversion - -Wctor-dtor-privacy - -Wenum-compare - -Wfloat-equal - -Wnon-virtual-dtor - -Wold-style-cast - -Woverloaded-virtual - -Wredundant-decls - -Wsign-conversion - -Wsign-promo ) endif () From 53663d36ec6693dc3ab24256a8316a41d5110996 Mon Sep 17 00:00:00 2001 From: bialger Date: Wed, 14 Aug 2024 17:02:52 +0300 Subject: [PATCH 09/12] Removed redundant flags for Windows --- CMakeLists.txt | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8166e79..9193570 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,15 +10,25 @@ project( set(CMAKE_CXX_COMPILER_VERSION 20) set(CMAKE_CXX_STANDARD 20) -if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") - add_compile_options( - /Wall - ) -else () +if (NOT WIN32) add_compile_options( -Wall - ) + -Wextra + -Wpedantic + -Wcast-align + -Wcast-qual + -Wconversion + -Wctor-dtor-privacy + -Wenum-compare + -Wfloat-equal + -Wnon-virtual-dtor + -Wold-style-cast + -Woverloaded-virtual + -Wredundant-decls + -Wsign-conversion + -Wsign-promo + ) endif () add_subdirectory(lib) From 9dc71a87717cf4cbd0b30b1e2ff3555b016aea6a Mon Sep 17 00:00:00 2001 From: bialger Date: Wed, 14 Aug 2024 17:30:06 +0300 Subject: [PATCH 10/12] Fixed Windows path output --- lib/bmp_writer/bmp_writer.cpp | 3 ++- lib/field/tsv_handler.cpp | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/bmp_writer/bmp_writer.cpp b/lib/bmp_writer/bmp_writer.cpp index afc2799..9c68185 100644 --- a/lib/bmp_writer/bmp_writer.cpp +++ b/lib/bmp_writer/bmp_writer.cpp @@ -3,6 +3,7 @@ #include #include +#include BmpWriter::BmpWriter() { width_ = 0; @@ -24,7 +25,7 @@ void BmpWriter::ExportField(char* dirname, CoordinatesField& field, file_.open(path, std::ios::out | std::ios::binary); if (!file_.is_open()) { - std::cout << "Can't open file: " << path.native() << std::endl; + std::cout << "Can't open file: " << path.string() << std::endl; return; } diff --git a/lib/field/tsv_handler.cpp b/lib/field/tsv_handler.cpp index 6941b92..c0f6af1 100644 --- a/lib/field/tsv_handler.cpp +++ b/lib/field/tsv_handler.cpp @@ -53,7 +53,7 @@ bool TsvHandler::ExportTSV(char* dirname, CoordinatesField& field, int64_t numbe std::ofstream file(path, std::ios::out); if (!file.is_open()) { - std::cout << "Can't open file: " << path.native() << std::endl; + std::cout << "Can't open file: " << path.string() << std::endl; return false; } From 6320652bea3b9c92f780266bf56a737bb6d9f7b8 Mon Sep 17 00:00:00 2001 From: bialger Date: Wed, 14 Aug 2024 18:05:06 +0300 Subject: [PATCH 11/12] Added NOMINMAX --- lib/CMakeLists.txt | 9 +++++++-- lib/basic/basic_functions.hpp | 3 +++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index f78bbcb..a9a14be 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -4,8 +4,13 @@ if(NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE Release) endif() -set(CMAKE_CXX_FLAGS_DEBUG "-g") -set(CMAKE_CXX_FLAGS_RELEASE "-O3") +if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") + set(CMAKE_CXX_FLAGS_DEBUG "/MDd") + set(CMAKE_CXX_FLAGS_RELEASE "/O2") +else () + set(CMAKE_CXX_FLAGS_DEBUG "-g") + set(CMAKE_CXX_FLAGS_RELEASE "-O3") +endif() message(STATUS "Build type: ${CMAKE_BUILD_TYPE}") diff --git a/lib/basic/basic_functions.hpp b/lib/basic/basic_functions.hpp index 4bee0f1..64d25eb 100644 --- a/lib/basic/basic_functions.hpp +++ b/lib/basic/basic_functions.hpp @@ -4,6 +4,9 @@ #include #if defined _WIN32 || defined _WIN64 || defined __CYGWIN__ +#ifndef NOMINMAX +#define NOMINMAX +#endif #include #else #define STD_OUTPUT_HANDLE 0 From a4f5d89f44880675561aed71d4e6b8f9a07894e0 Mon Sep 17 00:00:00 2001 From: bialger Date: Wed, 14 Aug 2024 18:19:44 +0300 Subject: [PATCH 12/12] Fixed workflow for MSVC --- .github/workflows/ci_tests.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci_tests.yml b/.github/workflows/ci_tests.yml index 5dc88e2..da11b68 100644 --- a/.github/workflows/ci_tests.yml +++ b/.github/workflows/ci_tests.yml @@ -66,6 +66,7 @@ jobs: working-directory: ./cmake-build-release run: | if [ "$RUNNER_OS" == "Windows" ]; then + cd Debug ./SandPile.exe --help else ./SandPile --help