macros.cmake 2.36 KB
Newer Older
Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
1 2
macro(check_clzll VARIABLE)
  check_c_source_compiles(
3 4 5 6
    "int main(int argc, char *argv[])
{return __builtin_clzll(1LL);}"
    ${VARIABLE}
    )
Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
7
endmacro()
8

Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
9 10
macro(check_bsr64 VARIABLE)
  check_c_source_compiles(
11 12 13 14 15
    "int main(int argc, char *argv[])
{unsigned long foo; unsigned __int64 bar=1LL;
return _BitScanReverse64(&foo, bar);}"
    ${VARIABLE}
    )
Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
16
endmacro()
17

Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
18
macro(find_inline_keyword)
19
  #Inspired from http://www.cmake.org/Wiki/CMakeTestInline
Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
20
  set(INLINE_TEST_SRC "/* Inspired by autoconf's c.m4 */
21 22 23
static inline int static_foo(){return 0\;}
int main(int argc, char *argv[]){return 0\;}
")
Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
24
  file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/CMakeTestCInline.c
25 26
    ${INLINE_TEST_SRC})

Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
27 28 29
  foreach(KEYWORD "inline" "__inline__" "__inline")
    if(NOT DEFINED C_INLINE)
      try_compile(C_HAS_${KEYWORD}
30 31 32 33
        ${CMAKE_CURRENT_BINARY_DIR}
        ${CMAKE_CURRENT_BINARY_DIR}/CMakeTestCInline.c
        COMPILE_DEFINITIONS "-Dinline=${KEYWORD}"
        )
Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
34 35 36 37 38 39 40
      if(C_HAS_${KEYWORD})
        set(C_INLINE TRUE)
        add_definitions("-Dinline=${KEYWORD}")
        message(STATUS "Inline keyword found - ${KEYWORD}")
      endif(C_HAS_${KEYWORD})
    endif(NOT DEFINED C_INLINE)
  endforeach(KEYWORD)
41

Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
42 43 44 45 46
  if(NOT DEFINED C_INLINE)
    add_definitions("-Dinline=")
    message(STATUS "Inline keyword - not found")
  endif(NOT DEFINED C_INLINE)
endmacro(find_inline_keyword)
47

Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
48 49
macro(find_restrict_keyword)
  set(RESTRICT_TEST_SRC "/* Inspired by autoconf's c.m4 */
50 51 52 53 54
int foo (int * restrict ip){return ip[0]\;}
int main(int argc, char *argv[]){int s[1]\;
int * restrict t = s\; t[0] = 0\; return foo(t)\;}
")

Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
55
  file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/CMakeTestCRestrict.c
56 57
    ${RESTRICT_TEST_SRC})

Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
58 59 60
  foreach(KEYWORD "restrict" "__restrict" "__restrict__" "_Restrict")
    if(NOT DEFINED C_RESTRICT)
      try_compile(C_HAS_${KEYWORD}
61 62 63 64
        ${CMAKE_CURRENT_BINARY_DIR}
        ${CMAKE_CURRENT_BINARY_DIR}/CMakeTestCRestrict.c
        COMPILE_DEFINITIONS "-Drestrict=${KEYWORD}"
        )
Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
65 66 67 68 69 70 71
      if(C_HAS_${KEYWORD})
        set(C_RESTRICT TRUE)
        add_definitions("-Drestrict=${KEYWORD}")
        message(STATUS "Restrict keyword found - ${KEYWORD}")
      endif(C_HAS_${KEYWORD})
    endif(NOT DEFINED C_RESTRICT)
  endforeach(KEYWORD)
72

Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
73 74 75 76 77
  if(NOT DEFINED C_RESTRICT)
    add_definitions("-Drestrict=")
    message(STATUS "Restrict keyword - not found")
  endif(NOT DEFINED C_RESTRICT)
endmacro(find_restrict_keyword)