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

Mike Jackson mike.jackson at imts.us
Tue Dec 19 12:03:54 EST 2006


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





More information about the CMake mailing list