CMake 中 AC_CHECK_FUNCS() 的等效物是什么?
在 automake/m4 中,你在 configure.ac 中使用类似这样的语法
configure.ac
AC_CHECK_FUNCS(atan2)如果函数可用,则定义 HAVE_FDATASYNC。
在 CMake 中,你可以使用 check_symbol_exists() 达到相同目的,如下所示:
CMakeLists.txt
cmake_minimum_required(VERSION 3.0)
include(CheckSymbolExists)
# 定义可执行文件
add_executable(myexe main.c)
# atan2 需要链接数学库
list(APPEND CMAKE_REQUIRED_LIBRARIES m)
check_symbol_exists(atan2 math.h HAVE_ATAN2)
# 如果我们有该库则添加编译定义
if(HAVE_ATAN2)
target_compile_definitions(myexe PRIVATE -DHAVE_ATAN2)
endif()注意 check_symbol_exists() 不会自动添加预处理器定义,你需要手动执行(参见上面代码中的最后一个块)。虽然这乍看之下可能不太舒适,但这种方法在如何处理缺失或可用的函数方面为你提供了更大的灵活性。
请参见 CMake check_symbol_exists() 文档了解更多详情。
Check out similar posts by category:
CMake
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow