Skip to content
GitLab
  • Menu
Projects Groups Snippets
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • CMake CMake
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,870
    • Issues 3,870
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 17
    • Merge requests 17
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Releases
  • Packages & Registries
    • Packages & Registries
    • Container Registry
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • External wiki
    • External wiki
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • CMake
  • CMakeCMake
  • Issues
  • #17113
Closed
Open
Created Jul 28, 2017 by George Karpenkov@cheshire

Appending to lists and macros do not work together

For the following code:

macro(add_to_array arr1)
    set(cflags ${arr1})
    list(APPEND cflags "myitem")
    message("Resulting list inside macro = ${cflags}")
endmacro()

set(my_array "list1")
list(APPEND my_array "list2")
message("Resulting list before calling the macro = ${my_array}")
add_to_array(${my_array})
message("Resulting list outside of macro = ${my_array}")

CMake prints:

Resulting list before calling the macro = list1;list2
Resulting list inside macro = list1;myitem
Resulting list outside of macro = list1;list2

Why is the update outside of the macro not seen inside? Also if I start modifying the passed variable inside the macro all kinds of very strange things start to happen.

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking