Using find_package on CMake projects added through ExternalProject_Add

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

Using find_package on CMake projects added through ExternalProject_Add

Saad Khattak

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

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.



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: