|
|
Line 1: |
Line 1: |
| [[CMake_User_Contributed_Macros|Back]]
| | {{CMake/Template/Moved}} |
|
| |
|
| This handy test is from Jack Kelly on the cmake email list. | | This page has moved [https://gitlab.kitware.com/cmake/community/wikis/contrib/macros/TestInline here]. |
| | |
| Here is a minimal working example. It tests the inline keyword, then __inline__ and then __inline. When it finds one that works, it will ADD_DEFINITIONS(-Dinline=${KEYWORD}) and if none work, it will ADD_DEFINITIONS(-Dinline=).
| |
| | |
| <pre>
| |
| # Inspired from /usr/share/autoconf/autoconf/c.m4
| |
| FOREACH(KEYWORD "inline" "__inline__" "__inline")
| |
| IF(NOT DEFINED C_INLINE)
| |
| TRY_COMPILE(C_HAS_${KEYWORD} "${GPUIT_BINARY_DIR}"
| |
| "${GPUIT_SOURCE_DIR}/test_inline.c"
| |
| COMPILE_DEFINITIONS "-Dinline=${KEYWORD}")
| |
| IF(C_HAS_${KEYWORD})
| |
| SET(C_INLINE TRUE)
| |
| ADD_DEFINITIONS("-Dinline=${KEYWORD}")
| |
| ENDIF(C_HAS_${KEYWORD})
| |
| ENDIF(NOT DEFINED C_INLINE)
| |
| ENDFOREACH(KEYWORD)
| |
| IF(NOT DEFINED C_INLINE)
| |
| ADD_DEFINITIONS("-Dinline=")
| |
| ENDIF(NOT DEFINED C_INLINE)
| |
| </pre>
| |
| | |
| You also need this file in your source directory.
| |
| | |
| <pre>
| |
| /* Test source lifted from /usr/share/autoconf/autoconf/c.m4 */ | |
| typedef int foo_t;
| |
| static inline foo_t static_foo(){return 0;}
| |
| foo_t foo(){return 0;}
| |
| int main(int argc, char *argv[]){return 0;}
| |
| </pre>
| |
| | |
| {{CMake/Template/Footer}}
| |
Latest revision as of 15:41, 30 April 2018