They should just need to do find_package(yourprogram)
. yourprogram-config.cmake
does find_package()
for your dependencies to bring in their imported targets. I usually add them to cmake
in the source tree and beside yourpackage-config.cmake
in the build/install tree. Just scope it so your Find modules don’t interfere with the caller’s.
set(CMAKE_MODULE_PATH_save "${CMAKE_MODULE_PATH}")
list(INSERT CMAKE_MODULE_PATH 0 "${CMAKE_CURRENT_LIST_DIR}")
# Any find_packages you need.
set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH_save}")
unset(CMAKE_MODULE_PATH_save)
I’d write a FindFoo.cmake
that does the pkg_search_module
inside of it.