Home | History | Annotate | Download | only in configuration
      1 
      2 include(CheckCXXSourceCompiles)
      3 
      4 set(CMAKE_REQUIRED_FLAGS "${FRUIT_COMPILE_FLAGS}")
      5 
      6 CHECK_CXX_SOURCE_COMPILES("
      7 int main() {}
      8 "
      9 FRUIT_TRIVIAL_SOURCE_COMPILES)
     10 
     11 if (NOT "${FRUIT_TRIVIAL_SOURCE_COMPILES}")
     12     message(FATAL_ERROR "A trivial program with an empty main doesn't compile, something is wrong with your compiler and/or with your compiler flags.")
     13 endif()
     14 
     15 CHECK_CXX_SOURCE_COMPILES("
     16 template <typename T, typename U>
     17 struct Pair {};
     18 
     19 struct Map : public Pair<int, float>, Pair<int, char> {};
     20 
     21 template <typename Value>
     22 Value f(Pair<int, Value>*) { return Value(); }
     23 
     24 int main() {
     25   f((Map*)0);
     26 }
     27 "
     28 FRUIT_HAS_CLANG_ARBITRARY_OVERLOAD_RESOLUTION_BUG)
     29 
     30 CHECK_CXX_SOURCE_COMPILES("
     31 int main() {
     32   bool b = __has_trivial_copy(int);
     33   (void) b;
     34   return 0;
     35 }
     36 "
     37 FRUIT_HAS_HAS_TRIVIAL_COPY)
     38 
     39 CHECK_CXX_SOURCE_COMPILES("
     40 int main() {
     41   bool b = __is_trivially_copyable(int);
     42   (void) b;
     43   return 0;
     44 }
     45 "
     46 FRUIT_HAS_IS_TRIVIALLY_COPYABLE)
     47 
     48 CHECK_CXX_SOURCE_COMPILES("
     49 #include <cstddef>
     50 using X = max_align_t;
     51 int main() {
     52   return 0;
     53 }
     54 "
     55 FRUIT_HAS_MAX_ALIGN_T)
     56 
     57 CHECK_CXX_SOURCE_COMPILES("
     58 #include <type_traits>
     59 int main() {
     60   bool b = std::is_trivially_copyable<int>::value;
     61   (void) b;
     62   return 0;
     63 }
     64 "
     65 FRUIT_HAS_STD_IS_TRIVIALLY_COPYABLE)
     66 
     67 CHECK_CXX_SOURCE_COMPILES("
     68 #include <type_traits>
     69 int main() {
     70   bool b = std::is_trivially_copy_constructible<int>::value;
     71   (void) b;
     72   return 0;
     73 }
     74 "
     75 FRUIT_HAS_STD_IS_TRIVIALLY_COPY_CONSTRUCTIBLE)
     76 
     77 CHECK_CXX_SOURCE_COMPILES("
     78 #include <cstddef>
     79 using X = std::max_align_t;
     80 int main() {
     81   return 0;
     82 }
     83 "
     84 FRUIT_HAS_STD_MAX_ALIGN_T)
     85 
     86 CHECK_CXX_SOURCE_COMPILES("
     87 #include <typeinfo>
     88 int main() {
     89   (void) typeid(int);
     90   return 0;
     91 }
     92 "
     93 FRUIT_HAS_TYPEID)
     94 
     95 CHECK_CXX_SOURCE_COMPILES("
     96 #include <typeinfo>
     97 int main() {
     98   constexpr static const std::type_info& x = typeid(int);
     99   (void) x;
    100   return 0;
    101 }
    102 "
    103 FRUIT_HAS_CONSTEXPR_TYPEID)
    104 
    105 CHECK_CXX_SOURCE_COMPILES("
    106 #include <cxxabi.h>
    107 int main() {
    108   auto* p = abi::__cxa_demangle;
    109   (void) p;
    110   return 0;
    111 }
    112 "
    113 FRUIT_HAS_CXA_DEMANGLE)
    114 
    115 if("${FRUIT_ENABLE_COVERAGE}")
    116     set(FRUIT_HAS_ALWAYS_INLINE_ATTRIBUTE OFF)
    117     set(FRUIT_HAS_FORCEINLINE OFF)
    118 else()
    119 CHECK_CXX_SOURCE_COMPILES("
    120 __attribute__((always_inline))
    121 void f() {
    122 }
    123 
    124 int main() {
    125   return 0;
    126 }
    127 "
    128 FRUIT_HAS_ALWAYS_INLINE_ATTRIBUTE)
    129 
    130 CHECK_CXX_SOURCE_COMPILES("
    131 __forceinline
    132 void f() {
    133 }
    134 
    135 int main() {
    136   return 0;
    137 }
    138 "
    139 FRUIT_HAS_FORCEINLINE)
    140 
    141 endif()
    142 
    143 CHECK_CXX_SOURCE_COMPILES("
    144 [[deprecated]] void f();
    145 
    146 int main() {
    147   return 0;
    148 }
    149 "
    150 FRUIT_HAS_ATTRIBUTE_DEPRECATED)
    151 
    152 CHECK_CXX_SOURCE_COMPILES("
    153 void f() __attribute__((deprecated));
    154 
    155 int main() {
    156   return 0;
    157 }
    158 "
    159 FRUIT_HAS_GCC_ATTRIBUTE_DEPRECATED)
    160 
    161 CHECK_CXX_SOURCE_COMPILES("
    162 __declspec(deprecated) void f();
    163 
    164 int main() {
    165   return 0;
    166 }
    167 "
    168 FRUIT_HAS_DECLSPEC_DEPRECATED)
    169 
    170 CHECK_CXX_SOURCE_COMPILES("
    171 int f() {
    172   static int x = 1;
    173   if (x == 1) {
    174     return 0;
    175   } else {
    176     __assume(0);
    177     // Note: the lack of return here is intentional
    178   }
    179 }
    180 
    181 int main() {
    182   return f();
    183 }
    184 "
    185 FRUIT_HAS_MSVC_ASSUME)
    186 
    187 CHECK_CXX_SOURCE_COMPILES("
    188 int f() {
    189   static int x = 1;
    190   if (x == 1) {
    191     return 0;
    192   } else {
    193     __builtin_unreachable();
    194     // Note: the lack of return here is intentional
    195   }
    196 }
    197 
    198 int main() {
    199   return f();
    200 }
    201 "
    202 FRUIT_HAS_BUILTIN_UNREACHABLE)
    203 
    204 
    205 if (NOT "${FRUIT_HAS_STD_MAX_ALIGN_T}" AND NOT "${FRUIT_HAS_MAX_ALIGN_T}")
    206   message(WARNING "The current C++ standard library doesn't support std::max_align_t nor ::max_align_t. Attempting to use std::max_align_t anyway, but it most likely won't work.")
    207 endif()
    208 
    209 if(NOT "${FRUIT_HAS_STD_IS_TRIVIALLY_COPYABLE}" AND NOT "${FRUIT_HAS_IS_TRIVIALLY_COPYABLE}"
    210    AND NOT "${FRUIT_HAS_HAS_TRIVIAL_COPY}")
    211   message(WARNING "The current standard library doesn't support std::is_trivially_copyable<T>, and the current compiler doesn't support __is_trivially_copyable(T) nor __has_trivial_copy(T). Attemping to use std::is_trivially_copyable<T> anyway, but it most likely won't work.")
    212 endif()
    213 
    214 if (NOT "${FRUIT_HAS_ATTRIBUTE_DEPRECATED}" AND NOT "${FRUIT_HAS_GCC_ATTRIBUTE_DEPRECATED}" AND NOT "${FRUIT_HAS_DECLSPEC_DEPRECATED}")
    215   message(WARNING "No supported way to mark functions as deprecated was found. Continuing anyway, without the 'deprecated' markers.")
    216 endif()
    217 
    218 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/fruit-config-base.h.in ${CMAKE_CURRENT_BINARY_DIR}/../include/fruit/impl/fruit-config-base.h)
    219 
    220 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/../include/fruit/impl/fruit-config-base.h
    221   DESTINATION ${INSTALL_INCLUDE_DIR}/impl)
    222