dusktreader
dusktreader

Reputation: 4055

How to properly check for a function using CMake

In converting from automake to cmake, I have to carry over some tests for function existence. I didn't write the configure.ac script, but I do have to reproduce the functionality as closely as follows, so please don't berate me about these checks. I have to make them.

So, I'm trying to use the CheckFunctionExists module to check for the existence of the time function (among others). Here's the cmake code

include(CheckIncludeFiles)

CHECK_FUNCTION_EXISTS(time, HAVE_TIME_FUNCTION)

if(NOT HAVE_TIME_FUNCTION)
    message(FATAL_ERROR "ERROR: required time function not found")
endif(NOT HAVE_TIME_FUNCTION)

This fails every time, even though I know for a fact that I have the time funcion (duh). I tried replacing time with printf and it still fails. Is there some setup I have to do to make this check work correctly?

Upvotes: 7

Views: 3537

Answers (2)

Fraser
Fraser

Reputation: 78330

You should remove the ,:

CHECK_FUNCTION_EXISTS(time HAVE_TIME_FUNCTION)

In CMake, separators are spaces or semi-colons, the comma is part of the variable.

Upvotes: 7

sakra
sakra

Reputation: 65801

Include the CMake standard module CheckFunctionExists and remove the comma in the check_function_exists invocation:

include(CheckFunctionExists)
check_function_exists(time HAVE_TIME_FUNCTION)

Upvotes: 6

Related Questions