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

Mike Jackson mike.jackson at imts.us
Wed Dec 20 11:27:45 EST 2006


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..

-- 
Mike Jackson   Senior Research Engineer
Innovative Management & Technology Services


On Dec 19, 2006, at 3:55 PM, David Cole wrote:

> Try GET_DIRECTORY_PROPERTY with VARIABLES -- it should give you a  
> list of variables for that directory. It will only be accurate  
> after the ADD_SUBDIRECTORY for the given directory...
>
> The presence or absence of the variable in question should give you  
> the "defined-ness" of it... As long as you can guarantee directory  
> A gets added first...
>
> C:\>cmake --help-command GET_DIRECTORY_PROPERTY
> cmake version 2.4-patch 5
>   GET_DIRECTORY_PROPERTY
>        Get a property of the directory.
>
>          GET_DIRECTORY_PROPERTY(VAR [DIRECTORY dir] property)
>
>        Get a property from the Directory.  The value of the  
> property is
>        stored in the variable VAR.  If the property is not found,  
> CMake will
>        report an error.  The properties include: VARIABLES,  
> CACHE_VARIABLES,
>        COMMANDS, MACROS, INCLUDE_DIRECTORIES, LINK_DIRECTORIES,  
> DEFINITIONS,
>        INCLUDE_REGULAR_EXPRESSION, LISTFILE_STACK,  
> PARENT_DIRECTORY, and
>        DEFINITION varname.  If the DIRECTORY argument is provided  
> then the
>        property of the provided directory will be retrieved instead  
> of the
>        current directory.  You can only get properties of a  
> directory during
>        or after it has been traversed by cmake.
>
> HTH,
> David
>
>
> On 12/19/06, Mike Jackson <mike.jackson at imts.us> wrote:
> well, that verified what I am seeing:
> #-- from Project B CMakeLists.txt file
> IF ( NOT DEFINED  MHD_INTERFACE_LIB_NAME)
>   MESSAGE ( FATAL_ERROR "MHD_INTERFACE_LIB_NAME is not defined and  
> should be")
> ENDIF ( NOT DEFINED  )
>
> where MHD_INTERFACE_LIB_NAME is defined in Project A, and I want to  
> use it in Project B.
>
> When I run cmake on the project B directory I get the fatal error.
>
> So.. do I get access to variables in other CMakeLists.txt files  
> that are included from top level cmake file?
>
> Thanks
> -- 
> Mike Jackson   Senior Research Engineer
> Innovative Management & Technology Services
>
>
> On Dec 19, 2006, at 1:37 PM, David Cole wrote:
>
>> DEFINED should be used with the variable name itself, not the  
>> value of the variable:
>>
>> IF(NOT DEFINED PROJECT_A_LIB_NAME)
>>
>> Scratch the ${} and see what happens...
>>
>>
>> On 12/19/06, Mike Jackson < mike.jackson at imts.us> wrote:
>> I have couple of projects, lets call them A and B. In project A I
>> "SET" a variable as follows:
>>
>> SET (PROJECT_A_LIB_NAME MyLib)
>>
>> then use that further down A's cmake file in the ADD_LIBRARY()  
>> function.
>>
>> Now in Project B I would like to automagically be able to read the
>> PROJECT_A_LIB_NAME variable. I have  added the "ADD_SUBDIRECTORY
>> (PATH_TO_A BIN_DIR) to B's CMakeLists.txt file and then I tried just
>> using the variable like usual ( ${PROJECT_A_LIB_NAME} )  but it is
>> undefined.
>>
>> IF (NOT DEFINED ${PROJECT_A_LIB_NAME} )
>>         MESSAGE (FATAL_ERROR "Ahh.. this is a problem")
>> ENDIF (NOT DEFINED ${PROJECT_A_LIB_NAME} )
>>
>> So.. is there a way to get the variable value from one CMakeLists.txt
>> file to another?
>>
>> Thanks for any help.
>> --
>> Mike Jackson   Senior Research Engineer
>> Innovative Management & Technology Services
>>
>>
>>
>> _______________________________________________
>> CMake mailing list
>> CMake at cmake.org
>> http://www.cmake.org/mailman/listinfo/cmake
>>
>
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://public.kitware.com/pipermail/cmake/attachments/20061220/09269dd0/attachment-0001.htm


More information about the CMake mailing list