[CMake] find_package scoping mystery

Dave Abrahams dave at boostpro.com
Mon Apr 16 01:37:58 EDT 2012


consider this simple wrapper:

  function(my_find_package)
    find_package(${ARGV})
  endfunction()

If I replace all the calls to find_package in my project with calls to
my_find_package, everything breaks.  It appears variable settings in any
found <packagename>Config.cmake files are visible inside
my_find_package, but disappear from the point of view of the caller,
unless I "manually" hoist them into the parent scope using

  function(my_find_package)
    find_package(${ARGV})
    set(some_variable ${some_variable} PARENT_SCOPE)
  endfunction()

I've tried hoisting everything as in
https://github.com/ryppl/ryppl-cmake/blob/find-package-hook/Modules/Ryppl.cmake#L9,
but apparently that is too much and it clobbers some variables that it
shouldn't.

Can anyone explain to me what I'm failing to grasp, here?

Thanks,

-- 
Dave Abrahams
BoostPro Computing
http://www.boostpro.com




More information about the CMake mailing list