I have the following directory structure:
.
├── CMakeLists.txt
└── deps
├── eigen
│ └── include
│ ├── Eigen
│ └── eigen.h
└── osg
├── include
│ └── Osg
└── lib
└── libosg.so
I am trying to get a maximum of the files I don't need to deploy my software, i.e. the libraries.
I tried to create a globbing expression that matches the *.h
files and the include
directories:
file(GLOB_RECURSE
FOUND_FILES
LIST_DIRECTORIES true
${CMAKE_SOURCE_DIR}/deps/*/include
${CMAKE_SOURCE_DIR}/deps/*/*.h)
message(STATUS "Files are ${FOUND_FILES}")
However, for some reason, the variable FOUND_FILES
contains deps/osg/lib
. What did I not understand about the GLOB_RECURSE
function?
- deps/eigen/include
- deps/eigen/include/eigen.h
- deps/osg/include
- deps/osg/lib
- deps/eigen/include
- deps/osg/include
- deps/osg/lib
I think this could be a workaround:
file(GLOB_RECURSE
FOUND_FILES
LIST_DIRECTORIES true
${CMAKE_SOURCE_DIR}/deps/*/include
)
list(FILTER FOUND_FILES INCLUDE REGEX "^${CMAKE_SOURCE_DIR}/deps/.*/include$")
file(GLOB_RECURSE
tmp
${CMAKE_BINARY_DIR}/deps/*/*.h
)
list(APPEND FOUND_FILES ${tmp})
I guess this is a bug when GLOB_RECURSE
is used with LIST_DIRECTORIES true
with an expression that has *
not on the last entry in the path. Once a directory containing the matched entry is matched in cmake:Glob.cxx#L404, next directories will be added recursively to the output unconditionally at this add_file() in cmake Glob.cxx#L316. So once a ${CMAKE_SOURCE_DIR}/deps/*
directory has a include
directory or file inside it, all directories recursively from ${CMAKE_SOURCE_DIR}/deps/
are added to the output. Files are not added, as they are checked against the regex at cmake Glob.cxx:#L326.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With