annotate 3rdparty/vmime/cmake/cmake-cxx11/Modules/CheckCXX11Features.cmake @ 0:a4671277546c tip

created the repository for the thymian project
author ferencd
date Tue, 17 Aug 2021 11:19:54 +0200
parents
children
rev   line source
ferencd@0 1 # - Check which parts of the C++11 standard the compiler supports
ferencd@0 2 #
ferencd@0 3 # When found it will set the following variables
ferencd@0 4 #
ferencd@0 5 # CXX11_COMPILER_FLAGS - the compiler flags needed to get C++11 features
ferencd@0 6 #
ferencd@0 7 # HAS_CXX11_AUTO - auto keyword
ferencd@0 8 # HAS_CXX11_AUTO_RET_TYPE - function declaration with deduced return types
ferencd@0 9 # HAS_CXX11_CLASS_OVERRIDE - override and final keywords for classes and methods
ferencd@0 10 # HAS_CXX11_CONSTEXPR - constexpr keyword
ferencd@0 11 # HAS_CXX11_CSTDINT_H - cstdint header
ferencd@0 12 # HAS_CXX11_DECLTYPE - decltype keyword
ferencd@0 13 # HAS_CXX11_FUNC - __func__ preprocessor constant
ferencd@0 14 # HAS_CXX11_INITIALIZER_LIST - initializer list
ferencd@0 15 # HAS_CXX11_LAMBDA - lambdas
ferencd@0 16 # HAS_CXX11_LIB_REGEX - regex library
ferencd@0 17 # HAS_CXX11_LONG_LONG - long long signed & unsigned types
ferencd@0 18 # HAS_CXX11_NULLPTR - nullptr
ferencd@0 19 # HAS_CXX11_RVALUE_REFERENCES - rvalue references
ferencd@0 20 # HAS_CXX11_SIZEOF_MEMBER - sizeof() non-static members
ferencd@0 21 # HAS_CXX11_STATIC_ASSERT - static_assert()
ferencd@0 22 # HAS_CXX11_VARIADIC_TEMPLATES - variadic templates
ferencd@0 23
ferencd@0 24 #=============================================================================
ferencd@0 25 # Copyright 2011,2012 Rolf Eike Beer <eike@sf-mail.de>
ferencd@0 26 # Copyright 2012 Andreas Weis
ferencd@0 27 #
ferencd@0 28 # Distributed under the OSI-approved BSD License (the "License");
ferencd@0 29 # see accompanying file Copyright.txt for details.
ferencd@0 30 #
ferencd@0 31 # This software is distributed WITHOUT ANY WARRANTY; without even the
ferencd@0 32 # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
ferencd@0 33 # See the License for more information.
ferencd@0 34 #=============================================================================
ferencd@0 35 # (To distribute this file outside of CMake, substitute the full
ferencd@0 36 # License text for the above reference.)
ferencd@0 37
ferencd@0 38 #
ferencd@0 39 # Each feature may have up to 3 checks, every one of them in it's own file
ferencd@0 40 # FEATURE.cpp - example that must build and return 0 when run
ferencd@0 41 # FEATURE_fail.cpp - example that must build, but may not return 0 when run
ferencd@0 42 # FEATURE_fail_compile.cpp - example that must fail compilation
ferencd@0 43 #
ferencd@0 44 # The first one is mandatory, the latter 2 are optional and do not depend on
ferencd@0 45 # each other (i.e. only one may be present).
ferencd@0 46 #
ferencd@0 47
ferencd@0 48 if (NOT CMAKE_CXX_COMPILER_LOADED)
ferencd@0 49 message(FATAL_ERROR "CheckCXX11Features modules only works if language CXX is enabled")
ferencd@0 50 endif ()
ferencd@0 51
ferencd@0 52 cmake_minimum_required(VERSION 2.8.3)
ferencd@0 53
ferencd@0 54 #
ferencd@0 55 ### Check for needed compiler flags
ferencd@0 56 #
ferencd@0 57 include(CheckCXXCompilerFlag)
ferencd@0 58 check_cxx_compiler_flag("-std=c++11" _HAS_CXX11_FLAG)
ferencd@0 59 if (NOT _HAS_CXX11_FLAG)
ferencd@0 60 check_cxx_compiler_flag("-std=c++0x" _HAS_CXX0X_FLAG)
ferencd@0 61 endif ()
ferencd@0 62
ferencd@0 63 if (_HAS_CXX11_FLAG)
ferencd@0 64 set(CXX11_COMPILER_FLAGS "-std=c++11")
ferencd@0 65 elseif (_HAS_CXX0X_FLAG)
ferencd@0 66 set(CXX11_COMPILER_FLAGS "-std=c++0x")
ferencd@0 67 endif ()
ferencd@0 68
ferencd@0 69 function(cxx11_check_feature FEATURE_NAME RESULT_VAR)
ferencd@0 70 if (NOT DEFINED ${RESULT_VAR})
ferencd@0 71 set(_bindir "${CMAKE_CURRENT_BINARY_DIR}/cxx11_${FEATURE_NAME}")
ferencd@0 72
ferencd@0 73 set(_SRCFILE_BASE ${CMAKE_CURRENT_LIST_DIR}/CheckCXX11Features/cxx11-test-${FEATURE_NAME})
ferencd@0 74 set(_LOG_NAME "\"${FEATURE_NAME}\"")
ferencd@0 75 message(STATUS "Checking C++11 support for ${_LOG_NAME}")
ferencd@0 76
ferencd@0 77 set(_SRCFILE "${_SRCFILE_BASE}.cpp")
ferencd@0 78 set(_SRCFILE_FAIL "${_SRCFILE_BASE}_fail.cpp")
ferencd@0 79 set(_SRCFILE_FAIL_COMPILE "${_SRCFILE_BASE}_fail_compile.cpp")
ferencd@0 80
ferencd@0 81 if (CROSS_COMPILING)
ferencd@0 82 try_compile(${RESULT_VAR} "${_bindir}" "${_SRCFILE}"
ferencd@0 83 COMPILE_DEFINITIONS "${CXX11_COMPILER_FLAGS}")
ferencd@0 84 if (${RESULT_VAR} AND EXISTS ${_SRCFILE_FAIL})
ferencd@0 85 try_compile(${RESULT_VAR} "${_bindir}_fail" "${_SRCFILE_FAIL}"
ferencd@0 86 COMPILE_DEFINITIONS "${CXX11_COMPILER_FLAGS}")
ferencd@0 87 endif (${RESULT_VAR} AND EXISTS ${_SRCFILE_FAIL})
ferencd@0 88 else (CROSS_COMPILING)
ferencd@0 89 try_run(_RUN_RESULT_VAR _COMPILE_RESULT_VAR
ferencd@0 90 "${_bindir}" "${_SRCFILE}"
ferencd@0 91 COMPILE_DEFINITIONS "${CXX11_COMPILER_FLAGS}")
ferencd@0 92 if (_COMPILE_RESULT_VAR AND NOT _RUN_RESULT_VAR)
ferencd@0 93 set(${RESULT_VAR} TRUE)
ferencd@0 94 else (_COMPILE_RESULT_VAR AND NOT _RUN_RESULT_VAR)
ferencd@0 95 set(${RESULT_VAR} FALSE)
ferencd@0 96 endif (_COMPILE_RESULT_VAR AND NOT _RUN_RESULT_VAR)
ferencd@0 97 if (${RESULT_VAR} AND EXISTS ${_SRCFILE_FAIL})
ferencd@0 98 try_run(_RUN_RESULT_VAR _COMPILE_RESULT_VAR
ferencd@0 99 "${_bindir}_fail" "${_SRCFILE_FAIL}"
ferencd@0 100 COMPILE_DEFINITIONS "${CXX11_COMPILER_FLAGS}")
ferencd@0 101 if (_COMPILE_RESULT_VAR AND _RUN_RESULT_VAR)
ferencd@0 102 set(${RESULT_VAR} TRUE)
ferencd@0 103 else (_COMPILE_RESULT_VAR AND _RUN_RESULT_VAR)
ferencd@0 104 set(${RESULT_VAR} FALSE)
ferencd@0 105 endif (_COMPILE_RESULT_VAR AND _RUN_RESULT_VAR)
ferencd@0 106 endif (${RESULT_VAR} AND EXISTS ${_SRCFILE_FAIL})
ferencd@0 107 endif (CROSS_COMPILING)
ferencd@0 108 if (${RESULT_VAR} AND EXISTS ${_SRCFILE_FAIL_COMPILE})
ferencd@0 109 try_compile(_TMP_RESULT "${_bindir}_fail_compile" "${_SRCFILE_FAIL_COMPILE}"
ferencd@0 110 COMPILE_DEFINITIONS "${CXX11_COMPILER_FLAGS}")
ferencd@0 111 if (_TMP_RESULT)
ferencd@0 112 set(${RESULT_VAR} FALSE)
ferencd@0 113 else (_TMP_RESULT)
ferencd@0 114 set(${RESULT_VAR} TRUE)
ferencd@0 115 endif (_TMP_RESULT)
ferencd@0 116 endif (${RESULT_VAR} AND EXISTS ${_SRCFILE_FAIL_COMPILE})
ferencd@0 117
ferencd@0 118 if (${RESULT_VAR})
ferencd@0 119 message(STATUS "Checking C++11 support for ${_LOG_NAME}: works")
ferencd@0 120 else (${RESULT_VAR})
ferencd@0 121 message(STATUS "Checking C++11 support for ${_LOG_NAME}: not supported")
ferencd@0 122 endif (${RESULT_VAR})
ferencd@0 123 set(${RESULT_VAR} ${${RESULT_VAR}} CACHE INTERNAL "C++11 support for ${_LOG_NAME}")
ferencd@0 124 endif (NOT DEFINED ${RESULT_VAR})
ferencd@0 125 endfunction(cxx11_check_feature)
ferencd@0 126
ferencd@0 127 cxx11_check_feature("__func__" HAS_CXX11_FUNC)
ferencd@0 128 cxx11_check_feature("auto" HAS_CXX11_AUTO)
ferencd@0 129 cxx11_check_feature("auto_ret_type" HAS_CXX11_AUTO_RET_TYPE)
ferencd@0 130 cxx11_check_feature("class_override_final" HAS_CXX11_CLASS_OVERRIDE)
ferencd@0 131 cxx11_check_feature("constexpr" HAS_CXX11_CONSTEXPR)
ferencd@0 132 cxx11_check_feature("cstdint" HAS_CXX11_CSTDINT_H)
ferencd@0 133 cxx11_check_feature("decltype" HAS_CXX11_DECLTYPE)
ferencd@0 134 cxx11_check_feature("initializer_list" HAS_CXX11_INITIALIZER_LIST)
ferencd@0 135 cxx11_check_feature("lambda" HAS_CXX11_LAMBDA)
ferencd@0 136 cxx11_check_feature("long_long" HAS_CXX11_LONG_LONG)
ferencd@0 137 cxx11_check_feature("nullptr" HAS_CXX11_NULLPTR)
ferencd@0 138 cxx11_check_feature("regex" HAS_CXX11_LIB_REGEX)
ferencd@0 139 cxx11_check_feature("rvalue-references" HAS_CXX11_RVALUE_REFERENCES)
ferencd@0 140 cxx11_check_feature("sizeof_member" HAS_CXX11_SIZEOF_MEMBER)
ferencd@0 141 cxx11_check_feature("static_assert" HAS_CXX11_STATIC_ASSERT)
ferencd@0 142 cxx11_check_feature("variadic_templates" HAS_CXX11_VARIADIC_TEMPLATES)