Skip to content

Commit ea62ea4

Browse files
committed
[cmake] Changed trex_0_5_x to describe its version using git *(as it was done for the master
1 parent c5a9e65 commit ea62ea4

4 files changed

Lines changed: 126 additions & 28 deletions

File tree

cmake/getgit.cmake

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
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)

trex/utils/CMakeLists.txt

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -130,45 +130,44 @@ add_library(TREXutils SHARED
130130

131131
if(TREX_FROM_PKG)
132132
# svn data is given by the package
133-
set(SVN_HH ${CMAKE_SOURCE_DIR}/${TREX_EXTRA_SRC}/svn/version.hh)
133+
set(GIT_HH ${CMAKE_SOURCE_DIR}/${TREX_EXTRA_SRC}/git/version.hh)
134134

135-
if(EXISTS ${SVN_HH})
135+
if(EXISTS ${GIT_HH})
136136
include_directories(${CMAKE_SOURCE_DIR}/${TREX_EXTRA_SRC})
137-
add_definitions(-DWITH_SVN_TRACK)
137+
add_definitions(-DWITH_GIT_TRACK)
138138
endif()
139139
else(TREX_FROM_PKG)
140140
# I need to generate the file
141141

142-
option(WITH_SVN_TRACK "Enable tracking of svn compiled version in TREXversion" ON)
143-
mark_as_advanced(WITH_SVN_TRACK)
142+
option(WITH_GIT_TRACK "Enable tracking of git compiled version in TREXversion" ON)
143+
mark_as_advanced(WITH_GIT_TRACK)
144144

145-
if(WITH_SVN_TRACK)
146-
set(SVN_HH svn/version.hh)
147-
add_custom_target(svnheader ALL
148-
DEPENDS ${SVN_HH})
149-
add_dependencies(trex_prep svnheader)
145+
if(WITH_GIT_TRACK)
146+
set(GIT_HH git/version.hh)
147+
add_custom_target(githeader ALL
148+
DEPENDS ${GIT_HH})
149+
add_dependencies(trex_prep githeader)
150150

151151
# this run my svn script
152-
add_custom_command(OUTPUT ${SVN_HH}
152+
add_custom_command(OUTPUT ${GIT_HH}
153153
PRE_BUILD
154154
COMMAND ${CMAKE_COMMAND} -DSOURCE_DIR=${CMAKE_SOURCE_DIR}
155-
-DMY_SVN_TRUNK=trex2-agent.googlecode.com/svn/trunk
156155
-DOUTPUT_DIR=${TREX_EXTRA_DIR}
157-
-P ${CMAKE_SOURCE_DIR}/cmake/getsvn.cmake)
156+
-P ${CMAKE_SOURCE_DIR}/cmake/getgit.cmake)
158157

159158
include_directories(${TREX_EXTRA_DIR})
160-
set_source_files_properties(${SVN_HH}
159+
set_source_files_properties(${GIT_HH}
161160
PROPERTIES GENERATED TRUE
162161
# HEADER_FILE_ONLY TRUE
163162
LOCATION ${TREX_EXTRA_DIR}
164163
)
165164

166-
add_dependencies(TREXutils svnheader)
165+
add_dependencies(TREXutils githeader)
167166

168167
set_source_files_properties(TREXversion.cc
169-
PROPERTIES OBJECT_DEPENDS ${TREX_EXTRA_DIR}/${SVN_HH})
170-
add_definitions(-DWITH_SVN_TRACK)
171-
endif(WITH_SVN_TRACK)
168+
PROPERTIES OBJECT_DEPENDS ${TREX_EXTRA_DIR}/${GIT_HH})
169+
add_definitions(-DWITH_GIT_TRACK)
170+
endif(WITH_GIT_TRACK)
172171
endif(TREX_FROM_PKG)
173172

174173
# map ditectory structure for XCode

trex/utils/TREXversion.cc

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@
3636

3737
#include <sstream>
3838

39-
#ifdef WITH_SVN_TRACK
40-
# include "svn/version.hh"
39+
#ifdef WITH_GIT_TRACK
40+
# include "git/version.hh"
4141
#else
4242
// Make the default dimilar to when we do not find svn
43-
# define SVN_INFO false
44-
# define SVN_ROOT "unknown"
45-
# define SVN_REV "exported"
43+
# define GIT_INFO false
44+
# define GIT_BRANCH "unknown"
45+
# define GIT_REV "exported"
4646
#endif
4747

4848
unsigned short TREX::version::major() {
@@ -78,20 +78,32 @@ std::string TREX::version::str() {
7878
}
7979

8080
bool TREX::version::svn_info() {
81-
return SVN_INFO;
81+
return false;
8282
}
8383

8484
std::string TREX::version::svn_root() {
85-
return SVN_ROOT;
85+
return std::string();
8686
}
8787

8888
std::string TREX::version::svn_revision() {
89-
return SVN_REV;
89+
return std::string();
90+
}
91+
92+
bool TREX::version::git_info() {
93+
return GIT_INFO;
94+
}
95+
96+
std::string TREX::version::git_branch() {
97+
return GIT_BRANCH;
98+
}
99+
100+
std::string TREX::version::git_revision() {
101+
return GIT_REV;
90102
}
91103

92104
std::string TREX::version::full_str() {
93-
if( svn_info() )
94-
return str()+" (svn:"+svn_root()+"["+svn_revision()+"])";
105+
if( git_info() )
106+
return str()+" (git:"+git_branch()+"["+git_revision()+"])";
95107
else
96108
return str();
97109
}

trex/utils/TREXversion.hh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,10 @@ namespace TREX {
115115
static std::string svn_root();
116116
static std::string svn_revision();
117117

118+
static bool git_info();
119+
static std::string git_branch();
120+
static std::string git_revision();
121+
118122
}; // TREX::version
119123

120124
} // TREX

0 commit comments

Comments
 (0)