以下代码不打印任何内容
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之后)仍未定义。
答案 0 :(得分:8)
看看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)