以下代码不输出任何内容
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/