Xcode: Incorrect optimization level set when using `add_compile_options( -Oz )`
The GCC_OPTIMIZATION_LEVEL
Xcode property is still set to -O3
and -Oz
is added to OTHER_CPLUSPLUSFLAGS
. This is problematic for cases when I want to override the -Oz
to -O3
for a specific target using target_compile_options
. This then leaves the GCC_OPTIMIZATION_LEVEL
of the target on -O3
and does not remove -Oz
from targets OTHER_CPLUSPLUSFLAGS
.
The problem is that Xcode, when generating an argument list for clang, first puts the contents of GCC_OPTIMIZATION_LEVEL
and then OTHER_CPLUSPLUSFLAGS
, thus -Oz
overrides the -O3
.
The CMake should correctly parse the -Oz
flag and put it to GCC_OPTIMIZATION_LEVEL
Xcode property - it does the same if I use -Os
instead. I haven't tested if -Ofast
is parsed correctly.
I'm using CMake 3.21.3 and have observed this issue at least from CMake 3.16 (haven't tested with earlier versions of Xcode).