@@ -1041,6 +1041,13 @@ define_property(DIRECTORY PROPERTY "EP_UPDATE_DISCONNECTED" INHERITED
1041
1041
"ExternalProject module."
1042
1042
)
1043
1043
1044
+ define_property (DIRECTORY PROPERTY "EP_SOURCE_DIR_PERSISTENT" INHERITED
1045
+ BRIEF_DOCS "Whether source dir stored outside the build directory should be preserved."
1046
+ FULL_DOCS
1047
+ "See documentation of the ExternalProject_Add() function in the "
1048
+ "ExternalProject module."
1049
+ )
1050
+
1044
1051
function (_ep_write_gitclone_script script_filename source_dir git_EXECUTABLE git_repository git_tag git_remote_name git_submodules git_shallow git_progress git_config src_name work_dir gitclone_infofile gitclone_stampfile tls_verify )
1045
1052
if (NOT GIT_VERSION_STRING VERSION_LESS 1.7.10)
1046
1053
set (git_clone_shallow_options "--depth 1 --no-single-branch" )
@@ -1072,14 +1079,6 @@ if(NOT run)
1072
1079
return()
1073
1080
endif()
1074
1081
1075
- execute_process(
1076
- COMMAND \$ {CMAKE_COMMAND} -E remove_directory \" ${source_dir} \"
1077
- RESULT_VARIABLE error_code
1078
- )
1079
- if(error_code)
1080
- message(FATAL_ERROR \" Failed to remove directory: '${source_dir} '\" )
1081
- endif()
1082
-
1083
1082
set(git_options)
1084
1083
1085
1084
# disable cert checking if explicitly told not to do it
@@ -1106,23 +1105,94 @@ foreach(config IN LISTS git_config)
1106
1105
list(APPEND git_clone_options --config \$ {config})
1107
1106
endforeach()
1108
1107
1109
- # try the clone 3 times in case there is an odd git clone issue
1110
- set(error_code 1)
1111
- set(number_of_tries 0)
1112
- while(error_code AND number_of_tries LESS 3)
1113
- execute_process(
1114
- COMMAND \" ${git_EXECUTABLE} \" \$ {git_options} clone \$ {git_clone_options} --origin \" ${git_remote_name} \" \" ${git_repository} \" \" ${src_name} \"
1115
- WORKING_DIRECTORY \" ${work_dir} \"
1116
- RESULT_VARIABLE error_code
1117
- )
1118
- math(EXPR number_of_tries \"\$ {number_of_tries} + 1\" )
1119
- endwhile()
1120
- if(number_of_tries GREATER 1)
1121
- message(STATUS \" Had to git clone more than once:
1122
- \$ {number_of_tries} times.\" )
1108
+ if(EXISTS \" ${source_dir} \" AND ${source_dir_persistent} )
1109
+ if(NOT IS_DIRECTORY \" ${source_dir} \" )
1110
+ # FIXME Perhaps support symbolic links?
1111
+ message(FATAL_ERROR \"\\\" ${source_dir} \\\" exists and is not a git repository. Remove it and try again\" )
1112
+ elseif(NOT IS_DIRECTORY \" ${source_dir} /.git\" )
1113
+ file(GLOB files \" ${source_dir} /*\" )
1114
+ list(LENGTH files nfiles)
1115
+ if(nfiles)
1116
+ message(FATAL_ERROR \"\\\" ${source_dir} \\\" folder exists and is not a git repository. Remove it and try again\" )
1117
+ endif()
1118
+ else()
1119
+ # Already initialized git repository: no need to clone again
1120
+ execute_process(
1121
+ COMMAND \" ${git_EXECUTABLE} \" config --local --get remote.origin.url
1122
+ WORKING_DIRECTORY \" ${work_dir} /${src_name} \"
1123
+ OUTPUT_VARIABLE origin_url
1124
+ RESULT_VARIABLE error_code
1125
+ OUTPUT_STRIP_TRAILING_WHITESPACE
1126
+ )
1127
+ if(error_code)
1128
+ message(FATAL_ERROR \" Failed to get origin remote url in: '${work_dir} /${src_name} '\" )
1129
+ endif()
1130
+ if(\"\$ {origin_url}\" STREQUAL \" ${git_repository} \" )
1131
+ message(STATUS \" Avoiding repeated git clone, repository already exists\" )
1132
+ return()
1133
+ else()
1134
+ string(TIMESTAMP now \" %Y%m%d%H%M%S\" )
1135
+ message(WARNING \" Repository URL is different. Renaming origin remote to origin.\$ {now}\" )
1136
+ execute_process(
1137
+ COMMAND \" ${git_EXECUTABLE} \" remote rename origin origin.\$ {now}
1138
+ WORKING_DIRECTORY \" ${work_dir} /${src_name} \"
1139
+ RESULT_VARIABLE error_code
1140
+ )
1141
+ if(error_code)
1142
+ message(FATAL_ERROR \" Failed to rename remote in: '${work_dir} /${src_name} '\" )
1143
+ endif()
1144
+
1145
+ execute_process(
1146
+ COMMAND \" ${git_EXECUTABLE} \" remote add origin \" ${git_repository} \"
1147
+ WORKING_DIRECTORY \" ${work_dir} /${src_name} \"
1148
+ RESULT_VARIABLE error_code
1149
+ )
1150
+ if(error_code)
1151
+ message(FATAL_ERROR \" Failed to add origin remote in: '${work_dir} /${src_name} '\" )
1152
+ endif()
1153
+
1154
+ # try the fetch 3 times incase there is an odd git fetch issue
1155
+ set(error_code 1)
1156
+ set(number_of_tries 0)
1157
+ while(error_code AND number_of_tries LESS 3)
1158
+ execute_process(
1159
+ COMMAND \" ${git_EXECUTABLE} \" \$ {git_options} fetch \$ {git_clone_options} origin
1160
+ WORKING_DIRECTORY \" ${work_dir} /${src_name} \"
1161
+ RESULT_VARIABLE error_code
1162
+ )
1163
+ math(EXPR number_of_tries \"\$ {number_of_tries} + 1\" )
1164
+ endwhile()
1165
+ if(number_of_tries GREATER 1)
1166
+ message(STATUS \" Had to git fetch more than once:
1167
+ \$ {number_of_tries} times.\" )
1168
+ endif()
1169
+ if(error_code)
1170
+ message(FATAL_ERROR \" Failed to fetch in: '${work_dir} /${src_name} '\" )
1171
+ endif()
1172
+ endif()
1173
+ endif()
1123
1174
endif()
1124
- if(error_code)
1125
- message(FATAL_ERROR \" Failed to clone repository: '${git_repository} '\" )
1175
+
1176
+ # Now perform the clone if still required
1177
+ if(NOT IS_DIRECTORY \" ${source_dir} /.git\" )
1178
+ # try the clone 3 times incase there is an odd git clone issue
1179
+ set(error_code 1)
1180
+ set(number_of_tries 0)
1181
+ while(error_code AND number_of_tries LESS 3)
1182
+ execute_process(
1183
+ COMMAND \" ${git_EXECUTABLE} \" \$ {git_options} clone \$ {git_clone_options} --origin \" ${git_remote_name} \" \" ${git_repository} \" \" ${src_name} \"
1184
+ WORKING_DIRECTORY \" ${work_dir} \"
1185
+ RESULT_VARIABLE error_code
1186
+ )
1187
+ math(EXPR number_of_tries \"\$ {number_of_tries} + 1\" )
1188
+ endwhile()
1189
+ if(number_of_tries GREATER 1)
1190
+ message(STATUS \" Had to git clone more than once:
1191
+ \$ {number_of_tries} times.\" )
1192
+ endif()
1193
+ if(error_code)
1194
+ message(FATAL_ERROR \" Failed to clone repository: '${git_repository} '\" )
1195
+ endif()
1126
1196
endif()
1127
1197
1128
1198
execute_process(
0 commit comments