Search code examples
c++cmakeincludec++20

CMake way of wildcard values on set variables


I have the next snippet on a CMake based project

set(Headers
    ./include/MyLib/main.hpp
)
set(Sources
    src/main.cpp
)

add_library(${This} STATIC ${Headers} ${Sources})

How can I indicate to recursively include all the interface files under the:

  • ./include/MyLib/{ /* File name here */ }.ixx

and all the source files under the

  • src/{ /* File name here */ }.cpp

Solution

  • One solution is to replace set() by:

    file(
      GLOB_RECURSE
      Headers
      ./include/MyLib/*.ixx
    )
    

    and same thing for your source files.