When using install(DIRECTORY … […]), how can I prevent empty directories from being created?
For instance, when installing all header files and template implementation files using
# Install the header files and template implementation files (.tcc).
install(DIRECTORY "src/"
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${TARGET_NAME}
FILES_MATCHING
PATTERN "*.h"
PATTERN "*.tcc"
)
the entire folder structure is reproduced, even though in some folders there might only be .cpp
files in them and therfore they do not need to be created.
If I know the name of the folder to exclude, e.g. “FolderWithCppOnly” I can explicitly exclude it using
PATTERN "FolderWithCppOnly" EXCLUDE
but I would have to manually add them one by one and keep track of name changes.
I also tried using regular expressions like so
REGEX "\.h"
REGEX "\.tcc"
REGEX ".*[^(\.h)]$" EXCLUDE
REGEX ".*[^(\.tcc)]$" EXCLUDE
but it does not work.
Is there a way to exclude all folders and only create them if there are actually matched files in them?