如何使用CMake正确检查功能

dus*_*der 7 cmake

在从automake转换为cmake时,我必须对函数存在进行一些测试.我没有编写configure.ac脚本,但我必须尽可能地重现这些功能,所以请不要因为这些检查而责备我.我必须制作它们.

所以,我正在尝试使用CheckFunctionExists模块来检查时间函数的存在(以及其他).这是cmake代码

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)
Run Code Online (Sandbox Code Playgroud)

每次都失败,尽管我知道我有时间功能(duh).我尝试用printf替换时间,但仍然失败.我是否需要进行一些设置才能使此检查正常工作?

Fra*_*ser 7

你应该删除,:

CHECK_FUNCTION_EXISTS(time HAVE_TIME_FUNCTION)
Run Code Online (Sandbox Code Playgroud)

在CMake中,分隔符是空格或分号,逗号是变量的一部分.


sak*_*kra 6

包括CMake标准模块CheckFunctionExists并删除check_function_exists调用中的逗号:

include(CheckFunctionExists)
check_function_exists(time HAVE_TIME_FUNCTION)
Run Code Online (Sandbox Code Playgroud)