-
Notifications
You must be signed in to change notification settings - Fork 30
/
CMakeLists.txt
executable file
·368 lines (305 loc) · 10.7 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
cmake_minimum_required(VERSION 3.16)
project(Gravity)
enable_testing()
include(ExternalProject)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/cmake)
set(MACOSX_RPATH 1)
# Debug mode
option(Debug "Turn on debug mode" OFF)
# Coverage
option(Cov "Turn on coverage" OFF)
# Find PcapPlusPlus (optional)
option(PcapPlusPlus "Link to PcapPlusPlus libraries" OFF)
# Find GUROBI (optional)
option(Gurobi "Link to GUROBI libraries" OFF)
# Find HiGHS (optional)
option(HiGHS "Link to HiGHS libraries" OFF)
# Find IPOPT (optional)
option(Ipopt "Link to IPOPT libraries" ON)
option(MP "Link to AMPL MP libraries" OFF)
option(CoinUtils "Link to CoinUtils libraries" OFF)
# Find XLNT (optional)
option(Xlnt "Link to XLNT libraries" OFF)
# Find BONMIN (optional)
option(Bonmin "Link to BONMIN libraries" OFF)
# Find CPLEX (optional)
option(Cplex "Link to CPLEX libraries" OFF)
# Find SDPA (optional)
option(Sdpa "Link to SDPA libraries" OFF)
# Find MOSEK (optional)
option(Mosek "Link to MOSEK libraries" OFF)
# include BOOST (optional)
option(Boost "Link to BOOST libraries" OFF)
# include QPP (optional)
option(Qpp "Link to QPP libraries" OFF)
# Find CLP (optional)
option(Clp "Link to CLP libraries" OFF)
# Find OpenMPI (optional)
option(OpenMPI "Link to OpenMPI libraries" OFF)
# Find OPT_PARSER (optional)
option(OPT_PARSER "Link to OPT_PARSER libraries" OFF)
if (OpenMPI)
SET(CMAKE_CXX_COMPILER mpicxx)
SET(CMAKE_C_COMPILER mpicc)
message("Compilers used: ${CMAKE_C_COMPILER} and ${CMAKE_CXX_COMPILER}")
message(STATUS "Enable OpenMPI")
add_definitions(-DUSE_MPI)
# find_package(OpenMPI REQUIRED)
# include_directories(${OpenMPI_INCLUDE_DIRS})
# set(LIBS ${LIBS} ${OpenMPI_LIBRARIES})
endif()
if (PcapPlusPlus)
message(STATUS "Enable PcapPlusPlus")
add_definitions(-DUSE_PcapPlusPlus)
find_package(PcapPlusPlus REQUIRED)
include_directories(${PcapPlusPlus_INCLUDE_DIRS}/pcapplusplus)
set(LIBS ${LIBS} ${PcapPlusPlus_LIBRARIES})
endif()
# Find xlnt
if (Xlnt)
message(STATUS "Enable XLNT")
add_definitions(-DUSE_XLNT)
find_package(XLNT REQUIRED)
include_directories(${XLNT_INCLUDE_DIRS}/..)
set(LIBS ${LIBS} ${XLNT_LIBRARIES})
endif()
# Find SDPA.
if (Sdpa)
message(STATUS "Enable SDPA")
add_definitions(-DUSE_SDPA)
find_package(SDPA REQUIRED)
include_directories(${SDPA_INCLUDE_DIRS})
set(LIBS ${LIBS} ${SDPA_LIBRARIES})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -funroll-all-loops -Wall -fPIC -funroll-all-loops")
set(CMAKE_Fortran_FLAGS "-g -O2 -Wall -fPIC -funroll-all-loops")
endif()
# Find MOSEK.
if (Mosek)
set(MOSEK_ROOT_DIR "$ENV{MOSEK_ROOT_DIR}" CACHE PATH "MOSEK root directory.")
message(STATUS "Enable MOSEK")
add_definitions(-DUSE_MOSEK)
find_package(MOSEK REQUIRED)
include_directories(${MOSEK_INCLUDE_DIRS})
set(LIBS ${LIBS} ${MOSEK_LIBRARIES})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
link_directories(${MOSEK_ROOT_DIR}/bin)
link_directories(${MOSEK_ROOT_DIR}/src/fusion_cxx)
endif()
# Find gurobi?
if (Gurobi)
message(STATUS "Enable GUROBI")
add_definitions(-DUSE_GUROBI)
find_package(GUROBI)
include_directories(${GUROBI_INCLUDE_DIRS})
set(LIBS ${LIBS} ${GUROBI_LIBRARIES})
endif()
# Find CLP?
if (Clp)
message(STATUS "Enable CLP")
add_definitions(-DUSE_CLP)
find_package(CLP REQUIRED)
include_directories(${CLP_INCLUDE_DIRS}/)
set(LIBS ${LIBS} ${CLP_LIBRARIES})
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lCoinUtils -lClp")
endif()
# Find BONMIN?
if (Bonmin)
message(STATUS "Enable BONMIN")
add_definitions(-DUSE_BONMIN)
find_package(BONMIN)
include_directories(${BONMIN_INCLUDE_DIRS}/..)
set(LIBS ${LIBS} ${BONMIN_LIBRARIES})
endif()
# Find CPLEX?
if (Cplex)
message(STATUS "Enable CPLEX")
add_definitions(-DUSE_CPLEX)
find_package(CPLEX)
include_directories(${CPLEX_INCLUDE_DIRS})
set(LIBS ${LIBS} ${CPLEX_LIBRARIES})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -DNDEBUG -DIL_STD")
endif()
# Find BOOST?
if (Boost)
message(STATUS "Enable BOOST")
add_definitions(-DUSE_BOOST)
include_directories("/usr/local/include/")
set(LIBS ${LIBS} "usr/local/lib/")
endif()
set(UNZIPPED OFF CACHE BOOL "Already unzipped")
if(NOT UNZIPPED)
message(STATUS "Unzipping Classification Data")
execute_process(
COMMAND ${CMAKE_COMMAND} -E tar xzf ${PROJECT_SOURCE_DIR}/data_sets/Classification/Archive.tar.gz
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/data_sets/Classification
)
endif()
set_directory_properties(PROPERTIES EP_BASE ${CMAKE_BINARY_DIR}/third_party)
get_directory_property(THIRDPARTY_BASE_PATH EP_BASE)
set(THIRDPARTY_INSTALL_PATH ${THIRDPARTY_BASE_PATH})
if(NOT WIN32)
#CoinUtils
if (CoinUtils)
message(STATUS "Enable CoinUtils")
add_definitions(-DUSE_CoinUtils)
find_package(CoinUtils QUIET)
if (CoinUtils_FOUND)
message("-- Found CoinUtils: ${CoinUtils_INCLUDE_DIRS}")
include_directories(${CoinUtils_INCLUDE_DIRS})
set(LIBS ${LIBS} ${CoinUtils_LIBRARIES})
else(CoinUtils_FOUND)
set(ADD_CoinUtils TRUE)
message(STATUS "Will download CoinUtils library from https://github.com/coin-or/CoinUtils")
include(ExternalCoinUtils)
if(APPLE)
set(CoinUtils_LIBRARY ${THIRDPARTY_INSTALL_PATH}/Install/CoinUtils/build/lib/libCoinUtils.dylib)
elseif(UNIX)
set(CoinUtils_LIBRARY ${THIRDPARTY_INSTALL_PATH}/Install/CoinUtils/build/lib/libCoinUtils.so)
endif(APPLE)
endif()
endif()
#MP
if (MP)
message(STATUS "Enable AMPL MP")
add_definitions(-DUSE_MP)
find_package(MP QUIET)
if (MP_FOUND)
message("-- Found AMPL MP: ${MP_INCLUDE_DIRS}")
include_directories(${MP_INCLUDE_DIRS}/..)
set(LIBS ${LIBS} ${MP_LIBRARIES})
else(MP_FOUND)
set(ADD_MP TRUE)
message(STATUS "Will download AMPL MP library from https://github.com/ampl/mp.git")
include(ExternalMP)
set(MP_LIBRARY ${THIRDPARTY_INSTALL_PATH}/Install/MP/build/lib/libmp.a)
endif()
endif()
# Find HiGHS?
if (HiGHS)
message(STATUS "Enable HiGHS")
add_definitions(-DUSE_HiGHS)
find_package(HiGHS)
if (HiGHS_FOUND)
message("-- Found HiGHS: ${HiGHS_INCLUDE_DIRS}")
include_directories(${HiGHS_INCLUDE_DIRS})
set(LIBS ${LIBS} ${HiGHS_LIBRARIES})
else(HiGHS_FOUND)
set(ADD_HiGHS TRUE)
message(STATUS "Will download HiGHS library from https://github.com/ERGO-Code/HiGHS")
include(ExternalHiGHS)
if(APPLE)
set(HiGHS_LIBRARIES ${THIRDPARTY_INSTALL_PATH}/Install/HiGHS/build/lib/libhighs.dylib)
elseif(UNIX)
set(HiGHS_LIBRARIES ${THIRDPARTY_INSTALL_PATH}/Install/HiGHS/build/lib/libhighs.so)
elseif(WIN32)
set(HiGHS_LIBRARIES ${THIRDPARTY_INSTALL_PATH}/Install/HiGHS/build/lib/libhighs.lib)
endif(APPLE)
endif(HiGHS_FOUND)
endif(HiGHS)
endif()
if(Ipopt)
# Add Ipopt include dir and link to libraries
if(WIN32)
# include_directories("${PROJECT_SOURCE_DIR}/thirdparty/Ipopt")
include_directories("${PROJECT_SOURCE_DIR}/thirdparty/Ipopt/include/coin-or")
# add_subdirectory(thirdparty/Ipopt)
# find_library(IPOPT_LIBRARIES
# ipopt.dll
# HINTS /usr/local/lib
# HINTS ${PROJECT_SOURCE_DIR}/thirdparty/Ipopt
# HINTS ${IPOPT_ROOT_DIR}/lib
# )
endif(WIN32)
message(STATUS "Enable IPOPT")
add_definitions(-DUSE_IPOPT)
find_package(IPOPT QUIET)
if (IPOPT_FOUND)
message("-- Found IPOPT: ${IPOPT_INCLUDE_DIRS}")
include_directories(${IPOPT_INCLUDE_DIRS})
set(LIBS ${LIBS} ${IPOPT_LIBRARIES})
else(IPOPT_FOUND)
set(ADD_IPOPT TRUE)
if(APPLE)
set(IPOPT_LIBRARIES ${THIRDPARTY_INSTALL_PATH}/Install/ipopt/build/lib/libipopt.dylib)
elseif(UNIX)
set(IPOPT_LIBRARIES ${PROJECT_SOURCE_DIR}/thirdparty/Ipopt/libipopt.so)
elseif(WIN32)
set(IPOPT_LIBRARIES ${PROJECT_SOURCE_DIR}/thirdparty/Ipopt/libipopt-3.lib)
endif(APPLE)
include(ExternalIpopt)
endif (IPOPT_FOUND)
endif()
# Eigen
if(!WIN32)
find_package(Eigen QUIET)
if (EIGEN_FOUND)
message("-- Found Eigen version ${EIGEN_VERSION}: ${EIGEN_INCLUDE_DIRS}")
else(EIGEN_FOUND)
set(EIGEN_VERSION 3.3.7)
include(ExternalEigen)
set(EIGEN_INCLUDE_DIR ${THIRDPARTY_INSTALL_PATH}/Install/eigen)
set(ADD_EIGEN TRUE)
endif (EIGEN_FOUND)
include_directories(${EIGEN_INCLUDE_DIR})
endif()
# cpp_option_parser
if (OPT_PARSER)
set(OPT_PARSER_VERSION v1.0)
message(STATUS "Enable OPT_PARSER")
add_definitions(-DUSE_OPT_PARSER)
include(ExternalOptParser)
set(OPT_PARSER_INCLUDE_DIR ${THIRDPARTY_INSTALL_PATH}/Source/opt_parser)
link_directories(${THIRDPARTY_INSTALL_PATH}/Build/opt_parser)
link_directories(${THIRDPARTY_INSTALL_PATH}/Build/opt_parser/Debug)
include_directories(${OPT_PARSER_INCLUDE_DIR})
include_directories(${THIRDPARTY_INSTALL_PATH}/include)
endif()
# Find QPP?
if (Qpp AND NOT UNZIPPED)
message(STATUS "Unzipping QPP v1.0")
execute_process(
COMMAND ${CMAKE_COMMAND} -E tar xzf ${PROJECT_SOURCE_DIR}/third_party/qpp-1.0.tar.gz
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/third_party
)
add_definitions(-DUSE_QPP)
include_directories(${PROJECT_SOURCE_DIR}/third_party/qpp-1.0/include)
endif()
set(UNZIPPED ON CACHE BOOL "Already unzipped" FORCE)
# Include Power dirs
include_directories(${PROJECT_SOURCE_DIR}/examples/Optimization/NonLinear/Power)
include_directories(${PROJECT_SOURCE_DIR}/examples/Optimization/Linear/Rostering)
# include_directories(${PROJECT_SOURCE_DIR}/solvers)
# Include ML dirs
include_directories(${PROJECT_SOURCE_DIR}/examples/MachineLearning)
set(LIBS ${LIBS} ${PROJECT_SOURCE_DIR}/lib ${PROJECT_SOURCE_DIR}/lib/Release ${PROJECT_SOURCE_DIR}/lib/Debug)
# Compiler options
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Ofast")
# Build options
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/bin/Release)
set(PROJECT_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/include)
set(PROJECT_BINARY_DIR ${PROJECT_SOURCE_DIR}/build)
set(CMAKE_BUILD_TYPE "Release")
if (Debug)
set(CMAKE_BUILD_TYPE "Debug")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/bin/Debug)
endif()
if(Cov)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage")
set(CMAKE_LINKER_FLAGS "${CMAKE_LINKER_FLAGS} -fprofile-arcs -lgcov")
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wno-absolute-value")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-rpath,'\$ORIGIN/lib'")
if(UNIX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pthread")
set(CMAKE_LINKER_FLAGS "${CMAKE_LINKER_FLAGS} -pthread")
endif()
set(CMAKE_XCODE_ATTRIBUTE_LD_RUNPATH_SEARCH_PATHS "$ENV{DYLD_LIBRARY_PATH}")
add_subdirectory(src)
add_subdirectory(examples)
# add_subdirectory(solvers)
#Get user defined configuration including passing project source directory into c++ code
configure_file(GravityConfig.h.in ${PROJECT_SOURCE_DIR}/include/gravity/GravityConfig.h)
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/gravity DESTINATION include)