In CMake, how does CHECK_INCLUDE_FILE_CXX work?

瘦欲@ 提交于 2021-01-26 05:07:05

问题


The following code prints nothing

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

But I have the following environment variable set:

export CPLUS_INCLUDE_PATH=/usr/local/include

And, "ls /usr/local/include/glog/logging.h" returns the file.

I tried using

include_directories( "/usr/local/include" )

but GLOG_INCLUDE remains undefined after (logging.h remains not found.)


回答1:


Take a look at the CheckIncludeFileCXX.cmake. It should be in a directory in your cmake installation (I have it in /usr/share/cmake-2.8/Modules).

This file states:

# 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
#  

So you can try setting this variable before caling the command, like this:

set (CMAKE_REQUIRED_INCLUDES "/usr/local/include")
CHECK_INCLUDE_FILE_CXX(glog/logging.h GLOG_INCLUDE)
IF(GLOG_INCLUDE)
   MESSAGE("YY")
ENDIF(GLOG_INCLUDE)


来源:https://stackoverflow.com/questions/3043675/in-cmake-how-does-check-include-file-cxx-work

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!