The cx Book 1.0.0
cx: a package manager and build tool for C and C++
Loading...
Searching...
No Matches
Profiles

A profile is a set of build settings: optimization, debug info, LTO, sanitizers and extra flags. Each profile builds into its own directory, target/<profile>/, so switching between them doesn't rebuild everything.

Built-in profiles

Profile Selected with CMake build type Default settings
debug (default) Debug opt-level = 0, debug = true
release --release or --profile release Release opt-level = 3, debug = false

Custom profiles

[profile.release]
lto = true # change a built-in profile
[profile.asan]
inherits = "debug" # required for custom profiles
sanitizers = ["address", "undefined"]
[profile.profiling]
inherits = "release"
debug = true
$ cx test --profile asan
$ cx build --profile profiling # output in target/profiling/
$ cx clean --profile asan

A custom profile must say which profile it builds on with inherits. It can inherit from another custom profile. Settings it doesn't set come from the profile it inherits; defines, flags and link-flags add to the inherited ones. A cycle in inherits is an error.

Settings

Key Values Applies to Meaning
inherits profile name the profile to build on (custom profiles only)
opt-level 0, 1, 2, 3, "s", "z" root package optimization level (-O<n>, /O1 or /O2 on MSVC)
debug boolean root package debug info (-g / /Zi)
lto boolean every package link-time optimization, checked with CMake's CheckIPOSupported
sanitizers "address", "undefined", "thread", "memory", "leak" every package -fsanitize=...; MSVC only supports address
defines list root package added to [build] defines
flags list root package added to [build] flags
link-flags list root package added to [build] link-flags

Most settings apply only to the root package. Dependencies are built with the CMake build type of the profile (Debug or Release). Sanitizers and LTO are different: they apply to every package, including plain CMake ones, because a sanitizer build with uninstrumented dependencies gives false results.

How profiles fail

  • An unknown profile: cx build --profile x fails and lists the profiles that exist.
  • A sanitizer the compiler can't use: configuring fails with a message that names the sanitizer and the profile, instead of a link error later. address together with thread or memory is rejected when cx.toml is read.
  • LTO the compiler doesn't support: configuring fails with CMake's reason.

Only the root package's [profile.*] sections count, as in Cargo. In a workspace, that's the workspace root's.