Check for the existence of the alloca.h header and only use it it exists,
otherwise fallback to stdlib.h. Some OS's like macOS and QNX have both
headers and can use either (stdlib.h includes alloca.h), some OS's like
OpenBSD / FreeBSD / NetBSD do not have the alloca.h header and require
the stdlib.h header.
if(CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
target_compile_definitions(loader_specific_options INTERFACE __BSD_VISIBLE=1)
endif()
+ check_include_file("alloca.h" HAVE_ALLOCA_H)
+ if(HAVE_ALLOCA_H)
+ target_compile_definitions(loader_specific_options INTERFACE HAVE_ALLOCA_H)
+ endif()
endif()
set(NORMAL_LOADER_SRCS
#if defined(_WIN32)
#include <malloc.h>
-#else
+#elif defined(HAVE_ALLOCA_H)
#include <alloca.h>
+#else
+#include <stdlib.h>
#endif
#if defined(__linux__) || defined(__APPLE__) || defined(__Fuchsia__) || defined(__QNXNTO__) || defined(__FreeBSD__) || defined(__OpenBSD__)