[CMake] Deriving version number from a header (safely)
Doug Gregor
doug.gregor at gmail.com
Thu May 14 11:03:20 EDT 2009
Hello,
I'm hacking on a CMake build system for Boost, and we'd like to
extract the Boost version number from our version header
(boost/version.hpp) so that we can use the version number within
CMake. Actually doing this is trivial:
file(STRINGS ${CMAKE_CURRENT_SOURCE_DIR}/boost/version.hpp BOOST_VERSIONSTR
REGEX "#define[ ]+BOOST_VERSION[ ]+[0-9]+")
string(REGEX MATCH "[0-9]+" BOOST_VERSIONSTR ${BOOST_VERSIONSTR})
if (BOOST_VERSIONSTR)
math(EXPR BOOST_VERSION_MAJOR "${BOOST_VERSIONSTR} / 100000")
math(EXPR BOOST_VERSION_MINOR "${BOOST_VERSIONSTR} / 100 % 1000")
math(EXPR BOOST_VERSION_SUBMINOR "${BOOST_VERSIONSTR} % 100")
set(BOOST_VERSION
"${BOOST_VERSION_MAJOR}.${BOOST_VERSION_MINOR}.${BOOST_VERSION_SUBMINOR}")
endif()
However, we'd also like to force CMake to reconfigure when
boost/version.hpp changes. Is there some top-level target that we can
attach such a dependency to? e.g., I could imagine that there could
exist a cmake-cache target, such that we could add
add_dependencies(cmake-cache ${CMAKE_CURRENT_SOURCE_DIR}/boost/version.hpp)
and then CMake would be re-run if boost/version.hpp changes. Does
something like this exist?
- Doug
More information about the CMake
mailing list