1
- #
1
+ #
2
2
# Copyright (c) 2021, RTE (http://www.rte-france.com)
3
3
# See AUTHORS.txt
4
4
# All rights reserved.
5
5
# This Source Code Form is subject to the terms of the Mozilla Public
6
6
# License, v. 2.0. If a copy of the MPL was not distributed with this
7
7
# file, you can obtain one at http://mozilla.org/MPL/2.0/.
8
8
# SPDX-License-Identifier: MPL-2.0
9
- #
9
+ #
10
10
11
+ # Minimal CMake required version
11
12
cmake_minimum_required (VERSION 3.14 FATAL_ERROR)
12
13
14
+ # Include helper functions for creating config files
13
15
include (CMakePackageConfigHelpers)
14
16
15
- project (MetrixSimulator
17
+ # Project description
18
+ project (MetrixSimulator
16
19
VERSION 7.4.0
17
20
LANGUAGES C CXX)
18
21
22
+ # Explicitly activate policies
19
23
cmake_policy (SET CMP0074 NEW) # Use <package>_ROOT variables to find package
24
+ if (POLICY CMP0167)
25
+ # The new version of this policy removes the FindBoost.cmake and uses the official Boost Cmake support
26
+ # However it's only available after the version 1.70+ so, since we ask for version 1.66+, we need the old policy
27
+ cmake_policy (SET CMP0167 OLD)
28
+ endif ()
20
29
21
- message ("Build directory : ${CMAKE_BINARY_DIR} " )
22
- message ("Source directory : ${CMAKE_SOURCE_DIR} " )
30
+ # Show build and source directories
31
+ message ("-- Build directory : ${CMAKE_BINARY_DIR} " )
32
+ message ("-- Source directory : ${CMAKE_SOURCE_DIR} " )
23
33
34
+ # Enable C++11 standards
24
35
set (CMAKE_CXX_STANDARD 11)
25
36
set (CMAKE_CXX_STANDARD_REQUIRED true )
26
37
27
- set (CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR} /cmake" )
28
- set (INSTALL_CMAKE_DIR cmake CACHE PATH "Installation directory for cmake files" )
29
-
38
+ # Specify some parameters depending on if it's run on the compiler
30
39
if (MSVC )
31
40
add_definitions (-D_WIN32_WINNT=0x0A00)
32
41
add_compile_definitions ("_CRT_SECURE_NO_WARNINGS" )
@@ -46,29 +55,69 @@ else()
46
55
set (CMAKE_C_FLAGS_RELEASE "-O3" )
47
56
endif (MSVC )
48
57
58
+ # Add custom cmake modules to the path
59
+ set (CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR} /cmake" )
60
+
61
+ # Specify where the cmake files will be installed
62
+ set (INSTALL_CMAKE_DIR cmake CACHE PATH "Installation directory for cmake files" )
63
+
64
+ # ==================================== Boost =================================================
49
65
set (Boost_USE_STATIC_LIBS ON )
50
66
set (Boost_USE_MULTITHREADED ON )
51
67
find_package (Boost 1.66.0 REQUIRED COMPONENTS system program_options log filesystem)
52
68
69
+ # ================================ Sirius_solver =============================================
70
+ # Add an option to use or not shared library for sirius solver
53
71
option (USE_SIRIUS_SHARED "Use shared library for sirius solver" OFF )
54
72
if (USE_SIRIUS_SHARED)
55
- set (SIRIUS_NAME sirius_solver)
73
+ message ("-- Use shared sirius_solver in ${sirius_solver_DIR} " )
74
+ set (SIRIUS_NAME sirius_solver)
56
75
else ()
57
- set (SIRIUS_NAME sirius_solver_static)
76
+ message ("-- Use static sirius_solver in ${sirius_solver_static_DIR} " )
77
+ set (SIRIUS_NAME sirius_solver_static)
58
78
endif ()
59
79
80
+ # Define already existing sirius installation path
60
81
set (${SIRIUS_NAME} _ROOT ${CMAKE_CURRENT_BINARY_DIR} /external/sirius_solver CACHE PATH "Path where a Sirius installation already exists" )
82
+
83
+ # Find the sirius_solver package
61
84
find_package (${SIRIUS_NAME} REQUIRED)
62
85
63
- # SUITESPARSE
64
- set (SUITESPARSE_HOME ${CMAKE_CURRENT_BINARY_DIR} /external/suitesparse CACHE PATH "Path where an SuiteSparse installation already exists" )
65
- find_package (SuiteSparse REQUIRED)
86
+ # ================================= SuiteSparse ==============================================
87
+ # Add suitesparse cmake directory to the path
88
+ set (SUITESPARSE_DIR ${CMAKE_CURRENT_BINARY_DIR} /external/suitesparse CACHE PATH "Path where an SuiteSparse installation already exists" )
89
+ list (APPEND CMAKE_PREFIX_PATH "${SUITESPARSE_DIR} /lib/cmake" )
90
+
91
+ # Find the required SuiteSparse packages
92
+ find_package (AMD REQUIRED)
93
+ find_package (COLAMD REQUIRED)
94
+ find_package (BTF REQUIRED)
95
+ find_package (KLU REQUIRED)
66
96
97
+ # Find the actual library name
98
+ find_library (SUITESPARSECONFIG_LIB
99
+ NAMES suitesparseconfig SuiteSparse_config
100
+ PATHS ${SUITESPARSE_DIR} /lib
101
+ REQUIRED
102
+ )
103
+
104
+ # Create an "imported" targer if it does not already exists
105
+ if (NOT TARGET SuiteSparse::config)
106
+ add_library (SuiteSparse::config UNKNOWN IMPORTED )
107
+ set_target_properties (SuiteSparse::config PROPERTIES
108
+ IMPORTED_LOCATION "${SUITESPARSECONFIG_LIB} "
109
+ INTERFACE_INCLUDE_DIRECTORIES "${SUITESPARSE_DIR} /include"
110
+ )
111
+ endif ()
112
+
113
+ # ================================= The rest ==============================================
114
+ # Add the log directory to the build
67
115
add_subdirectory (log )
68
116
69
117
message (STATUS "METRIX" )
70
118
71
- set (METRIX_HEADERS
119
+ # Define required headers
120
+ set (METRIX_HEADERS
72
121
src/calcul.h
73
122
src/err/error.h
74
123
src/parametres.h
@@ -92,17 +141,18 @@ set(METRIX_HEADERS
92
141
src/margin_variations_compute.h
93
142
)
94
143
95
- set (METRIX_SOURCES
144
+ # Define required source files
145
+ set (METRIX_SOURCES
96
146
src/calculmacrofonctions.cpp
97
- src/err/error.cpp
98
- src/reseau.cpp
99
- src/calculrepports.cpp
100
- src/calculecrirecontraintesdodu.cpp
101
- src/connexite.cpp
102
- src/err/IoDico.cpp
147
+ src/err/error.cpp
148
+ src/reseau.cpp
149
+ src/calculrepports.cpp
150
+ src/calculecrirecontraintesdodu.cpp
151
+ src/connexite.cpp
152
+ src/err/IoDico.cpp
103
153
src/calculeEmpilementGroupes.cpp
104
154
src/metrix.cpp
105
- src/metrix2assess.cpp
155
+ src/metrix2assess.cpp
106
156
src/config/configuration .cpp
107
157
src/config/input_configuration.cpp
108
158
src/config/variant_configuration.cpp
@@ -115,38 +165,40 @@ set(METRIX_SOURCES
115
165
src/margin_variations_compute.cpp
116
166
)
117
167
168
+ # Define binary executable file name
118
169
set (target "metrix-simulator" )
119
170
171
+ # Generate a version.h file
120
172
configure_file (${CMAKE_CURRENT_SOURCE_DIR} /cmake/version .h.in ${CMAKE_CURRENT_SOURCE_DIR} /src/config/version .h)
121
173
122
- add_executable (${target}
123
- ${METRIX_HEADERS} ${METRIX_SOURCES} )
174
+ # Create the executable
175
+ add_executable (${target}
176
+ ${METRIX_HEADERS} ${METRIX_SOURCES} )
124
177
178
+ # Add the required directories for the executable
125
179
target_include_directories (${target}
126
180
PRIVATE
127
181
metrix::log
128
182
src
129
183
${SIRIUS_NAME}
130
- SuiteSparse::SuiteSparse_KLU
131
- SuiteSparse::SuiteSparse_AMD
132
- SuiteSparse::SuiteSparse_COLAMD
133
- SuiteSparse::SuiteSparse_BTF
134
- SuiteSparse::SuiteSparse_Config
135
184
${Boost_INCLUDE_DIRS}
136
185
)
186
+
187
+ # Add the required libraries
137
188
target_link_libraries (${target}
138
189
PRIVATE
139
190
metrix::log
140
191
${SIRIUS_NAME}
141
- SuiteSparse::SuiteSparse_KLU
142
- SuiteSparse::SuiteSparse_AMD
143
- SuiteSparse::SuiteSparse_COLAMD
144
- SuiteSparse::SuiteSparse_BTF
145
- SuiteSparse::SuiteSparse_Config
192
+ SuiteSparse::config
193
+ SuiteSparse::AMD
194
+ SuiteSparse::COLAMD
195
+ SuiteSparse::BTF
196
+ SuiteSparse::KLU
146
197
${Boost_LIBRARIES}
147
198
$<$<BOOL :${MSVC} >:msvcrt.lib>
148
199
)
149
200
201
+ # Checks whether the shared library for Sirius is available and installs it
150
202
if (USE_SIRIUS_SHARED)
151
203
# Export sirius library if using shared
152
204
get_target_property (sirius_PATH_LIB_RELEASE sirius_solver IMPORTED_LOCATION_RELEASE )
@@ -162,12 +214,13 @@ if (USE_SIRIUS_SHARED)
162
214
install (FILES ${sirius_PATH_LIB} DESTINATION lib)
163
215
endif ()
164
216
217
+ # Option to enable code coverage (disabled by default)
165
218
set (CODE_COVERAGE FALSE CACHE BOOL "Enable code coverage" )
166
219
if (CODE_COVERAGE)
167
- message (STATUS "CODE COVERAGE" )
168
- set (CMAKE_BUILD_TYPE "Debug" )
169
- list (APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR} " )
170
- include (cmake/CodeCoverage)
220
+ message (STATUS "CODE COVERAGE" ) # Output message for code coverage
221
+ set (CMAKE_BUILD_TYPE "Debug" ) # Switch to Debug build type
222
+ list (APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR} " ) # Add current source to module path
223
+ include (cmake/CodeCoverage) # Include custom code coverage script
171
224
CODE_COVERAGE(NAME code-coverage
172
225
OUTPUT_DIR coverage
173
226
ROOT_DIR src
@@ -176,24 +229,36 @@ if (CODE_COVERAGE)
176
229
)
177
230
endif ()
178
231
232
+ # Install SuiteSparse config files
233
+ install (FILES "${SUITESPARSECONFIG_LIB} " DESTINATION lib)
234
+
235
+ # Install the executable to bin directory
179
236
install (TARGETS ${target} EXPORT targets RUNTIME DESTINATION bin)
237
+ # Install the CMake configuration files
180
238
install (EXPORT targets
181
239
FILE metrix-simulator-config.cmake
182
240
DESTINATION ${INSTALL_CMAKE_DIR}
183
241
)
242
+ # Install 'etc' directory to the root of install
184
243
install (DIRECTORY ${PROJECT_SOURCE_DIR} /etc DESTINATION .)
185
244
245
+ # Option to run a reduced scope of tests
186
246
option (METRIX_RUN_ALL_TESTS "Run reduced scope of tests" ON )
187
247
248
+ # Enable CTest for running tests
188
249
enable_testing ()
189
- add_subdirectory (tests)
190
250
251
+ # Add the tests subdirectory, which contains the tests
252
+ add_subdirectory (tests)
191
253
254
+ # Generate a basic package version file for the installed package
192
255
write_basic_package_version_file(
193
256
"${CMAKE_CURRENT_BINARY_DIR} /metrix-simulator-config.cmake"
194
257
VERSION ${MetrixSimulator_VERSION}
195
258
COMPATIBILITY SameMajorVersion
196
259
)
260
+
261
+ # Install the generated version file to the CMake install directory
197
262
install (FILES "${CMAKE_CURRENT_BINARY_DIR} /metrix-simulator-config.cmake"
198
263
DESTINATION ${INSTALL_CMAKE_DIR}
199
264
)
0 commit comments