Compiler
Compilation of the sources embedded in an FMU for the host platform.
Some FMUs ship their C or C++ sources in sources/ but no binary for the platform of the user. SourceCompiler reads how to build them (FMI-2: <SourceFiles> of each interface; FMI-3: sources/buildDescription.xml) and calls the C compiler of the host (Toolchain) to build the shared library into binaries/<platform>/.
BuildConfiguration dataclass ¶
How to build the shared library of one model identifier.
Attributes:
| Name | Type | Description |
|---|---|---|
model_identifier | str | Name of the shared library, without suffix. |
source_file_sets | list[SourceFileSet] | Sources and their settings. |
libraries | list[str] | Libraries to link with, by name. |
Source code in fmu_manipulation_toolbox/compiler.py
OperationCompileSources ¶
Bases: OperationAbstract
Compile the embedded sources when the binary of the host platform is missing.
For each model identifier of the FMU, the shared library of the host platform is built from sources/ into binaries/<host platform>/, unless it already exists. The descriptor is not changed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
compiler_options | Sequence[str] | Additional options of every compilation command, e.g. | () |
linker_options | Sequence[str] | Additional options of the link command, e.g. | () |
libraries | Sequence[str] | Additional libraries to link with, by name, e.g. | () |
Attributes:
| Name | Type | Description |
|---|---|---|
compilation_failed | bool |
|
Raises:
| Type | Description |
|---|---|
OperationError | If a binary is missing and cannot be built (no sources, no list of the sources, no compiler, compilation failure). |
Source code in fmu_manipulation_toolbox/compiler.py
SourceCompiler ¶
Compile the sources/ of an extracted FMU for the host platform.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fmu_directory | Path | str | Directory where the FMU is extracted. | required |
fmi_version | int | FMI version of the FMU ( | required |
Source code in fmu_manipulation_toolbox/compiler.py
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 | |
binary_path(model_identifier) ¶
Path of the shared library of model_identifier for the host platform.
Source code in fmu_manipulation_toolbox/compiler.py
build_commands(configuration, toolchain, build_directory, library, compiler_options=(), linker_options=(), libraries=()) ¶
Command lines building configuration into library: one compilation per source, then the link.
The commands run in the directory of the extracted FMU: its sources and include directories are given relative to it, with / separators (accepted by every compiler), so that the compiler messages name sources/model.c on every platform. Object files are written in build_directory.
compiler_options, linker_options and libraries are added to those of the build description: the compiler options after its definitions and options, the libraries after its libraries.
Source code in fmu_manipulation_toolbox/compiler.py
build_configurations(model_description) ¶
Read how to build the shared libraries of the FMU, one configuration per model identifier.
Raises:
| Type | Description |
|---|---|
OperationError | If the FMU embeds no sources, if the list of the sources is missing, or if a listed source file does not exist. |
Source code in fmu_manipulation_toolbox/compiler.py
compile(configuration, toolchain=None, compiler_options=(), linker_options=(), libraries=()) ¶
Build the shared library of configuration into binaries/<host platform>/.
The compiler output is forwarded to the logger. Nothing is written into the FMU if the build fails.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
configuration | BuildConfiguration | What to build (see | required |
toolchain | Toolchain | None | Compilers to use; by default, those of the host ( | None |
compiler_options | Sequence[str] | Additional options of every compilation command. | () |
linker_options | Sequence[str] | Additional options of the link command. | () |
libraries | Sequence[str] | Additional libraries to link with, by name. | () |
Returns:
| Name | Type | Description |
|---|---|---|
Path | Path | Path of the shared library. |
Raises:
| Type | Description |
|---|---|
OperationError | If no compiler is found or if the build fails. |
Source code in fmu_manipulation_toolbox/compiler.py
host_platform(fmi_version) staticmethod ¶
Name of the binaries/ sub-directory of the host platform.
Raises:
| Type | Description |
|---|---|
OperationError | If the host platform has no name in this FMI version. |
Source code in fmu_manipulation_toolbox/compiler.py
library_suffix() staticmethod ¶
SourceFileSet dataclass ¶
Sources compiled with the same settings (a <SourceFileSet> of FMI-3, all the sources for FMI-2).
Attributes:
| Name | Type | Description |
|---|---|---|
source_files | list[Path] | Source files, in the order of the build description. |
language | str | None | Language, e.g. |
compiler | str | None | Compiler for which |
compiler_options | str | None | Options for |
definitions | dict[str, str | None] | Preprocessor definitions ( |
include_directories | list[Path] | Include directories ( |
Source code in fmu_manipulation_toolbox/compiler.py
is_cxx(source_file) ¶
True if source_file is C++: given by the language of the set, else by the suffix of the file.
Source code in fmu_manipulation_toolbox/compiler.py
Toolchain dataclass ¶
Compilers of the host platform.
Attributes:
| Name | Type | Description |
|---|---|---|
family | str |
|
c_compiler | list[str] | Command of the C compiler. |
cxx_compiler | list[str] | Command of the C++ compiler. |
environment | dict[str, str] | None | Environment of the compilers (MSVC), |
Source code in fmu_manipulation_toolbox/compiler.py
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 | |
compile_command(source_file, object_file, cxx, include_directories, definitions, options) ¶
Command line compiling source_file into object_file.
Source code in fmu_manipulation_toolbox/compiler.py
find() cached staticmethod ¶
Compilers of the host platform, searched once.
Windows: MSVC found by vswhere.exe (its environment is set by vcvarsall.bat), else cl.exe from PATH. Elsewhere: $CC (default cc) and $CXX (default c++).
Raises:
| Type | Description |
|---|---|
OperationError | If no C compiler is found. |
Source code in fmu_manipulation_toolbox/compiler.py
link_command(object_files, library, cxx, libraries, options=()) ¶
Command line linking object_files into the shared library library.
options (e.g. -L/opt/lib, /LIBPATH:C:\lib) come before the libraries.
Source code in fmu_manipulation_toolbox/compiler.py
matches(compiler) ¶
True if compiler (the attribute of a SourceFileSet) designates this toolchain.