3

I'm using the alloca function in one of my projects and decided to use CMake to make sure it's available. So I added this bit to my CMakeLists.txt file:

include(CheckSymbolExists)
check_symbol_exists(alloca stdlib.h;cstdlib ALLOCA_EXISTS)
if (NOT ALLOCA_EXISTS)
    message(FATAL_ERROR "Platform does not support alloca")
endif ()

When I run CMake, this is the (relevant part of the) output:

-- Looking for alloca
-- Looking for alloca - found
CMake Error at CMakeLists.txt:11 (message):
  Platform does not support alloca


-- Configuring incomplete, errors occurred!

So how come the shown code finds the function but doesn't set the variable? Or is it something else?

Dovahkiin
  • 946
  • 14
  • 25

1 Answers1

1

You must add quotes when you specify the headers:

check_symbol_exists(alloca "stdlib.h;cstdlib" ALLOCA_EXISTS)

Otherwise, ALLOCA_EXISTS is ignored and a variable cstdlib is created with value TRUE.

oLen
  • 5,177
  • 1
  • 32
  • 48