1

Basically i would like to be able to have a mix between the functions install_subdir and install_headers.
I want to copy all header files from my project source directory over to some other directory and still maintain the subdirectory structure.

Source

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

Destination


MyProject
|-- folder1
|   |-- file11.h
|   |-- file12.h
`-- folder2
    `-- file21.h

What I tried was copying the source directory and exclude all cpp files and to just use the intended install_headers() function but both didn't work out.
I added comments to things I did and why. Maybe somebody knows what's up:

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)

Does anyone have a solution to this?
I have a full list of my sources and headers if that is necessary for any method.
I am currently copying the files via shell commands, but including this into the install/build process would be preferred.

// EDIT:
I am using meson-build on windows.

DJSchaffner
  • 562
  • 7
  • 22
  • if i understand correctly, you are looking for a way to copy a directory - with the same subdirectory structure - into another directory, is linux command is an option? if yes, so you can use **cp** or the advanced version of it **rsync**, please take a look [here](https://stackoverflow.com/questions/4585929/how-to-use-cp-command-to-exclude-a-specific-directory/4586025#4586025). – walid barakat Feb 05 '20 at 20:30
  • Sorry, i forgot to mention i am using windows. Although i do know a sequnce of shell commands that would do what i want, i would still like to integrate this into the build process directly (as i said at the bottom of the question) – DJSchaffner Feb 05 '20 at 21:18

1 Answers1

1

I found a work-around that does what i want.
If someone finds a better solution to this that requires a list of all header files feel free to still answer and i will accept it.

For now here is what i did:

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)
DJSchaffner
  • 562
  • 7
  • 22