gpt4 book ai didi

c++ - Meson 将头文件复制/安装到输出目录并保留文件夹结构

转载 作者:行者123 更新时间:2023-11-30 16:06:01 24 4
gpt4 key购买 nike

基本上我希望能够混合使用 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 上使用介子构建。

最佳答案

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

现在这就是我所做的:

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)

关于c++ - Meson 将头文件复制/安装到输出目录并保留文件夹结构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60083339/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com