[CMake] When should I use add_subdirectory and when ExternalProject?

Benjamin Eikel cmake at eikel.org
Mon Feb 4 07:17:09 EST 2013


Am Montag, 4. Februar 2013, 09:23:20 schrieb Ansis Māliņš:
> If I have a dependency (e.g. SDL2) that seems to work with add_subdirectory
> just fine, should I still use ExternalProject_Add instead? Given both ways
> work, what should I prefer? What are the tradeoffs?

Hello Ansis,

most of the time, you do not want to have external libraries (like SDL2) 
inside your source directory structure. Therefore, I do not think that 
add_subdirectory is the right way. For libraries installed on your system, you 
should use find_package.

ExternalProject_Add does not integrate so well into the build of the project. 
You can use it to bootstrap (download, patch, build, and install external 
dependences).

Kind regards
Benjamin


More information about the CMake mailing list