0

I would like to use file(GLOB_RECURSE... as follows:

file(GLOB_RECURSE _tmp_files
     LIST_DIRECTORIES false
     "${mydir}/*.cpp|${mydir}/*.h")

This -- along with variations such as ${mydir}/*{.cpp,.h} -- yields an empty list. However, this works as expected -- produces all the *.cpp files in the ${mydir} along with its subdirectories:

file(GLOB_RECURSE _tmp_files
     LIST_DIRECTORIES false
     "${mydir}/*.cpp")

So, does the file( feature in CMake indeed support "full" globbing? In particular, how to glob for a pattern {*.cpp,*.h} using file(?

Ilonpilaaja
  • 1,169
  • 2
  • 15
  • 26
  • 1
    [Do not glob for sources in CMake](https://stackoverflow.com/a/65191951/2137996) – Alex Reinking Nov 13 '21 at 19:07
  • Globbing/wildcards are generally not well liked by the CMake maintainers (even Meson doesn't like it): - https://discourse.cmake.org/t/is-glob-still-considered-harmful-with-configure-depends/808 - https://discourse.cmake.org/t/add-globbing-support-to-target-sources/3749 - https://mesonbuild.com/FAQ.html#why-cant-i-specify-target-files-with-a-wildcard –  Nov 14 '21 at 20:34

1 Answers1

1

So, does the file( feature in CMake indeed support "full" globbing?

Yes.

Your expressions do not work the way you expect them to work. {..,..} is not a way to match multiple suffixes in glob, { , } are matched literally and have no special meaning in glob. "${mydir}/*.cpp|${mydir}/*.h" is not an OR in glob - | is matched literally, it has no special meaning in glob. See man 7 glob.

how to glob for a pattern {.cpp,.h} using file(?

Write it twice.

file(GLOB_RECURSE _tmp_files
     LIST_DIRECTORIES false
     ${mydir}/*.cpp
     ${mydir}/*.h
)
KamilCuk
  • 120,984
  • 8
  • 59
  • 111