variable scoping confusion..

I am totally confused about the set() command and variable scoping.

I am trying to refactor a number of things into smaller reusable cmake things and when I do - things go wrong - really wrong.

For example - I want to - in my cmake scripts do something like this:

set_target_riscv()
or:
include( common-target-riscv )

I have others I need to support, microblaze and arm-cortex-m4

Today - I have a huge unwieldy CMAKE script that is hundreds of lines of boiler plate code.
I want to refactor this into either “include” files or functions I can call.

And in those functions - I want to set - for lack of a better word: “global variables”

As an example, I have a function I wrote that works like this:

function( noisy_set VARNAME VALUE )
message( STATUS “${VARNAME}: ${VALUE}”)
set( “${VARNAME}” “${VALUE}” PARENT_SCOPE )
endfunction()

I invoke it like this:

 noisy_set( FOOBAR   'some string' )

The variable is not set in the calling script or any other scope

How do I set the variable GLOBALLY?
How do I set a variable LOCALLY?
Is there a means to declare a variable GLOBAL or LOCAL?

My other problem is - of course I am refactoring things so …
FunctionA() - calls functionB() and functionC() … finally C does the work
For example it might call “noisy_set()” - I have no idea how many parent scopes I need.
In TCL - there is a means to set GLOBAL or “upvar” - type things
In python there is a “global” command
I’m looking for something like GLOBA_SCOPE in CMAKE … but it does not seem to exist.

Then when I return to A … the variables et by B, C,D or E - do not exist,“parentscope” is not viable here - I need GLOBAL SCOPE but that does not seem to exist?

And - is there a reasonable debugger for CMAKE? I am resorting to message() far to much
I really would like to be able to step through things so I can better understand this