cmake - 在CMake中,CHECK_INCLUDE_FILE_CXX如何工作?

标签 cmake

以下代码不输出任何内容

CHECK_INCLUDE_FILE_CXX(glog/logging.h GLOG_INCLUDE)
IF(GLOG_INCLUDE)
   MESSAGE("YY")
ENDIF(GLOG_INCLUDE)

但是我设置了以下环境变量:
export CPLUS_INCLUDE_PATH=/usr/local/include

并且,“ls/usr/local/include/glog/logging.h”返回文件。

我尝试使用
include_directories( "/usr/local/include" )

但之后GLOG_INCLUDE仍未定义(未找到logging.h。)

最佳答案

看一下CheckIncludeFileCXX.cmake。它应该在您的cmake安装目录中(我在/usr/share/cmake-2.8/Modules中)。

该文件指出:

# The following variables may be set before calling this macro to
# modify the way the check is run:
#
#  CMAKE_REQUIRED_FLAGS = string of compile command line flags
#  CMAKE_REQUIRED_DEFINITIONS = list of macros to define (-DFOO=bar)
#  CMAKE_REQUIRED_INCLUDES = list of include directories
#  

因此,您可以在校准命令之前尝试设置此变量,如下所示:
set (CMAKE_REQUIRED_INCLUDES "/usr/local/include")
CHECK_INCLUDE_FILE_CXX(glog/logging.h GLOG_INCLUDE)
IF(GLOG_INCLUDE)
   MESSAGE("YY")
ENDIF(GLOG_INCLUDE)

关于cmake - 在CMake中,CHECK_INCLUDE_FILE_CXX如何工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3043675/

相关文章:

shell - CMake 的 execute_process 和任意 shell 脚本

c++ - GoogleTest CMake 链接未定义函数

c++ - 设置库之间的依赖关系 (CMake)

c++ - 链接到通过 cmake 使用 boost 的库时删除 boost 依赖项

c++ - M1 MacBook Pro 和 cmake 的编译错误

c++ - 运行在同一台机器上编译的程序时 GLIBCXX 版本错误

c++ - 通过复制 include 目录的内容来安装 spdlog

cmake、add_custom_command 与来自不同目录的依赖项

C++ 库组织

c++ - 从 Makefile 到 Cmake