使用 CMake 创建包含文件
create include file using CMake
我有一个包含 hpp 和 cpp 文件的文件夹。我需要创建一个头文件,其中包含上述文件夹中的所有 hpp 文件:
#pragma once
#include "test_1.hpp"
#include "test_2.hpp"
#include "test_3.hpp"
CMake 可以做到吗?
注意:我不会把 'my' 研究工作放在你的肩上。我只需要知道这样的事情是否可能,并且可能 link 到我可以阅读的地方。我最初的谷歌搜索没有显示任何有用的信息。
谢谢
您可以使用configure_file
来填充模板文件中的变量。创建一个模板文件,其中包含所需文件的概要和包含语句的占位符,例如:
list.hpp.in
#pragma once
@include_statements@
然后,在您的 CMakeLists.txt 中,您可以用包含 #include
语句的文件列表填充占位符 @include_statements@
。
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)
我有一个包含 hpp 和 cpp 文件的文件夹。我需要创建一个头文件,其中包含上述文件夹中的所有 hpp 文件:
#pragma once
#include "test_1.hpp"
#include "test_2.hpp"
#include "test_3.hpp"
CMake 可以做到吗?
注意:我不会把 'my' 研究工作放在你的肩上。我只需要知道这样的事情是否可能,并且可能 link 到我可以阅读的地方。我最初的谷歌搜索没有显示任何有用的信息。 谢谢
您可以使用configure_file
来填充模板文件中的变量。创建一个模板文件,其中包含所需文件的概要和包含语句的占位符,例如:
list.hpp.in
#pragma once
@include_statements@
然后,在您的 CMakeLists.txt 中,您可以用包含 #include
语句的文件列表填充占位符 @include_statements@
。
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)