Skip to content

Commit a24977a

Browse files
Fix cmake helper functions collision (#1065)
* add etl prefix name for cmake helper functions * remove unused functions from GetGitRevistionDescription
1 parent 2fd4e17 commit a24977a

File tree

3 files changed

+13
-98
lines changed

3 files changed

+13
-98
lines changed

CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ cmake_minimum_required(VERSION 3.10)
66
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/helpers.cmake)
77

88
set(MSG_PREFIX "etl |")
9-
determine_version_with_git(${GIT_DIR_LOOKUP_POLICY})
9+
etl_determine_version_with_git(${GIT_DIR_LOOKUP_POLICY})
1010
if(NOT ETL_VERSION)
11-
determine_version_with_file("version.txt")
11+
etl_determine_version_with_file("version.txt")
1212
endif()
1313

1414
project(etl VERSION ${ETL_VERSION} LANGUAGES CXX)

cmake/GetGitRevisionDescription.cmake

Lines changed: 8 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,6 @@
1212
# Returns the results of git describe on the source tree, and adjusting
1313
# the output so that it tests false if an error occurs.
1414
#
15-
# git_describe_working_tree(<var> [<additional arguments to git describe> ...])
16-
#
17-
# Returns the results of git describe on the working tree (--dirty option),
18-
# and adjusting the output so that it tests false if an error occurs.
19-
#
20-
# git_get_exact_tag(<var> [<additional arguments to git describe> ...])
21-
#
22-
# Returns the results of git describe --exact-match on the source tree,
23-
# and adjusting the output so that it tests false if there was no exact
24-
# matching tag.
25-
#
26-
# git_local_changes(<var>)
27-
#
28-
# Returns either "CLEAN" or "DIRTY" with respect to uncommitted changes.
29-
# Uses the return code of "git diff-index --quiet HEAD --".
30-
# Does not regard untracked files.
31-
#
3215
# Requires CMake 2.6 or newer (uses the 'function' command)
3316
#
3417
# Original Author:
@@ -43,10 +26,10 @@
4326
# (See accompanying file LICENSE_1_0.txt or copy at
4427
# http://www.boost.org/LICENSE_1_0.txt)
4528

46-
if(__get_git_revision_description)
29+
if(__etl_get_git_revision_description)
4730
return()
4831
endif()
49-
set(__get_git_revision_description YES)
32+
set(__etl_get_git_revision_description YES)
5033

5134
# We must run the following at "include" time, not at function call time,
5235
# to find the path to this module rather than the path to a calling list file
@@ -62,7 +45,7 @@ get_filename_component(_gitdescmoddir ${CMAKE_CURRENT_LIST_FILE} PATH)
6245
# neither foo nor bar contain a file/directory .git. This will return
6346
# C:/bla/.git
6447
#
65-
function(_git_find_closest_git_dir _start_dir _git_dir_var)
48+
function(_etl_git_find_closest_git_dir _start_dir _git_dir_var)
6649
set(cur_dir "${_start_dir}")
6750
set(git_dir "${_start_dir}/.git")
6851
while(NOT EXISTS "${git_dir}")
@@ -83,8 +66,8 @@ function(_git_find_closest_git_dir _start_dir _git_dir_var)
8366
PARENT_SCOPE)
8467
endfunction()
8568

86-
function(get_git_head_revision _refspecvar _hashvar)
87-
_git_find_closest_git_dir("${CMAKE_CURRENT_SOURCE_DIR}" GIT_DIR)
69+
function(etl_get_git_head_revision _refspecvar _hashvar)
70+
_etl_git_find_closest_git_dir("${CMAKE_CURRENT_SOURCE_DIR}" GIT_DIR)
8871

8972
if("${ARGN}" STREQUAL "ALLOW_LOOKING_ABOVE_CMAKE_SOURCE_DIR")
9073
set(ALLOW_LOOKING_ABOVE_CMAKE_SOURCE_DIR TRUE)
@@ -143,7 +126,7 @@ function(get_git_head_revision _refspecvar _hashvar)
143126
string(REGEX REPLACE "gitdir: (.*)$" "\\1" git_worktree_dir
144127
${worktree_ref})
145128
string(STRIP ${git_worktree_dir} git_worktree_dir)
146-
_git_find_closest_git_dir("${git_worktree_dir}" GIT_DIR)
129+
_etl_git_find_closest_git_dir("${git_worktree_dir}" GIT_DIR)
147130
set(HEAD_SOURCE_FILE "${git_worktree_dir}/HEAD")
148131
endif()
149132
else()
@@ -172,11 +155,11 @@ function(get_git_head_revision _refspecvar _hashvar)
172155
PARENT_SCOPE)
173156
endfunction()
174157

