Skip to content

Commit 0f2d313

Browse files
committed
Build scripts was significantly improvement: added separate targets for unit tests, microbenchmarks and examples; added install target; replace strong warning options from main target into tests. Reflect changes into README and travis-ci build script.
1 parent 41efdf0 commit 0f2d313

File tree

6 files changed

+231
-163
lines changed

6 files changed

+231
-163
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ before_script:
2121
- cmake -DCMAKE_BUILD_TYPE=Debug ${BUILD_DIR}/..
2222
script:
2323
- cd ${BUILD_DIR}
24-
- make
24+
- make && make tests
2525
- cd ${BUILD_DIR}/tests && ./munkrestest > /dev/null
2626
after_success:
2727
- cd ${BUILD_DIR}

CMakeLists.txt

Lines changed: 46 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -4,108 +4,48 @@ project (munkres-cpp)
44
set (munkres-cpp_VERSION_MAJOR 0)
55
set (munkres-cpp_VERSION_MINOR 1)
66

7-
8-
# Getting external tools which used by the Project.
9-
10-
# Enable the ExternalProject_Add directive.
11-
include (ExternalProject)
12-
13-
# Framework for writing tests.
14-
ExternalProject_Add (
15-
googletest
16-
GIT_REPOSITORY "https://github.com/google/googletest.git"
17-
UPDATE_COMMAND cd ${PROJECT_BINARY_DIR}/googletest && mv googletest gtest && mv gtest/googletest .
18-
CMAKE_ARGS "-DCMAKE_BUILD_TYPE=Release"
19-
SOURCE_DIR "${PROJECT_BINARY_DIR}/googletest/googletest"
20-
BINARY_DIR "${PROJECT_BINARY_DIR}/googletest/googletest"
21-
INSTALL_COMMAND ""
22-
TEST_COMMAND ""
23-
)
24-
set (GTEST_ROOT "${PROJECT_BINARY_DIR}/googletest/googletest")
25-
set (GTEST_FOUND true)
26-
set (GTEST_INCLUDE_DIRS "${PROJECT_BINARY_DIR}/googletest/googletest/include")
27-
set (GTEST_LIBRARIES "${PROJECT_BINARY_DIR}/googletest/googletest/libgtest.a")
28-
set (GTEST_MAIN_LIBRARIES "${PROJECT_BINARY_DIR}/googletest/googletest/libgtest_main.a")
29-
set (GTEST_BOTH_LIBRARIES ${GTEST_LIBRARIES} ${GTEST_MAIN_LIBRARIES})
30-
31-
# Microbenchmarking tools.
32-
# Google Benchmark.
33-
ExternalProject_Add (
34-
benchmark
35-
GIT_REPOSITORY "https://github.com/google/benchmark.git"
36-
CMAKE_ARGS "-DBENCHMARK_ENABLE_TESTING=OFF;-DCMAKE_BUILD_TYPE=Release"
37-
SOURCE_DIR "${PROJECT_BINARY_DIR}/benchmark"
38-
BINARY_DIR "${PROJECT_BINARY_DIR}/benchmark"
39-
INSTALL_COMMAND ""
40-
TEST_COMMAND ""
41-
)
42-
set (GBENCHMARK_FOUND true)
43-
set (GBENCHMARK_INCLUDE_DIR "${PROJECT_BINARY_DIR}/benchmark/include")
44-
set (GBENCHMARK_LIBRARY "${PROJECT_BINARY_DIR}/benchmark/src/libbenchmark.a")
45-
46-
# Celero.
47-
ExternalProject_Add (
48-
Celero
49-
GIT_REPOSITORY "https://github.com/DigitalInBlue/Celero.git"
50-
CMAKE_ARGS "-DCELERO_ENABLE_EXPERIMENTS=OFF;-DCMAKE_BUILD_TYPE=Release"
51-
SOURCE_DIR "${PROJECT_BINARY_DIR}/Celero"
52-
BINARY_DIR "${PROJECT_BINARY_DIR}/CeleroBuild"
53-
INSTALL_COMMAND ""
54-
TEST_COMMAND ""
55-
)
56-
set (CELERO_FOUND true)
57-
set (CELERO_INCLUDE_DIR "${PROJECT_BINARY_DIR}/Celero/include")
58-
set (CELERO_LIBRARY "${PROJECT_BINARY_DIR}/CeleroBuild/libcelero.so")
59-
60-
# Hayai.
61-
ExternalProject_Add (
62-
hayai
63-
GIT_REPOSITORY "https://github.com/nickbruun/hayai.git"
64-
SOURCE_DIR "${PROJECT_BINARY_DIR}/hayai"
65-
BUILD_COMMAND ""
66-
INSTALL_COMMAND ""
67-
TEST_COMMAND ""
68-
)
69-
set (HAYAI_FOUND true)
70-
set (HAYAI_INCLUDE_DIR "${PROJECT_BINARY_DIR}/hayai/src")
71-
72-
737
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
748
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra")
75-
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wmissing-include-dirs -Wundef -Wfloat-equal -Wunsafe-loop-optimizations")
76-
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wdouble-promotion -Winit-self -Wvector-operation-performance -Wnoexcept -Weffc++ -Wstrict-null-sentinel")
77-
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Woverloaded-virtual -Wsign-promo")
78-
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wvla -Winvalid-pch -Winline -Wredundant-decls")
79-
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wlogical-op -Wcast-align")
80-
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wcast-qual -Wpointer-arith -Wtrampolines")
81-
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wold-style-cast")
82-
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wzero-as-null-pointer-constant")
839
set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS} -O0 -ggdb3 -DDEBUG")
8410
set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} -O3")
8511

