Repository navigation
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
492 lines (423 loc) · 17 KB
/
Copy pathCMakeLists.txt
File metadata and controls
492 lines (423 loc) · 17 KB
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
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
# --------------------------------------------------------------------------- #
# Main CMake file for SMS++ umbrella project #
# #
# The goal of this list file is to provide a quick way to configure #
# and build all the SMS++ projects together. It doesn't do much besides #
# calling the list files of the subprojects. #
# #
# Donato Meoli #
# Dipartimento di Informatica #
# Universita' di Pisa #
# --------------------------------------------------------------------------- #
cmake_minimum_required(VERSION 3.21)
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/DeriveVersion.cmake)
smspp_derive_version(SMSPP_MODULE_VERSION)
# ----- Project definition and configuration -------------------------------- #
project(SMS++_project
VERSION ${SMSPP_MODULE_VERSION}
DESCRIPTION "The SMS++ Project"
HOMEPAGE_URL https://gitlab.com/smspp-project
LANGUAGES C CXX)
# This file can contain custom settings.
# Use it as an alternative to specify CMake variables manually with -D.
include(CMakeSettings.txt OPTIONAL)
option(BUILD_SHARED_LIBS "Build libraries as shared" OFF)
# ----- Third-party sources of a release tarball ---------------------------- #
# The release tarball carries FastFlow and RECORD in third-party/, at the
# commits of packaging/modules.py [see packaging/third_party.py]: they are
# used in place of the FastFlow that SMS++ fetches and of a RECORD checkout,
# so that a build of the tarball fetches nothing, unless something else is
# given on the command line.
set(_smspp_third_party "${CMAKE_CURRENT_SOURCE_DIR}/third-party")
if (EXISTS "${_smspp_third_party}/fastflow/ff" AND
NOT FETCHCONTENT_SOURCE_DIR_FASTFLOW)
set(FETCHCONTENT_SOURCE_DIR_FASTFLOW "${_smspp_third_party}/fastflow"
CACHE PATH "The source tree of FastFlow, not fetched")
endif ()
if (EXISTS "${_smspp_third_party}/record/source/RECORD.cpp" AND
NOT RECORD_ROOT)
set(RECORD_ROOT "${_smspp_third_party}/record"
CACHE PATH "The directory of RECORD, with source/RECORD.cpp")
endif ()
# Only apply this on Windows when building shared libraries
if (WIN32 AND BUILD_SHARED_LIBS)
# Enable automatic symbol export introduced in CMake 3.4
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON CACHE BOOL "Force export of all symbols on Windows")
endif ()
# Disable linker manifest on MSVC to avoid conflicts
if (MSVC)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /MANIFEST:NO")
endif ()
# Define options for modules in the order of the blocks and solvers
macro(smspp_option option_name option_description)
string(REPLACE "BUILD_" "" dir ${option_name})
# if the submodule is already initialized...
if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${dir}/CMakeLists.txt")
# ... then set the default option to ON...
option(${option_name} "${option_description}" ON)
else ()
# ... otherwise set the default option to OFF
option(${option_name} "${option_description}" OFF)
endif ()
endmacro()
# Blocks
smspp_option(BUILD_BinaryKnapsackBlock "Build BinaryKnapsackBlock")
smspp_option(BUILD_UCBlock "Build UCBlock")
smspp_option(BUILD_MCFBlock "Build MCFBlock")
smspp_option(BUILD_MMCFBlock "Build MMCFBlock")
smspp_option(BUILD_LukFiBlock "Build LukFiBlock")
smspp_option(BUILD_StochasticBlock "Build StochasticBlock")
smspp_option(BUILD_SDDPBlock "Build SDDPBlock")
smspp_option(BUILD_CapacitatedFacilityLocationBlock "Build CapacitatedFacilityLocationBlock")
smspp_option(BUILD_InvestmentBlock "Build InvestmentBlock")
smspp_option(BUILD_TwoStageStochasticBlock "Build TwoStageStochasticBlock")
smspp_option(BUILD_MultiStageStochasticBlock "Build MultiStageStochasticBlock")
smspp_option(BUILD_SVMBlock "Build SVMBlock")
smspp_option(BUILD_SingleFlowDCRBlock "Build SingleFlowDCRBlock")
smspp_option(BUILD_SATBlock "Build SATBlock")
smspp_option(BUILD_SatellitesBlock "Build SatellitesBlock")
smspp_option(BUILD_MultiKnapsackAssignBlock "Build MultiKnapsackAssignBlock")
smspp_option(BUILD_HQPBlock "Build HQPBlock")
# Solvers
smspp_option(BUILD_MILPSolver "Build MILPSolver")
smspp_option(BUILD_BendersDecompositionSolver "Build BendersDecompositionSolver")
smspp_option(BUILD_BranchAndXSolver "Build BranchAndXSolver")
smspp_option(BUILD_FrankWolfeSolver "Build FrankWolfeSolver")
smspp_option(BUILD_BundleSolver "Build BundleSolver")
smspp_option(BUILD_SubGradSolver "Build SubGradSolver")
smspp_option(BUILD_LagrangianDualSolver "Build LagrangianDualSolver")
smspp_option(BUILD_MCFClassSolver "Build MCFClassSolver")
smspp_option(BUILD_MCFLemonSolver "Build MCFLemonSolver")
smspp_option(BUILD_ScenarioReductionSolver "Build ScenarioReductionSolver")
smspp_option(BUILD_tools "Build tools")
smspp_option(BUILD_tests "Build system tests")
smspp_option(BUILD_experiments "Build the computational studies of the papers")
# Read the dependencies default location from a file written in a
# bash-style syntax since it is shared with the other hand-written Makefiles,
# so we define a function to convert these macros written as `lhs = rhs` into
# their equivalent cmake variants, i.e., `set(lhs rhs)`, avoiding comments.
macro(makefile_macros_to_cmake file)
FILE(STRINGS ${file} paths)
foreach (path IN LISTS paths)
if (path) # ignore empty lines, i.e., \n
# makes empty the comment lines, i.e., those start with #...
string(REGEX REPLACE "^[ \t]*[#].*" "" path ${path})
if (path) # ... and then ignore them
string(REGEX MATCH ".*[=]" lhs "${path}") # retrieve the lhs
string(REGEX REPLACE "=" "" lhs ${lhs}) # remove =
# remove tab or white spaces from head
string(STRIP "${lhs}" lhs)
# if it's not already defined before in custom makefile-paths...
if (NOT DEFINED ${lhs})
# then read its rhs...
string(REGEX MATCH "[=].*" rhs "${path}") # retrieve the rhs
# remove comments starting with # from tails, if any
string(REGEX REPLACE "[#].*" "" rhs ${rhs})
string(REGEX REPLACE "=" "" rhs ${rhs}) # remove =
string(REGEX REPLACE "\"" "" rhs ${rhs}) # remove ", if any
# remove tab or white space from head or tail
string(STRIP "${rhs}" rhs)
# ... and if it is not a default path in Unix...
if (NOT (rhs STREQUAL /usr OR
rhs STREQUAL /usr/local))
# ... then set the one defined in makefile-default-paths-*
set("${lhs}" ${rhs})
#message(STATUS "Specify ${lhs}: " ${rhs})
endif ()
endif ()
unset(lhs)
unset(rhs)
endif ()
endif ()
endforeach ()
unset(path)
unset(paths)
endmacro()
# firstly, set the custom makefile-paths, if any...
if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/extlib/makefile-paths")
makefile_macros_to_cmake(extlib/makefile-paths)
endif ()
# ... then set the default other ones ignoring those already previously set,
# according to the specific OS. A package turns them off, so that what a
# machine has under the default locations (e.g., /opt) is not built into it
option(SMSPP_EXTLIB_DEFAULTS
"Look for the dependencies in the default locations of extlib/" ON)
if (SMSPP_EXTLIB_DEFAULTS)
if (UNIX)
if (APPLE)
makefile_macros_to_cmake(extlib/makefile-default-paths-macos)
else ()
makefile_macros_to_cmake(extlib/makefile-default-paths-linux)
endif ()
elseif (WIN32)
makefile_macros_to_cmake(extlib/makefile-default-paths-win)
endif ()
endif ()
# Retrieve the system architecture
if (CMAKE_SIZEOF_VOID_P EQUAL 8)
if (UNIX)
if (APPLE)
if (CMAKE_SYSTEM_PROCESSOR STREQUAL "arm64") # Apple Silicon MX arch
set(ARCH arm64)
else () # Intel arch
set(ARCH x86-64)
endif ()
else ()
set(ARCH x86-64)
endif ()
elseif (WIN32)
set(ARCH x64)
endif ()
else ()
set(ARCH x86)
endif ()
# ----- Handle dependencies ------------------------------------------------- #
# Resolve dependencies before adding subdirectories
# Blocks
if (BUILD_MMCFBlock)
set(BUILD_MCFBlock ON) # Requires MCFBlock
set(BUILD_BinaryKnapsackBlock ON) # Requires BinaryKnapsackBlock
endif ()
if (BUILD_InvestmentBlock)
set(BUILD_SDDPBlock ON) # Requires SDDPBlock
set(BUILD_TwoStageStochasticBlock ON) # Requires TwoStageStochasticBlock
set(BUILD_UCBlock ON) # Requires UCBlock
endif ()
if (BUILD_TwoStageStochasticBlock)
set(BUILD_StochasticBlock ON) # Requires StochasticBlock
endif ()
if (BUILD_MultiStageStochasticBlock)
set(BUILD_TwoStageStochasticBlock ON) # Requires TwoStageStochasticBlock
set(BUILD_StochasticBlock ON) # Requires StochasticBlock
endif ()
if (BUILD_SDDPBlock)
set(BUILD_StochasticBlock ON) # Requires StochasticBlock
endif ()
if (BUILD_CapacitatedFacilityLocationBlock)
set(BUILD_MCFBlock ON) # Requires MCFBlock
set(BUILD_BinaryKnapsackBlock ON) # Requires BinaryKnapsackBlock
endif ()
if (BUILD_MultiKnapsackAssignBlock)
set(BUILD_BinaryKnapsackBlock ON) # Requires BinaryKnapsackBlock
endif ()
# Solvers
if (BUILD_BundleSolver)
set(BUILD_MILPSolver ON) # Requires MILPSolver
endif ()
if (BUILD_LagrangianDualSolver)
set(BUILD_MILPSolver ON) # Requires MILPSolver
endif ()
if (BUILD_MCFClassSolver)
set(BUILD_MCFBlock ON) # Requires MCFBlock
endif ()
if (BUILD_MCFLemonSolver)
set(BUILD_MCFBlock ON) # Requires MCFBlock
endif ()
if (BUILD_ScenarioReductionSolver)
set(BUILD_TwoStageStochasticBlock ON) # Requires TwoStageStochasticBlock
endif ()
# ----- Initialize submodules ----------------------------------------------- #
macro(init_submodule name)
# if the submodule is not initialized...
if (NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${name}/CMakeLists.txt")
execute_process(
COMMAND git submodule update --init --recursive ${name}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
endif ()
endmacro()
# smspp_check_module(), which the modules call before SMS++ is added below
# [see SMS++/cmake/CheckModule.cmake]: the core, which every module needs, is
# initialized here, since a build of a single module (e.g., in its CI) may
# start with no submodule checked out
init_submodule(SMS++)
include(${CMAKE_CURRENT_SOURCE_DIR}/SMS++/cmake/CheckModule.cmake OPTIONAL)
# ----- Testing ------------------------------------------------------------- #
# Enable testing at the top level, so that the per-module tests are
# reachable by ctest from the build root even when the system tests
# (BUILD_tests) are not built; CTest defines BUILD_TESTING (default ON).
# CTest also gives each test a default timeout of 1500 s, which the
# batteries of the bundle and of the decompositions exceed: 0 leaves the
# tests with no timeout, unless they have one of their own.
set(DART_TESTING_TIMEOUT 0 CACHE STRING "Default timeout of a test (s)")
include(CTest)
# ----- Subprojects --------------------------------------------------------- #
# The core library is required by all other SMS++ modules, if any
# Requires Boost (headers only), netCDF-C++ and Eigen3.
set(SMSPP_REQUIRED OFF)
# Blocks
if (BUILD_BinaryKnapsackBlock)
init_submodule(BinaryKnapsackBlock)
add_subdirectory(BinaryKnapsackBlock)
set(SMSPP_REQUIRED ON)
endif ()
if (BUILD_UCBlock)
init_submodule(UCBlock)
add_subdirectory(UCBlock)
set(SMSPP_REQUIRED ON)
endif ()
if (BUILD_MCFBlock)
init_submodule(MCFBlock)
add_subdirectory(MCFBlock)
set(SMSPP_REQUIRED ON)
endif ()
if (BUILD_MMCFBlock)
init_submodule(MMCFBlock)
add_subdirectory(MMCFBlock)
set(SMSPP_REQUIRED ON)
endif ()
if (BUILD_LukFiBlock)
init_submodule(LukFiBlock)
add_subdirectory(LukFiBlock)
set(SMSPP_REQUIRED ON)
endif ()
if (BUILD_StochasticBlock)
init_submodule(StochasticBlock)
add_subdirectory(StochasticBlock)
set(SMSPP_REQUIRED ON)
endif ()
if (BUILD_SDDPBlock)
init_submodule(SDDPBlock)
add_subdirectory(SDDPBlock)
set(SMSPP_REQUIRED ON)
endif ()
if (BUILD_CapacitatedFacilityLocationBlock)
init_submodule(CapacitatedFacilityLocationBlock)
add_subdirectory(CapacitatedFacilityLocationBlock)
set(SMSPP_REQUIRED ON)
endif ()
if (BUILD_TwoStageStochasticBlock)
init_submodule(TwoStageStochasticBlock)
add_subdirectory(TwoStageStochasticBlock)
set(SMSPP_REQUIRED ON)
endif ()
if (BUILD_InvestmentBlock)
init_submodule(InvestmentBlock)
add_subdirectory(InvestmentBlock)
set(SMSPP_REQUIRED ON)
endif ()
if (BUILD_MultiStageStochasticBlock)
init_submodule(MultiStageStochasticBlock)
add_subdirectory(MultiStageStochasticBlock)
set(SMSPP_REQUIRED ON)
endif ()
if (BUILD_SVMBlock)
init_submodule(SVMBlock)
add_subdirectory(SVMBlock)
set(SMSPP_REQUIRED ON)
endif ()
if (BUILD_SingleFlowDCRBlock)
init_submodule(SingleFlowDCRBlock)
add_subdirectory(SingleFlowDCRBlock)
set(SMSPP_REQUIRED ON)
endif ()
if (BUILD_SATBlock)
init_submodule(SATBlock)
add_subdirectory(SATBlock)
set(SMSPP_REQUIRED ON)
endif ()
if (BUILD_SatellitesBlock)
init_submodule(SatellitesBlock)
add_subdirectory(SatellitesBlock)
set(SMSPP_REQUIRED ON)
endif ()
if (BUILD_MultiKnapsackAssignBlock)
init_submodule(MultiKnapsackAssignBlock)
add_subdirectory(MultiKnapsackAssignBlock)
set(SMSPP_REQUIRED ON)
endif ()
if (BUILD_HQPBlock)
init_submodule(HQPBlock)
add_subdirectory(HQPBlock)
set(SMSPP_REQUIRED ON)
endif ()
# Solvers
if (BUILD_MILPSolver)
init_submodule(MILPSolver)
add_subdirectory(MILPSolver)
set(SMSPP_REQUIRED ON)
endif ()
if (BUILD_BendersDecompositionSolver)
init_submodule(BendersDecompositionSolver)
add_subdirectory(BendersDecompositionSolver)
set(SMSPP_REQUIRED ON)
endif ()
if (BUILD_BranchAndXSolver)
init_submodule(BranchAndXSolver)
add_subdirectory(BranchAndXSolver)
set(SMSPP_REQUIRED ON)
endif ()
if (BUILD_FrankWolfeSolver)
init_submodule(FrankWolfeSolver)
add_subdirectory(FrankWolfeSolver)
set(SMSPP_REQUIRED ON)
endif ()
if (BUILD_BundleSolver)
init_submodule(BundleSolver)
add_subdirectory(BundleSolver)
set(SMSPP_REQUIRED ON)
endif ()
if (BUILD_SubGradSolver)
init_submodule(SubGradSolver)
add_subdirectory(SubGradSolver)
set(SMSPP_REQUIRED ON)
endif ()
if (BUILD_LagrangianDualSolver)
init_submodule(LagrangianDualSolver)
add_subdirectory(LagrangianDualSolver)
set(SMSPP_REQUIRED ON)
endif ()
if (BUILD_MCFClassSolver)
init_submodule(MCFClassSolver)
add_subdirectory(MCFClassSolver)
set(SMSPP_REQUIRED ON)
endif ()
if (BUILD_MCFLemonSolver)
init_submodule(MCFLemonSolver)
add_subdirectory(MCFLemonSolver)
set(SMSPP_REQUIRED ON)
endif ()
if (BUILD_ScenarioReductionSolver)
init_submodule(ScenarioReductionSolver)
add_subdirectory(ScenarioReductionSolver)
set(SMSPP_REQUIRED ON)
endif ()
# ----- Tools --------------------------------------------------------------- #
if (BUILD_tools)
init_submodule(tools)
add_subdirectory(tools)
set(SMSPP_REQUIRED ON)
endif ()
# ----- System tests -------------------------------------------------------- #
if (BUILD_tests)
init_submodule(tests)
add_subdirectory(tests)
set(SMSPP_REQUIRED ON)
enable_testing()
endif ()
# ----- Experiments --------------------------------------------------------- #
# The computational studies of the papers are a private submodule, which
# .gitmodules marks "update = none" so that a recursive clone or update skips
# it: it is built only when whoever has access has initialized it.
if (BUILD_experiments AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/experiments/CMakeLists.txt")
add_subdirectory(experiments)
set(SMSPP_REQUIRED ON)
endif ()
# ----- SMS++ --------------------------------------------------------------- #
if (SMSPP_REQUIRED)
init_submodule(SMS++)
add_subdirectory(SMS++)
endif ()
# ----- Binary packages ----------------------------------------------------- #
# cpack packs what the build installs, i.e. the libraries, the headers and the
# tools of the enabled modules, in the archives the release pipeline publishes
set(CPACK_PACKAGE_NAME ${PROJECT_NAME})
set(CPACK_PACKAGE_VENDOR "SMS++ Project")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY ${PROJECT_DESCRIPTION})
set(CPACK_PACKAGE_HOMEPAGE_URL ${PROJECT_HOMEPAGE_URL})
set(CPACK_PACKAGE_VERSION ${PROJECT_VERSION})
set(CPACK_PACKAGE_FILE_NAME
"${PROJECT_NAME}-${PROJECT_VERSION}-${CMAKE_SYSTEM_NAME}")
set(CPACK_RESOURCE_FILE_LICENSE ${CMAKE_CURRENT_SOURCE_DIR}/LICENSE)
set(CPACK_SOURCE_GENERATOR "")
include(CPack)
# --------------------------------------------------------------------------- #