[CMake] How to find list of directories

Michael Hertling mhertling at online.de
Thu Dec 15 09:44:01 EST 2011


On 12/15/2011 02:34 PM, Renato Utsch wrote:
> Hello,
> 
> I am writing a plugin compiler that will do linke this:
> 
> -- main
> ---- plugin
> ----| CMakeLists.txt (in the plugin folder)
> ------ example (example plugin)
> ------| CMakeLists.txt (in the example folder)
> 
> The CMakeLists.txt file inside the plugin folder will do a foreach() to use
> add_subdirectory() for each folder inside the plugin directory:
> 
> foreach( FOREACH_FOLDER ${FOLDERS_INSIDE_PLUGIN} )
>     add_subdirectory( ${FOREACH_FOLDER} )
> endforeach()
> 
> Then, the CMakeLists.txt of each folder will do the compilation of the
> plugin....
> 
> 
> How can I set the FOLDERS_INSIDE_PLUGIN variable to a list with all the
> folder names in the plugin directory? My program will be compiled only in
> UNIX (and cygwin), so if there is an UNIX command that does this, it can
> work as well (couldn't remember any)...

You might use FILE(GLOB ...), iterate over the results and pick out the
directories with IF(IS_DIRECTORY ...), but you shouldn't do this: Your
project wouldn't be aware of added/removed/renamed directories, the
typical pitfall when using FILE(GLOB ...) in CMakeLists.txt files.
Instead, play safe and explicitly specify the directories in the
FOLDERS_INSIDE_PLUGIN variable by hand.

Regards,

Michael


More information about the CMake mailing list