File: GCCBuiltins.cmake

package info (click to toggle)
swi-prolog 9.0.4%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 82,408 kB
  • sloc: ansic: 387,503; perl: 359,326; cpp: 6,613; lisp: 6,247; java: 5,540; sh: 3,147; javascript: 2,668; python: 1,900; ruby: 1,594; yacc: 845; makefile: 428; xml: 317; sed: 12; sql: 6
file content (46 lines) | stat: -rw-r--r-- 1,568 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# Compiler features

check_c_source_compiles(
    "unsigned int x = 11; int main() { return __builtin_clz(x); }"
    HAVE__BUILTIN_CLZ)
check_c_source_compiles(
    "unsigned int x = 11; int main() { return __builtin_popcount(x); }"
    HAVE__BUILTIN_POPCOUNT)
check_c_source_compiles(
    "int i=0; int main() { return __builtin_expect(i, 0) ? 0 : 1; }"
    HAVE___BUILTIN_EXPECT)
check_c_source_compiles(
    "__thread int i=0; int main() { return 0; }"
    HAVE___THREAD)
check_c_source_compiles(
    "volatile int i=0; int main() { return 0; }"
    HAVE_VOLATILE)
check_c_source_compiles(
    "static inline int foo() { return 0; } int main() { return foo(); }"
    HAVE_INLINE)
check_c_source_compiles(
    "int main() { void *p = &&lbl; goto *p; lbl: return 0; }"
    O_LABEL_ADDRESSES)
check_c_source_runs(
    "extern int __attribute__((weak)) foo(); int main() { return &foo == 0 ? 0 : 1; }"
    HAVE_WEAK_ATTRIBUTE)

function(check_visibility)
  set(CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS} -Werror)
  check_c_source_compiles(
      "int foo __attribute__((visibility (\"hidden\"))) = 1; int main() { return 0; }"
      HAVE_VISIBILITY_ATTRIBUTE)
  if(HAVE_VISIBILITY_ATTRIBUTE)
    set(HAVE_VISIBILITY_ATTRIBUTE 1 PARENT_SCOPE)
  endif()
endfunction()
check_visibility()

# Builtin functions that lead to conflicts

check_c_source_compiles(
    "#include <alloca.h>\nint main() { char *s = alloca(10); return s!=0; }"
    HAVE_ALLOCA)
check_c_source_compiles(
    "#include <math.h>\nint main() { double x = 0.0; return signbit(x); }"
    HAVE_SIGNBIT)