Skip to content

Commit 4cb48bd

Browse files
author
vrobles
committed
CMake + format
1 parent 9791783 commit 4cb48bd

7 files changed

+94
-65
lines changed

CMakeLists.txt

+27-4
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,38 @@ set(BOOST_LIBS program_options)
44
set(LIBS_DIR third_party/boost/stage/lib/)
55
set(BOOST_REQUIRED_VERSION 1.62.0)
66
set(EXE_NAME "packer")
7+
8+
# Compiler flags
9+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wfatal-errors -std=c++11 -fopenmp")
10+
11+
# Options
712
option(FORCE_UNPACK "Boost unpack forcing" 0) #Set to 1 to force local installation of Boost (ensure that it will take priority)
8-
option(ENABLE_DISPLAY "Display build" 0)
13+
option(DISPLAY "Display build" 0)
14+
option(DEBUG "Enable debug compilation flags" 0)
915

1016
set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/CMakeModules)
1117

18+
# Testing enabling
1219
if (NOT (DEFINED target-os AND target-os STREQUAL "windows"))
1320
enable_testing()
1421
endif()
1522

16-
if(${ENABLE_DISPLAY})
23+
# SFML Enabling
24+
if(${DISPLAY})
1725
message(STATUS "Will build with display support")
1826
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DENABLE_DISPLAY")
1927
else ()
2028
message(STATUS "Will build WITHOUT display support")
2129
endif ()
2230

23-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wfatal-errors -std=c++11 -O0 -g -fopenmp")
31+
# Debug enabling (use it with cmake -DDEBUG=1 ..)
32+
if(${DEBUG})
33+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0 -g")
34+
else ()
35+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
36+
endif ()
37+
38+
# Coverage build (use it with cmake -DCMAKE_BUILD_TYPE=coverage ..)
2439
if(CMAKE_BUILD_TYPE STREQUAL "coverage")
2540
SET(CMAKE_CXX_FLAGS "-g -O0 -pg -fprofile-arcs -ftest-coverage")
2641
SET(CMAKE_C_FLAGS "-g -O0 -pg -fprofile-arcs -ftest-coverage")
@@ -35,6 +50,7 @@ endif()
3550
include_directories(SYSTEM ${CMAKE_SOURCE_DIR}/third_party)
3651
include_directories(${CMAKE_SOURCE_DIR}/src)
3752

53+
# Boost finding and / or unpacking
3854
find_package(Boost ${BOOST_REQUIRED_VERSION} COMPONENTS ${BOOST_LIBS})
3955
if(NOT Boost_FOUND OR ${FORCE_UNPACK})
4056
find_package(Boost)
@@ -89,22 +105,27 @@ else ()
89105
include_directories(${Boost_INCLUDE_DIRS})
90106
link_directories(${Boost_LIBRARY_DIRS})
91107
endif ()
108+
# End of boost wizardry
92109

110+
# Add other targets
93111
add_subdirectory(doc)
94112
add_subdirectory(src)
95113
#add_subdirectory(test)
96114
add_executable(packer src/main.cpp)
97115

98116
target_link_libraries(packer packer_lib)
99-
if (${ENABLE_DISPLAY})
117+
if (${DISPLAY})
100118
target_link_libraries(packer ${SFML_LIBRARIES})
101119
endif ()
102120

121+
# Windows cross-compilation
103122
if (DEFINED target-os AND target-os STREQUAL "windows")
104123
message(STATUS "cross compilation")
105124
target_link_libraries(${EXE_NAME} boost_program_options-mt-s)
106125
set(EXE_NAME_PLUGIN "${EXE_NAME}.exe")
126+
# Normal compilation
107127
else ()
128+
# Fome installing
108129
message(STATUS "Classic compilation")
109130
target_link_libraries(${EXE_NAME} boost_program_options)
110131
set(EXE_NAME_PLUGIN "${EXE_NAME}")
@@ -124,6 +145,8 @@ else ()
124145
DESTINATION ~/.config/inkscape/extensions/
125146
PERMISSIONS OWNER_READ OWNER_WRITE)
126147
endif ()
148+
149+
# Copy runtime files to the build directory
127150
configure_file(${CMAKE_SOURCE_DIR}/extensions/packer.inx ${CMAKE_BINARY_DIR}/packer.inx @ONLY)
128151
configure_file(${CMAKE_SOURCE_DIR}/extensions/packer.py ${CMAKE_BINARY_DIR}/packer.py @ONLY)
129152
file(COPY ${CMAKE_SOURCE_DIR}/font.ttf DESTINATION ${CMAKE_BINARY_DIR})

