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 out similar posts by category: CMake