gil_mo
gil_mo

Reputation: 625

CMake: Getting a list of directories (non-recursive)

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

Answers (1)

Chris
Chris

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

Related Questions