【问题标题】:Meson copy/install header files to output directory and keep folder structure介子复制/安装头文件到输出目录并保持文件夹结构
【发布时间】:2020-05-21 19:30:37
【问题描述】:

基本上,我希望能够在 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() 函数,但两者都没有成功。
我在我所做的事情中添加了 cmets 以及为什么。也许有人知道发生了什么:

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。

【问题讨论】:

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

标签: c++ c build meson-build


【解决方案1】:

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

现在这就是我所做的:

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)

【讨论】:

    猜你喜欢
    • 2016-09-04
    • 1970-01-01
    • 2010-11-04
    • 2013-07-18
    • 1970-01-01
    • 2021-02-22
    • 1970-01-01
    • 2020-04-06
    • 1970-01-01
    相关资源
    最近更新 更多