GUI: improve systray tooltips
[trojita.git] / cmake / FindCXXFeatures.cmake
blob22f0cdb1066ea9f83dbb530fc32a4fa060af2493
1 # - Check which features of the C++ standard the compiler supports
3 # When found it will set the following variables
5 #  CXX11_COMPILER_FLAGS                   - the compiler flags needed to get C++11 features
7 #  CXXFeatures_alignof_FOUND              - alignof keyword
8 #  CXXFeatures_auto_FOUND                 - auto keyword
9 #  CXXFeatures_class_override_final_FOUND - override and final keywords for classes and methods
10 #  CXXFeatures_constexpr_FOUND            - constexpr keyword
11 #  CXXFeatures_cstdint_header_FOUND       - cstdint header
12 #  CXXFeatures_decltype_FOUND             - decltype keyword
13 #  CXXFeatures_defaulted_functions_FOUND  - default keyword for functions
14 #  CXXFeatures_deleted_functions_FOUND    - delete keyword for functions
15 #  CXXFeatures_func_identifier_FOUND      - __func__ preprocessor constant
16 #  CXXFeatures_initializer_list_FOUND     - initializer list
17 #  CXXFeatures_lambda_FOUND               - lambdas
18 #  CXXFeatures_long_long_FOUND            - long long signed & unsigned types
19 #  CXXFeatures_nullptr_FOUND              - nullptr
20 #  CXXFeatures_rvalue_references_FOUND    - rvalue references
21 #  CXXFeatures_sizeof_member_FOUND        - sizeof() non-static members
22 #  CXXFeatures_static_assert_FOUND        - static_assert()
23 #  CXXFeatures_variadic_templates_FOUND   - variadic templates
25 #=============================================================================
26 # Copyright 2011,2012,2013 Rolf Eike Beer <eike@sf-mail.de>
27 # Copyright 2012 Andreas Weis
28 # Copyright 2013 Jan Kundrát
30 # Distributed under the OSI-approved BSD License (the "License");
31 # see accompanying file Copyright.txt for details.
33 # This software is distributed WITHOUT ANY WARRANTY; without even the
34 # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
35 # See the License for more information.
36 #=============================================================================
37 # (To distribute this file outside of CMake, substitute the full
38 #  License text for the above reference.)
40 if (NOT CMAKE_CXX_COMPILER_LOADED)
41     message(FATAL_ERROR "CXXFeatures modules only works if language CXX is enabled")
42 endif ()
44 cmake_minimum_required(VERSION 2.8.3)
47 ### Check for needed compiler flags
49 include(CheckCXXCompilerFlag)
50 check_cxx_compiler_flag("-std=c++11" _HAS_CXX11_FLAG)
51 if (_HAS_CXX11_FLAG)
52     set(CXX11_COMPILER_FLAGS "-std=c++11")
53 else ()
54     check_cxx_compiler_flag("-std=c++0x" _HAS_CXX0X_FLAG)
55     if (_HAS_CXX0X_FLAG)
56         set(CXX11_COMPILER_FLAGS "-std=c++0x")
57     endif ()
58 endif ()
60 function(cxx_check_feature FEATURE_NAME)
61     set(RESULT_VAR "CXXFeatures_${FEATURE_NAME}_FOUND")
62     if (DEFINED ${RESULT_VAR})
63         return()
64     endif()
66     set(_bindir "${CMAKE_CURRENT_BINARY_DIR}/cxx_${FEATURE_NAME}")
68     set(_SRCFILE_BASE ${CMAKE_CURRENT_LIST_DIR}/FindCXXFeatures/cxx11-test-${FEATURE_NAME})
69     set(_LOG_NAME "\"${FEATURE_NAME}\"")
70     message(STATUS "Checking C++ support for ${_LOG_NAME}")
72     set(_SRCFILE "${_SRCFILE_BASE}.cxx")
73     set(_SRCFILE_FAIL_COMPILE "${_SRCFILE_BASE}_fail_compile.cxx")
75     try_compile(${RESULT_VAR} "${_bindir}" "${_SRCFILE}"
76                 COMPILE_DEFINITIONS "${CXX11_COMPILER_FLAGS}")
78     if (${RESULT_VAR} AND EXISTS ${_SRCFILE_FAIL_COMPILE})
79         try_compile(_TMP_RESULT "${_bindir}_fail_compile" "${_SRCFILE_FAIL_COMPILE}"
80                     COMPILE_DEFINITIONS "${CXX11_COMPILER_FLAGS}")
81         if (_TMP_RESULT)
82             set(${RESULT_VAR} FALSE)
83         else ()
84             set(${RESULT_VAR} TRUE)
85         endif ()
86     endif ()
88     if (${RESULT_VAR})
89         message(STATUS "Checking C++ support for ${_LOG_NAME}: works")
90     else ()
91         message(STATUS "Checking C++ support for ${_LOG_NAME}: not supported")
92     endif ()
93     set(${RESULT_VAR} "${${RESULT_VAR}}" CACHE INTERNAL "C++ support for ${_LOG_NAME}")
94 endfunction(cxx_check_feature)
96 set(_CXX_ALL_FEATURES
97     alignof
98     auto
99     class_override_final
100     constexpr
101     cstdint_header
102     decltype
103     defaulted_functions
104     deleted_functions
105     func_identifier
106     initializer_list
107     lambda
108     long_long
109     nullptr
110     rvalue_references
111     sizeof_member
112     static_assert
113     variadic_templates
116 if (CXXFeatures_FIND_COMPONENTS)
117     foreach (_cxx_feature IN LISTS CXXFeatures_FIND_COMPONENTS)
118         list(FIND _CXX_ALL_FEATURES "${_cxx_feature}" _feature_index)
119         if (_feature_index EQUAL -1)
120             message(FATAL_ERROR "Unknown component: '${_cxx_feature}'")
121         endif ()
122     endforeach ()
123     unset(_feature_index)
124 else ()
125     set(CXXFEATURES_FIND_COMPONENTS ${_CXX_ALL_FEATURES})
126 endif ()
128 foreach (_cxx_feature IN LISTS CXXFEATURES_FIND_COMPONENTS)
129     cxx_check_feature(${_cxx_feature} ${FEATURE_NAME})
130 endforeach (_cxx_feature)
132 include(FindPackageHandleStandardArgs)
133 set(DUMMY_VAR TRUE)
134 find_package_handle_standard_args(CXXFeatures REQUIRED_VARS DUMMY_VAR HANDLE_COMPONENTS)
135 unset(DUMMY_VAR)
136 unset(_CXX_ALL_FEATURES)