...

/

Working With Whole Directories

Working With Whole Directories

Let's learn how to deal with whole directories.

If we don't want to add individual files to our installation command, we can choose the broader approach and work with entire directories instead.

The install(DIRECTORY) mode

The install(DIRECTORY) mode was created for this purpose. It will copy the listed directories verbatim to the chosen destination. Let's see what it looks like:

Press + to interact
install(DIRECTORY dirs...
TYPE <type> | DESTINATION <dir>
[FILE_PERMISSIONS permissions...]
[DIRECTORY_PERMISSIONS permissions...]
[USE_SOURCE_PERMISSIONS] [OPTIONAL] [MESSAGE_NEVER]
CONFIGURATIONS [Debug|Release|...]]
[COMPONENT <component>] [EXCLUDE_FROM_ALL]
[FILES_MATCHING]
[[PATTERN <pattern> | REGEX <regex>] [EXCLUDE]
[PERMISSIONS permissions...]] [...])

As you can see, many options are repeated from install(FILES|PROGRAMS). They work the same way. There's one detail worth noting: if the paths that are provided after the DIRECTORY keyword do not end with /, the last directory of the path will be appended to the destination, like so:

install(DIRECTORY a DESTINATION /x)

This will create a directory called /x/a and copy the contents of a to it. Now, look at the following code:

install(DIRECTORY a/ DESTINATION /x)

This will copy the contents of a directly to /x.

Options for install(DIRECTORY) mode

install(DIRECTORY) also introduces other mechanisms that are not available for files:

  • Output silencing ...