Although @Angew's answer is correct, there are not many things in CMake that are really impossible :-)
If you have a string like
set(BOX2D_VERSION 2.2.1)
in Box2D_v2.2.1 / CMakeLists.txt, you can get the version in the parent area by doing something like:
file(STRINGS Box2D_v2.2.1/CMakeLists.txt VersionSetter REGEX "^[ ]*set\\(BOX2D_VERSION") string(REGEX REPLACE "(^[ ]*set\\(BOX2D_VERSION[ ]*)([^\\)]*)\\)" "\\2" BOX2D_VERSION ${VersionSetter})
It is a little fragile; it is not suitable for extra spaces in the set command, for example, or for setting a value set twice. You can also use these features, but if you know the format of the set command, and that is unlikely to change, then this is a smart solution.
source share