[CMake] Best practice for modifying search path for find_package()

Robert Dailey rcdailey.lists at gmail.com
Thu Aug 24 14:36:45 EDT 2017


So I have a "super build" CMake script that runs a series of
ExternalProject_Add() functions to execute builds of various third
party libraries and install them to a path relative to the parent
project's CMAKE_BINARY_DIR.

Once the parent project generation occurs, it is expected to do a
series of find_package() commands to locate the packages installed by
the previous super build.

What is the best way to intercept the find_package() search paths to
prioritize searching to the custom relative root directory managed by
the super build? Based on the documentation for find_package()[1],
seems like CMAKE_PREFIX_PATH might be the best way (set it as a normal
variable, not a cache variable) inside the CMake scripts prior to the
find_package() invocations (which are done indirectly by other CMake
scripts I do not manage and cannot change). Although, the usage intent
for CMAKE_PREFIX_PATH seems to be documented differently than how I
plan to use it.

Any advice?

[1]: https://cmake.org/cmake/help/v3.6/command/find_package.html


More information about the CMake mailing list