install(DIRECTORY): Prevent creating empty directories
In the place I work they have a specific way of structuring the code, all public files are under a PUBLIC folder and all private files are under the PRIVATE folder. With the following install command cmake copies all the public headers to the right destination however, it also creates the entire folder structure of the source path. Reading from the doc it appears this is indeed the right behaviour but in my setup there are some empty folders that I don't want them to get created (it's useless).
install(
DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/
FILES_MATCHING REGEX "PUBLIC/.+\.h"
PERMISSIONS
OWNER_READ OWNER_EXECUTE
GROUP_READ GROUP_EXECUTE
WORLD_READ WORLD_EXECUTE
)
I have tried to use the EXCLUDE option with a regex pattern to exclude directories but it seems that cmake first creates the exact copy of the folder structure then copies the files.
How can I tell cmake not to create folders that will end up being empty?