[CMake] How to get a variable that is defined in another CMakeLists.txt file

Axel Roebel Axel.Roebel at ircam.fr
Wed Dec 20 15:15:23 EST 2006


On Wednesday 20 December 2006 17:27, Mike Jackson wrote:
> That did not seem to work either. Basically I am trying to set a
> place where we can set the names of the libraries and apps and have
> those found by other projects that depend on these base libraries.
>
>    I have noticed that if you "INCLUDE(${PROJECT_SOURCE_DIR}/
> FindHDF.cmake)" a file, in this case our module to find HDF, then
> those variables are found..  So I guess I could have a Names.cmake
> file where these variables are defined and then include that file in
> each CMakeLists.txt file for the project..
>
> Kinda seems like a heavy handed way to do this..
 For a single variable  PORTAUDIO_LINK_LIBRARIES)
defined in a sub directory "portaudio"
this definitely works for me.

 GET_DIRECTORY_PROPERTY(outvar DIRECTORY portaudio 
DEFINITION PORTAUDIO_LINK_LIBRARIES)

If you use DEFINITIONS as suggested earlier here you get outvar to contain a 
text with all definitions   made in the sub dir which is not what you want.

Note, that with get_directory_property the output variable
will always be set - to an empty string if the the variable
in the directory is not set. So testing for undefined
state is probably not working with this scheme.

You can however test for empty values
and -NOTFOUND and the like.

cheers

-- 
Axel Roebel
IRCAM Analysis/Synthesis Team
Phone: ++33-1-4478 4845 | Fax: ++33-1-4478 1540


More information about the CMake mailing list