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

Alexander Neundorf a.neundorf-work at gmx.net
Sun Oct 1 11:45:51 EDT 2017


On 2017 M08 24, Thu 13:36:45 CEST Robert Dailey wrote:
> 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.

You have one install dir for your external-package libraries and then want to 
use them ?
IMO using CMAKE_PREFIX_PATH is just fine for this.

Alex



More information about the CMake mailing list