-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
402 lines (325 loc) · 13.2 KB
/
Copy pathCMakeLists.txt
File metadata and controls
402 lines (325 loc) · 13.2 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
cmake_minimum_required(VERSION 3.14) # FetchContent_MakeAvailable
# Version
set(ANTARES_VERSION_HI 10)
set(ANTARES_VERSION_LO 1)
set(ANTARES_VERSION_REVISION 1)
# Beta release
set(ANTARES_BETA 0)
set(ANTARES_RC 0)
set(ANTARES_VERSION_YEAR 2026)
project(antares
VERSION ${ANTARES_VERSION_HI}.${ANTARES_VERSION_LO}.${ANTARES_VERSION_REVISION})
set(ANTARES_PUBLISHER "RTE France")
set(ANTARES_WEBSITE "https://antares-simulator.org/")
set(ANTARES_ONLINE_DOC "https://antares-simulator.readthedocs.io/")
# OR-Tools tag
file(READ "ortools_tag" ORTOOLS_TAG)
# CMAKE - Suppress useless features
set(CMAKE_SKIP_PREPROCESSED_SOURCE_RULES true)
set(CMAKE_SKIP_ASSEMBLY_SOURCE_RULES true)
set(CMAKE_INSTALL_RPATH $ORIGIN)
include(CheckCXXSourceCompiles)
include(CheckIncludeFiles)
include(CheckIncludeFileCXX)
include(CheckCXXCompilerFlag)
include(CMakeDependentOption)
include(FetchContent)
set(CMAKE_CXX_STANDARD 20)
if (DEFINED VCPKG_ROOT)
include(${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake)
endif ()
#CMake function
include("src/cmake/utils.cmake")
# Only used for code generation (optional)
set(ANTLR_JAR_PATH "" CACHE FILEPATH "Path to ANTLR 4 .jar file (e.g., antlr-4.13.2-complete.jar)")
message(STATUS "ANTLR_JAR_PATH is: ${ANTLR_JAR_PATH}")
#Generate ANTLR4 source files from grammar files
include("src/cmake/antlr4-generate.cmake")
#CMake Macro to display message
include("src/cmake/messages.cmake")
set(ANTARES_VERSION_TAG "")
if (${ANTARES_BETA})
set(ANTARES_VERSION_TAG "-beta${ANTARES_BETA}")
endif ()
if (${ANTARES_RC})
set(ANTARES_VERSION_TAG "-rc${ANTARES_RC}")
endif ()
# git SHA-1
find_package(Git QUIET)
execute_process(COMMAND
"${GIT_EXECUTABLE}" describe --match=NeVeRmAtCh --abbrev=7 --always --dirty
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
OUTPUT_VARIABLE GIT_SHA1_SHORT
ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
# Build Configuration
set(ANTARES_TARGET "${CMAKE_BUILD_TYPE}")
OMESSAGE("")
OMESSAGE_TITLE("Antares " "v${ANTARES_VERSION_HI}.${ANTARES_VERSION_LO}.${ANTARES_VERSION_REVISION}${ANTARES_VERSION_TAG}-${ANTARES_TARGET}")
OMESSAGE("A New Tool for Adequacy Reporting of Electric Systems (RTE France)")
OMESSAGE_BOLD("Configuring...")
OMESSAGE("")
# Making gatherings of several projects under a project folder in IDEs
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
# Copy changelog
include("src/cmake/changelog.cmake")
#Check compiler version
include("src/cmake/checks.cmake")
if (ANTARES_LICENSE)
OMESSAGE("{antares} License : ${ANTARES_LICENSE}")
endif ()
set(ANTARES_PRG_VERSION "${ANTARES_VERSION_HI}.${ANTARES_VERSION_LO}")
#TODO : define if MSVC is used (check if can be removed)
if ((WIN32 OR WIN64) AND (NOT MINGW AND NOT MSVC AND NOT CYGWIN AND NOT MSYS))
set(MSVC 1)
set(ICC 1)
endif ()
#Define which version is compiled (32bits or 64bits)
if (CMAKE_SIZEOF_VOID_P EQUAL 8)
OMESSAGE(" Enabled 64bits instructions sets")
set(ANTARES_x86_64 true)
set(ANTARES_INSTALLER_ARCH "64bits")
set(ANTARES_INSTALLER_REDIST_ARCH "x64")
set(ANTARES_MANIFEST_ARCH "ia64")
else ()
set(ANTARES_INSTALLER_ARCH "32bits")
set(ANTARES_INSTALLER_REDIST_ARCH "x86")
set(ANTARES_MANIFEST_ARCH "x86")
endif ()
#TODO : should not defined compiler name with a global variable
if (WIN32)
if (MSVC)
set(COMPILER_NAME "vc14")
set(COMPILER_LIB_INCLUDE "vc")
else (MSVC)
set(COMPILER_NAME "gcc4.x")
set(COMPILER_LIB_INCLUDE "gcc")
endif (MSVC)
endif (WIN32)
# GNU ld is single-pass for static libraries: circular dependencies between
# libraries (e.g. antares-solver-simulation <-> model_antares) cause unresolved
# symbols. --start-group/--end-group tells ld to re-scan until all are resolved.
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
add_link_options("LINKER:--start-group")
endif ()
#
# Beta
#
if (NOT ANTARES_BETA EQUAL 0)
set(ANTARES_INSTALLER_BETA "-beta${ANTARES_BETA}")
else ()
set(ANTARES_INSTALLER_BETA "")
endif ()
if (${ANTARES_RC})
set(ANTARES_INSTALLER_RC "-rc${ANTARES_RC}")
else ()
set(ANTARES_INSTALLER_RC "")
endif ()
OMESSAGE("")
OMESSAGE("")
#Display Build Configuration (debug or release)
if ("${CMAKE_BUILD_TYPE}" STREQUAL "Release")
OMESSAGE("{antares} Build Configuration: RELEASE")
else ()
OMESSAGE("{antares} Build Configuration: DEBUG")
endif ()
#
# Yuni Framework
#
if ("${CMAKE_BUILD_TYPE}" STREQUAL "Release")
set(YUNI_TARGET_MODE "release")
set(ANTARES_VERSION_TARGET "release")
else ()
set(YUNI_TARGET_MODE "debug")
set(ANTARES_VERSION_TARGET "debug")
endif ()
set(CODE_COVERAGE FALSE CACHE BOOL "Enable code coverage")
if (CODE_COVERAGE)
# if code-coverage is ON, force tests build
set(BUILD_TESTING ON)
include("src/cmake/CodeCoverage.cmake")
code_coverage(NAME code-coverage
OUTPUT_DIR coverage
EXCLUDE_DIRS tests)
endif ()
# TODO : removed to be confirmed : old fashion CMake All libraries will be stored in /bin directory
#set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/../bin/${YUNI_TARGET_MODE})
option(BUILD_TOOLS "Build antares tools" OFF)
message(STATUS "Build antares tools: ${BUILD_TOOLS}")
option(BUILD_ORTOOLS "Build OR-Tools" OFF)
message(STATUS "Build OR-Tools: ${BUILD_ORTOOLS}")
option(BUILD_MERSENNE_TWISTER_PYBIND11 "Build pybind11 bindings for Mersenne-Twister" OFF)
if (${BUILD_MERSENNE_TWISTER_PYBIND11})
find_package(pybind11 REQUIRED)
endif ()
#Boost header libraries
find_package(Boost REQUIRED)
find_package(antlr4-runtime REQUIRED)
find_package(yaml-cpp REQUIRED)
find_package(fmt REQUIRED)
#Sirius solver
if (POLICY CMP0074)
cmake_policy(SET CMP0074 NEW)
endif ()
find_package(sirius_solver REQUIRED)
# When using a pre-compiled OR-Tools package, its transitive dependencies
# (absl, re2) must come from the same installation prefix. The vcpkg toolchain
# prepends vcpkg paths to CMAKE_PREFIX_PATH, so without intervention,
# find_dependency(absl) inside ortoolsConfig.cmake resolves to vcpkg's absl
# (a different version than what OR-Tools was compiled against), causing
# linker errors due to ABI incompatibility (different inline namespaces:
# e.g. absl::lts_20250512 vs absl::lts_20240722).
#
# Fix: locate the OR-Tools install prefix (from ortools_DIR or CMAKE_PREFIX_PATH)
# and set absl_DIR/re2_DIR to the co-installed versions before find_package(ortools)
# triggers find_dependency(absl). Recompute this even when absl_DIR/re2_DIR are
# already cached: switching branches with a reused build directory can leave
# stale paths behind, and CMake will otherwise keep mixing headers/libs from
# different Abseil installations.
# Note: GNUInstallDirs uses "lib" on Windows/Ubuntu but may use "lib64" on
# some 64-bit Linux distributions (e.g. Oracle Linux 8).
# Candidate lib directory names (GNUInstallDirs may use lib or lib64)
set(_lib_dirs lib lib64)
# Determine OR-Tools prefix: either from explicit ortools_DIR or CMAKE_PREFIX_PATH
set(_ortools_prefix "")
if (DEFINED ortools_DIR)
get_filename_component(_ortools_prefix "${ortools_DIR}/../../.." ABSOLUTE)
else ()
foreach(_prefix IN LISTS CMAKE_PREFIX_PATH)
foreach(_libdir IN LISTS _lib_dirs)
if (EXISTS "${_prefix}/${_libdir}/cmake/ortools/ortoolsConfig.cmake")
set(_ortools_prefix "${_prefix}")
break()
endif ()
endforeach ()
if (_ortools_prefix)
break()
endif ()
endforeach ()
endif ()
if (_ortools_prefix)
foreach(_libdir IN LISTS _lib_dirs)
if (EXISTS "${_ortools_prefix}/${_libdir}/cmake/absl/abslConfig.cmake")
set(_ortools_absl_dir "${_ortools_prefix}/${_libdir}/cmake/absl")
if (NOT DEFINED absl_DIR OR NOT absl_DIR STREQUAL "${_ortools_absl_dir}")
set(absl_DIR "${_ortools_absl_dir}" CACHE PATH
"Path to absl CMake config (co-installed with OR-Tools)" FORCE)
message(STATUS "Setting absl_DIR to OR-Tools co-installed version: ${absl_DIR}")
endif ()
endif ()
if (EXISTS "${_ortools_prefix}/${_libdir}/cmake/re2/re2Config.cmake")
set(_ortools_re2_dir "${_ortools_prefix}/${_libdir}/cmake/re2")
if (NOT DEFINED re2_DIR OR NOT re2_DIR STREQUAL "${_ortools_re2_dir}")
set(re2_DIR "${_ortools_re2_dir}" CACHE PATH
"Path to re2 CMake config (co-installed with OR-Tools)" FORCE)
message(STATUS "Setting re2_DIR to OR-Tools co-installed version: ${re2_DIR}")
endif ()
endif ()
endforeach ()
# Ensure OR-Tools' absl headers are found BEFORE vcpkg headers.
# This is necessary because vcpkg.cmake (line 425-426) reverses the
# CMAKE_PREFIX_PATH order for Debug builds, causing vcpkg's absl
# (different ABI version) to be found instead of OR-Tools' co-installed absl.
set(_absl_include "${_ortools_prefix}/include")
if (EXISTS "${_absl_include}/absl")
include_directories(BEFORE "${_absl_include}")
message(STATUS "Prepending include dir for OR-Tools absl: ${_absl_include}")
endif ()
endif ()
unset(_ortools_absl_dir)
unset(_ortools_re2_dir)
unset(_ortools_prefix)
unset(_lib_dirs)
find_package(ortools)
if (NOT ortools_FOUND OR BUILD_ORTOOLS)
message(STATUS "OR-Tools tag ${ORTOOLS_TAG}")
FetchContent_Declare(ortools-rte
GIT_REPOSITORY "https://github.com/rte-france/or-tools-rte.git"
GIT_TAG ${ORTOOLS_TAG}
GIT_SHALLOW TRUE
)
# Pass options to OR-Tools's CMake
set(BUILD_DEPS "ON" CACHE INTERNAL "")
set(BUILD_SAMPLES "OFF" CACHE INTERNAL "")
set(BUILD_FLATZINC "OFF" CACHE INTERNAL "")
set(BUILD_EXAMPLES "OFF" CACHE INTERNAL "")
set(USE_SCIP "ON" CACHE INTERNAL "")
set(USE_GLPK "ON" CACHE INTERNAL "")
# We build OR-Tools as a static lib. Cyclic dependencies are detected
# without this flag.
set(BUILD_SHARED_LIBS "OFF" CACHE INTERNAL "")
# In mode optimization error analysis, we call Sirius through or-tools
# So we need to activate Sirius in or-tools configuration (OFF by default)
set(USE_SIRIUS "ON" CACHE INTERNAL "")
set(ortools_REPO "https://github.com/google/or-tools.git")
string(REGEX MATCH "^[^-]+" OFFICIAL_TAG ${ORTOOLS_TAG})
set(ortools_REF ${OFFICIAL_TAG})
FetchContent_MakeAvailable(ortools-rte)
endif ()
find_package(minizip-ng QUIET)
if (minizip-ng_FOUND)
add_library(MINIZIP::minizip ALIAS MINIZIP::minizip-ng)
else ()
find_package(minizip)
if (minizip_FOUND)
message(STATUS "Found minizip (not minizip-ng).")
else ()
message(FATAL_ERROR "Minizip not found.")
endif ()
endif ()
# TODO : review Standard Settings
include(src/cmake/common-settings.cmake)
# Opt-in build/link time profiling (-DANTARES_TIME_TRACE=ON). Must be included
# before any add_subdirectory() so the flags reach every target.
include(src/cmake/build-profiling.cmake)
add_subdirectory("src/config")
# Configure config.h with current ANTARES version
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/src/config/config.h.in"
"${CMAKE_CURRENT_SOURCE_DIR}/src/config/include/antares/config/config.h")
# Yuni Framework
configure_file("src/cmake/ProfileBuild.template.cmake" "src/ext/yuni/src/ProfileBuild.cmake")
add_subdirectory("src/ext/yuni/src")
OMESSAGE("") # empty line
add_subdirectory("src/api")
add_subdirectory("src/io")
add_subdirectory("src/libs") #antares-core fswalker
add_subdirectory("src/expressions") #modeler expressions (AST)
add_subdirectory("src/optimisation") #optimisation APIs
add_subdirectory("src/study") #antares study model
add_subdirectory("src/solver") #antares solver and all associated libs
add_subdirectory("src/modeler") #antares modeler
add_subdirectory("src/modeler-optimisation-container") #antares modeler
add_subdirectory("src/view-builder") #legacy study to YAML converter
# Tools
if (BUILD_TOOLS)
add_subdirectory("src/tools") #All antares tools
endif ()
# Tests
# Not setting BUILD_TESTING as a command line argument is equivalent to use -DBUILD_TESTING=OFF
# To build tests, use -DBUILD_TESTING=ON
option(BUILD_TESTING "Activates unit tests building" OFF)
if (BUILD_TESTING)
# include(CTest) # calls enable_testing() and turns BUILD_TESTING to ON by default (among other useful things)
enable_testing()
add_subdirectory("src/tests")
endif ()
OMESSAGE("")
if (CMAKE_SYSTEM_NAME MATCHES "Linux")
get_linux_lsb_release_information()
message(STATUS "Linux ${LSB_RELEASE_ID_SHORT} ${LSB_RELEASE_VERSION_SHORT} ${LSB_RELEASE_CODENAME_SHORT}")
set(CPACK_SYSTEM_NAME "${LSB_RELEASE_ID_SHORT}-${LSB_RELEASE_VERSION_SHORT}")
endif ()
#For now only test deb, need to define several CPACK variable
set(CPACK_PROJECT_NAME "antares-deb-test")
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "RTE")
set(CPACK_DEBIAN_PACKAGE_NAME "antares")
set(CPACK_PACKAGE_VERSION_MAJOR ${ANTARES_VERSION_HI})
set(CPACK_PACKAGE_VERSION_MINOR ${ANTARES_VERSION_LO})
set(CPACK_PACKAGE_VERSION_PATCH ${ANTARES_VERSION_REVISION}${ANTARES_VERSION_TAG})
configure_file("src/distrib/unix/packages.cmake" "distrib/unix/packages.sh")
# Load packaging facilities.
include(CPack)
#Last. We need all target defined
add_subdirectory("src/packaging")
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
add_link_options("LINKER:--end-group")
endif()