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
C++ 使用CMake创建包含文件_C++_Cmake - Fatal编程技术网

C++ 使用CMake创建包含文件

C++ 使用CMake创建包含文件,c++,cmake,C++,Cmake,我有一个包含hpp和cpp文件的文件夹。我需要创建一个包含上述文件夹中所有hpp文件的头文件: #pragma once #include "test_1.hpp" #include "test_2.hpp" #include "test_3.hpp" 我能做到吗 注:我不会把“我的”研究工作放在你的肩上。我只需要知道这样的事情是否可能,以及我可以从哪里阅读的链接。我最初的谷歌搜索没有显示任何有用的东西。 谢谢您可以使用配置_文件在模板文件中填充变量。创建一个模板文件,其中包含所需文件的大纲和

我有一个包含hpp和cpp文件的文件夹。我需要创建一个包含上述文件夹中所有hpp文件的头文件:

#pragma once
#include "test_1.hpp"
#include "test_2.hpp"
#include "test_3.hpp"
我能做到吗

注:我不会把“我的”研究工作放在你的肩上。我只需要知道这样的事情是否可能,以及我可以从哪里阅读的链接。我最初的谷歌搜索没有显示任何有用的东西。
谢谢

您可以使用
配置_文件
在模板文件中填充变量。创建一个模板文件,其中包含所需文件的大纲和包含语句的占位符,例如:

列表.hpp.in

#pragma once
@include_statements@
然后,在您的CMakeLists.txt中,您可以用
\include
语句包装的文件列表填充占位符
@include\u statements@

项目(测试)
cmake_最低要求(2.8版)
#获取文件夹include中某些*.hpp文件的列表
文件(GLOB include_文件include/*.hpp)
#将文件列表转换为#includes
foreach(include_file${include_files})
集合(include_语句“${include_语句}#include\”${include_文件}\“\n”)
endforeach()
#填写模板
配置_文件(list.hpp.in list.hpp)

常见做法是将.in扩展添加到cmake使用的模板中。在您的情况下,配置_文件(list.hpp.In list.hpp)可以更容易地将输入与输出关联起来。请记住,此解决方案需要运行CMake来反映添加到包含目录中的任何新文件。@Andrzej谢谢,它可以工作
include_文件
在CMakeLists.txt`中包含绝对路径。有什么方法可以使用相对路径吗?当然,请检查file命令的相对选项