Finding and including/linking external projects generated by CMake

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

Finding and including/linking external projects generated by CMake

Saad Khattak

Let's say I have a project I cloned from github which uses CMake to build. What is the best way to link to said dependency assuming the dependency is already built and installed [1].

So let's say I have LibA that is a dependency to my ProjA. LibA has already been built. What would be the 'correct' way to find and include/link against LibA?

Currently, I inspect the install/ directory of the libraries, then specify the paths for the headers/libraries/DLLs manually. 

However, considering the project has been built by CMake and CMake knows where the include/lib/DLL files are, I am hoping that there is a way to get another CMake project to use some auto-generated CMake files to figure out the location of the headers and libraries (and DLLs) so that ultimately, the command boils down to:

find_library(LibA Path/To/Install)
# CMake now gives me variables such as LibA_INCLUDE_DIRS, LibA_LIB_DIRS or similar
# so that I can easily include and link to the library


[1] And in case it matters, for all dependencies I override the CMAKE_INSTALL_PREFIX to be at the root of the dependency. So, if I build LibA located at D:/Deps/LibA, the install folder will be D:/Deps/LibA/install/.  


Powered by

Please keep messages on-topic and check the CMake FAQ at:

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support:
CMake Consulting:
CMake Training Courses:

Visit other Kitware open-source projects at

Follow this link to subscribe/unsubscribe: