Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9174581
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:46:42+00:00 2026-06-17T16:46:42+00:00

I asked a questions about cmake and passing variables here . I can make

  • 0

I asked a questions about cmake and passing variables here. I can make it work, but only if I name my variable in the function differently than the variable in parent scope I call the function for. So in essence:

function(strange name)
   message(STATUS ${name})
   message(STATUS ${${name}})
endfunction()

set(name foo)
set(anothername foo)
strange(name)
strange(anothername)

Which results in:

-- name   (message(STATUS ${name}) for var "name")
-- name   (message(STATUS ${${name}}) for var "name")
-- anothername message(STATUS ${name}) for var "anothername")
-- foo    (message(STATUS ${${name}}) for var "anothername")

Isn’t that a little weird? What’s happening?
I think the behaviour of a function should not depend on the naming of variable in the parent scope – should it?!

Any clarification is much appreciated!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T16:46:43+00:00Added an answer on June 17, 2026 at 4:46 pm

    Unfortunately, the language of CMake is extremely primitive. In this case, the naming of local variables may interact with variables with the same name in outer scopes.

    Concretely, in the two calls ${${name}} expands to ${name} and ${anothername}, respectively. In the former name is the name of a local variable whose value is used. In the latter, the anothername from the outer scope is used.

    I don’t know of any way around this, except using obfuscated variable names in function accept variable names as arguments.

    Maybe we should petition for a ${name:PARENT_SCOPE} from the CMake team?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Questions about renaming files in Git have been asked before, but I can't work
There seem to be many questions asked about this subject here on stackoverflow, but
I know questions about thumbnails have been asked in the past but I can't
There have been a few questions asked here about why you can't define static
I've asked a few questions about this, but haven't found the answer (or maybe
I've asked questions on here so many times about this ruddy game that I'm
I've look all over the web and in the questions asked here about MySQL
I know similar questions have been asked, but I'm not sure about the answers
Ok, so I've asked a bunch of smaller questions about this project, but I
I've asked questions about Quartz.NET a lot today, but I'm making progress in understand

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.