From 0b328a09b55ff4a590e9ed59906f12f8d7f61eb9 Mon Sep 17 00:00:00 2001 From: Sascha Nitsch Date: Sat, 31 May 2025 02:35:27 +0200 Subject: [PATCH] added CMake file and split output line in 2 lines --- CMakeLists.txt | 23 +++++++++++++++++++++++ main.cpp | 8 +++++--- 2 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..cdcea6a --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,23 @@ +cmake_minimum_required(VERSION 3.10.0) +set(CMAKE_BUILD_TYPE release CACHE STRING "build mode ") +cmake_policy(SET CMP0017 NEW) +project(StringArt) +if (CMAKE_BUILD_TYPE STREQUAL "debug") + message("building debug version") + add_definitions(-Wall -Wextra -O0 -g) +elseif (CMAKE_BUILD_TYPE STREQUAL "native") + message("building release version optimized for local CPU") + add_definitions(-Wall -Wextra -O3 -march=native -mtune=native) +else() + message("building generic release version") + add_definitions(-Wall -Wextra -O3) +endif() + +add_definitions(-std=c++20) +set (CMAKE_CXX_STANDARD 20) +set (CMAKE_C_STANDARD 20) + +find_package(ImageMagick COMPONENTS Magick++) + +add_executable(stringart main.cpp) +target_link_libraries(stringart ImageMagick::Magick++) diff --git a/main.cpp b/main.cpp index 915128b..202234f 100644 --- a/main.cpp +++ b/main.cpp @@ -10,7 +10,8 @@ * */ // compile with -/// g++ --std=c++20 -march=native`Magick++-config --cxxflags --cppflags` -Wall -Werror -o main main.cpp -O3 `Magick++-config --ldflags --libs` +/// g++ --std=c++20 -march=native `Magick++-config --cxxflags --cppflags` -Wall -Werror -o main main.cpp -O3 `Magick++-config --ldflags --libs` +/// or use cmake: mkdir build;cd build;cmake ..;make #include #include @@ -58,6 +59,7 @@ class Main { /// mutex for finished motification std::mutex m_finishedMutex; + /// finished notification condition std::binary_semaphore m_finishedNotification{0}; @@ -316,6 +318,7 @@ class Main { m_worker[i].join(); } free(m_lineResult); + free(m_usedpaths); } /// \brief main function @@ -505,13 +508,12 @@ class Main { gettimeofday(&tv2, NULL); float timeNeeded = (tv2.tv_sec - tv1.tv_sec) + (tv2.tv_usec - tv1.tv_usec) / 1000000.0; fprintf(fh, "\n"); - fprintf(fh, "%s %i %i %i %i %.2f %i%i nails, %li paths, %.1f sec", imageName, resolutionX, resolutionY, requestedNumberOfNails, maxIter, m_duplicateFactor, lineColor, imgHeight - 30, m_numberOfNails, path.size(), timeNeeded); + fprintf(fh, "%s %i %i %i %i %.2f %i%i nails, %li segments,%.1f sec", imageName, resolutionX, resolutionY, requestedNumberOfNails, maxIter, m_duplicateFactor, lineColor, imgHeight - 70, m_numberOfNails, path.size(), imgHeight - 10, timeNeeded); fprintf(fh, ""); fclose(fh); // cleanup free(m_targetState); free(m_currentState); - free(m_usedpaths); path.clear(); m_linesFromSource.clear(); return 0;