1+ # -*- cmake -*-
2+ #######################################################################
3+ # Software License Agreement (BSD License) #
4+ # #
5+ # Copyright (c) 2014, Frederic Py. #
6+ # All rights reserved. #
7+ # #
8+ # Redistribution and use in source and binary forms, with or without #
9+ # modification, are permitted provided that the following conditions #
10+ # are met: #
11+ # #
12+ # * Redistributions of source code must retain the above copyright #
13+ # notice, this list of conditions and the following disclaimer. #
14+ # * Redistributions in binary form must reproduce the above #
15+ # copyright notice, this list of conditions and the following #
16+ # disclaimer in the documentation and/or other materials provided #
17+ # with the distribution. #
18+ # * Neither the name of the TREX Project nor the names of its #
19+ # contributors may be used to endorse or promote products derived #
20+ # from this software without specific prior written permission. #
21+ # #
22+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS #
23+ # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT #
24+ # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS #
25+ # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE #
26+ # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, #
27+ # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,#
28+ # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; #
29+ # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER #
30+ # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT #
31+ # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN #
32+ # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE #
33+ # POSSIBILITY OF SUCH DAMAGE. #
34+ #######################################################################
35+ find_package (GIT QUIET )
36+ # Now I need to extract the project version info
37+ message ("Looking for git: ${GIT_FOUND} " )
38+
39+ if (GIT_FOUND)
40+ # Now I need to extract the project version info
41+ message ("git found: ${GIT_EXECUTABLE} " )
42+ # extract git branch
43+ execute_process (COMMAND ${GIT_EXECUTABLE} describe --all
44+ WORKING_DIRECTORY ${SOURCE_DIR}
45+ RESULT_VARIABLE GIT_RET
46+ OUTPUT_VARIABLE MY_WC_BRANCH
47+ OUTPUT_STRIP_TRAILING_WHITESPACE )
48+ message (STATUS "git describe -> ${GIT_RET} : \" ${MY_WC_BRANCH} \" " )
49+
50+ if (GIT_RET EQUAL 0)
51+ # extract version number and info
52+ execute_process (COMMAND ${GIT_EXECUTABLE} describe --always --dirty
53+ WORKING_DIRECTORY ${SOURCE_DIR}
54+ RESULT_VARIABLE GIT_RET
55+ OUTPUT_VARIABLE MY_WC_REV
56+ OUTPUT_STRIP_TRAILING_WHITESPACE )
57+ endif (GIT_RET EQUAL 0 )
58+
59+ if (NOT GIT_RET EQUAL 0)
60+ set (MY_FLAG 0)
61+ set (MY_WC_BRANCH "" )
62+ set (MY_WC_REV "not_from_git" )
63+ else (NOT GIT_RET EQUAL 0 )
64+ set (MY_FLAG 1)
65+ endif (NOT GIT_RET EQUAL 0 )
66+
67+ else (GIT_FOUND )
68+ set (MY_FLAG 0)
69+ set (MY_WC_BRANCH "" )
70+ set (MY_WC_REV "git_not_found" )
71+ endif (GIT_FOUND )
72+
73+ file (WRITE git_version.hh.txt
74+ "/* DO NOT EDIT: File automatically generated */\n\n "
75+ "#define GIT_INFO ${MY_FLAG} \n "
76+ "#define GIT_BRANCH \" ${MY_WC_BRANCH} \"\n "
77+ "#define GIT_REV \" ${MY_WC_REV} \"\n "
78+ )
79+
80+ message (STATUS "Git version: [${MY_WC_BRANCH} :${MY_WC_REV} ]" )
81+
82+ execute_process (COMMAND ${CMAKE_COMMAND } -E copy_if_different
83+ git_version.hh.txt ${OUTPUT_DIR} /git/version.hh )
0 commit comments