forked from acados/acados
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
333 lines (282 loc) · 12 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
#
# Copyright (c) The acados authors.
#
# This file is part of acados.
#
# The 2-Clause BSD License
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.;
#
cmake_minimum_required(VERSION 3.1)
if(CMAKE_MAKE_PROGRAM)
file(TO_CMAKE_PATH ${CMAKE_MAKE_PROGRAM} CMAKE_MAKE_PROGRAM)
find_program(CMAKE_MAKE_PROGRAM ${CMAKE_MAKE_PROGRAM})
endif()
project(acados LANGUAGES C CXX)
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")
set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)
### Defaults
set(ACADOS_INSTALL_DIR "${PROJECT_SOURCE_DIR}" CACHE PATH "Installation path to PROJECT_SOURCE_DIR")
if ("${CMAKE_HOST_SYSTEM_PROCESSOR}" STREQUAL "aarch64")
set(BLASFEO_TARGET "ARMV8A_ARM_CORTEX_A57" CACHE STRING "BLASFEO Target architecture")
else()
set(BLASFEO_TARGET "X64_AUTOMATIC" CACHE STRING "BLASFEO Target architecture")
endif()
set(HPIPM_TARGET "X64_AUTOMATIC" CACHE STRING "HPIPM Target architecture")
set(LA "HIGH_PERFORMANCE" CACHE STRING "Linear algebra optimization level")
if (CMAKE_SYSTEM_NAME MATCHES "Windows")
set(BUILD_SHARED_LIBS OFF CACHE STRING "Build shared libraries")
else()
set(BUILD_SHARED_LIBS ON CACHE STRING "Build shared libraries")
endif()
option(ACADOS_WITH_OPENMP "OpenMP Parallelization" OFF)
option(ACADOS_SILENT "No console status output" OFF)
option(ACADOS_DEBUG_SQP_PRINT_QPS_TO_FILE "Print QP inputs and outputs to file in SQP" OFF)
# Additional targets
option(ACADOS_UNIT_TESTS "Compile Unit tests" OFF)
option(ACADOS_EXAMPLES "Compile Examples" OFF)
option(ACADOS_LINT "Compile Lint" OFF)
# External libs
option(ACADOS_WITH_QPOASES "qpOASES solver" OFF)
option(ACADOS_WITH_DAQP "DAQP solver" OFF)
option(ACADOS_WITH_HPMPC "HPMPC solver" OFF)
option(ACADOS_WITH_QORE "QORE solver" OFF)
option(ACADOS_WITH_OOQP "OOQP solver" OFF)
option(ACADOS_WITH_QPDUNES "qpDUNES solver" OFF)
option(ACADOS_WITH_OSQP "OSQP solver" OFF)
# Interfaces
option(ACADOS_OCTAVE "Octave Interface tests" OFF)
option(ACADOS_PYTHON "Python Interface tests" OFF)
# Set custom path
set(CMAKE_INSTALL_PREFIX ${ACADOS_INSTALL_DIR})
set(EXTERNAL_SRC_DIR ${PROJECT_SOURCE_DIR}/external)
set(BLASFEO_SRC_DIR ${PROJECT_SOURCE_DIR}/external/blasfeo)
# Set up build type
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release
CACHE STRING "Valid build types are: \
Release (default), None, Debug, WithExternalLibs, RelWithDebInfo, MinSizeRel." FORCE)
endif()
message(STATUS "Build type is ${CMAKE_BUILD_TYPE}")
enable_testing(true)
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU" AND NOT CMAKE_SYSTEM_NAME MATCHES "Windows")
add_definitions(-D _GLIBCXX_USE_CXX11_ABI=0) # Needed for CasADi compatibility
endif()
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU" AND CMAKE_SYSTEM_NAME MATCHES "Windows")
# MinGW: remove prefix and change suffix to match MSVC
# (such that Matlab mex recognizes the libraries)
set(CMAKE_SHARED_LIBRARY_PREFIX "")
set(CMAKE_IMPORT_LIBRARY_SUFFIX ".lib")
set(CMAKE_IMPORT_LIBRARY_PREFIX "")
set(CMAKE_STATIC_LIBRARY_SUFFIX ".lib")
set(CMAKE_STATIC_LIBRARY_PREFIX "")
if(BUILD_SHARED_LIBS MATCHES ON)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wl,--export-all-symbols")
endif()
endif()
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99 -Wall -fdiagnostics-show-option")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x -Wall -fdiagnostics-show-option")
elseif(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /MT")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT")
if(BUILD_SHARED_LIBS MATCHES ON)
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS 1)
endif()
endif()
# OPENMP
if(ACADOS_WITH_OPENMP)
if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.9.0")
find_package(OpenMP)
else()
if(NOT TARGET OpenMP::OpenMP_CXX)
set(OpenMP_CXX_FLAGS "-fopenmp")
set(OpenMP_C_FLAGS "-fopenmp")
find_package(Threads REQUIRED)
add_library(OpenMP::OpenMP_CXX IMPORTED INTERFACE)
set_property(TARGET OpenMP::OpenMP_CXX
PROPERTY INTERFACE_COMPILE_OPTIONS ${OpenMP_CXX_FLAGS})
# Only works if the same flag is passed to the linker; use CMake 3.9+ otherwise (Intel, AppleClang)
set_property(TARGET OpenMP::OpenMP_CXX
PROPERTY INTERFACE_LINK_LIBRARIES ${OpenMP_CXX_FLAGS} Threads::Threads)
set(OpenMP_CXX_FOUND TRUE)
set(OpenMP_C_FOUND TRUE)
endif()
endif()
if(OpenMP_CXX_FOUND AND OpenMP_C_FOUND)
message(STATUS "OpenMP_CXX_FLAGS: ${OpenMP_CXX_FLAGS}, OpenMP_C_FLAGS: ${OpenMP_C_FLAGS}")
# add openmp compiler flags
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
if(ACADOS_NUM_THREADS)
add_definitions(-DACADOS_NUM_THREADS=${ACADOS_NUM_THREADS}) # supported by CMAKE_VERSION < 3.12.0
endif()
else()
message(STATUS "OpenMP NOT found.")
set(ACADOS_WITH_OPENMP OFF)
endif()
else()
set(ACADOS_WITH_OPENMP OFF)
message(STATUS "ACADOS_WITH_OPENMP: ${ACADOS_WITH_OPENMP}")
endif()
if(ACADOS_SILENT)
message(STATUS "ACADOS_SILENT is ON")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DACADOS_SILENT")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DACADOS_SILENT")
endif()
if(ACADOS_DEBUG_SQP_PRINT_QPS_TO_FILE)
message(STATUS "ACADOS_DEBUG_SQP_PRINT_QPS_TO_FILE is ON")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DACADOS_DEBUG_SQP_PRINT_QPS_TO_FILE")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DACADOS_DEBUG_SQP_PRINT_QPS_TO_FILE")
endif()
# uninstall
if(NOT TARGET uninstall)
# Configure Uninstall
# https://gitlab.kitware.com/cmake/community/-/wikis/FAQ#can-i-do-make-uninstall-with-cmake
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/cmake/cmake_uninstall.cmake"
IMMEDIATE @ONLY)
add_custom_target(uninstall
"${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake/cmake_uninstall.cmake")
endif()
# Rpath handling, see https://cmake.org/Wiki/CMake_RPATH_handling#What_is_RPATH_.3F
set(CMAKE_SKIP_BUILD_RPATH FALSE)
set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
if(CMAKE_BUILD_TYPE MATCHES WithExternalLibs)
set(ACADOS_WITH_HPMPC ON CACHE BOOL "Add HPMPC solver")
set(ACADOS_WITH_QORE ON CACHE BOOL "Add QORE solver")
set(ACADOS_WITH_OOQP ON CACHE BOOL "Add OOQP solver")
set(ACADOS_WITH_QPOASES ON CACHE BOOL "Add qpOASES solver")
set(ACADOS_WITH_DAQP ON CACHE BOOL "Add DAQP solver")
set(ACADOS_WITH_QPDUNES ON CACHE BOOL "Add qpDUNES solver")
set(ACADOS_WITH_OSQP ON CACHE BOOL "Add OSQP solver")
endif()
## External lib checks (
if(ACADOS_WITH_HPMPC MATCHES ON AND CMAKE_C_COMPILER_ID MATCHES "MSVC")
set(ACADOS_WITH_HPMPC OFF CACHE BOOL "HPMPC solver" FORCE)
message(WARNING "HPMPC has been disabled, not compatible with ${CMAKE_C_COMPILER_ID}")
endif()
if(ACADOS_WITH_OOQP MATCHES ON)
if(CMAKE_SYSTEM_NAME MATCHES "dSpace")
set(ACADOS_WITH_OOQP OFF CACHE BOOL "Add OOQP solver" FORCE)
message(WARNING "OOQP is not compatible with dSpace, OOQP is disabled")
elseif(NOT EXISTS ${PROJECT_SOURCE_DIR}/external/OOQP)
set(ACADOS_WITH_OOQP OFF CACHE BOOL "Add OOQP solver" FORCE)
message(WARNING "OOQP folder not found, OOQP has been disabled")
endif()
endif()
if(ACADOS_WITH_QORE MATCHES ON)
if(CMAKE_SYSTEM_NAME MATCHES "dSpace" OR CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
set(ACADOS_WITH_QORE OFF CACHE BOOL "Add QORE solver" FORCE)
message(WARNING "QORE is not compatible with MSVC or dSpace, QORE is has been disabled")
elseif(NOT EXISTS ${PROJECT_SOURCE_DIR}/external/qore)
set(ACADOS_WITH_QORE OFF CACHE BOOL "Add QORE solver" FORCE)
message(WARNING "QORE folder not found, QORE has been disabled")
endif()
endif()
if(ACADOS_LINT)
if(CMAKE_SYSTEM_NAME MATCHES "Windows" OR CMAKE_SYSTEM_NAME MATCHES "dSpace")
set(ACADOS_LINT OFF CACHE BOOL "Lint" FORCE)
message(WARNING "Lint has been disabled, not compatible with ${CMAKE_SYSTEM_NAME}")
endif()
endif()
if(ACADOS_OCTAVE OR ACADOS_PYTHON)
add_subdirectory(${PROJECT_SOURCE_DIR}/interfaces)
endif()
## ) External lib checks
# Configure acados
add_subdirectory(acados)
# Configure interfaces
add_subdirectory(${PROJECT_SOURCE_DIR}/interfaces/acados_c)
# Configure external libraries
add_subdirectory(${EXTERNAL_SRC_DIR})
# Configure examples
if(ACADOS_EXAMPLES)
add_subdirectory(examples)
endif()
# Configure tests
if(ACADOS_UNIT_TESTS)
add_subdirectory(test)
endif()
# Configure lint
if(ACADOS_LINT)
include(Lint)
else()
add_custom_target(lint echo "Lint is disabled")
endif()
# Current config messages
message(STATUS " ")
message(STATUS "Target: BLASFEO is ${BLASFEO_TARGET}, HPIPM is ${HPIPM_TARGET}")
message(STATUS "Linear algebra: ${LA}")
message(STATUS "Octave MEX (${ACADOS_OCTAVE})")
message(STATUS "System name:version ${CMAKE_SYSTEM_NAME}:${CMAKE_SYSTEM_VERSION}")
message(STATUS "Build type is ${CMAKE_BUILD_TYPE}")
message(STATUS "Installation directory is ${CMAKE_INSTALL_PREFIX}")
if(ACADOS_WITH_OPENMP)
message(STATUS "OpenMP parallelization is ON")
if(ACADOS_NUM_THREADS)
message(STATUS "Number of threads for acados with openMP (ACADOS_NUM_THREADS) ${ACADOS_NUM_THREADS}")
else()
message(STATUS "Number of threads for acados with openMP (ACADOS_NUM_THREADS) not set, will use omp_get_max_threads")
endif()
else()
message(STATUS "OpenMP parallelization is OFF")
endif()
message(STATUS " ")
# Write libraries to be linked into a json file
if(${ACADOS_WITH_OPENMP})
set(LINK_FLAG_OPENMP ${OpenMP_C_FLAGS})
endif()
if(${ACADOS_WITH_QPOASES})
set(LINK_FLAG_QPOASES -lqpOASES_e)
endif()
if(${ACADOS_WITH_DAQP})
set(LINK_FLAG_DAQP -ldaqp)
endif()
if(${ACADOS_WITH_QPDUNES})
set(LINK_FLAG_QPDUNES -lqpdunes)
endif()
# TODO: add -lqdldl (?!)
if(${ACADOS_WITH_OSQP})
set(LINK_FLAG_OSQP -losqp)
endif()
if(${ACADOS_WITH_HPMPC})
set(LINK_FLAG_HPMPC -lhpmpc)
endif()
# if(${ACADOS_WITH_QORE})
# set(LINK_FLAG_QORE -lqore)
# endif()
if(${ACADOS_WITH_OOQP})
set(LINK_FLAG_OOQP -looqp)
endif()
file(WRITE lib/link_libs.json {\n)
file(APPEND lib/link_libs.json \t\"openmp\":\ \"${LINK_FLAG_OPENMP}\",\n)
file(APPEND lib/link_libs.json \t\"qpoases\":\ \"${LINK_FLAG_QPOASES}\",\n)
file(APPEND lib/link_libs.json \t\"daqp\":\ \"${LINK_FLAG_DAQP}\",\n)
file(APPEND lib/link_libs.json \t\"qpdunes\":\ \"${LINK_FLAG_QPDUNES}\",\n)
file(APPEND lib/link_libs.json \t\"osqp\":\ \"${LINK_FLAG_OSQP}\",\n)
file(APPEND lib/link_libs.json \t\"hpmpc\":\ \"${LINK_FLAG_HPMPC}\",\n)
# file(APPEND lib/link_libs.json \t\"qore\":\ \"${LINK_FLAG_QORE}\",\n)
file(APPEND lib/link_libs.json \t\"ooqp\":\ \"${LINK_FLAG_OOQP}\"\n) # no final comma!
file(APPEND lib/link_libs.json })