Reputation: 625
In CMake, how can I get a non-recursive list of directories that exist in a certain directory? I can see that using GLOB isn't recommended.
Upvotes: 0
Views: 612
Reputation: 2304
Why wouldn't GLOB be recommended? That's what the GLOB is for. I love GLOB, especially in cases like this where it's extremely helpful to grab multiple items.
The macro from this question may be what you're looking for.
MACRO(SUBDIRLIST result curdir)
FILE(GLOB children RELATIVE ${curdir} ${curdir}/*)
SET(dirlist "")
FOREACH(child ${children})
IF(IS_DIRECTORY ${curdir}/${child})
LIST(APPEND dirlist ${child})
ENDIF()
ENDFOREACH()
SET(${result} ${dirlist})
ENDMACRO()
You basically grab the items from the current source directory, check to see if it's a directory, and if so, append it to a list.
Credit to refaim in the link for that macro.
Upvotes: 1