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

Mike Jackson mike.jackson at imts.us
Tue Dec 19 14:49:43 EST 2006


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/20061219/4f365e06/attachment.htm


More information about the CMake mailing list