Skip to content

[feature] Set build type specific compiler flags #18780

@aagor

Description

@aagor

What is your suggestion?

Hi,

I think it would be helpful to be able to set build type specific compiler flags.

Currently it's only possible to set compiler flags via tools.build:cflags and tools.build:cxxflags, but they affect all build types.

However, there are use cases where you want some flags only for specific build types.
Two examples of real-world use-cases would be

  • Disable some warnings for build type Release and RelWithDebInfo, due to compiler issues.
    E.g. adding -Wno-error=restrict for GCC < 12.4
    GCC issue tracker
    Godbolt
    This only happens with -O2 or -O3, so the warning may still be useful for Debug builds.
  • Adjust default settings of optimization.
    E.g. Use -O2 for Release build type instead of -O3.
  • ...

Currently this is maybe possible via some generic tool_requires that's pulled into from the profile, which has something like this:

def package_info(self):
    if self.settings_host.build_type in ("Release", "RelWithDebInfo"):
        self.conf_info.append("tools.build:cxxflags", "-Wno-error=restrict")

(I haven't tested this, I guess it's not supported anyway.)

But that seems problematic for multi-config builds like native Visual Studio and Ninja Multi-Config.
Also the above solution (if working) feels like a huge hack for such a simple task.

How can this be solved?
If not, can this be added?

Have you read the CONTRIBUTING guide?

  • I've read the CONTRIBUTING guide

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions