-
Notifications
You must be signed in to change notification settings - Fork 130
/
CMakeLists.txt
372 lines (337 loc) · 15.2 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
###################################################################################################
# #
# This file is part of HPIPM. #
# #
# HPIPM -- High-Performance Interior Point Method. #
# Copyright (C) 2019 by Gianluca Frison. #
# Developed at IMTEK (University of Freiburg) under the supervision of Moritz Diehl. #
# All rights reserved. #
# #
# 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 OWNER 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. #
# #
# Author: Gianluca Frison, gianluca.frison (at) imtek.uni-freiburg.de #
# #
###################################################################################################
cmake_minimum_required(VERSION 2.8.11)
# installation directory ( has to be before `project()` )
set(CMAKE_INSTALL_PREFIX "/opt/hpipm" CACHE STRING "Installation path")
project(hpipm C)
set(CMAKE_VERBOSE_MAKEFILE ON)
# Options
# Target architecture
set(TARGET AVX CACHE STRING "Set CPU architecture target")
#set(TARGET GENERIC CACHE STRING "Set CPU architecture target")
# Populate a list of allowable targets and link it to the option
set(ALLOWED_TARGETS
AVX
GENERIC
)
set_property(CACHE TARGET PROPERTY STRINGS ${ALLOWED_TARGETS})
# Use C99 extension to math library
set(USE_C99_MATH ON CACHE STRING "Use C99 extension to math library")
# Compile auxiliary functions with external dependencies
# (for memory allocation and printing)
set(EXT_DEP ON CACHE BOOL "Compile external dependencies in BLASFEO")
# BLAS and LAPACK version (only used for LA=BLAS in BLASFEO)
set(REF_BLAS 0 CACHE STRING "Set CPU architecture target")
# set(REF_BLAS OPENBLAS CACHE STRING "Set CPU architecture target")
# set(REF_BLAS NETLIB CACHE STRING "Set CPU architecture target")
# set(REF_BLAS MKL CACHE STRING "Set CPU architecture target")
# set(REF_BLAS BLIS CACHE STRING "Set CPU architecture target")
# set(REF_BLAS ATLAS CACHE STRING "Set CPU architecture target")
# Populate a list of allowable BLAS versions and link it to the option
set(ALLOWED_REF_BLAS
0
OPENBLAS
NETLIB
MKL
BLIS
ATLAS
)
set_property(CACHE REF_BLAS PROPERTY STRINGS ${ALLOWED_REF_BLAS})
set(HPIPM_TESTING ON CACHE BOOL "Tests enabled")
# set(HPIPM_TESTING OFF CACHE BOOL "Tests disabled")
# build shared library
set(BUILD_SHARED_LIBS OFF CACHE STRING "Build shared libraries")
# Pass the allowed items up to the parent scope (if there is one)
# This is detected by comparing the project name to the one set earlier in this file
if(NOT ${CMAKE_PROJECT_NAME} STREQUAL hpipm)
set(HPIPM_ALLOWED_TARGETS ${ALLOWED_TARGETS} PARENT_SCOPE)
set(HPIPM_ALLOWED_REF_BLAS ${ALLOWED_REF_BLAS} PARENT_SCOPE)
endif()
# Use CMake to automatically find BLASFEO (OFF by default -- only for use in other software packages ATM)
set(HPIPM_FIND_BLASFEO OFF CACHE BOOL "Use CMake to find BLASFEO.")
# Try to find blasfeo using CMake (also sets BLASFEO_PATH and BLASFEO_INCLUDE_DIR if found)
if(HPIPM_FIND_BLASFEO)
find_package(blasfeo REQUIRED)
endif()
# BLASFEO option
if(NOT TARGET blasfeo)
# manually set BLASFEO installation path
set(BLASFEO_PATH "/opt/blasfeo" CACHE STRING "BLASFEO installation path")
# match BLASFEO library type with HPIPM library type
if(BUILD_SHARED_LIBS MATCHES OFF)
set(HPIPM_BLASFEO_LIB "Static" CACHE STRING "BLASFEO library link type")
else()
set(HPIPM_BLASFEO_LIB "Shared" CACHE STRING "BLASFEO library link type")
endif()
# select correct name for BLASFEO library
if(HPIPM_BLASFEO_LIB STREQUAL "Static")
add_library(blasfeo STATIC IMPORTED)
if(CMAKE_C_COMPILER_ID MATCHES MSVC)
set_target_properties(blasfeo PROPERTIES IMPORTED_LOCATION ${BLASFEO_PATH}/lib/blasfeo.lib)
else()
set_target_properties(blasfeo PROPERTIES IMPORTED_LOCATION ${BLASFEO_PATH}/lib/libblasfeo.a)
endif()
elseif(HPIPM_BLASFEO_LIB STREQUAL "Shared")
add_library(blasfeo SHARED IMPORTED)
if(CMAKE_C_COMPILER_ID MATCHES MSVC)
set_target_properties(blasfeo PROPERTIES IMPORTED_LOCATION ${BLASFEO_PATH}/lib/blasfeo.dll)
else()
set_target_properties(blasfeo PROPERTIES IMPORTED_LOCATION ${BLASFEO_PATH}/lib/libblasfeo.so)
endif()
endif()
endif()
# Needed to compile examples
set(BLASFEO_INCLUDE_DIR "${BLASFEO_PATH}/include" CACHE STRING "Path to BLASFEO header files.")
set(HPIPM_INCLUDE_DIR "${PROJECT_SOURCE_DIR}/include")
# headers installation directory
set(HPIPM_HEADERS_INSTALLATION_DIRECTORY "include" CACHE STRING "Headers local installation directory")
# enable runtine checks
set(RUNTIME_CHECKS ON)
#set(RUNTIME_CHECKS OFF)
## compiler flags
#set(CMAKE_C_FLAGS "")
#
## optimization flags
# common flags
if(CMAKE_C_COMPILER_ID STREQUAL "GNU" OR CMAKE_C_COMPILER_ID STREQUAL "Clang")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O2 -fPIC")
endif()
# target-specific flags
if(${TARGET} MATCHES AVX)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DTARGET_AVX")
if(CMAKE_C_COMPILER_ID STREQUAL "GNU" OR CMAKE_C_COMPILER_ID STREQUAL "Clang")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -m64 -mavx")
endif()
elseif(${TARGET} MATCHES GENERIC)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DTARGET_GENERIC")
endif()
#
if(${REF_BLAS} MATCHES 0)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ")
endif(${REF_BLAS} MATCHES 0)
if(${REF_BLAS} MATCHES OPENBLAS)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DREF_BLAS_OPENBLAS -I/opt/openblas/include")
endif(${REF_BLAS} MATCHES OPENBLAS)
if(${REF_BLAS} MATCHES BLIS)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DREF_BLAS_BLIS -std=c99")
endif(${REF_BLAS} MATCHES BLIS)
if(${REF_BLAS} MATCHES NETLIB)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DREF_BLAS_NETLIB")
endif(${REF_BLAS} MATCHES NETLIB)
if(${REF_BLAS} MATCHES MKL)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DREF_BLAS_MKL -m64 -I/opt/intel/mkl/include")
endif(${REF_BLAS} MATCHES MKL)
if(${REF_BLAS} MATCHES ATLAS)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DREF_BLAS_ATLAS")
endif(${REF_BLAS} MATCHES ATLAS)
#
if(${USE_C99_MATH} MATCHES ON)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DUSE_C99_MATH")
endif()
#
if(${RUNTIME_CHECKS} MATCHES ON)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DRUNTIME_CHECKS")
endif()
# source files
# cond
file(GLOB COND_SRC
# double
${PROJECT_SOURCE_DIR}/cond/d_cond.c
${PROJECT_SOURCE_DIR}/cond/d_cond_aux.c
${PROJECT_SOURCE_DIR}/cond/d_part_cond.c
${PROJECT_SOURCE_DIR}/cond/d_cond_qcqp.c
${PROJECT_SOURCE_DIR}/cond/d_cast_qcqp.c
${PROJECT_SOURCE_DIR}/cond/d_part_cond_qcqp.c
# single
${PROJECT_SOURCE_DIR}/cond/s_cond.c
${PROJECT_SOURCE_DIR}/cond/s_cond_aux.c
${PROJECT_SOURCE_DIR}/cond/s_part_cond.c
${PROJECT_SOURCE_DIR}/cond/s_cond_qcqp.c
${PROJECT_SOURCE_DIR}/cond/s_cast_qcqp.c
${PROJECT_SOURCE_DIR}/cond/s_part_cond_qcqp.c
)
# dense qp
file(GLOB DENSE_QP_SRC
# double
${PROJECT_SOURCE_DIR}/dense_qp/d_dense_qp.c
${PROJECT_SOURCE_DIR}/dense_qp/d_dense_qp_dim.c
${PROJECT_SOURCE_DIR}/dense_qp/d_dense_qp_sol.c
${PROJECT_SOURCE_DIR}/dense_qp/d_dense_qp_kkt.c
${PROJECT_SOURCE_DIR}/dense_qp/d_dense_qp_ipm.c
${PROJECT_SOURCE_DIR}/dense_qp/d_dense_qp_res.c
${PROJECT_SOURCE_DIR}/dense_qp/d_dense_qp_utils.c
${PROJECT_SOURCE_DIR}/dense_qp/d_dense_qcqp_dim.c
${PROJECT_SOURCE_DIR}/dense_qp/d_dense_qcqp.c
${PROJECT_SOURCE_DIR}/dense_qp/d_dense_qcqp_sol.c
${PROJECT_SOURCE_DIR}/dense_qp/d_dense_qcqp_res.c
${PROJECT_SOURCE_DIR}/dense_qp/d_dense_qcqp_ipm.c
${PROJECT_SOURCE_DIR}/dense_qp/d_dense_qcqp_utils.c
# single
${PROJECT_SOURCE_DIR}/dense_qp/s_dense_qp.c
${PROJECT_SOURCE_DIR}/dense_qp/s_dense_qp_dim.c
${PROJECT_SOURCE_DIR}/dense_qp/s_dense_qp_sol.c
${PROJECT_SOURCE_DIR}/dense_qp/s_dense_qp_kkt.c
${PROJECT_SOURCE_DIR}/dense_qp/s_dense_qp_ipm.c
${PROJECT_SOURCE_DIR}/dense_qp/s_dense_qp_res.c
${PROJECT_SOURCE_DIR}/dense_qp/s_dense_qp_utils.c
${PROJECT_SOURCE_DIR}/dense_qp/s_dense_qcqp_dim.c
${PROJECT_SOURCE_DIR}/dense_qp/s_dense_qcqp.c
${PROJECT_SOURCE_DIR}/dense_qp/s_dense_qcqp_sol.c
${PROJECT_SOURCE_DIR}/dense_qp/s_dense_qcqp_res.c
${PROJECT_SOURCE_DIR}/dense_qp/s_dense_qcqp_ipm.c
${PROJECT_SOURCE_DIR}/dense_qp/s_dense_qcqp_utils.c
)
# core ipm
if(${TARGET} MATCHES AVX)
file(GLOB IPM_CORE_SRC
${PROJECT_SOURCE_DIR}/ipm_core/d_core_qp_ipm_aux_avx.c
${PROJECT_SOURCE_DIR}/ipm_core/d_core_qp_ipm.c
${PROJECT_SOURCE_DIR}/ipm_core/s_core_qp_ipm_aux_avx.c
${PROJECT_SOURCE_DIR}/ipm_core/s_core_qp_ipm.c
)
else(${TARGET} MATCHES AVX)
file(GLOB IPM_CORE_SRC
${PROJECT_SOURCE_DIR}/ipm_core/d_core_qp_ipm_aux.c
${PROJECT_SOURCE_DIR}/ipm_core/d_core_qp_ipm.c
${PROJECT_SOURCE_DIR}/ipm_core/s_core_qp_ipm_aux.c
${PROJECT_SOURCE_DIR}/ipm_core/s_core_qp_ipm.c
)
endif(${TARGET} MATCHES AVX)
# ocp qp
file(GLOB OCP_QP_SRC
# double
${PROJECT_SOURCE_DIR}/ocp_qp/d_ocp_qp.c
${PROJECT_SOURCE_DIR}/ocp_qp/d_ocp_qp_dim.c
${PROJECT_SOURCE_DIR}/ocp_qp/d_ocp_qp_sol.c
${PROJECT_SOURCE_DIR}/ocp_qp/d_ocp_qp_kkt.c
${PROJECT_SOURCE_DIR}/ocp_qp/d_ocp_qp_ipm.c
${PROJECT_SOURCE_DIR}/ocp_qp/d_ocp_qp_res.c
${PROJECT_SOURCE_DIR}/ocp_qp/d_ocp_qp_utils.c
${PROJECT_SOURCE_DIR}/ocp_qp/d_ocp_qp_red.c
${PROJECT_SOURCE_DIR}/ocp_qp/d_ocp_qcqp.c
${PROJECT_SOURCE_DIR}/ocp_qp/d_ocp_qcqp_dim.c
${PROJECT_SOURCE_DIR}/ocp_qp/d_ocp_qcqp_sol.c
${PROJECT_SOURCE_DIR}/ocp_qp/d_ocp_qcqp_ipm.c
${PROJECT_SOURCE_DIR}/ocp_qp/d_ocp_qcqp_res.c
${PROJECT_SOURCE_DIR}/ocp_qp/d_ocp_qcqp_utils.c
# single
${PROJECT_SOURCE_DIR}/ocp_qp/s_ocp_qp.c
${PROJECT_SOURCE_DIR}/ocp_qp/s_ocp_qp_dim.c
${PROJECT_SOURCE_DIR}/ocp_qp/s_ocp_qp_sol.c
${PROJECT_SOURCE_DIR}/ocp_qp/s_ocp_qp_kkt.c
${PROJECT_SOURCE_DIR}/ocp_qp/s_ocp_qp_ipm.c
${PROJECT_SOURCE_DIR}/ocp_qp/s_ocp_qp_res.c
${PROJECT_SOURCE_DIR}/ocp_qp/s_ocp_qp_utils.c
${PROJECT_SOURCE_DIR}/ocp_qp/s_ocp_qp_red.c
${PROJECT_SOURCE_DIR}/ocp_qp/s_ocp_qcqp.c
${PROJECT_SOURCE_DIR}/ocp_qp/s_ocp_qcqp_dim.c
${PROJECT_SOURCE_DIR}/ocp_qp/s_ocp_qcqp_sol.c
${PROJECT_SOURCE_DIR}/ocp_qp/s_ocp_qcqp_ipm.c
${PROJECT_SOURCE_DIR}/ocp_qp/s_ocp_qcqp_res.c
${PROJECT_SOURCE_DIR}/ocp_qp/s_ocp_qcqp_utils.c
# ${PROJECT_SOURCE_DIR}/ocp_qp/m_ocp_qp.c
# ${PROJECT_SOURCE_DIR}/ocp_qp/m_ocp_qp_kkt.c
# ${PROJECT_SOURCE_DIR}/ocp_qp/m_ocp_qp_ipm_hard.c
)
# tree qp
file(GLOB TREE_OCP_QP_SRC
# common
${PROJECT_SOURCE_DIR}/tree_ocp_qp/scenario_tree.c
# double
${PROJECT_SOURCE_DIR}/tree_ocp_qp/d_tree_ocp_qp_dim.c
${PROJECT_SOURCE_DIR}/tree_ocp_qp/d_tree_ocp_qp.c
${PROJECT_SOURCE_DIR}/tree_ocp_qp/d_tree_ocp_qp_sol.c
${PROJECT_SOURCE_DIR}/tree_ocp_qp/d_tree_ocp_qp_res.c
${PROJECT_SOURCE_DIR}/tree_ocp_qp/d_tree_ocp_qp_kkt.c
${PROJECT_SOURCE_DIR}/tree_ocp_qp/d_tree_ocp_qp_ipm.c
${PROJECT_SOURCE_DIR}/tree_ocp_qp/d_tree_ocp_qp_utils.c
${PROJECT_SOURCE_DIR}/tree_ocp_qp/d_tree_ocp_qcqp_dim.c
${PROJECT_SOURCE_DIR}/tree_ocp_qp/d_tree_ocp_qcqp.c
${PROJECT_SOURCE_DIR}/tree_ocp_qp/d_tree_ocp_qcqp_sol.c
${PROJECT_SOURCE_DIR}/tree_ocp_qp/d_tree_ocp_qcqp_res.c
${PROJECT_SOURCE_DIR}/tree_ocp_qp/d_tree_ocp_qcqp_ipm.c
${PROJECT_SOURCE_DIR}/tree_ocp_qp/d_tree_ocp_qcqp_utils.c
# single
${PROJECT_SOURCE_DIR}/tree_ocp_qp/s_tree_ocp_qp_dim.c
${PROJECT_SOURCE_DIR}/tree_ocp_qp/s_tree_ocp_qp.c
${PROJECT_SOURCE_DIR}/tree_ocp_qp/s_tree_ocp_qp_sol.c
${PROJECT_SOURCE_DIR}/tree_ocp_qp/s_tree_ocp_qp_res.c
${PROJECT_SOURCE_DIR}/tree_ocp_qp/s_tree_ocp_qp_kkt.c
${PROJECT_SOURCE_DIR}/tree_ocp_qp/s_tree_ocp_qp_ipm.c
${PROJECT_SOURCE_DIR}/tree_ocp_qp/s_tree_ocp_qp_utils.c
${PROJECT_SOURCE_DIR}/tree_ocp_qp/s_tree_ocp_qcqp_dim.c
${PROJECT_SOURCE_DIR}/tree_ocp_qp/s_tree_ocp_qcqp.c
${PROJECT_SOURCE_DIR}/tree_ocp_qp/s_tree_ocp_qcqp_sol.c
${PROJECT_SOURCE_DIR}/tree_ocp_qp/s_tree_ocp_qcqp_res.c
${PROJECT_SOURCE_DIR}/tree_ocp_qp/s_tree_ocp_qcqp_ipm.c
${PROJECT_SOURCE_DIR}/tree_ocp_qp/s_tree_ocp_qcqp_utils.c
)
# auxiliary
file(GLOB AUXILIARY_SRC
${PROJECT_SOURCE_DIR}/auxiliary/aux_string.c
${PROJECT_SOURCE_DIR}/auxiliary/aux_mem.c
${PROJECT_SOURCE_DIR}/auxiliary/timing.c
)
# auxiliary
file(GLOB SIM_SRC
# double
${PROJECT_SOURCE_DIR}/sim_core/d_sim_rk.c
${PROJECT_SOURCE_DIR}/sim_core/d_sim_erk.c
# single
${PROJECT_SOURCE_DIR}/sim_core/s_sim_rk.c
${PROJECT_SOURCE_DIR}/sim_core/s_sim_erk.c
)
set(HPIPM_SRC ${COND_SRC} ${DENSE_QP_SRC} ${IPM_CORE_SRC} ${OCP_QP_SRC} ${TREE_OCP_QP_SRC} ${AUXILIARY_SRC})
add_library(hpipm ${HPIPM_SRC})
target_include_directories(hpipm
PUBLIC
$<BUILD_INTERFACE:${HPIPM_INCLUDE_DIR}>
$<BUILD_INTERFACE:${BLASFEO_INCLUDE_DIR}>
$<INSTALL_INTERFACE:${HPIPM_HEADERS_INSTALLATION_DIRECTORY}>)
target_link_libraries(hpipm blasfeo)
install(TARGETS hpipm EXPORT hpipmConfig
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
RUNTIME DESTINATION bin)
install(EXPORT hpipmConfig DESTINATION cmake)
file(GLOB_RECURSE HPIPM_HEADERS "include/*.h")
install(FILES ${HPIPM_HEADERS} DESTINATION ${HPIPM_HEADERS_INSTALLATION_DIRECTORY})
# test problems
if(HPIPM_TESTING MATCHES ON)
add_subdirectory(test_problems)
add_subdirectory(examples/c)
endif()
message(STATUS "Using BLASFEO path: ${BLASFEO_PATH}")
message(STATUS "Installation directory: ${CMAKE_INSTALL_PREFIX}")