HaxeFoundation / HaxeFoundation/hxcpp

Avoid overriding O2 flag when compiling.

Open
#929 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
330
Forks
227
Avg merge
2d 16h
Merged PRs (30d)
18

Description

I'd like to compile build files with no optimization (using `O0` or `Od` flags), but I'd **like to avoid overriding the O2 flag that's there by default**.

Gcc and clang silently accept overrides (for `-O2 -O0`). Msvc, while accepting the override, complains about it with warning [D9025](https://docs.microsoft.com/en-us/cpp/error-messages/tool-errors/command-line-warning-d9025?view=vs-2019) (for `/O2 /Od`).

`-O2` is included by hxcpp's various toolchains for files that have the `release` or `optim-std` tag. When no optimization level is specified in a Build.xml file via tags, it defaults to `optim-std`, so `-O2` is a standard inclusion.

The only way to completely avoid the warning is to only add our own optimization flags for files that are being compiled with the `optim-none` tag, since no toolchain files add optimization flags when `optim-none` is specified.

I'm doing so by adding these lines to my `.hxcpp_config.xml` file:

```xml


```

Tags are normally specified in the `Build.xml` file:

```xml

or

```

And in Haxe source files:

```haxe
@:fileXml('tags="haxe,optim-none"')
```

This works well enough if you want to specify an unchanging optimization level for all the files in your own project. However, I'd also like to compile third-party sources with a different optimization level without changing any files.

For *Haxe sources*, this isn't very difficult to do. You can insert the needed `@:fileXml` metadata into all classes using an initialization macro, which you can specify on the command line.

```hxml
--macro "addGlobalMetadata('', '@:fileXml(\'tags=\"haxe,optim-none\"\')')"
```

I'm wondering if there's a way in hxcpp to specify the use of `optim-none` (or just removing the `O2` flag) from the command line, or from the `.hxcpp_config.xml` file.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.