• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# C++14 feature support detection
2
3include(CheckCXXSourceCompiles)
4include(CheckCXXCompilerFlag)
5
6if (NOT CMAKE_CXX_STANDARD)
7  set(CMAKE_CXX_STANDARD 11)
8endif()
9message(STATUS "CXX_STANDARD: ${CMAKE_CXX_STANDARD}")
10
11if (CMAKE_CXX_STANDARD EQUAL 20)
12  check_cxx_compiler_flag(-std=c++20 has_std_20_flag)
13  check_cxx_compiler_flag(-std=c++2a has_std_2a_flag)
14
15  if (has_std_20_flag)
16    set(CXX_STANDARD_FLAG -std=c++20)
17  elseif (has_std_2a_flag)
18    set(CXX_STANDARD_FLAG -std=c++2a)
19  endif ()
20elseif (CMAKE_CXX_STANDARD EQUAL 17)
21  check_cxx_compiler_flag(-std=c++17 has_std_17_flag)
22  check_cxx_compiler_flag(-std=c++1z has_std_1z_flag)
23
24  if (has_std_17_flag)
25    set(CXX_STANDARD_FLAG -std=c++17)
26  elseif (has_std_1z_flag)
27    set(CXX_STANDARD_FLAG -std=c++1z)
28  endif ()
29elseif (CMAKE_CXX_STANDARD EQUAL 14)
30  check_cxx_compiler_flag(-std=c++14 has_std_14_flag)
31  check_cxx_compiler_flag(-std=c++1y has_std_1y_flag)
32
33  if (has_std_14_flag)
34    set(CXX_STANDARD_FLAG -std=c++14)
35  elseif (has_std_1y_flag)
36    set(CXX_STANDARD_FLAG -std=c++1y)
37  endif ()
38elseif (CMAKE_CXX_STANDARD EQUAL 11)
39  check_cxx_compiler_flag(-std=c++11 has_std_11_flag)
40  check_cxx_compiler_flag(-std=c++0x has_std_0x_flag)
41
42  if (has_std_11_flag)
43    set(CXX_STANDARD_FLAG -std=c++11)
44  elseif (has_std_0x_flag)
45    set(CXX_STANDARD_FLAG -std=c++0x)
46  endif ()
47endif ()
48
49set(CMAKE_REQUIRED_FLAGS ${CXX_STANDARD_FLAG})
50
51# Check if user-defined literals are available
52check_cxx_source_compiles("
53  void operator\"\" _udl(long double);
54  int main() {}"
55  SUPPORTS_USER_DEFINED_LITERALS)
56if (NOT SUPPORTS_USER_DEFINED_LITERALS)
57  set (SUPPORTS_USER_DEFINED_LITERALS OFF)
58endif ()
59
60# Check if <variant> is available
61set(CMAKE_REQUIRED_FLAGS -std=c++1z)
62check_cxx_source_compiles("
63  #include <variant>
64  int main() {}"
65  FMT_HAS_VARIANT)
66if (NOT FMT_HAS_VARIANT)
67  set (FMT_HAS_VARIANT OFF)
68endif ()
69
70set(CMAKE_REQUIRED_FLAGS )
71