Skip to content

Instantly share code, notes, and snippets.

@jcfr
Created February 23, 2012 00:54
Show Gist options
  • Save jcfr/1888836 to your computer and use it in GitHub Desktop.
Save jcfr/1888836 to your computer and use it in GitHub Desktop.
Small example illustrating how CMake function scope works
function(myfunc)
set(foo "myfunc")
message("Line ${CMAKE_CURRENT_LIST_LINE} - foo: ${foo} [scope: myfunc]")
endfunction()
function(myfunc_parent_scope)
set(foo "myfunc_parent_scope" PARENT_SCOPE)
message("Line ${CMAKE_CURRENT_LIST_LINE} - foo: ${foo} [scope: myfunc_parent_scope]")
endfunction()
set(foo "foo")
message("Line ${CMAKE_CURRENT_LIST_LINE} - foo: ${foo} [scope: global]")
myfunc()
message("Line ${CMAKE_CURRENT_LIST_LINE} - foo: ${foo} [scope: global]")
myfunc_parent_scope()
message("Line ${CMAKE_CURRENT_LIST_LINE} - foo: ${foo} [scope: global]")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment