summaryrefslogtreecommitdiff
path: root/TestCInline.cmake
blob: 4fdd4c5bb3a02ea3bb4648e6e6fcb9cffb018029 (plain)
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
#Inspired from http://www.cmake.org/Wiki/CMakeTestInline

IF(NOT DEFINED C_INLINE_DETECTED)

  SET(INLINE_TEST_SRC "/* Inspired by autoconf's c.m4 */
static inline int static_foo() {return 0\;}
int main(int argc, char *argv[]){return 0\;}
")

  FILE(WRITE ${CMAKE_CURRENT_BINARY_DIR}/CMakeTestCInline.c ${INLINE_TEST_SRC})

  FOREACH(KEYWORD "inline" "__inline__" "__inline")
    IF(NOT DEFINED C_INLINE)
      TRY_COMPILE(C_HAS_${KEYWORD}
        ${CMAKE_CURRENT_BINARY_DIR}
        ${CMAKE_CURRENT_BINARY_DIR}/CMakeTestCInline.c
        COMPILE_DEFINITIONS "-Dinline=${KEYWORD}"
        )
      IF(C_HAS_${KEYWORD})
        SET(C_INLINE ${KEYWORD})
      ENDIF(C_HAS_${KEYWORD})
    ENDIF(NOT DEFINED C_INLINE)
  ENDFOREACH(KEYWORD)

  SET(C_INLINE_DETECTED True CACHE BOOL INTERNAL)

ENDIF(NOT DEFINED C_INLINE_DETECTED)