Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/cmake/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在CMakeCache.txt中指定include_路径时,如何告诉CMake递归搜索include目录_Cmake_Ncurses - Fatal编程技术网

在CMakeCache.txt中指定include_路径时,如何告诉CMake递归搜索include目录

在CMakeCache.txt中指定include_路径时,如何告诉CMake递归搜索include目录,cmake,ncurses,Cmake,Ncurses,我最近使用源代码构建了ncurses-6.1,并希望将我构建的STIR(断层图像重建软件)配置为使用这个最新版本的ncurses。但是,我不知道如何让cmake在include文件夹中搜索子目录。在CMakeCache.txt文件中指定ncurses include路径时: 诅咒包括路径:路径=/home/matthew/Programs/ncurses/ncurses-6.1-build/INCLUDE 在我的STIR构建目录中运行make时,我收到以下错误: In file included

我最近使用源代码构建了ncurses-6.1,并希望将我构建的STIR(断层图像重建软件)配置为使用这个最新版本的ncurses。但是,我不知道如何让cmake在include文件夹中搜索子目录。在CMakeCache.txt文件中指定ncurses include路径时:

诅咒包括路径:路径=/home/matthew/Programs/ncurses/ncurses-6.1-build/INCLUDE

在我的STIR构建目录中运行make时,我收到以下错误:

In file included from /home/matthew/Programs/stir/STIR/src/display/gen.c:21:0:
/home/matthew/Programs/stir/STIR/src/display/gen.h:111:10: fatal error: curses.h: No such file or directory
 #include <curses.h>             /* for getch */
          ^~~~~~~~~~
compilation terminated.
包含在/home/matthew/Programs/stir/stir/src/display/gen.c:21:0:
/home/matthew/Programs/stir/stir/src/display/gen.h:111:10:致命错误:curses.h:没有这样的文件或目录
#包括/*用于getch*/
^~~~~~~~~~
编译终止。
但是,如果指定子目录:

In file included from /home/matthew/Programs/stir/STIR/src/display/gen.c:21:0:
/home/matthew/Programs/stir/STIR/src/display/gen.h:111:10: fatal error: curses.h: No such file or directory
 #include <curses.h>             /* for getch */
          ^~~~~~~~~~
compilation terminated.
诅咒包括路径:路径=/home/matthew/Programs/ncurses/ncurses-6.1-build/INCLUDE/ncurses

然后我收到以下错误:

In file included from /home/matthew/Programs/stir/STIR/src/display/gen.h:111:0,
                 from /home/matthew/Programs/stir/STIR/src/display/screengen.c:23:
/home/matthew/Programs/ncurses/ncurses-6.1-build/include/ncurses/curses.h:60:10: fatal error: ncurses/ncurses_dll.h: No such file or directory
 #include <ncurses/ncurses_dll.h>
          ^~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
包含在/home/matthew/Programs/stir/stir/src/display/gen.h:111:0中的文件中,
from/home/matthew/Programs/stir/stir/src/display/screengen.c:23:
/home/matthew/Programs/ncurses/ncurses-6.1-build/include/ncurses/curses.h:60:10:致命错误:ncurses/ncurses\u dll.h:没有这样的文件或目录
#包括
^~~~~~~~~~~~~~~~~~~~~~~
编译终止。

当我将头文件从子目录直接复制到include文件夹(与子目录一起)时,构建成功。如何让cmake递归地查看子目录?

cmake不直接提供这样的功能。您可以编写
文件(GLOB\u RECURSE..)
命令,将给定目录下的所有目录收集到一个列表中,然后根据该列表发出
include\u directories()
命令。e、 g

set(myDesiredRootForHeaderFileSearch ~/special/include/path)
file(GLOB my_include_directories ${myDesiredRootForHeaderFileSearch})
include_directories(${my_include_directories})
GLOB
命令获取目录,因此这很好

您也可以使用我在论坛上找到的非常有用的宏:

MACRO(HEADER_DIRECTORIES return_list)
    FILE(GLOB_RECURSE new_list *.h)
    SET(dir_list "")
    FOREACH(file_path ${new_list})
        GET_FILENAME_COMPONENT(dir_path ${file_path} PATH)
        SET(dir_list ${dir_list} ${dir_path})
    ENDFOREACH()
    LIST(REMOVE_DUPLICATES dir_list)
    SET(${return_list} ${dir_list})
ENDMACRO()

HEADER_DIRECTORIES(header_list)

include_directories(${header_list}
正如这篇文章所建议的那样


我还没有测试过。让我知道这是否有效。

为什么要更新cmakcache.txt?我认为您应该在CMakeLists.txt中添加find_package(需要ncurses)和target_link_libraries/target_include_目录以及find_package语句提供的目录。我只在使用-D配置时从终端使用cmake构建程序,从不更新CMakeLists.txt,可能是因为我在自述文件中阅读的说明以及设置的选项的性质。我将研究如何做到这一点。非常感谢。