使用CMake创建包含文件

rah*_*man 2 c++ cmake

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

#pragma once
#include "test_1.hpp"
#include "test_2.hpp"
#include "test_3.hpp"
Run Code Online (Sandbox Code Playgroud)

CMake能做到吗?

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

And*_*bis 5

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

list.hpp.in

#pragma once
@include_statements@
Run Code Online (Sandbox Code Playgroud)

然后,在您的CMakeLists.txt中,您可以@include_statements@使用包含#include语句的文件列表填充占位符.

project(test)
cmake_minimum_required(VERSION 2.8)

# Get list of some *.hpp files in folder include 
file(GLOB include_files include/*.hpp)

# Convert the list of files into #includes
foreach(include_file ${include_files})
  set(include_statements "${include_statements}#include \"${include_file}\"\n")
endforeach()

# Fill the template    
configure_file(list.hpp.in list.hpp)
Run Code Online (Sandbox Code Playgroud)