[CMake] Using find_package on CMake projects added through ExternalProject_Add

Saad Khattak saadrustam at gmail.com
Thu Nov 2 22:09:18 EDT 2017


Hi,

I have a SuperBuild where I am adding dependencies using
ExternalProject_Add. I am also using the same mechanism to add my projects
(which are subprojects).

The dependencies are being cloned into a directory in the root of the
project called "Dep" and installed in the "Install" directory, also in root.

All the dependencies have their own CMakeLists.txt and when installed,
generate their respective xxxConfig.cmake and xxxTargets.cmake (among a few
other files generated by CMake).

I am using:

find_package(dep_name HINTS "path_to_install_folder")

and my assumption/hope was that find_package will find the autogenerated
files and since the dependencies are built and installed through CMake, the
include and library directories and the library names will be picked up
automatically.

Now find_package 'is' able to find the dependencies i.e. if I am trying to
find SDL2, it is able to do so and SDL2_FOUND is set. However, nothing else
is picked up by find_package, including the include directories, library
directories nor the name of the library (e.g. in SDL's case, it is called
libSDL2.so).

I am also not sure which variables are set by find_package. For example, if
the SDL2 library is found by find_package, what do I pass to
target_include_directories and target_link_libraries? My first thought was
to use "message(STATUS variable_set_by_find_package)" but I don't know what
the variables are called.

Here's the project folder structure in case it helps visualize everything:

- CMakeLists.txt (root level, superbuild that adds all deps and subprojs)
- Dep/ (folder where dependencies are cloned)
- Install/ (folder where dependencies are installed)
-- SubProject1/CMakeLists.txt (subproject1 dependent on above deps)
-- SubProject2/CMakeLists.txt (subproject2 dependent on above deps)

Here's the auto-generated files by one of the dependencies, SDL2 (all
dependencies generate similar files which are put in one of the nested
directores inside the root "Install" directory):

- SDL2Config.cmake
- SDL2ConfigVersion.cmake
- SDL2Targets.cmake
- SDL2Targets-noconfig.cmake

Hopefully I have explained the issue properly.

Thanks,
Saad
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20171103/66017b5b/attachment.html>


More information about the CMake mailing list