Reputation: 4663
I want to modify a variable passed to a function. Here's the code I wrote:
FUNCTION(TEST var)
set(${var} "ABC")
message(${var}) # 2) 123
set(${var} "ABC" PARENT_SCOPE)
ENDFUNCTION(TEST)
set(v "123")
message(${v}) # 1) 123
TEST(${v})
message(${v}) # 3) 123
Why all three outputs print 123
. I expected #2
and #3
print ABC
?
If I pass variable like this - TEST(v)
- I have other output: #1 - 123
, #2 - v
, #3 - ABC
. Why is this? What's the difference?
Upvotes: 0
Views: 408
Reputation: 42842
You are passing the content of v
to TEST()
. So it should be:
FUNCTION(TEST var)
set(${var} "ABC")
message(${${var}})
set(${var} "ABC" PARENT_SCOPE)
ENDFUNCTION(TEST)
set(v "123")
message(${v})
TEST(v)
message(${v})
Reference
Upvotes: 1