[cmake-developers] C++11 and target_compiler_feature proposal
Stephen Kelly
steveire at gmail.com
Mon Oct 21 16:05:01 EDT 2013
Stephen Kelly wrote:
> We'll initially defer the concept of generating a header file with
> defines/MyStaticAssert etc.
I've looked into this a bit. The previous discussion on this ended here:
http://thread.gmane.org/gmane.comp.programming.tools.cmake.devel/6726/focus=7814
I'm still not sure that generating a header specific to the compiler (ID and
version) is a good idea.
That means that if I build a binary package of my library using GCC, and I
list cxx_final as an optional feature, you can't use clang with my binary
package.
Qt makes binary packages for x86 and x86_64 available, not both for each
compiler:
http://master.qt-project.org/snapshots/qt/5.2/5.2.0-beta1/2013-10-21_107/
The generate_export_header feature is also different, in that the header it
generates is compatible between different compilers on linux (because clang
chose to be compatible I suppose).
So, I think maybe it would make sense to list features separately, and if
someone does this:
write_compiler_detection_header(
FILE ${CMAKE_CURRENT_BINARY_DIR}/grantlee_compiler_detection.h
PREFIX Grantlee_
FEATURES cxx_final cxx_override
)
the generated header would look something like this:
#ifndef GRANTLEE_COMPILER_DETECTION_H
#define GRANTLEE_COMPILER_DETECTION_H
#if defined(__GNU__) && !defined(__clang__)
# if (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCH__) >= 407
# define Grantlee_FINAL final
# define Grantlee_OVERRIDE override
# else
# define Grantlee_FINAL
# define Grantlee_OVERRIDE
# endif
#elif defined(__clang__)
# if __has_feature(cxx_explicit_conversions)
# define Grantlee_FINAL final
# define Grantlee_OVERRIDE override
# else
# define Grantlee_FINAL
# define Grantlee_OVERRIDE
# endif
#elif defined(_MSC_VER)
// TODO: This could also be intel or other pretenders. Handle that too.
# if _MSC_VER >= 1700
# define Grantlee_FINAL final
# define Grantlee_OVERRIDE override
# else
# define Grantlee_FINAL
# define Grantlee_OVERRIDE
# endif
// TODO: Other compilers
#endif
#endif
Any further comments?
Thanks,
Steve.
More information about the cmake-developers
mailing list