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

  • SEARCH
  • Home
  • 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 9147109
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T10:54:30+00:00 2026-06-17T10:54:30+00:00

as in said in the title, I would like to write a nice function

  • 0

as in said in the title, I would like to write a “nice” function in cmake that is able to modify a variable which is passed as a parameter into that function.

The only way I can think of doing it is ugly:

Function definition

function(twice varValue varName)
set(${varName} ${varValue}${varValue} PARENT_SCOPE)
endfunction(twice)

Usage

set(arg foo)
twice(${arg} arg)
message("arg = "${arg})

Result

arg = foofoo

It seems to me, there is no real concept of variables that one can pass around at all?!
I feel like there is something fundamental about cmake that I didn’t take in yet.

So, is there a nicer way to do this?

Thanks a lot!

  • 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-17T10:54:31+00:00Added an answer on June 17, 2026 at 10:54 am

    You don’t need to pass the value and the name of the variable. The name is enough, because you can access the value by the name:

    function(twice varName)
      SET(${varName} ${${varName}}${${varName}} PARENT_SCOPE)
    endfunction()
    
    SET(arg "foo")
    twice(arg)
    MESSAGE(STATUS ${arg})
    

    outputs “foofoo”

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

Sidebar

Related Questions

as the title said i would like to create a button that says available
As the title said: I would like to find all elements that are on
Like the title said, .load() function won't load javascript from called page. Would be
Like I said in the title, I was wondering whether it would be possible
As said in the title, I have a scrollview that should be listening for
Hope the title is not that confusing - honestly said I had no idea
I have a discussions controller for which I would like to have an edit
Like I said in the title. I'm trying to compile libipsec right now and
Basically the title speaks for itself. I would like to put elements on top
Like the title said, I'm looking to generate a word doc (or something word

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.