Skip to content
Create a gist now

Instantly share code, notes, and snippets.

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
Something went wrong with that request. Please try again.