added CMake file and split output line in 2 lines

This commit is contained in:
Sascha Nitsch 2025-05-31 02:35:27 +02:00
parent 71f9f726af
commit 0b328a09b5
2 changed files with 28 additions and 3 deletions

23
CMakeLists.txt Normal file
View file

@ -0,0 +1,23 @@
cmake_minimum_required(VERSION 3.10.0)
set(CMAKE_BUILD_TYPE release CACHE STRING "build mode <debug|native|generic>")
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++)

View file

@ -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 <math.h>
#include <Magick++.h>
@ -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, "</g>\n");
fprintf(fh, "<text x=\"30\" y=\"10\" style=\"font-weight:bold;font-size:60px;font-family:'DejaVu Serif'\"><tspan x=\"30\" y=\"70\">%s %i %i</tspan><tspan x=\"70\" y=\"150\"> %i %i %.2f %i</tspan><tspan x=\"30\" y=\"%i\">%i nails, %li paths, %.1f sec</tspan></text>", imageName, resolutionX, resolutionY, requestedNumberOfNails, maxIter, m_duplicateFactor, lineColor, imgHeight - 30, m_numberOfNails, path.size(), timeNeeded);
fprintf(fh, "<text x=\"30\" y=\"10\" style=\"font-weight:normal;font-size:50px;font-family:'DejaVu Serif'\"><tspan x=\"30\" y=\"70\">%s %i %i</tspan><tspan x=\"70\" y=\"130\"> %i %i %.2f %i</tspan><tspan x=\"30\" y=\"%i\">%i nails, %li segments,</tspan><tspan x=\"30\" y=\"%i\">%.1f sec</tspan></text>", imageName, resolutionX, resolutionY, requestedNumberOfNails, maxIter, m_duplicateFactor, lineColor, imgHeight - 70, m_numberOfNails, path.size(), imgHeight - 10, timeNeeded);
fprintf(fh, "</svg>");
fclose(fh);
// cleanup
free(m_targetState);
free(m_currentState);
free(m_usedpaths);
path.clear();
m_linesFromSource.clear();
return 0;