HFinch
HFinch

Reputation: 626

install() with FILES_MATCHING PATTERN ignoring pattern and installing all

I'm currently having a problem with the install() function of CMake v3.13.4. My code is as follows:

install(
    DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
    DESTINATION ${CMAKE_INSTALL_PREFIX}
    FILES_MATCHING PATTERN "*.cfg"
)

My understanding is that CMake will copy all files matching this pattern to my location given by ${CMAKE_INSTALL_PREFIX}, but all the subfolders in my current directory also get copied. Also, how is it possible to copy more than one file-ending pattern to the destination? Simply putting *.cfg | *.xyz or *.cfg || *.xyz does not work.

Edit:

Also tried to replace the FILES_MATCHING PATTERN with:

FILES_MATCHING REGEX "[a-zA-Z0-9]*.ate|[a-zA-Z0-9]*.reserved"

which only copies files *.reserved AND all folders again.

Upvotes: 8

Views: 11196

Answers (1)

Kevin
Kevin

Reputation: 18313

If any of the subfolders in your directory also contain .cfg files, CMake will copy those as well. You need to explicitly tell CMake to ignore these using the EXCLUDE directive. Also, you can concatenate multiple PATTERN directives for CMake to search for and install:

install(
    DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
    DESTINATION ${CMAKE_INSTALL_PREFIX}
    FILES_MATCHING 
    PATTERN "*.cfg"
    PATTERN "*.xyz"
    PATTERN "subFolderA" EXCLUDE
)

Upvotes: 14

Related Questions