86-
8712
include_directories (${PROJECT_SOURCE_DIR}/src)
8813

14+
# Sources.
15+
set (
16+
MunkresCppLib_SOURCES
17+
${PROJECT_SOURCE_DIR}/src/munkres.cpp
18+
)
19+
20+
# Headers.
21+
set (
22+
MunkresCppLib_HEADERS
23+
${PROJECT_SOURCE_DIR}/src/matrix.h
24+
${PROJECT_SOURCE_DIR}/src/matrix.cpp
25+
${PROJECT_SOURCE_DIR}/src/munkres.h
26+
)
8927

9028
# Library.
91-
set (MunkresCppLib_SOURCES ${PROJECT_SOURCE_DIR}/src/munkres.cpp)
92-
add_library (munkres SHARED STATIC ${MunkresCppLib_SOURCES})
29+
add_library (
30+
munkres STATIC
31+
${MunkresCppLib_SOURCES}
32+
)
33+
34+
install (TARGETS munkres DESTINATION lib PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ)
35+
install (FILES ${MunkresCppLib_HEADERS} DESTINATION include PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ)
9336

9437

9538
# Binary example
9639
set (MunkresCppBin_SOURCES ${PROJECT_SOURCE_DIR}/examples/main.cpp)
97-
add_executable (munkres.bin ${MunkresCppBin_SOURCES})
40+
add_executable (munkres.bin EXCLUDE_FROM_ALL ${MunkresCppBin_SOURCES})
9841
target_link_libraries (munkres.bin munkres)
42+
add_custom_target (example)
43+
add_dependencies (example munkres.bin)
9944

10045

101-
# Static code analyse.
102-
set (CppCheck_REPORT ${PROJECT_BINARY_DIR}/cppcheck.report)
103-
add_custom_command (
104-
OUTPUT ${CppCheck_REPORT}
105-
COMMAND cppcheck ${MunkresCppLib_SOURCES} ${MunkresCppBin_SOURCES} -I${PROJECT_SOURCE_DIR}/src -I${PROJECT_SOURCE_DIR} --enable=all --force --inconclusive > cppcheck.report 2>&1
106-
)
107-
add_custom_target (cppcheck DEPENDS ${CppCheck_REPORT})
108-
set_directory_properties (PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES ${CppCheck_REPORT})
46+
# Enable the ExternalProject_Add directive.
47+
# Which used for getting external tools for the Project.
48+
include (ExternalProject)
10949

