Skip to content

Commit 31fc274

Browse files
committed
Optimizing cmake building process
Previous version forces rebuild whole project after changing revision. Now it should rebuild only 4 files that relies on version.h. Additional feature: You can define OPENXCOM_VERSION_STRING variable during configuration to add your own string to version name. For example: ```cmake -DOPENXCOM_VERSION_STRING=" 2016-01-01"``` or ```cmake -DOPENXCOM_VERSION_STRING=" Xmas Edition"``` Have fun.
1 parent 00ba092 commit 31fc274

3 files changed

Lines changed: 56 additions & 14 deletions

File tree

‎CMakeLists.txt‎

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ option ( ENABLE_CLANG_ANALYSIS "When building with clang, enable the static anal
1212
set ( MSVC_WARNING_LEVEL 3 CACHE STRING "Visual Studio warning levels" )
1313
option ( FORCE_INSTALL_DATA_TO_BIN "Force installation of data to binary directory" OFF )
1414
set ( DATADIR "" CACHE STRING "Where to place datafiles" )
15+
set ( OPENXCOM_VERSION_STRING "" CACHE STRING "Version string (after x.x)" )
16+
1517

1618
if ( WIN32 )
1719
set ( default_deps_dir "${CMAKE_SOURCE_DIR}/deps" )
@@ -99,22 +101,32 @@ set ( CPACK_PACKAGE_VERSION_MAJOR ${CMAKE_MATCH_1} )
99101
set ( CPACK_PACKAGE_VERSION_MINOR ${CMAKE_MATCH_2} )
100102
set ( CPACK_PACKAGE_VERSION_PATCH "" )
101103
find_package ( Git )
102-
if ( GIT_FOUND )
103-
message("git found: ${GIT_EXECUTABLE}")
104-
execute_process ( COMMAND ${GIT_EXECUTABLE} describe --dirty
105-
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
106-
OUTPUT_VARIABLE git_describe_out
107-
ERROR_VARIABLE git_describe_error
108-
RESULT_VARIABLE git_describe_result
109-
)
110-
string ( REGEX MATCH "([a-z|0-9|.]*)-([0-9]*)-([a-z|0-9]*)([-|a-z]*)" git_commit "${git_describe_out}" )
111-
set ( git_tag ${CMAKE_MATCH_1} )
112-
set ( git_nb_commit ${CMAKE_MATCH_2} )
113-
set ( git_commit ${CMAKE_MATCH_3} )
114-
set ( git_dirty ${CMAKE_MATCH_4} )
115-
add_definitions( -DOPENXCOM_VERSION_GIT="${git_commit}" )
104+
105+
if ( "${OPENXCOM_VERSION_STRING}" STREQUAL "" )
106+
find_package ( Git )
107+
if ( GIT_FOUND )
108+
message("git found: ${GIT_EXECUTABLE}")
109+
execute_process ( COMMAND ${GIT_EXECUTABLE} describe --dirty
110+
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
111+
OUTPUT_VARIABLE git_describe_out
112+
ERROR_VARIABLE git_describe_error
113+
RESULT_VARIABLE git_describe_result
114+
)
115+
string ( REGEX MATCH "([a-z|0-9|.]*)-([0-9]*)-([a-z|0-9]*)([-|a-z]*)" git_commit "${git_describe_out}" )
116+
set ( git_tag ${CMAKE_MATCH_1} )
117+
set ( git_nb_commit ${CMAKE_MATCH_2} )
118+
set ( git_commit ${CMAKE_MATCH_3} )
119+
set ( git_dirty ${CMAKE_MATCH_4} )
120+
set ( OPENXCOM_VERSION_STRING ".${git_commit}" )
121+
endif()
116122
endif()
117123

124+
add_definitions( -DGIT_BUILD=1 )
125+
126+
configure_file("${CMAKE_SOURCE_DIR}/src/git_version.h.in" "${CMAKE_CURRENT_BINARY_DIR}/src/git_version.h" )
127+
include_directories ( "${CMAKE_CURRENT_BINARY_DIR}/src" )
128+
129+
118130
if ( DEV_BUILD )
119131
# Append the commit to version number
120132
set ( CPACK_PACKAGE_VERSION_PATCH "${git_commit}${git_dirty}" )

‎src/git_version.h.in‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright 2010-2015 OpenXcom Developers.
3+
*
4+
* This file is part of OpenXcom.
5+
*
6+
* OpenXcom is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* OpenXcom is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with OpenXcom. If not, see <http://www.gnu.org/licenses/>.
18+
*/
19+
#ifndef GIT_VERSION_H
20+
#define GIT_VERSION_H
21+
22+
#ifndef OPENXCOM_VERSION_GIT
23+
#define OPENXCOM_VERSION_GIT "@OPENXCOM_VERSION_STRING@"
24+
#endif
25+
26+
#endif

‎src/version.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323
#define OPENXCOM_VERSION_LONG "1.0.0.0"
2424
#define OPENXCOM_VERSION_NUMBER 1,0,0,0
2525

26+
#ifdef GIT_BUILD
27+
#include "git_version.h"
28+
#endif
29+
2630
#ifndef OPENXCOM_VERSION_GIT
2731
#define OPENXCOM_VERSION_GIT ""
2832
#endif

0 commit comments

Comments
 (0)