[cmake-developers] Xcode generator does not recognize -Ofast

umireon@gmail.com umireon at gmail.com
Fri Jul 3 22:48:15 EDT 2015


Hi all,  

I am working on Xcode with CMake's Xcode Generator and it works nicely.  

However, the Xcode Generator does not handle the -Ofast flag properly,  
and then it is necessary to the set Optimization Level manually  
when -Ofast flag is utilized in the project.  

This is because the Xcode Generator uses just one letter right after the `-O`  
to determine what the project setting should be.  
When `-O3` is given, `3` is used for Optimization Level and everything is fine,  
but when `-Ofast` is given, `f` is used for it, which is an invalid value.  

It is not tested but it can be resolved by accepting all letter after `-O` flags.  

Here is the relevant code handling Optimization Level:  
https://github.com/Kitware/CMake/blob/3ae8e84ef5c94e5fa250b4e2466aa6632a233bb2/Source/cmGlobalXCodeGenerator.cxx#L2218  

The following is an example to reproduce this problem:  

-- CMakeLists.txt  
cmake_minimum_required(VERSION 3.2)  
add_executable(hello hello.c)  
target_compile_definitions(hello PRIVATE -Ofast)  
#target_compile_definitions(hello PRIVATE -O3)  

-- hello.c  
#include <stdio.h>  
int main(void)  
{  
  printf("hello world\n");  
  return 0;  
}  

-- Shell  
$ cd /path/to/project  
$ mkdir build; cd build  
$ cmake -G Xcode ..  
$ open Project.xcodeproj  

Then open the project setting on Xcode and show the setting of 'hello'  
Finally it is found that Optimization Level is -O0, not -Ofast  
When -O3 is specified, Optimization Level is set to -O3, correctly.  

I would appreciate any comments.  

Thank you for reading,  
Kaito  

--  
Signed-Off-By: Udagawa Kaito <umireon at gmail.com>  




More information about the cmake-developers mailing list