C++ 介子复制/安装头文件到输出目录并保持文件夹结构

C++ 介子复制/安装头文件到输出目录并保持文件夹结构,c++,c,build,meson-build,C++,C,Build,Meson Build,基本上,我希望能够混合使用函数install_subdir和install_header。 我想将所有头文件从我的项目源目录复制到其他目录,并且仍然保持子目录结构 来源 MyProject |-- folder1 | |-- file11.h | |-- file11.cpp | |-- file12.h | `-- file12.cpp `-- folder2 `-- file21.h 目的地 MyProject |-- folder1

基本上,我希望能够混合使用函数install_subdir和install_header。
我想将所有头文件从我的项目源目录复制到其他目录,并且仍然保持子目录结构

来源

MyProject  
|-- folder1  
|   |-- file11.h  
|   |-- file11.cpp  
|   |-- file12.h  
|   `-- file12.cpp  
`-- folder2  
    `-- file21.h
目的地


MyProject
|-- folder1
|   |-- file11.h
|   |-- file12.h
`-- folder2
    `-- file21.h
我尝试的是复制源目录并排除所有cpp文件,并仅使用预期的
install\u headers()
函数,但两者都不起作用。
我对我所做的事情和原因添加了评论。也许有人知道怎么回事:

project('MyProject', 'cpp')

test_src = [  'src/MyProject/folder1/file11.cpp'
              'src/MyProject/folder1/file12.cpp']

# Passing files seems to be preferred but exclude_files only takes list of strings
# test_src = files([  'src/MyProject/folder1/file11.cpp'
#                     'src/MyProject/folder1/file12.cpp'])

test_hdr = files([  'src/MyProject/folder1/file11.h',
                    'src/MyProject/folder1/file12.h',
                    'src/MyProject/folder2/file21.h'])


base_dir = meson.current_source_dir()

static_library('MyProject', name_prefix: '', name_suffix : 'lib', 
                sources: test_src,
                install: true,
                install_dir: base_dir + '/build/lib')

# Produces flat hierarchy       
install_headers(test_hdr, install_dir: base_dir + '/build/include')

# Also copies all cpp files into destination folder
install_subdir('src/MyProject', install_dir: base_dir + '/build/include', exclude_files: '*.cpp')

# Same result as wildcard exclusion
install_subdir('src/MyProject', install_dir: base_dir + '/build/include', exclude_files: test_src)
有人能解决这个问题吗?
如果任何方法都需要,我有一个完整的源和标题列表。
我目前正在通过shell命令复制文件,但最好将其包含在安装/构建过程中

//编辑:

我在windows上使用介子构建。

我找到了一个解决方案,可以满足我的需要。
如果有人找到一个更好的解决方案,需要一个所有头文件的列表,请随时回答,我会接受它

现在我所做的是:

project('MyProject', 'cpp')


test_src = files([  'src/MyProject/folder1/file11.cpp',
                    'src/MyProject/folder1/file12.cpp' ])

# Note that i'm omitting the base folder here since exclude_files searches relative to the subdir path
# Also, forward slash doesnt work. You have to use double backslash
test_src_exclude = [  'folder1\\file11.cpp',
                      'folder1\\file12.cpp' ]

dir_base = meson.current_source_dir()
dir_install = join_paths(dir_base, 'build/meson-out/MyProject')
dir_install_hdr = join_paths(dir_install, 'include')

static_library('MyProject', name_prefix: '', name_suffix : 'lib', 
                sources: test_src,
                install: true,
                install_dir: dir_install)

install_subdir( 'src/MyProject', 
                install_dir: dir_install_hdr, 
                strip_directory: true,
                exclude_files: text_src_exclude)

我找到了一份适合我的工作。
如果有人找到一个更好的解决方案,需要一个所有头文件的列表,请随时回答,我会接受它

现在我所做的是:

project('MyProject', 'cpp')


test_src = files([  'src/MyProject/folder1/file11.cpp',
                    'src/MyProject/folder1/file12.cpp' ])

# Note that i'm omitting the base folder here since exclude_files searches relative to the subdir path
# Also, forward slash doesnt work. You have to use double backslash
test_src_exclude = [  'folder1\\file11.cpp',
                      'folder1\\file12.cpp' ]

dir_base = meson.current_source_dir()
dir_install = join_paths(dir_base, 'build/meson-out/MyProject')
dir_install_hdr = join_paths(dir_install, 'include')

static_library('MyProject', name_prefix: '', name_suffix : 'lib', 
                sources: test_src,
                install: true,
                install_dir: dir_install)

install_subdir( 'src/MyProject', 
                install_dir: dir_install_hdr, 
                strip_directory: true,
                exclude_files: text_src_exclude)

如果我理解正确,您正在寻找一种方法来将一个目录(具有相同的子目录结构)复制到另一个目录中,linux命令是一个选项吗?如果是,那么您可以使用cp或它的高级版本rsync,请看一看。对不起,我忘了提到我正在使用windows。虽然我知道一系列shell命令可以实现我想要的功能,但我仍然希望将其直接集成到构建过程中(正如我在问题底部所说的),如果我理解正确,您正在寻找一种方法,将具有相同子目录结构的目录复制到另一个目录中,linux命令是一个选项吗?如果是,那么您可以使用cp或它的高级版本rsync,请看一看。对不起,我忘了提到我正在使用windows。虽然我知道一系列shell命令可以实现我想要的功能,但我仍然希望将其直接集成到构建过程中(正如我在问题的底部所说的)