It is possible to express this recipe more compactly. Instead of explicitly constructing vars_dict, which felt a bit repetitive, we could have used get_cmake_property(_vars VARIABLES) to obtain a list of all variables defined at this particular time, and could have looped over all elements of _vars to access their values:
get_cmake_property(_vars VARIABLES)foreach(_var IN ITEMS ${_vars}) message("variable ${_var} has the value ${${_var}}")endforeach()
Using this approach, it is possible to build vars_dict implicitly. However, care has to be taken to escape values that contain characters such as ";", which Python interprets as terminating an instruction.