[CMake] Scope of find_package inside a function block

Lori Pritchett-Sheats lpritch at lanl.gov
Thu Sep 22 17:17:14 EDT 2011


I was wondering what the scope of the variables set in a FindXXX.cmake 
file is and does find_package_handle_standard_args change that scope.

For example, I create a FindBar.cmake file that sets Bar_INCLUDE_DIR, 
Bar_LIBRARY, Bar_INCLUDE_DIRS and Bar_LIBRARIES, and calls 
find_package_handle_standard_args to set Bar_FOUND correctly if 
Bar_INCLUDE_DIRS and Bar_LIBRARIES is set. If I call find_package(Bar) 
inside a function-endfunction block, are the variables scoped outside 
the function block?

I have a simple test case and I'm seeing strange results where some of 
the Bar_* variables are defined outside the function block. It's very 
strange. I'm wondering if my find_package_handle_standard_args call 
affects the variable scope, because  in my simple test case, Bar_FOUND, 
Bar_INCLUDE_DIRS and Bar_LIBRARIES are not set outside the function 
block, but Bar_INCLUDE_DIR and Bar_LIBRARY are.

Thanks.

-- 
Lori A. Pritchett-Sheats, PhD.
CCS-2, Computational Physics and Methods
Office: 505-665-6675
Fax: 505-665-4972

Los Alamos National Laboratory
P.O. Box 1663
MS D413
Los Alamos, NM 87544



More information about the CMake mailing list