[CMake] Add multiple directories

Alexander Neundorf a.neundorf-work at gmx.net
Mon Feb 18 15:40:18 EST 2008


On Monday 18 February 2008, Robert Bielik wrote:
> I'm setting up a project repository with subversion where I'll have
> external libs linked in via svn:externals svn property. Each external lib
> will have a CMakeLists.txt file.
>
> Ideally, I'd like to have the possibility to include N subdirectories
> without having to alter the CMakeLists.txt file to do it (by just changing
> the svn:externals property).
>
> Like:
>
> ADD_SUBDIRECTORY( * )
>
> Can it be done?

Yes.
You could do file(GLOB */ ) or something like this and then iterate over the 
result and add each directory.

Or you could
if(EXISTS some_dir)
  add_subdirectory(some_dir)
endif(EXISTS some_dir)
if(EXISTS some_other_dir
  add_subdirectory(some_other_dir)
endif(EXISTS some_other_dir)

But actually I wouldn't recommend that.
If you do that, you rely on the dirs at the time cmake runs. There could be 
additional directories which you don't want to have included in your build 
(e.g. a build dir).
And cmake is not automatically rerun if a directory is created.
If you use plain add_subdirectory(), you know that you have to edit the file 
and this will always cause cmake to run again.

Alex


More information about the CMake mailing list