-
Notifications
You must be signed in to change notification settings - Fork 6
/
CMakeLists.txt
426 lines (351 loc) · 10.8 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
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
##
## This file is part of qp42.
##
## qp42 -- An Implementation of the Online Active Set Strategy.
## Copyright (C) 2012 by Janick Frasch, Hans Joachim Ferreau et al.
## All rights reserved.
##
## qp42 is free software; you can redistribute it and/or
## modify it under the terms of the GNU Lesser General Public
## License as published by the Free Software Foundation; either
## version 2.1 of the License, or (at your option) any later version.
##
## qp42 is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
## See the GNU Lesser General Public License for more details.
##
## You should have received a copy of the GNU Lesser General Public
## License along with qp42; if not, write to the Free Software
## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
##
################################################################################
#
# Description:
# CMake script for building qpDUNES static libraries, etc.
#
# Authors:
# Milan Vukov, [email protected]
#
# Year:
# 2013 - 2014.
#
# Usage:
# - mkdir build && cd build && cmake .. && make && make test
# - For installation of the library and corr. headers: sudo make install
#
################################################################################
################################################################################
#
# Project settings
#
################################################################################
#
# Minimum required version of cmake
#
CMAKE_MINIMUM_REQUIRED( VERSION 2.8 )
#
# Project name and programming languages used
#
PROJECT( qpDUNES C CXX )
#
# Folder path for generated executables
#
SET( EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin )
#
# Folder path for generated libraries
#
SET( LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib )
#
# CMake module(s) path
#
SET( CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR} )
################################################################################
#
# User configuration
#
################################################################################
#
# Build type
#
IF( NOT CMAKE_BUILD_TYPE )
SET(CMAKE_BUILD_TYPE Release CACHE STRING
"Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel."
FORCE
)
ENDIF( NOT CMAKE_BUILD_TYPE )
OPTION( QPDUNES_SIMPLE_BOUNDS_ONLY
"Enable compilation of the library for simple bounds only"
OFF
)
OPTION( QPDUNES_USE_ASSERTS
"Check return values of routines rigorously (useful for debugging)"
OFF
)
OPTION( QPDUNES_SUPPRESS_ALL_OUTPUT
"No printing"
OFF
)
OPTION( QPDUNES_SUPPRESS_ALL_WARNINGS
"Do not display warnings"
OFF
)
OPTION( QPDUNES_MEASURE_TIMINGS
"Measure computation times"
OFF
)
OPTION( QPDUNES_ANALYZE_FACTORIZATION
"Log inverse Newton Hessian for analysis"
OFF
)
OPTION( QPDUNES_FULL_LOGGING
"Enable full logging"
ON
)
OPTION( QPDUNES_PARALLEL
"Use openMP parallelization"
OFF
)
OPTION( QPDUNES_WITH_LAPACK
"Build qpOASES using original LAPACK routines"
OFF
)
OPTION( QPDUNES_WITH_BLAS
"Build qpOASES using original BLAS routines"
OFF
)
################################################################################
#
# Compiler settings
#
################################################################################
SET( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC -Wall -Wextra -pedantic -Wshadow -g -finline-functions -std=c99" )
SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -D__DEBUG__")
SET(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -march=native")
IF ( QPDUNES_SIMPLE_BOUNDS_ONLY )
ADD_DEFINITIONS( -D__SIMPLE_BOUNDS_ONLY__ )
ENDIF()
IF ( QPDUNES_USE_ASSERTS )
ADD_DEFINITIONS( -D__USE_ASSERTS__ )
ENDIF()
IF ( QPDUNES_SUPPRESS_ALL_OUTPUT )
ADD_DEFINITIONS( -D__SUPPRESS_ALL_OUTPUT__ )
ENDIF()
IF ( QPDUNES_SUPPRESS_ALL_WARNINGS )
ADD_DEFINITIONS( -D__SUPPRESS_ALL_WARNINGS__ )
ENDIF()
IF ( QPDUNES_MEASURE_TIMINGS )
ADD_DEFINITIONS( -D__MEASURE_TIMINGS__ )
ENDIF()
IF ( QPDUNES_ANALYZE_FACTORIZATION )
ADD_DEFINITIONS( -D__ANALYZE_FACTORIZATION__ )
ENDIF()
IF ( QPDUNES_FULL_LOGGING )
ADD_DEFINITIONS( -D__FULL_LOGGING__ )
ENDIF()
IF ( QPDUNES_PARALLEL )
FIND_PACKAGE( OpenMP )
ENDIF()
IF( OPENMP_FOUND )
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}")
ADD_DEFINITIONS( -D__QPDUNES_PARALLEL__ )
ENDIF()
# This will add the "make test" target
ENABLE_TESTING()
################################################################################
#
# Include directories
#
################################################################################
INCLUDE_DIRECTORIES(
.
./include
./include/qp
./interfaces
./interfaces/mpc
)
################################################################################
#
# Sources and headers
#
################################################################################
SET( qpDUNES_HEADERS
${CMAKE_CURRENT_SOURCE_DIR}/include/qpDUNES.h
${CMAKE_CURRENT_SOURCE_DIR}/include/qp/dual_qp.h
${CMAKE_CURRENT_SOURCE_DIR}/include/qp/matrix_vector.h
${CMAKE_CURRENT_SOURCE_DIR}/include/qp/setup_qp.h
${CMAKE_CURRENT_SOURCE_DIR}/include/qp/stage_qp_solver_clipping.h
${CMAKE_CURRENT_SOURCE_DIR}/include/qp/types.h
${CMAKE_CURRENT_SOURCE_DIR}/include/qp/qpdunes_utils.h
# mpcDUNES
${CMAKE_CURRENT_SOURCE_DIR}/interfaces/mpc/setup_mpc.h
)
SET( qpDUNES_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/src/dual_qp.c
${CMAKE_CURRENT_SOURCE_DIR}/src/stage_qp_solver_clipping.c
${CMAKE_CURRENT_SOURCE_DIR}/src/matrix_vector.c
${CMAKE_CURRENT_SOURCE_DIR}/src/setup_qp.c
${CMAKE_CURRENT_SOURCE_DIR}/src/qpdunes_utils.c
# mpcDUNES
${CMAKE_CURRENT_SOURCE_DIR}/interfaces/mpc/setup_mpc.c
)
IF ( NOT QPDUNES_SIMPLE_BOUNDS_ONLY )
ENABLE_LANGUAGE( CXX )
SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -pedantic -Wshadow -finline-functions -fPIC" )
SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DLINUX -D__cplusplus -D__NO_COPYRIGHT__" )
INCLUDE_DIRECTORIES(
# qpOASES include paths
./externals/qpOASES-3.0beta
./externals/qpOASES-3.0beta/include
)
SET ( qpDUNES_HEADERS ${qpDUNES_HEADERS}
${CMAKE_CURRENT_SOURCE_DIR}/include/qp/stage_qp_solver_qpoases.hpp
)
SET ( qpDUNES_SOURCES ${qpDUNES_SOURCES}
${CMAKE_CURRENT_SOURCE_DIR}/src/stage_qp_solver_qpoases.cpp
)
SET( QPOASES_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/externals/qpOASES-3.0beta/src/Bounds.cpp
${CMAKE_CURRENT_SOURCE_DIR}/externals/qpOASES-3.0beta/src/Constraints.cpp
${CMAKE_CURRENT_SOURCE_DIR}/externals/qpOASES-3.0beta/src/Flipper.cpp
${CMAKE_CURRENT_SOURCE_DIR}/externals/qpOASES-3.0beta/src/Indexlist.cpp
${CMAKE_CURRENT_SOURCE_DIR}/externals/qpOASES-3.0beta/src/LoggedSQProblem.cpp
${CMAKE_CURRENT_SOURCE_DIR}/externals/qpOASES-3.0beta/src/Matrices.cpp
${CMAKE_CURRENT_SOURCE_DIR}/externals/qpOASES-3.0beta/src/MessageHandling.cpp
${CMAKE_CURRENT_SOURCE_DIR}/externals/qpOASES-3.0beta/src/Options.cpp
${CMAKE_CURRENT_SOURCE_DIR}/externals/qpOASES-3.0beta/src/QProblem.cpp
${CMAKE_CURRENT_SOURCE_DIR}/externals/qpOASES-3.0beta/src/QProblemB.cpp
${CMAKE_CURRENT_SOURCE_DIR}/externals/qpOASES-3.0beta/src/SQProblem.cpp
${CMAKE_CURRENT_SOURCE_DIR}/externals/qpOASES-3.0beta/src/SubjectTo.cpp
${CMAKE_CURRENT_SOURCE_DIR}/externals/qpOASES-3.0beta/src/Utils.cpp
)
FILE( GLOB QPOASES_HEADERS
${CMAKE_CURRENT_SOURCE_DIR}/externals/qpOASES-3.0beta/include/*.hpp )
# Find LAPACK
IF ( QPDUNES_WITH_LAPACK )
ENABLE_LANGUAGE( Fortran )
FIND_PACKAGE( LAPACK )
IF ( NOT LAPACK_FOUND )
SET( QPOASES_SOURCES ${QPOASES_SOURCES} ${CMAKE_CURRENT_SOURCE_DIR}/externals/qpOASES-3.0beta/src/LAPACKReplacement.cpp )
ENDIF()
ELSE()
SET( QPOASES_SOURCES ${QPOASES_SOURCES} ${CMAKE_CURRENT_SOURCE_DIR}/externals/qpOASES-3.0beta/src/LAPACKReplacement.cpp )
ENDIF()
# Find BLAS
IF ( QPDUNES_WITH_BLAS )
ENABLE_LANGUAGE( Fortran )
FIND_PACKAGE( BLAS )
IF ( NOT BLAS_FOUND )
SET( QPOASES_SOURCES ${QPOASES_SOURCES} ${CMAKE_CURRENT_SOURCE_DIR}/externals/qpOASES-3.0beta/src/BLASReplacement.cpp )
ENDIF()
ELSE()
SET( QPOASES_SOURCES ${QPOASES_SOURCES} ${CMAKE_CURRENT_SOURCE_DIR}/externals/qpOASES-3.0beta/src/BLASReplacement.cpp )
ENDIF()
SET( qpDUNES_HEADERS ${qpDUNES_HEADERS} ${QPOASES_HEADERS} )
SET( qpDUNES_SOURCES ${qpDUNES_SOURCES} ${QPOASES_SOURCES} )
ENDIF()
################################################################################
#
# Build applications, libraries and examples
#
################################################################################
#
# Build the qpDUNES stand-alone library
#
ADD_LIBRARY(
qpdunes STATIC
# Sources and headers
${qpDUNES_HEADERS}
${qpDUNES_SOURCES}
)
TARGET_LINK_LIBRARIES( qpdunes m )
IF ( QPDUNES_WITH_LAPACK AND LAPACK_FOUND )
TARGET_LINK_LIBRARIES(
qpdunes
${LAPACK_LIBRARIES}
)
ENDIF()
IF ( QPDUNES_WITH_BLAS AND BLAS_FOUND )
TARGET_LINK_LIBRARIES(
qpdunes
${BLAS_LIBRARIES}
)
ENDIF()
#
# Build the examples
# NOTE: Assumption is that all examples are in C and that one example
# is in exactly one file.
#
FILE( GLOB qpDUNES_EXAMPLES ${CMAKE_CURRENT_SOURCE_DIR}/examples/*.c )
FOREACH( EXAMPLE ${qpDUNES_EXAMPLES} )
GET_FILENAME_COMPONENT( EXEC_NAME ${EXAMPLE} NAME_WE )
ADD_EXECUTABLE( example_${EXEC_NAME} ${EXAMPLE} )
TARGET_LINK_LIBRARIES(
example_${EXEC_NAME}
qpdunes
)
SET_TARGET_PROPERTIES( example_${EXEC_NAME}
PROPERTIES
OUTPUT_NAME "${EXEC_NAME}"
)
ADD_TEST(
NAME test_${EXEC_NAME}
WORKING_DIRECTORY ${EXECUTABLE_OUTPUT_PATH}
COMMAND ${EXEC_NAME}
)
ENDFOREACH()
################################################################################
#
# Installation rules
#
################################################################################
INSTALL(
DIRECTORY
include/
DESTINATION
include/qpdunes
)
INSTALL(
FILES
interfaces/mpc/setup_mpc.h
DESTINATION
include/qpdunes/interfaces/mpc
)
INSTALL(
TARGETS
qpdunes
DESTINATION
lib
)
################################################################################
#
# Configuration of the bash script
#
################################################################################
SET( qpDUNES_ENV_INCLUDE_DIRS
${PROJECT_SOURCE_DIR}
${PROJECT_SOURCE_DIR}/include
${PROJECT_SOURCE_DIR}/include/qp
${PROJECT_SOURCE_DIR}/interfaces
${PROJECT_SOURCE_DIR}/interfaces/mpc
)
IF (NOT QPDUNES_SIMPLE_BOUNDS_ONLY )
SET( qpDUNES_ENV_INCLUDE_DIRS
${qpDUNES_ENV_INCLUDE_DIRS}
${PROJECT_SOURCE_DIR}/externals/qpOASES-3.0beta
${PROJECT_SOURCE_DIR}/externals/qpOASES-3.0beta/include
)
ENDIF()
SET( qpDUNES_ENV_LIBRARY_DIRS
${LIBRARY_OUTPUT_PATH}
)
SET( qpDUNES_ENV_STATIC_LIBRARIES
qpdunes
)
CONFIGURE_FILE(
"${PROJECT_SOURCE_DIR}/cmake/qpDUNES_env.sh.in"
"${PROJECT_BINARY_DIR}/qpDUNES_env.sh"
@ONLY
)