在CMake中,CHECK\u INCLUDE\u FILE\u CXX如何工作?

在CMake中,CHECK\u INCLUDE\u FILE\u CXX如何工作?,cmake,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(

下面的代码不打印任何内容

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仍然未找到)。

查看checkIncludeFilexx.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)