CMake check_function_exists没有

jwm*_*jwm 3 c++ cmake

我正在完成CMake教程并与相关的项目文件进行交叉检查,我坚持第4步.

说明将这些行添加到顶级CMakeLists.txt文件中:

# does this system provide the log and exp functions?
include (CheckFunctionExists)
check_function_exists (log HAVE_LOG)
check_function_exists (exp HAVE_EXP)
Run Code Online (Sandbox Code Playgroud)

如上所述,这是一个微不足道的测试,因为地球上的每个系统都具有logexp.但它失败了.生成Makefile时,我明白了

-- Looking for log
-- Looking for log - not found
-- Looking for exp
-- Looking for exp - not found
Run Code Online (Sandbox Code Playgroud)

如果我深入挖掘,运行cmake --trace,我会看到以下几行:

.../tutorial/src/CMakeLists.txt(19):  include( CheckFunctionExists )
/usr/share/cmake/Modules/CheckFunctionExists.cmake(32):  macro(CHECK_FUNCTION_EXISTS FUNCTION VARIABLE )
.../tutorial/src/CMakeLists.txt(20):  check_function_exists(log HAVE_LOG )
/usr/share/cmake/Modules/CheckFunctionExists.cmake(33):  if(HAVE_LOG MATCHES ^HAVE_LOG$ )
.../tutorial/src/CMakeLists.txt(21):  check_function_exists(exp HAVE_EXP )
/usr/share/cmake/Modules/CheckFunctionExists.cmake(33):  if(HAVE_EXP MATCHES ^HAVE_EXP$ )
Run Code Online (Sandbox Code Playgroud)

在该CheckFunctionExists.cmake文件中,else该测试没有条件.我是cmake的新手,但测试似乎对我来说是真实的.我错过了什么?

CentOS 7,cmake 2.8.12.2

Mar*_*cel 6

CheckFunctionExists众所周知,它有严重的缺点.见文档.

在你的情况下,你可能会遇到第一个陷阱.功能logexp是内在的内联函数在许多平台上.在链接时无法检测到它们.

推荐的替代品是CheckSymbolExists.不幸的是,您的cmake版本不支持此功能.您需要升级至少3.0.2才能使用.