Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CMake "FILES_MATCHING_PATTERN" copies empty directories

Tags:

cmake

I use a CMakeLists.txt with the following install command:

install(DIRECTORY ./ DESTINATION include FILES_MATCHING PATTERN "*.h")

It correctly installs all "./*.h" files, but also copies the "./.git" directory structure (without any files).

The problem happens when using CMake 3.14.0 and did not happen with CMake 3.11.1.

Did the command change or is this a CMake bug? Should I use an explicit exclude for ".git" or can I somehow keep the whitelist approach, that will e.g. keep working when I actually need to install subfolders?

like image 594
allo Avatar asked Apr 01 '19 08:04

allo


1 Answers

As of now, there does not seem to exist any straightforward solution other than explictly specifying to exclude your directory. The behaviour is not new to version 3.14.0 and was similar in 3.11.1. The fact that your .git directory wasn't copied might be due to another command in your CMakeLists...
As you suggest and based on this post and this thread in the old CMake forum, a solution for you would be:

install(DIRECTORY ./ DESTINATION include FILES_MATCHING PATTERN "*.h" PATTERN ".git*" EXCLUDE)

There is a ticket to add a feature to not include empty directories when using install(DIRECTORY ...), so you might keep an eye on it for when it is finally implemented.

Alternatively, you may use nested file(GLOB ...) followed by install(FILES ...), with the inherent drawbacks of globbing (see the note in the documentation).

like image 93
hakutakun Avatar answered Oct 04 '22 00:10

hakutakun