Hi,
...
project(${TARGET_NAME} VERSION 1.0.0)
...
set(CMAKE_CXX_COMPILER ${CPP_COMPILER})
set(CMAKE_C_COMPILER ${C_COMPILER})
...
target_compile_features(${TARGET_NAME} PUBLIC cxx_std_14)
I get, with gcc 5.5.0 (Ubuntu 16.04):
g++ -I/MyPackage/src/MyProject -isystem /MyPackage/includes -DNDEBUG -O2 -Wall -Wextra -Wconversion -Wold-style-cast -Winline -pedantic -o CMakeFiles/MyProject.dir/source1.cpp.o -c /MyPackage/src/MyProject/source1.cpp
In file included from /usr/include/c++/5/tuple:35:0,
from /MyPackage/includes/ThaliaUtilities/SomeHeader.hpp:35,
from /MyPackage/src/ThaliaUtilities_UT/MyProject.h:21,
from /MyPackage/src/ThaliaUtilities_UT/MyProject.cpp:21:
/usr/include/c++/5/bits/c++0x_warning.h:32:2: error: #error This file requires compiler and library support for the ISO C++ 2011 standard. This support must be enabled with the -std=c++11 or -std=gnu++11 compiler options.
#error This file requires compiler and library support
I indeed cannot see -std=c++14 in the command line gcc does not seem to default to C++11.
I previously set CMAKE_CXX_COMPILER before calling project but then, successive calls of cmake on a project where I change CPP_COMPILER in-between, still call the previous compiler.
To sum it up:
What is the proper way, in modern CMake, to choose the compiler (and to change it, on demand)?
Is it possible from a CMakeLists?
What is the proper way, in modern CMake, to set the language standard use?
Is it possible from a CMakeLists?
Thanks