0

I've a directory and different subfolders, like this:

home
|
|-library1
|-library2
|
|-libraryn

Every subfolder contains a complete library that can compile by itself (every library has a different mantainer). In every subfolder there's a CMakeLists.txt that allows to compile the project.

I want to find a way to create a CMakeLists.txt on home folder, that calls compilation of every project, so after this I can simply call make on home folder (or wherever I call cmake) in order to have all libraries ready at once.

I'd like to avoid to put in CMakeLists.txt manually every project folder, because they are a lot.

How can I do it?

EDIT:

Simply using add_subdirectory does not work: as I've said, these are indipendent project. Some of them have same targets (like Example, doc etc) and when I add them with this command cmake returns an error saying that different CMakeFiles.txt's cannot have same targets. I'd like something like

for every folder
  create build/projec folder
  cd into that folder
  call cmake for specific folder project.

Maybe it's more simple using a bash script, but I'd like to use cmake in order to compile these libraries also on other platforms rather than Linux.

Jepessen
  • 11,744
  • 14
  • 82
  • 149
  • I think that [this answer](http://stackoverflow.com/a/7788165/1150918) pretty much sums up Your question. An idea, iterating through those sub-directories and adding those as sub-projects with [`ADD_SUBDIRECTORY()`](http://www.cmake.org/cmake/help/v3.0/command/add_subdirectory.html). – Kamiccolo Jul 03 '14 at 15:31
  • 1
    `add_subdirectory` will work if the subprojects are well-behaved (that is, not use `CMAKE_BINARY_DIR` when they should use `PROJECT_BINARY_DIR` for instance). A more robust alternative (although more tedious to set up) would be the use of [ExternalProject](http://www.cmake.org/cmake/help/v3.0/module/ExternalProject.html). – ComicSansMS Jul 03 '14 at 15:37
  • `add_directory` does not seems to work well for me, because cmake give me some error regardind sub-projects with same targets. Check my edited post for more clarifications. – Jepessen Jul 03 '14 at 16:04

0 Answers0