forked from pdlr/brick
-
Notifications
You must be signed in to change notification settings - Fork 2
/
CMakeLists.txt
254 lines (224 loc) · 7.63 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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
# Build file for the brick suite of support libraries.
#
# Recipes:
# - To manually control installation directory:
# cmake -DCMAKE_INSTALL_PREFIX=/foo/bar ..
#
# - To prevent building tests:
# cmake -DBRICK_BUILD_TESTS=OFF ..
#
# - To build with debugging flags and no optimization:
# cmake -DCMAKE_BUILD_TYPE=Debug ..
#
# - To run tests:
# make test
#
# - To run tests and see output from any that fail:
# env CTEST_OUTPUT_ON_FAILURE=1 make test
#
# - To build the source package:
# cmake -DCPACK_PACKAGE_VERSION=2.0.0 ..
# make package_source
#
# - To build brick as an external package in your own project, add this
# (or something similar) to your CMakeLists.txt:
# ExternalProject_Add(
# brickLibraries
# URL ${CMAKE_CURRENT_SOURCE_DIR}/external/Brick-2.0.0-Source.tar.gz
# CMAKE_ARGS
# -DBRICK_BUILD_SHARED_LIBRARIES=ON
# -DBRICK_BUILD_TESTS=OFF
# -DCMAKE_INSTALL_PREFIX:PATH=${CMAKE_CURRENT_SOURCE_DIR}
# )
cmake_minimum_required (VERSION 3.0)
project (Brick)
# Options for the project build.
option (BRICK_BUILD_SHARED_LIBRARIES "Controls whether generated libraries are static or shared." OFF)
option (BRICK_BUILD_POSITION_INDEPENDENT "Controls whether generated code is position independent." OFF)
option (BRICK_BUILD_TESTS "Build tests along with brick library code." ON)
option (BRICK_DEBUG_ARRAY_BOUNDS "Turn on run-time bounds checks." OFF)
option (BRICK_BUILD_COMMON
"brickCommon is used by all other brick libraries."
ON)
option (BRICK_BUILD_PORTABILITY
"brickPortability provides platform independence to the brick library suite."
ON)
option (BRICK_BUILD_TEST_LIB
"brickTest is a simple unit testing framework. You need this to test the other libraries in the brick library suite."
ON)
option (BRICK_BUILD_NUMERIC
"brickNumeric provides matrices, vectors, and basic math functions."
ON)
option (BRICK_BUILD_PIXEL_GRAPHICS
"brickPixelGraphics provides utilities for drawing directly on images."
ON)
option (BRICK_BUILD_LINEAR_ALGEBRA
"brickLinearAlgebra builds upon brickNumeric. It needs lapack and blas."
ON)
option (BRICK_BUILD_RANDOM
"brickRandom provides simple pseudorandom number generators. It needs lapack and blas."
ON)
option (BRICK_BUILD_OPTIMIZATION
"brickOptimization provides simple nonlinear optimization routines."
ON)
option (BRICK_BUILD_UTILITIES
"brickUtilities contains things that didn't fit elsewhere, like argument parsing, string manipulation, etc."
ON)
option (BRICK_BUILD_GEOMETRY
"brickGeometry needs brickLinearAlgebra."
ON)
option (BRICK_BUILD_COMPUTER_VISION
"brickComputerVision depends on all of the other brick libraries."
ON)
option (BRICK_BUILD_ISO12233
"brickIso12233 depends on all of the other brick libraries."
ON)
# Set up compiler flags. Be as strict as possible. The
# add_definitions line may not be portable. We'll look into how to
# make it generic later.
# Note that we don't specify --std=c++11 here. Instead, we use the
# target_compile_features() function when setting the properties
# of the libraries themselves.
set (CMAKE_CXX_EXTENSIONS OFF)
set (BUILD_SHARED_LIBS ${BRICK_BUILD_SHARED_LIBRARIES})
add_definitions (
-Wall
-Wextra
-Wshadow
-Wpedantic
-Werror)
if (BRICK_DEBUG_ARRAY_BOUNDS)
add_definitions (-DBRICK_NUMERIC_CHECKBOUNDS=1)
endif (BRICK_DEBUG_ARRAY_BOUNDS)
set(CMAKE_C_FLAGS_COVERAGE "${CMAKE_C_FLAGS_DEBUG} -O0 -fprofile-arcs -ftest-coverage")
set(CMAKE_CXX_FLAGS_COVERAGE "${CMAKE_CXX_FLAGS_DEBUG} -O0 -fprofile-arcs -ftest-coverage")
# Other configuration.
if (BRICK_BUILD_TESTS)
enable_testing()
endif (BRICK_BUILD_TESTS)
# Include each of the brick libraries.
set (BRICK_LIBS "")
macro (brick_configure_library directory_name library_name do_build)
if (${do_build})
include_directories ("${PROJECT_SOURCE_DIR}/${directory_name}")
add_subdirectory (${directory_name})
if (BRICK_BUILD_POSITION_INDEPENDENT AND TARGET ${library_name})
set_property(TARGET ${library_name} PROPERTY POSITION_INDEPENDENT_CODE 1)
endif (BRICK_BUILD_POSITION_INDEPENDENT AND TARGET ${library_name})
set (BRICK_LIBS ${BRICK_LIBS} ${library_name})
endif (${do_build})
endmacro (brick_configure_library directory_name library_name do_build)
brick_configure_library (
common brickCommon ${BRICK_BUILD_COMMON}
)
brick_configure_library (
portability brickPortability ${BRICK_BUILD_PORTABILITY}
)
brick_configure_library (
test brickTest ${BRICK_BUILD_TEST_LIB}
)
brick_configure_library (
numeric brickNumeric ${BRICK_BUILD_NUMERIC}
)
brick_configure_library (
pixelGraphics brickPixelGraphics ${BRICK_BUILD_PIXEL_GRAPHICS}
)
brick_configure_library (
linearAlgebra brickLinearAlgebra ${BRICK_BUILD_LINEAR_ALGEBRA}
)
brick_configure_library (
random brickRandom ${BRICK_BUILD_RANDOM}
)
brick_configure_library (
optimization brickOptimization ${BRICK_BUILD_OPTIMIZATION}
)
brick_configure_library (
utilities brickUtilities ${BRICK_BUILD_UTILITIES}
)
brick_configure_library (
geometry brickGeometry ${BRICK_BUILD_GEOMETRY}
)
brick_configure_library (
computerVision brickComputerVision ${BRICK_BUILD_COMPUTER_VISION}
)
brick_configure_library (
iso12233 brickIso12233 ${BRICK_BUILD_ISO12233}
)
# Packaging.
# We'll need a way to package up releases, but first, a list of files
# we _don't_ want to include in the source packages.
# Don't package version control files.
set (CPACK_SOURCE_IGNORE_FILES
${CPACK_SOURCE_IGNORE_FILES}
"^${CMAKE_CURRENT_SOURCE_DIR}/\\\\.hg.*"
)
# Don't package build files.
set (CPACK_SOURCE_IGNORE_FILES
${CPACK_SOURCE_IGNORE_FILES}
"^${CMAKE_CURRENT_SOURCE_DIR}/build.*"
"scripts$"
)
# Including CPack adds build targets that you can invoke with
# "make package" and "make package_source".
include (CPack)
# ========= Useful code that we don't need yet ============
# Here's how you link with brick libraries:
#
# # add_executable (foo foo.cc)
# # target_link_libraries (foo ${BRICK_LIBS})
# Useful code for setting version numbers. Maybe we'll want this
# in subdirectories.
#
# set (BRICK_NUMERIC_VERSION_MAJOR 1)
# set (BRICK_NUMERIC_VERSION_VERSION_MINOR 0)
#
# # Propagate our version information to the source code.
#
# configure_file (
# "${PROJECT_SOURCE_DIR}/numeric/brick/version.hh.in"
# "${PROJECT_BINARY_DIR}/numeric/brick/version.hh"
# )
#
# # Make sure the updated header file is visible via include
# # search path.
#
# include_directories("${PROJECT_BINARY_DIR}/numeric")
#
# # Here's example content for version.hh.in:
# #
# # #define BRICK_NUMERIC_VERSION_MAJOR @BRICK_NUMERIC_VERSION_MAJOR@
# # #define BRICK_NUMERIC_VERSION_MINOR @BRICK_NUMERIC_VERSION_MINOR@
# Useful code for setting options.
#
# # option (MY_OPTION "Option description")
#
# And in version.hh.in:
#
# # #cmakedefine MY_OPTION
# # [...]
# # #ifdef MY_OPTION
# # [...]
# # #endif
if (CMAKE_BUILD_TYPE STREQUAL "Coverage")
add_custom_target(coverage
COMMAND mkdir -p coverage
COMMAND find ${CMAKE_BINARY_DIR} -name "*.gcda" -delete
COMMAND ctest --no-compress-output -T Test || true
WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
add_custom_command(TARGET coverage
COMMAND echo "------ COVERAGE ------"
COMMAND gcovr --xml-pretty -xs -o coverage.xml -r ${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR}
COMMAND gcovr --html --html-details -o coverage.html -r ${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR}
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/coverage)
endif (CMAKE_BUILD_TYPE STREQUAL "Coverage")
#documentation
find_program(DOXYGEN doxygen)
if (DOXYGEN)
configure_file (
"${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.cmakein"
"${CMAKE_CURRENT_BINARY_DIR}/Doxyfile"
@ONLY
)
add_custom_target(doc
COMMAND ${DOXYGEN})
endif (DOXYGEN)