Search code examples
copycmake

Copy all files with given extension to output directory using CMake


I've seen that I can use this command in order to copy a directory using cmake:

file(COPY "myDir" DESTINATION "myDestination")

(from this post)

My problem is that I don't want to copy all of myDir, but only the .h files that are in there. I've tried with

file(COPY "myDir/*.h" DESTINATION "myDestination")

but I obtain the following error:

CMake Error at CMakeLists.txt:23 (file):
  file COPY cannot find
  "/full/path/to/myDIR/*.h".

How can I filter the files that I want to copy to a destination folder?


Solution

  • I've found the solution by myself:

    file(GLOB MY_PUBLIC_HEADERS
      "myDir/*.h"
    )
    file(COPY ${MY_PUBLIC_HEADERS} DESTINATION myDestination)