[CMake] Finding and including/linking external projects generated by CMake

Saad Khattak saadrustam at gmail.com
Tue Nov 14 10:50:18 EST 2017


Hi,

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

Thanks,
Saad

[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/.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20171114/e6049c03/attachment.html>


More information about the CMake mailing list