Add feature testing codes in CMakeLists.txt for future use. Doesn't work though.

This commit is contained in:
Carter Li 2015-02-13 20:05:57 +08:00
parent 4fccc4399f
commit 52039e8b71
3 changed files with 61 additions and 21 deletions

View File

@ -80,7 +80,7 @@ if (BIICODE)
endif ()
add_library(format ${FMT_SOURCES})
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
if (CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set_target_properties(format PROPERTIES COMPILE_FLAGS
"-Wall -Wextra -Wshadow -pedantic")
if (CPP11_FLAG)
@ -117,6 +117,49 @@ if (NOT FMT_VARIADIC_TEMPLATES)
add_definitions(-DGTEST_LANG_CXX11=0)
endif ()
# g++ 4.6 supports nullptr with __cplusplus==1
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=1773
check_cxx_source_compiles("
int main(){int*p=nullptr;}" FMT_NULLPTR)
if (FMT_NULLPTR)
add_definitions(-DFMT_USE_NULLPTR=1)
endif ()
check_cxx_source_compiles("
struct C{
C()=delete;
C(const C&)=delete;
C& operator=(const C&)=delete;
};
int main(){}" FMT_DELETED_FUNCTIONS)
if (FMT_DELETED_FUNCTIONS)
add_definitions(-DFMT_USE_DELETED_FUNCTIONS=1)
endif ()
check_cxx_source_compiles("
void f() noexcept {}
int main(){ f(); }" FMT_BASIC_NOEXCEPT_SUPPORT)
if (FMT_BASIC_NOEXCEPT_SUPPORT)
add_definitions(-DFMT_USE_NOEXCEPT=1)
endif ()
check_cxx_source_compiles("
#include <utility>
struct MoveOnly {
MoveOnly() {}
MoveOnly(MoveOnly&&) {}
private:
MoveOnly(const MoveOnly&);
};
int main() {
MoveOnly a;
MoveOnly b(std::move(a));
MoveOnly c(MoveOnly());
}" FMT_RVALUE_REFERENCES)
if (FMT_RVALUE_REFERENCES)
add_definitions(-DFMT_USE_RVALUE_REFERENCES=1)
endif ()
# GTest doesn't detect <tuple> with clang.
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
target_compile_definitions(gmock PUBLIC GTEST_USE_OWN_TR1_TUPLE=1)

View File

@ -115,46 +115,43 @@
#if FMT_USE_NOEXCEPT || FMT_HAS_FEATURE(cxx_noexcept) || \
(FMT_GCC_VERSION >= 408 && __cplusplus >= 201103L)
# define FMT_NOEXCEPT noexcept
# define FMT_NOEXCEPT_EXPR(expr) noexcept(expr)
#else
# define FMT_NOEXCEPT throw()
# define FMT_NOEXCEPT_EXPR(expr)
#endif
// A macro to disallow the copy constructor and operator= functions
// This should be used in the private: declarations for a class
#if FMT_HAS_FEATURE(cxx_deleted_functions)\
#if FMT_USE_DELETED_FUNCTIONS || FMT_HAS_FEATURE(cxx_deleted_functions)\
|| (FMT_GCC_VERSION >= 404 && __cplusplus >= 201103L)\
|| (_MSC_VER >= 1800)
#define FMT_DISALLOW_COPY_AND_ASSIGN(TypeName) \
TypeName(const TypeName&) = delete; \
void operator=(const TypeName&) = delete
TypeName& operator=(const TypeName&) = delete
#else
#define FMT_DISALLOW_COPY_AND_ASSIGN(TypeName) \
TypeName(const TypeName&); \
void operator=(const TypeName&)
TypeName& operator=(const TypeName&)
#endif
#if FMT_HAS_FEATURE(cxx_nullptr)\
#if FMT_USE_NULLPTR || FMT_HAS_FEATURE(cxx_nullptr)\
|| (FMT_GCC_VERSION >= 406 && __cplusplus >= 201103L)\
|| (_MSC_VER >= 1600)
// Use nullptr
#else
// Simulate it
namespace std {
class nullptr_t {
public:
template<typename T>
operator T*() const {
return 0;
}
template<typename C, typename T>
operator T C::*() const
{
return 0;
}
private:
void operator&() const;
class nullptr_t {
public:
template<typename T>
operator T*() const {
return 0;
}
template<typename C, typename T>
operator T C::*() const {
return 0;
}
private:
void operator&() const;
};
}

View File

@ -19,7 +19,7 @@ add_fmt_test(format-test)
add_fmt_test(format-impl-test CUSTOM_LINK)
add_fmt_test(printf-test)
foreach (target format-test printf-test)
if (CMAKE_COMPILER_IS_GNUCXX)
if (CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set_target_properties(${target} PROPERTIES COMPILE_FLAGS
"-Wall -Wextra -pedantic -Wno-long-long -Wno-variadic-macros")
endif ()