[cmake-developers] Making Config.cmake files easier to write

Brad King brad.king at kitware.com
Thu Feb 16 16:21:11 EST 2012


On 2/16/2012 4:13 PM, David Cole wrote:
> On Thu, Feb 16, 2012 at 3:52 PM, Eric Noulard <eric.noulard at gmail.com <mailto:eric.noulard at gmail.com>> wrote:
>     I'm not convinced, yet I'll have to try with the example provided by Alex
>     by adding proper CPack usage in it.
>
>     Currently I see in BarConfig.cmake
>     get_filename_component(BAR_HELPER_PREFIX_DIR
>     "${CMAKE_CURRENT_LIST_DIR}/../../../" ABSOLUTE)
[snip]
 > It can't work with CPack, not in the sense of "work" as in "the
 > software will run from its DESTDIR-based intermediate CPack
 > driven install location"

It can.  The main feature of what Alex wrote based on a combination
of his, Yury's, and my ideas is that the generated BarConfig.cmake has
no hard-coded paths containing the installation prefix in any form,
DESTDIR or not.  The line

   get_filename_component(BAR_HELPER_PREFIX_DIR
    "${CMAKE_CURRENT_LIST_DIR}/../../../" ABSOLUTE)

is evaluated when BarConfig.cmake is *loaded* at which point the
${CMAKE_CURRENT_LIST_DIR} will be replaced with the *current* location
of the file as it exists when loaded.  It doesn't matter if it is in
the real install location, DESTDIR, or a tarball that was extracted
at an arbitrary location on another machine.  The load-time prefix
is computed relative to the file's location.  Under that prefix the
file refers to all the other pieces (include, etc.) which exist at
a fixed location relative to BarConfig.cmake.

-Brad



More information about the cmake-developers mailing list