Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to properly check for a function using CMake

Tags:

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?

like image 407
dusktreader Avatar asked Aug 15 '12 20:08

dusktreader


2 Answers

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.

like image 144
Fraser Avatar answered Sep 19 '22 14:09

Fraser


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)
like image 36
sakra Avatar answered Sep 21 '22 14:09

sakra