10
10
# * Provides function
11
11
# git_external(<directory> <giturl> <gittag> [VERBOSE,SHALLOW]
12
12
# [RESET <files>])
13
- # which will check out directory in CMAKE_SOURCE_DIR ( if relative)
13
+ # which will check out directory in COMMON_SOURCE_DIR if relative,
14
14
# or in the given absolute path using the given repository and tag
15
- # ( commit-ish) .
15
+ # if commit-ish.
16
16
#
17
17
# Options which can be supplied to the function:
18
18
# VERBOSE, when present, this option tells the function to output
43
43
# If set, a remote called 'user' is set up for github repositories, pointing
44
44
# to [email protected] :<user>/<project>. Also, this remote is used by default
45
45
# for 'git push'.
46
+ # COMMON_SOURCE_DIR
47
+ # Download location of the source code of subprojects and externals.
48
+ # Defaults to CMAKE_SOURCE_DIR.
46
49
47
50
48
51
if (NOT GIT_FOUND)
@@ -53,8 +56,15 @@ if(NOT GIT_EXECUTABLE)
53
56
endif ()
54
57
55
58
include (CMakeParseArguments)
59
+
56
60
option (GIT_EXTERNAL_VERBOSE "Print git commands as they are executed" OFF )
57
61
62
+ set (COMMON_SOURCE_DIR "${CMAKE_SOURCE_DIR} " CACHE PATH
63
+ "Location of common directory of all sources" )
64
+ set (__common_source_dir ${COMMON_SOURCE_DIR} )
65
+ get_filename_component (__common_source_dir ${__common_source_dir} ABSOLUTE )
66
+ file (MAKE_DIRECTORY ${__common_source_dir} )
67
+
58
68
if (NOT GITHUB_USER AND DEFINED ENV{GITHUB_USER})
59
69
set (GITHUB_USER $ENV{GITHUB_USER} CACHE STRING
60
70
"Github user name used to setup remote for 'user' forks" )
@@ -95,7 +105,7 @@ function(GIT_EXTERNAL DIR REPO tag)
95
105
endif ()
96
106
97
107
if (NOT IS_ABSOLUTE "${DIR} " )
98
- set (DIR "${CMAKE_SOURCE_DIR } /${DIR} " )
108
+ set (DIR "${COMMON_SOURCE_DIR } /${DIR} " )
99
109
endif ()
100
110
get_filename_component (NAME "${DIR} " NAME )
101
111
get_filename_component (GIT_EXTERNAL_DIR "${DIR} /.." ABSOLUTE )
@@ -151,11 +161,7 @@ function(GIT_EXTERNAL DIR REPO tag)
151
161
OUTPUT_QUIET ERROR_QUIET WORKING_DIRECTORY "${DIR} " )
152
162
endif ()
153
163
154
- if (COMMON_SOURCE_DIR)
155
- file (RELATIVE_PATH __dir ${COMMON_SOURCE_DIR} ${DIR} )
156
- else ()
157
- file (RELATIVE_PATH __dir ${CMAKE_SOURCE_DIR} ${DIR} )
158
- endif ()
164
+ file (RELATIVE_PATH __dir ${COMMON_SOURCE_DIR} ${DIR} )
159
165
string (REGEX REPLACE "[:/\\ .]" "-" __target "${__dir} " )
160
166
if (TARGET ${__target} -rebase)
161
167
return ()
@@ -301,11 +307,11 @@ if(EXISTS ${GIT_EXTERNALS} AND NOT GIT_EXTERNAL_SCRIPT_MODE)
301
307
file (WRITE "${GIT_EXTERNAL_SCRIPT} " "
302
308
include(\" ${CMAKE_CURRENT_LIST_DIR} /GitExternal.cmake\" )
303
309
execute_process(COMMAND \" ${GIT_EXECUTABLE} \" fetch origin -q
304
- WORKING_DIRECTORY \" ${DIR} \" )
310
+ WORKING_DIRECTORY \" ${COMMON_SOURCE_DIR} / ${ DIR}\" )
305
311
execute_process(
306
312
COMMAND \" ${GIT_EXECUTABLE} \" show-ref --hash=7 refs/remotes/origin/master
307
313
OUTPUT_VARIABLE newref OUTPUT_STRIP_TRAILING_WHITESPACE
308
- WORKING_DIRECTORY \" ${DIR} \" )
314
+ WORKING_DIRECTORY \" ${COMMON_SOURCE_DIR} / ${ DIR}\" )
309
315
if(newref)
310
316
file(APPEND ${GIT_EXTERNALS} \" # ${DIR} ${REPO} \$ {newref}\\ n\" )
311
317
git_external(${DIR} ${REPO} \$ {newref})
0 commit comments