-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
208 lines (174 loc) · 7.95 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
cmake_minimum_required(VERSION 3.23)
project(Proj_cpp_2022)
# At least c++17 is required
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(TARGET_NAME "Thundercpp")
set(SRC
src/images.cpp
src/series.cpp)
set(LIB
include/ndarray.hpp
include/images.hpp
include/series.hpp)
add_library(thunder ${SRC})
target_include_directories(thunder PUBLIC include)
add_compile_options(-std=c++17 -Wall -Wextra -Wpedantic -Werror)
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
include_directories(SYSTEM /usr/local/Cellar/libpng/1.6.37/include/
/usr/local/Cellar/libtiff/4.4.0_1/include/
/usr/local/Cellar/jpeg/9e/include/)
find_library(TIFF_LIB tiff HINTS /usr/local/Cellar/libtiff/4.4.0_1/lib)
find_library(PNG_LIB png HINTS /usr/local/Cellar/libpng/1.6.37/lib)
find_library(JPEG_LIB jpeg HINTS /usr/local/Cellar/jpeg/9e/lib)
else ()
set(TIFF_LIB "tiff")
set(PNG_LIB "png")
set(JPEG_LIB "jpeg")
endif ()
add_executable(${TARGET_NAME} main.cpp)
target_link_libraries(${TARGET_NAME} PUBLIC thunder ${TIFF_LIB} ${PNG_LIB} ${JPEG_LIB})
# Docs
add_custom_target(
doc
COMMAND doxygen ../Doxyfile
)
# Testing
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
#add_subdirectory(third_party/Catch2)
set(CATCH_INCLUDE_DIR third_party/catch)
add_library(Catch2 INTERFACE)
target_include_directories(Catch2 INTERFACE ${CATCH_INCLUDE_DIR})
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
set(CATCH_INCLUDE_DIR third_party)
else ()
set(CATCH_INCLUDE_DIR third_party/catch2)
endif ()
target_include_directories(Catch2 INTERFACE ${CATCH_INCLUDE_DIR})
target_link_libraries(thunder PUBLIC gcov)
target_compile_options(thunder PUBLIC "--coverage" "-fprofile-arcs" "-ftest-coverage")
set(TEST_SRC
test/ndarray_test.cpp
test/series_test.cpp
test/images_test.cpp)
set(TEST_TARGET "test_Thundercpp")
add_library(test_sources OBJECT ${TEST_SRC})
target_link_libraries(test_sources Catch2 )
target_include_directories(test_sources PUBLIC include)
target_compile_options(test_sources PUBLIC "--coverage" "-fprofile-arcs" "-ftest-coverage")
add_executable(${TEST_TARGET} test/test.cpp )
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
include_directories(SYSTEM /usr/local/Cellar/libpng/1.6.37/include/
/usr/local/Cellar/libtiff/4.4.0_1/include/
/usr/local/Cellar/jpeg/9e/include/)
find_library(TIFF_LIB tiff HINTS /usr/local/Cellar/libtiff/4.4.0_1/lib)
find_library(PNG_LIB png HINTS /usr/local/Cellar/libpng/1.6.37/lib)
find_library(JPEG_LIB jpeg HINTS /usr/local/Cellar/jpeg/9e/lib)
target_link_libraries(${TEST_TARGET} PRIVATE Catch2 test_sources ${TIFF_LIB} ${PNG_LIB} ${JPEG_LIB})
else ()
target_link_libraries(${TEST_TARGET} PUBLIC Catch2 gcov test_sources ${TIFF_LIB} ${PNG_LIB} ${JPEG_LIB})
target_compile_options(${TEST_TARGET} PUBLIC "-g" "--coverage")
endif ()
target_compile_options(${TEST_TARGET} PUBLIC "-g" "--coverage")
#------------------
# COVERAGE SECTION
#------------------
add_custom_target(coverage
COMMAND mkdir -p ../doc/coverage
COMMAND lcov -c -i -d .. -o baseline.info --rc lcov_branch_coverage=1
COMMAND ./test_Thundercpp
COMMAND lcov --capture --directory .. --output-file coverage.info --rc lcov_branch_coverage=1
COMMAND lcov -a baseline.info -a coverage.info -o coverage_results.info --rc lcov_branch_coverage=1
COMMAND lcov --extract coverage_results.info '*${PROJECT_SOURCE_DIR}/include/*' '*${PROJECT_SOURCE_DIR}/src/*' --output-file ../doc/coverage/coverage_results.info --rc lcov_branch_coverage=1
COMMAND lcov --list ../doc/coverage/coverage_results.info --rc lcov_branch_coverage=1
COMMAND genhtml -o ../doc/coverage ../doc/coverage/coverage_results.info --rc lcov_branch_coverage=1
)
#------------------
# VALGRIND SECTION
#------------------
find_program(VALGRIND valgrind)
if (VALGRIND)
add_custom_target(valgrind
COMMAND ${CMAKE_COMMAND} --build . --target ${TARGET_NAME}
COMMAND ${VALGRIND} --leak-check=full --show-leak-kinds=all
--track-fds=yes --track-origins=yes ./${TARGET_NAME}
COMMAND ${VALGRIND} --tool=drd --show-stack-usage=yes ./${TARGET_NAME}
)
endif ()
#------------------
# SANITIZERS SECTION
#------------------
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
target_link_libraries(${TARGET_NAME} PRIVATE stdc++)
endif()
set(SANITIZERS
-fsanitize=address
-fsanitize=undefined
-fno-sanitize-recover=all
-fsanitize=float-divide-by-zero
-fsanitize=float-cast-overflow
-fno-sanitize=null
-fno-sanitize=alignment
-fno-omit-frame-pointer
)
target_compile_options(${TEST_TARGET} PUBLIC ${SANITIZERS})
target_compile_options(${TARGET_NAME} PUBLIC ${SANITIZERS})
target_compile_options(test_sources PUBLIC ${SANITIZERS})
target_compile_options(thunder PUBLIC ${SANITIZERS})
target_link_options(${TEST_TARGET} PUBLIC ${SANITIZERS})
target_link_options(${TARGET_NAME} PUBLIC ${SANITIZERS})
target_link_options(test_sources PUBLIC ${SANITIZERS})
target_link_options(thunder PUBLIC ${SANITIZERS})
#------------------
# STATIC ANALYZER SECTION
#------------------
find_program(SCAN scan-build)
# Making everything, but wrapping with scan-build
if (SCAN)
add_custom_target(scan_build
COMMAND ${SCAN} make)
endif()
#------------------
# CYCLOMATIC COMPLEXITY SECTION
#------------------
find_program(LIZARD lizard)
if (LIZARD)
add_custom_target(lizard
COMMAND ${LIZARD} ${PROJECT_SOURCE_DIR}/src
COMMAND ${LIZARD} ${PROJECT_SOURCE_DIR}/include)
endif()
#------------------
# LINTER SECTION
#------------------
find_program(LINTER clang-tidy)
if(LINTER)
add_custom_target(linter
COMMAND clang-tidy ${PROJECT_SOURCE_DIR}/src/*.cpp -header-filter=.* -- -I${PROJECT_SOURCE_DIR}/include -std=c++17
)
endif()
#------------------
# CLANG-FORMAT SECTION
#------------------
find_program(FORMAT clang-format)
if (FORMAT)
add_custom_target(format
COMMAND ${FORMAT} -i ${PROJECT_SOURCE_DIR}/src/*.cpp ${PROJECT_SOURCE_DIR}/include/*.hpp ${PROJECT_SOURCE_DIR}/include/ndarray/*.i.hpp
)
endif()
endif()
#
#-----------------
# INSTALL SECTION
#-----------------
install(TARGETS ${TARGET_NAME} DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/bin)
#------------------
# CLEANING SECTION
#------------------
add_custom_target(clean_all
COMMAND ${CMAKE_COMMAND} -E echo "Cleaning doc..."
COMMAND ${CMAKE_COMMAND} -E rm -rf ${PROJECT_SOURCE_DIR}/doc
COMMAND ${CMAKE_COMMAND} -E echo "Cleaning bin..."
COMMAND ${CMAKE_COMMAND} -E rm -rf ${PROJECT_SOURCE_DIR}/bin
COMMAND ${CMAKE_COMMAND} -E echo "Done!"
)