CMake does not add -std=c++11 flag with IBM xlC compiler si CMAKE_CXX_STANDARD is 11
I tried to activate C++11 compilation on an IBM machine with xlC. CMake raise no error but does not add -std=c++11 compile flag. Adding it by hand makes compilation work.
Here is a quick reproducer: CMakeLists.txt
cmake_minimum_required (VERSION 3.8)
project (CMakeHelloWorld)
set(CMAKE_CXX_STANDARD 11) # C++11...
set(CMAKE_CXX_STANDARD_REQUIRED ON) #...is required...
set(CMAKE_CXX_EXTENSIONS OFF) #...without compiler extensions like gnu++11
##### Uncommenting tis line makes it work
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
add_executable (CMakeHelloWorld HelloWorld.cpp)
install (TARGETS CMakeHelloWorld DESTINATION bin)
HelloWorld.cpp
#if __cplusplus <= 199711L
#error This library needs at least a C++11 compliant compiler
#endif
#include <iostream>
int main()
{
std::cout << "Hello World!" << std::endl;
return 0;
}
Am I doing something wrong or is it a bug ?
Regards,
XL