cmake: cannot use CheckSymbolExists for _alloca

_alloca is an intrinsic function on MSVC, which means it has no address and is no symbol.
Hence CheckSymbolExists will always fail finding it.
This commit is contained in:
Anonymous Maarten
2025-10-10 17:06:26 +02:00
committed by Anonymous Maarten
parent 6677fad1c8
commit 40d8ec4be9
3 changed files with 11 additions and 2 deletions

View File

@@ -1005,7 +1005,14 @@ set(SDL_DISABLE_ALLOCA 0)
check_include_file("alloca.h" "HAVE_ALLOCA_H")
if(MSVC)
check_include_file("malloc.h" "HAVE_MALLOC_H")
check_symbol_exists("_alloca" "malloc.h" _ALLOCA_IN_MALLOC_H)
# Cannot use CheckSymbolExists for _alloca: purely intrinsic functions have no address (C7552)
if(NOT DEFINED _ALLOCA_IN_MALLOC_H)
message(STATUS "Looking for _alloca in malloc.h")
set(testsrc "${CMAKE_CURRENT_SOURCE_DIR}/test_malloc_alloca.c")
file(WRITE "${testsrc}" "#include <malloc.h>\n\nint main(int argc, char *argv[]) { void *ptr = _alloca(argc * (int)argv[0][0]); return ptr != (void *)0; }")
try_compile(_ALLOCA_IN_MALLOC_H "${CMAKE_CURRENT_BINARY_DIR}/alloca_in_malloc_h" SOURCES "${testsrc}")
message(STATUS "Looking for _alloca in malloc.h - ${_ALLOCA_IN_MALLOC_H}")
endif()
if(NOT HAVE_ALLOCA_H AND NOT _ALLOCA_IN_MALLOC_H)
set(SDL_DISABLE_ALLOCA 1)
endif()