[CMake] FUNCTION doesn't changes parent variables
Alejandro Morell Garcia
alejandro.morell at gmail.com
Wed Apr 23 11:29:58 EDT 2008
Hello, I'm testing the new FUNCTION command. In documentation says it's the
same as a MACRO but local variables are deleted at exit.
Because of this, I want to port all my macros to functions, but it doesn't
changes parent variables. Check the following example:
FUNCTION(MYTEST VAR1 VAR2 OUTPUTVAR)
MESSAGE(STATUS "OUTPUTVAR = ${OUTPUTVAR}")
SET(${OUTPUTVAR} "Values var1 = ${VAR1} var2 = ${VAR2}")
MESSAGE(STATUS "${OUTPUTVAR}: ${${OUTPUTVAR}}")
ENDFUNCTION(MYTEST)
MESSAGE(STATUS "Test functions")
MYTEST("Hello" "World" MYMSG)
MESSAGE(STATUS ${MYMSG})
MYTEST("1" "2" MYMSG)
MESSAGE(STATUS ${MYMSG})
MYTEST("3" "4" MYMSG)
MESSAGE(STATUS ${MYMSG})
The output of executing this (with "cmake -P MyTest.cmake") it's the
following:
-- Test functions
-- OUTPUTVAR = MYMSG
-- MYMSG: Values var1 = Hello var2 = World
--
-- OUTPUTVAR = MYMSG
-- MYMSG: Values var1 = 1 var2 = 2
--
-- OUTPUTVAR = MYMSG
-- MYMSG: Values var1 = 3 var2 = 4
--
Why MYTEST function doesn't changes the parent variable MYMSG?
Do I need to FORCE it?
Thanks.
(Sorry for my english :P)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20080423/303f6e79/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: MyTest.cmake
Type: application/octet-stream
Size: 409 bytes
Desc: not available
URL: <http://www.cmake.org/pipermail/cmake/attachments/20080423/303f6e79/attachment.obj>
More information about the CMake
mailing list