Skip to main content

Add library using CMake

Classic approaches for resolving dependencies to the external libraries while using CMake is copying the source codes of the external libraries into the subdirectories, then use add_subdirectory() in your CMakeLists.txt to add the external libraries codes to your CMake tree, and build it all together with your software

The copying is done either by manually downloading the code (often as formats of .zip, tar.gz) from the website or using git submodule² and get it from the git repository or using ExternalProject module³ extension of CMake.

Also, instead of adding the copied external packages to your CMake tree, you can separately build & install the external packages out side of your CMake tree, then use find_package() in the CMakeLists.txt to import them when you build your software (You can check my previous post for more detail about how to export/import a CMake package).