I include pre-setup.cmake at the beginning of the root CMakeLists.txt
and post-setup.cmake is included at the bottom. add_subdirectory() and
other target stuff is done inbetween.
One issue I run into is that these files are sometimes re-entered. For
example, sometimes I have a git submodule with a CMakeLists.txt that
is the root when CMake is run on the submodule by itself, and in
others the submodule's root CMakeLists.txt is just a normal script
included by the parent repository's scripts.
At the moment I'm doing some counting logic to make sure that
pre-setup.cmake and post-setup.cmake are not included multiple times,
if they are not at the root CMakeLists.txt.
At the top of pre-setup.cmake:
if( NOT DEFINED PRE_SETUP_DEPTH_COUNT )
set( PRE_SETUP_DEPTH_COUNT 0 )