-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
269 lines (190 loc) · 6.33 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
cmake_minimum_required(VERSION 3.14)
project(sleqp
VERSION 1.0.2
LANGUAGES C CXX)
set(PROJECT_DESCRIPTION "Active set-based NLP solver")
set(PROJECT_MAINTAINER_NAME "Christoph Hansknecht")
set(PROJECT_MAINTAINER_EMAIL "[email protected]")
set(PROJECT_LONG_DESCRIPTION
"This package provides SLEQP, an \
open-source solver for large-scale nonlinear continuous \
optimization. SLEQP is available as a callable library with interfaces \
to C, Python, AMPL, and MATLAB / Octave. It uses an active set method based on a \
combination of successive linear programming and equality constrained \
quadratic programming.")
include(FeatureSummary)
include(GNUInstallDirs)
include(CMakePackageConfigHelpers)
include(FindPackageHandleStandardArgs)
include(GenerateExportHeader)
include(CTest)
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/")
set(VERSION_FILE "${PROJECT_BINARY_DIR}/sleqp_version")
write_file(${VERSION_FILE} "${PROJECT_VERSION}")
include(CompilerOptions)
include(ExtractDefine)
include(Sanitizers)
# Get the current working branch
execute_process(
COMMAND git rev-parse --abbrev-ref HEAD
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
OUTPUT_VARIABLE "PROJECT_GIT_BRANCH"
OUTPUT_STRIP_TRAILING_WHITESPACE
)
# Get the latest abbreviated commit hash of the working branch
execute_process(
COMMAND git log -1 --format=%h
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
OUTPUT_VARIABLE "PROJECT_GIT_COMMIT_HASH"
OUTPUT_STRIP_TRAILING_WHITESPACE
)
set(PROJECT_NAMESPACE "${PROJECT_NAME}::")
set(LICENSE_FILE_NAME "LICENSE")
set(LICENSE_FILE "${PROJECT_SOURCE_DIR}/${LICENSE_FILE_NAME}")
string(TOUPPER "${PROJECT_NAME}" PROJECT_PREFIX)
# Options / user variables
option(SLEQP_ENABLE_UNIT_TESTS "Whether or not to enable unit tests" ON)
option(SLEQP_ENABLE_C_UNIT_TESTS "Whether or not to enable C unit tests" ON)
option(SLEQP_ENABLE_NUM_ASSERTS "Whether or not to numerical assertions" OFF)
option(SLEQP_ENABLE_CUTEST "Whether or not to include the CUTest suite" OFF)
option(SLEQP_ENABLE_PYTHON "Whether or not to enable python bindings" ON)
option(SLEQP_DEBUG "Whether or not to enable debug messages" OFF)
option(SLEQP_GENERATE_COVERAGE "Whether or not to generate coverage" OFF)
option(SLEQP_FORMAT_CODES "Whether or not to enable ANSI format codes" ON)
option(SLEQP_ENABLE_OCTAVE_MEX "Compile with Octave MEX interface." OFF)
option(SLEQP_ENABLE_MATLAB_MEX "Compile with MATLAB MEX interface." OFF)
option(SLEQP_ENABLE_AMPL "Compile with AMPL interface." OFF)
option(SLEQP_MUMPS_INIT_MPI "Should MUMPS interface manually initialize MPI?" ON)
# May be required for MUMPS
set(SLEQP_WITH_MPI OFF)
set(SLEQP_LPS ""
CACHE STRING "The LP solver used as a backend")
# Find all packages
find_package(PkgConfig)
include(SearchLPS)
include(SearchFact)
find_package(trlib REQUIRED)
set(SLEQP_TRLIB_VERSION "${trlib_VERSION}")
find_package(Octave)
if(SLEQP_ENABLE_OCTAVE_MEX AND NOT(Octave_FOUND))
message(FATAL_ERROR "Could not find Octave")
endif()
find_package(Matlab COMPONENTS MAIN_PROGRAM)
if(SLEQP_ENABLE_MATLAB_MEX AND NOT(Matlab_FOUND))
message(FATAL_ERROR "Could not find MATLAB")
endif()
if(${SLEQP_ENABLE_MATLAB_MEX} OR ${SLEQP_ENABLE_OCTAVE_MEX})
set(SLEQP_ENABLE_MEX On)
endif()
pkg_check_modules(COINASL coinasl)
if(SLEQP_ENABLE_AMPL AND NOT(COINASL_FOUND))
message(FATAL_ERROR "Could not find ASL")
endif()
find_package(CHECK)
find_package(Threads REQUIRED)
if(NOT(OpenMP_FOUND))
find_package(OpenMP)
endif()
add_library(trlib INTERFACE IMPORTED)
set(SLEQP_DEP_LIBRARIES
Threads::Threads
trlib::trlib
${SLEQP_LPS_LIBRARIES}
${SLEQP_FACT_LIBRARIES}
m)
set(SLEQP_DEP_LIBRARY_DIRS
${SLEQP_FACT_LIBRARY_DIRS}
${SLEQP_LPS_LIBRARY_DIRS})
set(SLEQP_DEP_INCLUDE_DIRS
${SLEQP_FACT_INCLUDE_DIRS}
${SLEQP_LPS_INCLUDE_DIRS})
set(SLEQP_DEP_DEFINITIONS
${SLEQP_FACT_DEFINITIONS}
${SLEQP_LPS_DEFINITIONS})
if(UNIX AND NOT APPLE)
list(APPEND SLEQP_DEP_LIBRARIES rt)
endif()
add_custom_target(doc)
# Config files
set(PKGCONFIG_FILE "${PROJECT_BINARY_DIR}/sleqp.pc")
configure_file("${PROJECT_SOURCE_DIR}/cmake/sleqp.pc.in"
"${PKGCONFIG_FILE}"
@ONLY)
include_directories("${PROJECT_BINARY_DIR}")
# Testing
enable_testing()
set(TEST_DIR "${CMAKE_CURRENT_SOURCE_DIR}/src/test" CACHE INTERNAL "")
if(SLEQP_ENABLE_UNIT_TESTS)
add_custom_target(build_tests)
if(CHECK_FOUND)
include_directories(${CHECK_INCLUDE_DIR})
else()
message(STATUS "Could not find Check, C unit tests will be disabled")
set(SLEQP_ENABLE_C_UNIT_TESTS OFF)
endif()
else()
set(SLEQP_ENABLE_C_UNIT_TESTS OFF)
endif()
if(SLEQP_ENABLE_CUTEST)
set(SLEQP_ENABLE_UNIT_TESTS ON)
endif()
if(SLEQP_GENERATE_COVERAGE)
include(Coverage)
if(NOT SLEQP_ENABLE_UNIT_TESTS)
message(FATAL_ERROR "Cannot generate coverage without unit tests")
endif()
enable_coverage()
add_test_coverage_target(NAME "test_coverage"
OUTPUT "${PROJECT_BINARY_DIR}/coverage.xml"
DEPENDS build_tests
EXCLUDE ${TEST_DIR})
endif()
# Subdirectories
add_subdirectory(src)
add_subdirectory(bindings)
# Documentation
find_package(Doxygen)
if(DOXYGEN_FOUND)
add_subdirectory(doc)
endif()
# Coverage
# Miscellaneous installs
set(CONFIG_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/sleqp")
set(PKGCONFIG_DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
set(CONFIG_FILE "${PROJECT_SOURCE_DIR}/cmake/${PROJECT_NAME}-config.cmake")
set(CONFIG_VERSION_FILE "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake")
set(TARGET_FILE "${PROJECT_NAME}-targets.cmake")
install(EXPORT sleqp-targets
FILE ${TARGET_FILE}
NAMESPACE
${PROJECT_NAMESPACE}
DESTINATION
${CONFIG_DESTINATION}
COMPONENT "libraries")
write_basic_package_version_file(
${CONFIG_VERSION_FILE}
VERSION ${PROJECT_VERSION}
COMPATIBILITY SameMajorVersion
)
install(
FILES
${CONFIG_FILE}
${CONFIG_VERSION_FILE}
DESTINATION
${CONFIG_DESTINATION}
COMPONENT "libraries"
)
install(
FILES
"${PKGCONFIG_FILE}"
DESTINATION
${PKGCONFIG_DESTINATION}
COMPONENT "libraries"
)
include(Packaging)
add_feature_info(AMPL SLEQP_ENABLE_AMPL "Interface to AMPL using ASL")
add_feature_info(CUTEst SLEQP_ENABLE_CUTEST "Interface to CUTEst instances")
add_feature_info(Python SLEQP_ENABLE_PYTHON "Python interface")
add_feature_info(MATLAB SLEQP_ENABLE_MATLAB_MEX "MATLAB mex interface")
add_feature_info(Octave SLEQP_ENABLE_OCTAVE_MEX "Octave mex interface")
feature_summary(WHAT ALL)