On Tue, Mar 31, 2009 at 2:50 PM, Tyler Roscoe <span dir="ltr"><<a href="mailto:tyler@cryptio.net" target="_blank">tyler@cryptio.net</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div>On Tue, Mar 31, 2009 at 04:47:23PM -0400, Lezz Giles wrote:<br>
> What I want to do is pass values up from src/CMakeLists.txt and tst/CMakeLists.txt that can be used in the custom_command. A normal variable doesn't work - the value is scoped to the current CMakeLists.txt file. I can define the values in the project CMakeLists.txt, but then that separates them from where they really should be, i.e. src|tst/CMakeLists.txt.<br>
<br>
</div>Look at the PARENT_SCOPE argument to set():<br>
<br>
If PARENT_SCOPE is present, the variable will be set in the scope above<br>
the current scope. Each new directory or function creates a new scope.<br>
This command will set the value of a variable into the parent directory<br>
or calling function (whichever is applicable to the case at hand) If<br>
VALUE is not specified then the variable is removed from the parent<br>
scope.<br>
</blockquote><div><br>I just recently discovered another way to do this. I was troubled that pushing it up to the parent scope only pushes it up one level, so if you want to push a variable up to the top, you must push it at each level in the tree. My discovery was that using the environment variable mechanism is a great alternative to a global variable. ;)<br>
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">CMakeLists.txt:</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">set(ENV{myvar})</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">path/some/where/CMakeLists.txt:</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">set(ENV{myvar} "$ENV{myvar};${new_stuff}")</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> </span><br style="font-family: courier new,monospace;"></div></div><span style="font-family: courier new,monospace;">CMakeLists.txt:</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">set(myvar "$ENV{myvar}")</span><br style="font-family: courier new,monospace;"><br>You can also look into define/get/set_property, but I've never used those.<br>
<br>James<br>