文件存在时Cmake'check_include_files'函数失败

时间:2018-11-06 13:06:52

标签: c cmake

假设我们有一个CMakeLists.txt,其代码如下(以下是整个文件的一小部分):

cmake_minimum_required(VERSION 2.6.3)
#...
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -I/usr/include/mit-krb5/")
message("CMAKE_REQUIRED_INCLUDES=${CMAKE_REQUIRED_INCLUDES};CMAKE_REQUIRED_DEFINITIONS=${CMAKE_REQUIRED_DEFINITIONS};CMAKE_REQUIRED_FLAGS=${CMAKE_REQUIRED_FLAGS}")
message("before find path, fuckGssApiIncludes=${fuckGssApiIncludes}")
find_path(fuckGssApiIncludes "gssapi.h" "/usr/include")
if(NOT fuckGssApiIncludes)
   message(FATAL_ERROR "Can't find folder containing gssapi.h")
endif()
message("after, fuckGssApiIncludes=${fuckGssApiIncludes}")
include_directories(${fuckGssApiIncludes})
check_include_files("gssapi.h" HAVE_GSSAPI_H)
#....
if (NOT HAVE_GSSAPI_H)
  message(FATAL_ERROR "Cannot find GSS libraries")

我们有一些文件:

# ls /usr/include/gssapi.h
/usr/include/gssapi.h

但是当我使用 cmake版本3.12.1 运行此命令时,出现了这样的错误:

CMAKE_REQUIRED_INCLUDES=/usr/include/;/usr/include/x86_64-linux-gnu/;CMAKE_REQUIRED_DEFINITIONS=;CMAKE_REQUIRED_FLAGS=
before find path, fuckGssApiIncludes=
after, fuckGssApiIncludes=/usr/include
CMake Error at CMakeLists.txt:548 (message):
  Cannot find GSS libraries

我以某种方式认为Cmake.check_include_files不能作为Cmake的定义。

所以,问题1:我的想法正确,为什么? 问题2:如何解决,并使cmakelists.txt正常运行?

1 个答案:

答案 0 :(得分:0)

找到答案,只需删除所有cmake临时文件即可。