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

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

本文关键字:结构 文件夹 输出 复制 安装 文件      更新时间:2023-10-16

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

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)

有人对此有解决方案吗?
我有一个完整的来源和标题列表,如果这是任何方法所必需的。
我目前正在通过 shell 命令复制文件,但最好将其包含在安装/构建过程中。

编辑:
我在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)