I have a CMakeLists.txt which sometimes serves as a project top-level list file and is sometimes used with add_subdirectory().
Now, for reasons, this file needs to set a variable in the top-level scope. The way I achieve this right now is:
if (PROJECT_IS_TOP_LEVEL)
set(FOO "bar")
else()
set(FOO "bar" PARENT_SCOPE)
endif()
but this is verbose and redundant. What would be a better idiom for doing this?