Meson copy/install header 文件到输出目录并保持文件夹结构

Meson copy/install header files to output directory and keep folder structure

基本上我希望能够混合使用 install_subdir 和 install_headers 函数。
我想将所有 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_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)

有人对此有解决方案吗?
我有完整的来源列表和 headers,如果这对任何方法都是必要的。
我目前正在通过 shell 命令复制文件,但最好将其包含在 install/build 过程中。

// 编辑:
我在 windows.

上使用 meson-build

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

现在这是我所做的:

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)