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:
@@ -420,38 +420,32 @@ if(UNIX)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(MSVC)
|
||||
set(INLINE_OPTIONS "__inline;inline")
|
||||
else()
|
||||
set(INLINE_OPTIONS "__inline__;inline")
|
||||
endif()
|
||||
option(FORCE_INLINE "Force function inlining" TRUE)
|
||||
boolean_number(FORCE_INLINE)
|
||||
if(FORCE_INLINE)
|
||||
if(MSVC)
|
||||
set(INLINE "__forceinline")
|
||||
check_c_source_compiles("__forceinline void foo(void) {} int main(void) { foo(); }"
|
||||
FORCE_INLINE_WORKS)
|
||||
list(INSERT INLINE_OPTIONS 0 "__forceinline")
|
||||
else()
|
||||
set(INLINE "inline __attribute__((always_inline))")
|
||||
check_c_source_compiles("static inline __attribute__((always_inline)) void foo(void) {} int main(void) { foo(); }"
|
||||
FORCE_INLINE_WORKS)
|
||||
list(INSERT INLINE_OPTIONS 0 "inline __attribute__((always_inline))")
|
||||
list(INSERT INLINE_OPTIONS 0 "__inline__ __attribute__((always_inline))")
|
||||
endif()
|
||||
endif()
|
||||
if(NOT FORCE_INLINE OR NOT FORCE_INLINE_WORKS)
|
||||
if(MSVC)
|
||||
set(INLINE "__inline")
|
||||
check_c_source_compiles("__inline void foo(void) {} int main(void) { foo(); }"
|
||||
INLINE_WORKS)
|
||||
else()
|
||||
set(INLINE "__inline__")
|
||||
check_c_source_compiles("static __inline__ void foo(void) {} int main(void) { foo(); }"
|
||||
foreach(inline ${INLINE_OPTIONS})
|
||||
check_c_source_compiles("${inline} static void foo(void) {} int main(void) { foo(); }"
|
||||
INLINE_WORKS)
|
||||
if(INLINE_WORKS)
|
||||
set(INLINE ${inline})
|
||||
break()
|
||||
endif()
|
||||
endforeach()
|
||||
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()
|
||||
message(STATUS "INLINE = ${INLINE} (FORCE_INLINE = ${FORCE_INLINE})")
|
||||
|
||||
if(UNIX AND NOT APPLE)
|
||||
|
||||
Reference in New Issue
Block a user