• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# C++11 feature support detection
2
3if (NOT FMT_USE_CPP11)
4  return()
5endif ()
6
7include(CheckCXXCompilerFlag)
8
9if (FMT_USE_CPP11)
10  check_cxx_compiler_flag(-std=c++11 HAVE_STD_CPP11_FLAG)
11  if (HAVE_STD_CPP11_FLAG)
12    # Check if including cmath works with -std=c++11 and -O3.
13    # It may not in MinGW due to bug http://ehc.ac/p/mingw/bugs/2250/.
14    set(CMAKE_REQUIRED_FLAGS "-std=c++11 -O3")
15    check_cxx_source_compiles("
16      #include <cmath>
17      int main() {}" FMT_CPP11_CMATH)
18    # Check if including <unistd.h> works with -std=c++11.
19    # It may not in MinGW due to bug http://sourceforge.net/p/mingw/bugs/2024/.
20    check_cxx_source_compiles("
21      #include <unistd.h>
22      int main() {}" FMT_CPP11_UNISTD_H)
23    if (FMT_CPP11_CMATH AND FMT_CPP11_UNISTD_H)
24      set(CPP11_FLAG -std=c++11)
25    else ()
26      check_cxx_compiler_flag(-std=gnu++11 HAVE_STD_GNUPP11_FLAG)
27      if (HAVE_STD_CPP11_FLAG)
28        set(CPP11_FLAG -std=gnu++11)
29      endif ()
30    endif ()
31    set(CMAKE_REQUIRED_FLAGS )
32  else ()
33    check_cxx_compiler_flag(-std=c++0x HAVE_STD_CPP0X_FLAG)
34    if (HAVE_STD_CPP0X_FLAG)
35      set(CPP11_FLAG -std=c++0x)
36    endif ()
37  endif ()
38endif ()
39
40if (CMAKE_CXX_STANDARD)
41  # Don't use -std compiler flag if CMAKE_CXX_STANDARD is specified.
42  set(CPP11_FLAG )
43endif ()
44
45set(CMAKE_REQUIRED_FLAGS ${CPP11_FLAG})
46
47# Check if variadic templates are working and not affected by GCC bug 39653:
48# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=39653
49check_cxx_source_compiles("
50  template <class T, class ...Types>
51  struct S { typedef typename S<Types...>::type type; };
52  int main() {}" SUPPORTS_VARIADIC_TEMPLATES)
53
54# Check if initializer lists are supported.
55check_cxx_source_compiles("
56  #include <initializer_list>
57  int main() {}" SUPPORTS_INITIALIZER_LIST)
58
59# Check if enum bases are available
60check_cxx_source_compiles("
61  enum C : char {A};
62  int main() {}"
63  SUPPORTS_ENUM_BASE)
64
65# Check if type traits are available
66check_cxx_source_compiles("
67  #include <type_traits>
68  class C { void operator=(const C&); };
69  int main() { static_assert(!std::is_copy_assignable<C>::value, \"\"); }"
70  SUPPORTS_TYPE_TRAITS)
71
72# Check if user-defined literals are available
73check_cxx_source_compiles("
74  void operator\"\" _udl(long double);
75  int main() {}"
76  SUPPORTS_USER_DEFINED_LITERALS)
77
78set(CMAKE_REQUIRED_FLAGS )
79