src/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ add_library(packer_lib STATIC
2121
solver/ProbaSolver.cpp
2222
solver/ScanlineSolver.cpp)
2323

24-
if (${ENABLE_DISPLAY})
24+
if (${DISPLAY})
2525
find_package(SFML 2.0 REQUIRED system window graphics)
2626
target_link_libraries(packer_lib ${SFML_LIBRARIES})
2727
endif ()

src/Layout.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,15 @@ const Shape& Layout::operator[](unsigned n) const {
8383
* @brief Destructor, frees _s and _q if needed
8484
*/
8585
Layout::~Layout() {
86-
cerr << "Destructor : " << this << endl;
8786
if (_s != nullptr)
8887
delete _s;
89-
_s = nullptr;
88+
89+
_s = nullptr;
9090

9191
if (_q != nullptr)
9292
delete _q;
93-
_q = nullptr;
93+
94+
_q = nullptr;
9495
}
9596

9697
/**

src/Shape.hpp

+11-11
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,17 @@ class Shape {
3939
}
4040
Shape(Point P1, Point P2, unsigned i1, unsigned i2, unsigned id) : _oldP1(P1),
4141
_oldP2(P2), _indexP1(i1), _indexP2(i2), _id(id) {}
42-
virtual Shape& operator=(const Shape& s) {
43-
_multiP = s._multiP;
44-
_oldP1 = s._oldP1;
45-
_oldP2 = s._oldP2;
46-
_indexP1 = s._indexP1;
47-
_indexP2 = s._indexP2;
48-
_id = s._id;
49-
_out = s._out;
50-
return *this;
51-
}
52-
virtual ~Shape(){}
42+
virtual Shape& operator=(const Shape& s) {
43+
_multiP = s._multiP;
44+
_oldP1 = s._oldP1;
45+
_oldP2 = s._oldP2;
46+
_indexP1 = s._indexP1;
47+
_indexP2 = s._indexP2;
48+
_id = s._id;
49+
_out = s._out;
50+
return *this;
51+
}
52+
virtual ~Shape() {}
5353

5454
//Getters - Setters
5555
unsigned getID() const;

src/quadtree/InnerQuadTree.cpp

+18-15
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,24 @@ void InnerQuadTree::copy(const InnerQuadTree& q) {
2727
size = q.size;
2828

2929
if (q.q1 != nullptr)
30-
q1 = new InnerQuadTree(*q.q1);
31-
else
32-
q1 = nullptr;
33-
if (q.q2 != nullptr)
34-
q2 = new InnerQuadTree(*q.q2);
35-
else
36-
q2 = nullptr;
37-
if (q.q3 != nullptr)
38-
q3 = new InnerQuadTree(*q.q3);
39-
else
40-
q3 = nullptr;
41-
if (q.q4 != nullptr)
42-
q4 = new InnerQuadTree(*q.q4);
43-
else
44-
q4 = nullptr;
30+
q1 = new InnerQuadTree(*q.q1);
31+
else
32+
q1 = nullptr;
33+
34+
if (q.q2 != nullptr)
35+
q2 = new InnerQuadTree(*q.q2);
36+
else
37+
q2 = nullptr;
38+
39+
if (q.q3 != nullptr)
40+
q3 = new InnerQuadTree(*q.q3);
41+
else
42+
q3 = nullptr;
43+
44+
if (q.q4 != nullptr)
45+
q4 = new InnerQuadTree(*q.q4);
46+
else
47+
q4 = nullptr;
4548

4649
x1 = q.x1;
4750
y1 = q.y1;

src/quadtree/QuadTree.cpp

+31-29
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ static float pi = boost::math::constants::pi<float>();
2323
* @param q
2424
*/
2525
void QuadTree::copy(const QuadTree& q) {
26-
trees = new InnerQuadTree* [quadsNumber];
26+
trees = new InnerQuadTree* [quadsNumber];
2727

28-
for (unsigned i=0; i< quadsNumber; i++)
29-
trees[i] = new InnerQuadTree(*(q.trees[i]));
28+
for (unsigned i = 0; i < quadsNumber; i++)
29+
trees[i] = new InnerQuadTree(*(q.trees[i]));
3030

3131
treesOffset = q.treesOffset;
32-
currentTree = q.currentTree;
32+
currentTree = q.currentTree;
3333
_totalX = q._totalX;
3434
_totalY = q._totalY;
3535
_maxDepth = q._maxDepth;
@@ -50,45 +50,47 @@ QuadTree::QuadTree(const QuadTree& q) : Shape(q) {
5050
* @return the quadtree copied
5151
*/
5252
QuadTree& QuadTree::operator=(const QuadTree& q) {
53-
if (this != &q) {
54-
destroy();
55-
Shape::operator=(q);
53+
if (this != &q) {
54+
destroy();
55+
Shape::operator=(q);
5656
copy(q);
5757
}
5858

5959
return *this;
6060
}
6161

6262
QuadTree& QuadTree::operator=(QuadTree&& q) {
63-
if (this != &q) {
64-
destroy();
65-
q.trees = nullptr;
66-
trees = q.trees;
67-
treesOffset = q.treesOffset;
68-
currentTree = q.currentTree;
69-
_totalX = q._totalX;
70-
_totalY = q._totalY;
71-
_maxDepth = q._maxDepth;
72-
precision = q.precision;
63+
if (this != &q) {
64+
destroy();
65+
q.trees = nullptr;
66+
trees = q.trees;
67+
treesOffset = q.treesOffset;
68+
currentTree = q.currentTree;
69+
_totalX = q._totalX;
70+
_totalY = q._totalY;
71+
_maxDepth = q._maxDepth;
72+
precision = q.precision;
7373
}
7474

7575
return *this;
7676
}
7777

7878
void QuadTree::destroy() {
79-
if (trees != nullptr) {
80-
for (unsigned i=0; i<quadsNumber; i++)
81-
delete trees[i];
82-
delete[] trees;
83-
}
84-
trees = nullptr;
79+
if (trees != nullptr) {
80+
for (unsigned i = 0; i < quadsNumber; i++)
81+
delete trees[i];
82+
83+
delete[] trees;
84+
}
85+
86+
trees = nullptr;
8587
}
8688

8789
/**
8890
* @brief destructor
8991
*/
9092
QuadTree::~QuadTree() {
91-
destroy();
93+
destroy();
9294
}
9395

9496
/**
@@ -113,7 +115,7 @@ QuadTree::QuadTree(MultiPolygon& mult, float precision, unsigned id)
113115
: Shape(mult, id), trees(nullptr), precision(precision) {
114116
float rotationAngle = 360.f / quadsNumber;
115117
float currentAngle = 0.f;
116-
trees = new InnerQuadTree*[quadsNumber];
118+
trees = new InnerQuadTree*[quadsNumber];
117119
treesOffset.reserve(quadsNumber);
118120
// Put the shape at the (0,0) point
119121
Box preEnvelop;
@@ -160,9 +162,9 @@ QuadTree::QuadTree(MultiPolygon& mult, float precision, unsigned id)
160162
bitmap bmap(mult, size, size);
161163
// QuadTree size is shape envelop size
162164
trees[i] = new InnerQuadTree(envelop.min_corner().x() + _totalX,
163-
envelop.min_corner().y() + _totalY,
164-
envelop.max_corner().x() + _totalX, envelop.max_corner().y() + _totalY,
165-
bmap, 0, 0, size, 0);
165+
envelop.min_corner().y() + _totalY,
166+
envelop.max_corner().x() + _totalX, envelop.max_corner().y() + _totalY,
167+
bmap, 0, 0, size, 0);
166168
}
167169
}
168170

@@ -230,7 +232,7 @@ std::ostream& operator <<(std::ostream& s, const QuadTree& q) {
230232
s << "Absolute Position : (" << q._totalX << "," << q._totalY << ") " << endl;
231233
s << " - Trees : " << std::endl;
232234

233-
for (unsigned i=0; i<q.quadsNumber; i++)
235+
for (unsigned i = 0; i < q.quadsNumber; i++)
234236
s << *(q.trees[i]) << std::endl;
235237

236238
return s;

src/quadtree/QuadTree.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ class QuadTree : public Shape {
2525

2626
private:
2727
void copy(const QuadTree&);
28-
void destroy();
28+
void destroy();
2929
public:
3030
QuadTree(const QuadTree&); //copy operator
3131
QuadTree& operator=(const QuadTree&); //assignment operator
32-
QuadTree& operator=(QuadTree&& q);
32+
QuadTree& operator=(QuadTree&& q);
3333
~QuadTree();
3434

3535
public:

0 commit comments

Comments
 (0)