I'm trying to build bkchaind. One build option is to use cmake, so I installed it with Homebrew (OSX 10.9.1). When I do cmake
, though, I get:
[ 2%] Building C object json-rpc-cpp/src/jsonrpc/CMakeFiles/jsonrpcStatic.dir/connectors/mongoose.c.o
error: invalid argument '-std=c++11' not allowed with 'C/ObjC'
I am none too sure why cmake
would try to pass a C++-specific compiler option to a C/ObjC file. If I comment out this line in the main CMakeLists.txt
file:
ADD_DEFINITIONS(-std=c++11)
then it no longer passes the flag to any file. However, the C++ files do need it. How do I get cmake
to include the flag for C++ files, but not for C files?
This type of thing can be done explicitly without any dependence on the specific format of a compiler's flags:
target_compile_features
can also do this more implicitly I think, by requesting particular language features that are only found in the desired version of the language.Another way is to set a target property:
Or one may set
CMAKE_CXX_STANDARD
, whose value is used as the default value forCXX_STANDARD
on targets, and then allow targets to inherit that value implicitly.(Here I'm using the 2014 standard, but of course one may specify 11 or some other value.)
Use
CMAKE_CXX_FLAGS
to set c++ specific flags: