As Florian mentioned, you will have to resort to using a function with its own scope. Here is a more general version of what was suggested which can be given the path to the source file and the variable to be looked up:
function(lookup value)
set(options
""
)
set(oneValueArgs
SOURCE
VARIABLE
)
set(multiValueArgs
""
)
cmake_parse_arguments(LOOKUP "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
if(EXISTS "${LOOKUP_SOURCE}")
include("${LOOKUP_SOURCE}")
set(key ${LOOKUP_VARIABLE})
if(NOT ${key})
message(SEND_WARNING "No value was set for ${LOOKUP_VARIABLE} in the source file: ${LOOKUP_SOURCE}")
endif(${key})
set(${value} ${${key}} PARENT_SCOPE)
else()
message(SEND_ERROR "The source file was not found at ${LOOKUP_SOURCE}")
endif()
endfunction()
This is how you can use it:
lookup(val
SOURCE ../info.cmake
VARIABLE a)
message(SEND_ERROR ${val}) #Will Print 1