[cmake-developers] C++11 and target_compiler_feature proposal
Stephen Kelly
steveire at gmail.com
Thu Oct 17 10:28:02 EDT 2013
Stephen Kelly wrote:
> I'll try to get a reviewable and first-feature-complete infrastructure
> branch together soon.
I've pushed a first iteration of the target_compiler_features branch to my
clone.
For the language specification, I added a prefix to each feature. This
matches the feature tests of clang for standard features, and it is
extensible to extensions with gnuxx_typeof, msvc_sealed etc.
http://clang.llvm.org/docs/LanguageExtensions.html
So far, it only supports the REQUIRED signature of the command.
It will need to get a <PUBLIC|PRIVATE> specifier, so that the
INTERFACE_COMPILER_FEATURES property can be populated in PUBLIC mode. It
also needs to learn to process generator expressions and how to consume that
property.
Optional features with defines are not yet implemented. I was considering
renaming target_compiler_features to target_required_features and not using
the same command for optional features. Instead I think it might be a good
idea to have a separate command for optional features. Something like:
write_compiler_feature_file(
FILENAME "${CMAKE_CURRENT_BINARY_DIR}/grantlee_compiler_features.h"
FEATURES cxx_static_assert gnuxx_typeof cxx_variadic_templates
)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/grantlee_compiler_features.h"
DESTINATION include
)
which writes the file with appropriate content. I don't see any need to use
preprocessor macros for that instead of a file.
I also prototyped a simple way to test clang features as reportedly
supported by clang itself. This won't get us all of the way there with
clang, as some features (such as the gnu typeof extension) do not have
support via __has_extension.
Additionally, I changed my mind on the issue of whether to bump the dialect
to c++11 if the compiler supports the requested feature in c++98 mode. For
example, cxx_variadic_templates would be in CMAKE_CXX98_COMPILER_FEATURES
for GCC and clang, because both support variadic templates even when using
the -std=c++98 dialect. This will still warn, but that's ok, I think.
Note that adding -std=c++11 is almost, but not quite, entirely source
compatible.
For example, this will work with c++98, but errors with c++11:
#define add_prefix(suf) "pre_"suf
add_prefix("_end");
The feature can be extended for the C standard (89, 99, 11) features too as
well as extensions.
Any comments so far?
Thanks,
Steve.
More information about the cmake-developers
mailing list