175-
function(git_describe _var)
158+
function(etl_git_describe _var)
176159
if(NOT GIT_FOUND)
177160
find_package(Git QUIET)
178161
endif()
179-
get_git_head_revision(refspec hash ${ARGN})
162+
etl_get_git_head_revision(refspec hash ${ARGN})
180163
if(NOT GIT_FOUND)
181164
set(${_var}
182165
"GIT-NOTFOUND"
@@ -214,71 +197,3 @@ function(git_describe _var)
214197
"${out}"
215198
PARENT_SCOPE)
216199
endfunction()
217-
218-
function(git_describe_working_tree _var)
219-
if(NOT GIT_FOUND)
220-
find_package(Git QUIET)
221-
endif()
222-
if(NOT GIT_FOUND)
223-
set(${_var}
224-
"GIT-NOTFOUND"
225-
PARENT_SCOPE)
226-
return()
227-
endif()
228-
229-
execute_process(
230-
COMMAND "${GIT_EXECUTABLE}" describe --dirty ${ARGN}
231-
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
232-
RESULT_VARIABLE res
233-
OUTPUT_VARIABLE out
234-
ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
235-
if(NOT res EQUAL 0)
236-
set(out "${out}-${res}-NOTFOUND")
237-
endif()
238-
239-
set(${_var}
240-
"${out}"
241-
PARENT_SCOPE)
242-
endfunction()
243-
244-
function(git_get_exact_tag _var)
245-
git_describe(out --exact-match ${ARGN})
246-
set(${_var}
247-
"${out}"
248-
PARENT_SCOPE)
249-
endfunction()
250-
251-
function(git_local_changes _var)
252-
if(NOT GIT_FOUND)
253-
find_package(Git QUIET)
254-
endif()
255-
get_git_head_revision(refspec hash)
256-
if(NOT GIT_FOUND)
257-
set(${_var}
258-
"GIT-NOTFOUND"
259-
PARENT_SCOPE)
260-
return()
261-
endif()
262-
if(NOT hash)
263-
set(${_var}
264-
"HEAD-HASH-NOTFOUND"
265-
PARENT_SCOPE)
266-
return()
267-
endif()
268-
269-
execute_process(
270-
COMMAND "${GIT_EXECUTABLE}" diff-index --quiet HEAD --
271-
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
272-
RESULT_VARIABLE res
273-
OUTPUT_VARIABLE out
274-
ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
275-
if(res EQUAL 0)
276-
set(${_var}
277-
"CLEAN"
278-
PARENT_SCOPE)
279-
else()
280-
set(${_var}
281-
"DIRTY"
282-
PARENT_SCOPE)
283-
endif()
284-
endfunction()

cmake/helpers.cmake

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
function(determine_version_with_file VER_FILE_NAME)
1+
function(etl_determine_version_with_file VER_FILE_NAME)
22
file(READ ${VER_FILE_NAME} ETL_VERSION_RAW)
33
# Remove trailing whitespaces and/or newline
44
string(STRIP ${ETL_VERSION_RAW} ETL_VERSION)
@@ -8,9 +8,9 @@ function(determine_version_with_file VER_FILE_NAME)
88
message(STATUS "${MSG_PREFIX} Determined ETL version ${ETL_VERSION} from version.txt file")
99
endfunction()
1010

11-
function(determine_version_with_git)
11+
function(etl_determine_version_with_git)
1212
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/GetGitRevisionDescription.cmake)
13-
git_describe(VERSION ${ARGN})
13+
etl_git_describe(VERSION ${ARGN})
1414
string(FIND ${VERSION} "." VALID_VERSION)
1515
if(VALID_VERSION EQUAL -1)
1616
if(CMAKE_CURRENT_LIST_DIR STREQUAL PROJECT_SOURCE_DIR)

0 commit comments

Comments
 (0)