Cmake+svn or HG generate version number
The original CMake needed to generate the SVN version number with the shell script, and then passed in as the CMake parameter.
CMake Invocation Script Example:
#!/bin/sh
# cmake.sh
Servercoderoot=~/code/server
coderevnum= ' svn info ${servercoderoot} | grep Revision | Awk-f ' {print $} '
CMake S{servercoderoot}-dcmake_build_type=release-dversion_revision=s{coderevnum}
CMakeLists.txt in the following configuration:
Configure_file (
"Version.h.in"
"Version.h"
)
Version.h.in as follows:
#include <string>
Const std::string Version_majoy ("1");
Const std::string Version_minor ("0");
Const std::string version_revision ("@[email protected]");
Linux execution cmake.sh will automatically replace the SVN version number.
Instead of using a shell script to generate the SVN version number, use the Find_package (Subversion) mode
The version number can also be generated on Windows, and CMake calls do not have to pass version_revision parameters.
CMakeLists.txt instead (refer to the open source online game Ryzom CMake):
SET (Root_dir ${project_source_dir})
IF (EXISTS "${root_dir}/.svn/")
Find_package (Subversion)
IF (Subversion_found)
Subversion_wc_info (${root_dir} Project)
SET (Version_revision ${project_wc_revision})
ENDIF (Subversion_found)
ENDIF (EXISTS "${root_dir}/.svn/")
Configure_file (
"Version.h.in"
"Version.h"
)
If it is not svn, but with HG, the following script can be used:
IF (EXISTS "${root_dir}/.hg/")
Find_package (Mercurial)
IF (Mercurial_found)
Mercurial_wc_info (${root_dir} ER)
SET (REVISION ${er_wc_revision})
SET (CHANGESET ${er_wc_changeset})
SET (BRANCH ${er_wc_branch})
ENDIF (Mercurial_found)
ENDIF (EXISTS "${root_dir}/.hg/")
Cmake--cmake+svn or HG generate version number