• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1
2include(CheckCXXSourceCompiles)
3
4set(CMAKE_REQUIRED_FLAGS "${FRUIT_COMPILE_FLAGS}")
5
6CHECK_CXX_SOURCE_COMPILES("
7int main() {}
8"
9FRUIT_TRIVIAL_SOURCE_COMPILES)
10
11if (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.")
13endif()
14
15CHECK_CXX_SOURCE_COMPILES("
16template <typename T, typename U>
17struct Pair {};
18
19struct Map : public Pair<int, float>, Pair<int, char> {};
20
21template <typename Value>
22Value f(Pair<int, Value>*) { return Value(); }
23
24int main() {
25  f((Map*)0);
26}
27"
28FRUIT_HAS_CLANG_ARBITRARY_OVERLOAD_RESOLUTION_BUG)
29
30CHECK_CXX_SOURCE_COMPILES("
31int main() {
32  bool b = __has_trivial_copy(int);
33  (void) b;
34  return 0;
35}
36"
37FRUIT_HAS_HAS_TRIVIAL_COPY)
38
39CHECK_CXX_SOURCE_COMPILES("
40int main() {
41  bool b = __is_trivially_copyable(int);
42  (void) b;
43  return 0;
44}
45"
46FRUIT_HAS_IS_TRIVIALLY_COPYABLE)
47
48CHECK_CXX_SOURCE_COMPILES("
49#include <cstddef>
50using X = max_align_t;
51int main() {
52  return 0;
53}
54"
55FRUIT_HAS_MAX_ALIGN_T)
56
57CHECK_CXX_SOURCE_COMPILES("
58#include <type_traits>
59int main() {
60  bool b = std::is_trivially_copyable<int>::value;
61  (void) b;
62  return 0;
63}
64"
65FRUIT_HAS_STD_IS_TRIVIALLY_COPYABLE)
66
67CHECK_CXX_SOURCE_COMPILES("
68#include <type_traits>
69int main() {
70  bool b = std::is_trivially_copy_constructible<int>::value;
71  (void) b;
72  return 0;
73}
74"
75FRUIT_HAS_STD_IS_TRIVIALLY_COPY_CONSTRUCTIBLE)
76
77CHECK_CXX_SOURCE_COMPILES("
78#include <cstddef>
79using X = std::max_align_t;
80int main() {
81  return 0;
82}
83"
84FRUIT_HAS_STD_MAX_ALIGN_T)
85
86CHECK_CXX_SOURCE_COMPILES("
87#include <typeinfo>
88int main() {
89  (void) typeid(int);
90  return 0;
91}
92"
93FRUIT_HAS_TYPEID)
94
95CHECK_CXX_SOURCE_COMPILES("
96#include <typeinfo>
97int main() {
98  constexpr static const std::type_info& x = typeid(int);
99  (void) x;
100  return 0;
101}
102"
103FRUIT_HAS_CONSTEXPR_TYPEID)
104
105CHECK_CXX_SOURCE_COMPILES("
106#include <cxxabi.h>
107int main() {
108  auto* p = abi::__cxa_demangle;
109  (void) p;
110  return 0;
111}
112"
113FRUIT_HAS_CXA_DEMANGLE)
114
115if("${FRUIT_ENABLE_COVERAGE}")
116    set(FRUIT_HAS_ALWAYS_INLINE_ATTRIBUTE OFF)
117    set(FRUIT_HAS_FORCEINLINE OFF)
118else()
119CHECK_CXX_SOURCE_COMPILES("
120__attribute__((always_inline))
121void f() {
122}
123
124int main() {
125  return 0;
126}
127"
128FRUIT_HAS_ALWAYS_INLINE_ATTRIBUTE)
129
130CHECK_CXX_SOURCE_COMPILES("
131__forceinline
132void f() {
133}
134
135int main() {
136  return 0;
137}
138"
139FRUIT_HAS_FORCEINLINE)
140
141endif()
142
143CHECK_CXX_SOURCE_COMPILES("
144[[deprecated]] void f();
145
146int main() {
147  return 0;
148}
149"
150FRUIT_HAS_ATTRIBUTE_DEPRECATED)
151
152CHECK_CXX_SOURCE_COMPILES("
153void f() __attribute__((deprecated));
154
155int main() {
156  return 0;
157}
158"
159FRUIT_HAS_GCC_ATTRIBUTE_DEPRECATED)
160
161CHECK_CXX_SOURCE_COMPILES("
162__declspec(deprecated) void f();
163
164int main() {
165  return 0;
166}
167"
168FRUIT_HAS_DECLSPEC_DEPRECATED)
169
170CHECK_CXX_SOURCE_COMPILES("
171int 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
181int main() {
182  return f();
183}
184"
185FRUIT_HAS_MSVC_ASSUME)
186
187CHECK_CXX_SOURCE_COMPILES("
188int 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
198int main() {
199  return f();
200}
201"
202FRUIT_HAS_BUILTIN_UNREACHABLE)
203
204
205if (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.")
207endif()
208
209if(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.")
212endif()
213
214if (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.")
216endif()
217
218configure_file(${CMAKE_CURRENT_SOURCE_DIR}/fruit-config-base.h.in ${CMAKE_CURRENT_BINARY_DIR}/../include/fruit/impl/fruit-config-base.h)
219
220install(FILES ${CMAKE_CURRENT_BINARY_DIR}/../include/fruit/impl/fruit-config-base.h
221  DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/fruit/impl)
222