11050

11151
# Testing
@@ -115,3 +55,23 @@ add_subdirectory (tests)
11555
# Benchmarking
11656
add_subdirectory (benchmarks)
11757

58+
59+
# Custom target to build everything.
60+
add_custom_target (full)
61+
add_dependencies (
62+
full
63+
munkres
64+
example
65+
tests
66+
benchmarks
67+
)
68+
69+
70+
# Static code analyse.
71+
set (CppCheck_REPORT ${PROJECT_BINARY_DIR}/cppcheck.report)
72+
add_custom_command (
73+
OUTPUT ${CppCheck_REPORT}
74+
COMMAND cppcheck ${MunkresCppLib_SOURCES} ${MunkresCppBin_SOURCES} -I${PROJECT_SOURCE_DIR}/src -I${PROJECT_SOURCE_DIR} --enable=all --force --inconclusive > cppcheck.report 2>&1
75+
)
76+
add_custom_target (cppcheck DEPENDS ${CppCheck_REPORT})
77+
set_directory_properties (PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES ${CppCheck_REPORT})

README.md

Lines changed: 72 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -17,98 +17,124 @@ Licensed under the GPLv2. See the file COPYING for details.
1717

1818

1919

20-
Usage
21-
-----
20+
Requires
21+
--------
2222

23-
```$ git clone https://github.com/saebyn/munkres-cpp.git```
24-
25-
Requires:
23+
For using:
2624
- C++ compiler with C++11 support.
2725

