6.1.2.5. CMakeIntegration¶
Use CMake for analysis compilation
This rule calls CMake with the specified options.
For generators Unix Makefiles or Ninja you can use
execute_build, or you have to run make
or ninja, or some other build tool as an additional subsequent build
step.
For Visual Studio generators, you have to disable
execute_build and use the
MSBuildIntegration as an additional subsequent build
step.
When setting CMAKE_EXPORT_COMPILE_COMMANDS=ON (or enabling
export_compile_commands), then CMake will
generate a compile_commands.json database that can be used with the
CompileCommandsIntegration rule as a
subsequent build step. When using a compiler different than GCC or Clang, it is
recommended to use at least CMake 3.26 to create the
compile_commands.json.
In case CCache is used in the build, but fetches wrong Axivion IR objects from its
cache, you can disable CCache by setting environment
variable CCACHE_DISABLE=1.
At least one of execute_generate or execute_build has to be set to true.
If the build_directory existed prior to the build,
then the clean phase invokes the equivalent of the command
cmake --build build_directory --target clean to clean it, if the
build_directory did not exist prior to the build, then the clean phase
completely deletes it.
Options¶
The following places define options that affect this rule: BuildSystemIntegration, Project-GlobalOptions
abort_on_error¶
abort_on_error : bool = True
analysis_toolchain_file¶
analysis_toolchain_file
Type: AnalysisToolchainFile | bauhaus.analysis.config.ProjectRelativePath | None
Default:
'ENABLED'
When using generators Unix Makefiles or Ninja, you
have to select an Axivion toolchain file to inject the Axivion compiler toolchain
into the build.
Most of the time, ENABLED is the correct choice. If using CMake
older than 3.10 is required, you have to choose LEGACY instead, and
if you have to supply your own hand-crafted analysis toolchain file, you can also
specify a filename directly.
This setting corresponds roughly to setting
-DCMAKE_TOOLCHAIN_FILE=... on the CMake command-line to either one of
the internal toolchain files or the one you explicitly configure.
You should also configure the original toolchain file (if applicable) as native_toolchain_file.
When using generator for Visual Studio, set to DISABLED
here.
build_directory¶
build_directory : bauhaus.analysis.config.ProjectRelativePath = 'build'
-B).
build_environment¶
build_environment
Type: dict[str, str]
Default:
{ 'COMPILE_ONLYIR': '1' }
Environment for the call to CMake for building the project. These entries will be added to the ones in environment and take priority if the same keys are set.
Only relevant at all, if execute_build is set to true.
build_options¶
build_options : str | None = None
Additional command-line parameters for the call to CMake for building the project. These options will be added to the ones in options later on the command-line.
Only relevant at all, if execute_build is set to true.
build_preset¶
build_preset : str | None = None
Optional preset name to be passed to CMake for building the project. May be left empty, even if you use a generate_preset.
When setting this option, the configured
build_directory has to point to the same folder
that is configured via binaryDir of the configurePreset
that is referenced by the chosen buildPreset inside the
CMakePresets.json file, otherwise a different configuration may be
built/analyzed than the one that was generated.
Only relevant at all, if execute_build is set to true.
capture_output¶
capture_output : bool = False
The output will be parsed according to the format configured with the options output_format, stdout_format, stderr_format.
environment¶
environment : dict[str, str] = {}
Environment for all calls to CMake. These entries are added to the environment and existing ones will be overwritten.
E.g.:
CCACHE_DISABLE=1(to disable CCache)
execute_build¶
execute_build : bool = True
If set, also start the build using cmake --build build_directory
(which may or may not work that way). Otherwise you need to add another
build step to call a correctly configured build tool after CMake generation.
When using generator for Visual Studio, disable
execute_build and add a subsequent build step via
MSBuildIntegration.
When using original CMake build with
CMAKE_EXPORT_COMPILE_COMMANDS=ON (or with
export_compile_commands enabled),
CMake will generate a compile_commands.json database that
can be used with the
CompileCommandsIntegration rule as a
subsequent build step. When using a compiler different than GCC or Clang, it is
recommended to use at least CMake 3.26 to create the
compile_commands.json.
execute_generate¶
execute_generate : bool = True
If set, runs the configure/generate phase with the configured generator and the generate options.
This option should be left enabled for almost all cases, except if you only want to execute the build in an already configured build_directory.
export_compile_commands¶
export_compile_commands : bool = False
When set to true, CMake is instructed to write a
compile_commands.json database inside the
build_directory that can be used with the rule
CompileCommandsIntegration.
This setting corresponds to -DCMAKE_EXPORT_COMPILE_COMMANDS=ON.
generate_enforce_compiler¶
generate_enforce_compiler : bool = False
When set to true, try to enforce CMake to use the native compiler that was used
to create the compiler profile (i.e. by setting CC, CXX,
and NVCC_CCBIN to the respective native compilers from the profile).
generate_environment¶
generate_environment
Type: dict[str, str]
Default:
{ 'BAUHAUS_IR_COMPRESSION': 'none', 'COMPILE_ONLY': '1' }
Environment for the call to CMake for generating the project build system. These entries will be added to the ones in environment and take priority if the same keys are set.
generate_log_level¶
generate_log_level : LogLevel | None = None
Specify an explicit log level for the generate phase (default is
STATUS).
generate_options¶
generate_options : str | None = None
Additional command-line parameters for the call to CMake for generating the project build system. These options will be added to the ones in options later on the command-line.
An example of a sensible option is --fresh (CMake >= 3.24)
or --log-level=verbose.
generate_preset¶
generate_preset : str | None = None
Optional preset name to be passed to CMake for generating the project build system.
generate_variables¶
generate_variables : dict[str, str] = {}
CMake variables to configure.
Those variables will be converted to -DKEY=VALUE switches and
precede options and
generate_options on the command-line.
E.g.:
CMAKE_VERBOSE_MAKEFILE=1CMAKE_BUILD_TYPE=ReleaseCMAKE_PREFIX_PATH=$(HOME)/Qt/6.4.0/gcc_64CMAKE_C_FLAGS_INIT=-candCMAKE_CXX_FLAGS_INIT=-cfor IAR projects- etc.
When using generator Ninja you can use the variables
AXIVION_NUM_JOBS_COMPILE and/or AXIVION_NUM_JOBS_LINK
in order to specify the level of parallelization for the respective compile and/or
link steps.
generator¶
generator : Generator | str = 'Ninja'
CMake build system generator to use (CMake option -G).
When selecting one of the predefined generators Unix Makefiles
or Ninja, then set
analysis_toolchain_file and
native_toolchain_file accordingly.
For Visual Studio generators, you need neither
analysis_toolchain_file nor
native_toolchain_file but instead have to
disable execute_build and use a subsequent
MSBuildIntegration build step with the main
.vcxproj and/or .sln file configured.
native_toolchain_file¶
native_toolchain_file : bauhaus.analysis.config.ProjectRelativePath | None = None
When using generators Unix Makefiles or Ninja, you
have to configure the Axivion toolchain file for CMake, but you also need to
chainload the toolchain file you are using in your original build here.
This setting corresponds to -DAXIVION_CHAINLOAD_TOOLCHAIN_FILE=...
on the CMake command-line and is used by the Axivion toolchain to pick up
settings from your original CMake toolchain file.
options¶
options : str | None = None
output_cache_prefixes¶
output_cache_prefixes
Output variables from the CMake cache starting with the configured prefixes.Type: set[str]
Default:
{'AXIVION_', 'CCACHE_', 'CMAKE_AR:', 'CMAKE_ASM_COMPILER', 'CMAKE_ASM_LINKER', 'CMAKE_CUDA_COMPILER', 'CMAKE_CUDA_LINKER', 'CMAKE_CXX_COMPILER', 'CMAKE_CXX_LINKER', 'CMAKE_C_COMPILER', 'CMAKE_C_LINKER', 'CMAKE_LINKER:', 'CMAKE_MT:', 'CMAKE_OBJCOPY:', 'CMAKE_OBJDUMP:', 'CMAKE_SIZE:', 'CMAKE_STRIP:'}
output_format¶
output_format : list[str] = ['generic']
The format names available here correspond to the provider
options in /Analysis/AnalysisControl/ExternalAnalysisFormats.
This option only has an effect if capture_output is true.
skip_clean_before¶
skip_clean_before : bool = False
When set to true and either
ci_mode.clean_before or
local_mode.clean_before is set to
true, then the clean phase of this build step is skipped. This can be useful if you
want to run multiple CMakeIntegration steps on the same
build_directory, so that the later invocation does
not clean what the former one has built.
source_directory¶
source_directory : bauhaus.analysis.config.ProjectRelativePath | None = None
-S).
If unset, defaults to /Project/directory.
stderr_format¶
stderr_format : list[str] = []
The format names available here correspond to the provider
options in /Analysis/AnalysisControl/ExternalAnalysisFormats.
This option only has an effect if capture_output is true.
stdout_format¶
stdout_format : list[str] = []
The format names available here correspond to the provider
options in /Analysis/AnalysisControl/ExternalAnalysisFormats.
This option only has an effect if capture_output is true.
toolname¶
toolname : bauhaus.analysis.config.PlainPath = 'cmake'
Option Types¶
These types are used by options listed above:
AnalysisToolchainFile¶
An enumeration.ENABLED
Using CMake "launcher" functionality to inject the Axivion compiler into the build. This works starting with CMake 3.10, but improves with later versions:- 3.15+: more robust injection into CMake project via
CMAKE_PROJECT_INCLUDE_BEFORE - 3.21+: use linker launcher in addition to compiler launcher
- 3.29+: support for multiple
CMAKE_PROJECT_INCLUDE_BEFORE - 4.1+: more robust CUDA injection due to fixed
CMAKE_CUDA_LINKER_LAUNCHER
LEGACY
This mode is a fallback if support for CMake < 3.10 is required and may only work for simple projects.DISABLED
Disable Axivion compiler injection. Choose this setting when using one of theVisual Studio generators and therefore also having a separate
MSBuildIntegration build step, or when attempting to do a native build
for debugging purposes.Generator¶
An enumeration.Ninja
Generates build.ninja files.Ninja Multi-Config
Generates build-<Config>.ninja files.Unix Makefiles
Generates standard UNIX makefiles.MinGW Makefiles
Generates MinGW makefiles.NMake Makefiles
Generates NMake makefiles.NMake Makefiles JOM
Generates JOM makefiles.Visual Studio 14 2015
Generates Visual Studio 2015 project files.Visual Studio 15 2017
Generates Visual Studio 2017 project files.Visual Studio 16 2019
Generates Visual Studio 2019 project files.Visual Studio 17 2022
Generates Visual Studio 2022 project files.Visual Studio 18 2026
Generates Visual Studio 2026 project files.LogLevel¶
An enumeration.ERROR
WARNING
NOTICE
STATUS
VERBOSE
DEBUG
TRACE