Build: Clean up inline keyword detection

Strict C89-conformant compilers don't support the "inline" keyword, but
most of them support "__inline__", and that keyword can be used with the
always_inline atribute as well.  This commit also removes duplicate code
by using a foreach() loop to test the various keywords.
This commit is contained in:
DRC
2016-12-05 16:52:54 -06:00
parent 261db7706d
commit 2af2fe42a3

View File

@@ -420,37 +420,31 @@ if(UNIX)
endif() endif()
endif() endif()
if(MSVC)
set(INLINE_OPTIONS "__inline;inline")
else()
set(INLINE_OPTIONS "__inline__;inline")
endif()
option(FORCE_INLINE "Force function inlining" TRUE) option(FORCE_INLINE "Force function inlining" TRUE)
boolean_number(FORCE_INLINE) boolean_number(FORCE_INLINE)
if(FORCE_INLINE) if(FORCE_INLINE)
if(MSVC) if(MSVC)
set(INLINE "__forceinline") list(INSERT INLINE_OPTIONS 0 "__forceinline")
check_c_source_compiles("__forceinline void foo(void) {} int main(void) { foo(); }"
FORCE_INLINE_WORKS)
else() else()
set(INLINE "inline __attribute__((always_inline))") list(INSERT INLINE_OPTIONS 0 "inline __attribute__((always_inline))")
check_c_source_compiles("static inline __attribute__((always_inline)) void foo(void) {} int main(void) { foo(); }" list(INSERT INLINE_OPTIONS 0 "__inline__ __attribute__((always_inline))")
FORCE_INLINE_WORKS)
endif() endif()
endif() endif()
if(NOT FORCE_INLINE OR NOT FORCE_INLINE_WORKS) foreach(inline ${INLINE_OPTIONS})
if(MSVC) check_c_source_compiles("${inline} static void foo(void) {} int main(void) { foo(); }"
set(INLINE "__inline") INLINE_WORKS)
check_c_source_compiles("__inline void foo(void) {} int main(void) { foo(); }" if(INLINE_WORKS)
INLINE_WORKS) set(INLINE ${inline})
else() break()
set(INLINE "__inline__")
check_c_source_compiles("static __inline__ void foo(void) {} int main(void) { foo(); }"
INLINE_WORKS)
endif()
if(NOT INLINE_WORKS)
set(INLINE "inline")
check_c_source_compiles("static inline void foo(void) {} int main(void) { foo(); }"
C99_INLINE_WORKS)
if(NOT C99_INLINE_WORKS)
message(FATAL_ERROR "Could not determine how to inline functions.")
endif()
endif() endif()
endforeach()
if(NOT INLINE_WORKS)
message(FATAL_ERROR "Could not determine how to inline functions.")
endif() endif()
message(STATUS "INLINE = ${INLINE} (FORCE_INLINE = ${FORCE_INLINE})") message(STATUS "INLINE = ${INLINE} (FORCE_INLINE = ${FORCE_INLINE})")