28-
To usage code it's just required add ```src/munrkes.cpp``` file into your project.
26+
27+
For development:
28+
- [GCC](https://gcc.gnu.org/) (tested on 4.6.3, 4.8);
29+
- [GNU Make](https://www.gnu.org/software/make/);
30+
- [CMake](http://www.cmake.org/) (2.8.12);
31+
- the test suite requires the [Google C++ Test Framework](http://code.google.com/p/googletest/);
32+
- microbenchmaring requires [Benchmark](https://github.com/google/benchmark), [Celero](https://github.com/DigitalInBlue/Celero), [Hayai](https://github.com/nickbruun/hayai) and [gprof](http://www.gnu.org/software/binutils/);
33+
- code coverage requires [gcov](https://gcc.gnu.org/onlinedocs/gcc/Gcov.html) and lcov;
34+
- static code analyzis required [cppcheck](https://github.com/danmar/cppcheck).
35+
36+
37+
38+
Portability
39+
-----------
40+
41+
The project is developing under GNU/Linux OS with gcc compiler and usualy not tested under other OS and compilers.
42+
But in the project not used OS or compiler specific features (types, attributes, etc) so it's expected that the project will be normally work under other platforms.
43+
44+
45+
46+
Usage
47+
-----
48+
49+
To use the project the following steps are required:
50+
- download: ```$ git clone https://github.com/saebyn/munkres-cpp.git && cd munkres-cpp```
51+
- build: ```$ mkdir build && cd build $$ cmake .. && make```
52+
- install: ``` $ make install```
2953

3054

3155

3256
Example
3357
-------
3458

35-
TBD.
59+
TBD
3660

3761

3862

3963
Development
4064
-----------
4165

42-
Requires:
43-
- [GCC](https://gcc.gnu.org/) (tested on 4.6.3, 4.8);
44-
- [GNU Make](https://www.gnu.org/software/make/);
45-
- [CMake](http://www.cmake.org/) (2.8.12);
46-
- the test suite requires the [Google C++ Test Framework](http://code.google.com/p/googletest/);
47-
- microbenchmaring requires [Benchmark](https://github.com/google/benchmark), [Celero](https://github.com/DigitalInBlue/Celero), [Hayai](https://github.com/nickbruun/hayai) and [gprof](http://www.gnu.org/software/binutils/);
48-
- code coverage requires [gcov](https://gcc.gnu.org/onlinedocs/gcc/Gcov.html) and lcov;
49-
- static code analyzis required [cppcheck](https://github.com/danmar/cppcheck).
50-
51-
```
52-
$ git clone https://github.com/saebyn/munkres-cpp.git
53-
$ cd munkres-cpp
54-
$ mkdir build && cd build
55-
$ cmake -DCMAKE_BUILD_TYPE={Debug, Release, etc}
56-
$ make
57-
```
58-
etc...
66+
For development purpose in the project implemented a variety of build targets.
67+
All of them help to continuously check correctness of algorithm implementation, performance, memory management, etc.
5968

60-
Lunch unit tests:
69+
Launch of unit tests.
70+
The project contains unit tests to build and launch it performs the following steps:
6171
```
72+
$ git clone https://github.com/saebyn/munkres-cpp.git
73+
$ cd munkres-cpp
6274
$ mkdir build && cd build
6375
$ cmake -DCMAKE_BUILD_TYPE=Debug ..
64-
$ make
76+
$ make tests
6577
$ tests/munkrestest
6678
```
6779

68-
Lunck code coverage analyze:
80+
81+
Lunch code coverage analyze.
82+
To get correct report unit tests must be compiled in debug mode.
6983
```
70-
$ <build and lunch unit tests>
84+
$ <build and lunch unit tests>
7185
$ make coverage
7286
$ firefox coverage/index.html &
7387
```
7488

75-
Lunch memory profiler:
89+
90+
Lunch memory profiler.
91+
As far unit tests call all functions which implement algorithm this is appropriate way to check memory management by using valgrind during performing unit tests.
7692
```
77-
$ mkdir build && cd build
78-
$ cmake -DCMAKE_BUILD_TYPE=Debug ..
79-
$ make
93+
$ <build unit tests>
8094
$ valgrind tests/munkrestest
8195
```
8296

83-
Lunch microbenchmark tests:
97+
98+
Lunch microbenchmarks.
99+
Buildning microbenchmarks:
84100
```
101+
$ git clone https://github.com/saebyn/munkres-cpp.git
102+
$ cd munkres-cpp
85103
$ mkdir build && cd build
86104
$ cmake -DCMAKE_BUILD_TYPE=Release ..
87-
$ make
105+
$ make benchmarks
106+
```
107+
To get comparable results it's required to generate data set wich will be used for all benchmarks:
108+
```
88109
$ benchmarks/tools/generator/matrixgenerator.bin {dim_1 dim_2 ... dim_n}
110+
```
111+
Where every ```dim_x``` parameter generate square matrix dith ```dim_x``` dimension.
112+
To launch microbenchmark performs any following command:
113+
```
89114
$ benchmarks/tests/munkresbenchmark_celero.bin
90115
$ benchmarks/tests/munkresbenchmark_google.bin
91116
$ benchmarks/tests/munkresbenchmark_hayai.bin
92117
$ benchmarks/tests/munkresbenchmark_rdtsc.bin
93118
```
94119

95-
Lunch static code analyze tests:
96-
```
97-
$ make cppcheck
98-
```
99120

100-
Lunch performance analyze:
121+
Lunch performance analyze.
101122
```
102-
$ mkdir build && cd build
103-
$ cmake -DCMAKE_BUILD_TYPE=Release ..
104-
$ make
105-
$ benchmarks/tools/generator/matrixgenerator.bin {dim_1 dim_2 ... dim_n}
123+
$ <build microbenchmarks and generate data set>
106124
$ benchmarks/tests/munkresbenchmark_gprof.bin
107125
$ gprof benchmarks/tests/munkresbenchmark_gprof.bin gmon.out -p -b
108-
```
126+
```
127+
128+
129+
Lunch static code analyze.
130+
```
131+
$ make cppcheck
132+
```
133+
134+
135+
Lunch code formatter:
136+
TBD
109137

110-
Lunch code formatter:
111-
TBD
112138

113139

114140
Bug reporting and work to be done

0 commit comments

Comments
 (0)