install specific pattern files with cpack and cmake

545 views Asked by At

assuming i have the next structure in my project:

src_dir\a
src_dir\b\b2
src_dir\c\c2\c3

and in each folders i have few types of files (.txt, .lib, .dll....) i want to install only the dll files in directory X, so i tried:

install(
DIRECTORY src_dir
DESTINATION X/
COMPONENT DLLS
FILES_MATCHING PATTERN "*.dll"
)

it does work fine but it give me the full structure of my original structure (and i only want the dll files in X directory). the output it:

X/a/a.dll
X/b/b2/b.dll
X/c/c2/c3/c.dll

and i want it to be like that a.dll, b.dll and c.dll will be in X (without any sub-folders).

is there a way to do it without giving the full paths to every dll file i have in my project?

Thanks :)

1

There are 1 answers

1
Craig Scott On BEST ANSWER

You should be able to get the behaviour you want by listing each directory, not necessarily each DLL. If you include a trailing forward slash at the end of the DIRECTORY, it will omit the directory name when copying to the destination. I'd expect something like the following to achieve what you want:

install(
    DIRECTORY      src_dir/a/
    DESTINATION    X
    COMPONENT      DLLS
    FILES_MATCHING PATTERN "*.dll"
)
install(
    DIRECTORY      src_dir/b/b2/
    DESTINATION    X
    COMPONENT      DLLS
    FILES_MATCHING PATTERN "*.dll"
)
install(
    DIRECTORY      src_dir/c/c2/c3/
    DESTINATION    X
    COMPONENT      DLLS
    FILES_MATCHING PATTERN "*.dll"
)