CLion exporter adds -std=c++11 also on .c files


#1

I have been testing the new Clion exporter (why just not call it cmake exporter? :slight_smile: ) generates following compile options

target_compile_options (APP PRIVATE
    -mmacosx-version-min=10.9
    -O0
    -std=c++11)

I have some modules with .c files and -std=c++11 is invalid on macOS clang (but I assume any compiler would complain) for .C or Objective C files.


#2

Because we envision a future CMake exporter being much more general. See the discussion here:

Does the invalid flag cause a warning or an error?


#3

Thanks for the pointer , I have been missing that thread!

Yes, the invalid flag cause a compile error because CMake tries to add -std=C++11 to regular C files.
I have tested it compiling manually (I don’t have CLion) but I think that the error will be just the same on compiling with CLion.


#4

target_compile_options(TARGET PRIVATE -std=c++11) is not the proper way to get C++11 support, especially since the C compiler doesn’t know what that option means and fails.

You should use the following instead:

set_target_properties(TARGET PROPERTIES
  CXX_STANDARD 11
  CXX_EXTENSIONS OFF # to get -std=c++11 instead of -std=gnu++11
)

#5

Thanks, that’s saved me a bit of research :slight_smile:


#6

This is now fixed on the develop branch.


#7

Excellent! :smile: