2013-03-26 76 views
2

文件的正确方法我用的检测包括文件的这种方式,但这个错误,如果它不能检测到从未执行:检查包括在CMake的

include(CheckIncludeFile) 
check_include_file("getopt.h" HAVE_GETOPT_H) 
if(!HAVE_GETOPT_H) 
    message(FATAL_ERROR "getopt Not Found") 
endif() 

但如果我用空字符串检查工作,并消息打印包含文件时未找到:

include(CheckIncludeFile) 
check_include_file("getopt.h" HAVE_GETOPT_H) 
if("${HAVE_GETOPT_H}" STREQUAL "") 
    message(FATAL_ERROR "getopt Not Found") 
endif() 

我做错了什么?我正在使用cmake 2.8.3版。

回答

2

CMake的if命令通过使用NOT而不是!来否定参数。

你需要做的:

if(NOT HAVE_GETOPT_H) 
+0

我使用这个(显然是错误的)例子http://stackoverflow.com/questions/14674678/how-to-fail-cmake-gracefully-when-an -include-file-does-exist – Zhen 2013-03-26 16:07:00

+0

是的 - OP的问题在那里是错误的。 – Fraser 2013-03-26 16:58:07