CMake教程版本号:3.16.3
英文原文链接: https://cmake.org/cmake/help/latest/guide/tutorial/index.html#id2
github示例代码 https://github.com/sxpsxp12/cmake-learning-exampes
添加自检
我们的代码有时候会使用平台相关的一些实现,我们该怎么去判定这些接口存不存在呢?
我们可以通过宏来校验是否存在该相关的符号。
include(CheckSymbolExists)
set(CMAKE_REQUIRED_LIBRARIES "m")
check_symbol_exists(log "math.h" HAVE_LOG)
check_symbol_exists(exp "math.h" HAVE_EXP)
configure_file(config.h.in config.h)
target_include_directories(helloworld
PUBLIC "${CMAKE_BINARY_DIR}"
INTERFACE ${CMAKE_SOURCE_DIR}
)
然后,在配置头文件中添加定义,以将CMake结果传递到头文件
// does the platform provide exp and log functions?
#cmakedefine HAVE_LOG
#cmakedefine HAVE_EXP
<