10.MariaDB笔记——cmake使用介绍五系统自带函数
继续,如果考虑增加系统平台的函数到我们的项目中。
而我们增加的代码取决于目标平台是否存在函数。
现在假设平台有log函数,我们用于在mysqrt函数中调用。
使用CheckFunctionExists.cmake宏来判断这些函数是否存在。
在主CMakeLists中增加如下:
#does this system provide the log and exp functions?
include(CheckFunctionExists)
check_function_exists(log HAVE_LOG)
check_function_exists(exp HAVE_EXP)
然后修改TutorialConfig.h,如下,定义值
#cmakedefineHAVE_LOG
#cmakedefineHAVE_EXP
对log和exp的测试比configure_file 命令对TutorialConfig.h文件要早。
如果存在log和exp函数,可以使用如下代码
//if we have both log and exp then use them
#ifdefined (HAVE_LOG) && defined (HAVE_EXP)
result = exp(log(x)*0.5);
#else// otherwise use an iterative approach
. . .