Selaa lähdekoodia

BUG: In CMake/ExternalProject, fix the download step specific to GIT repository.

A cmake script named "${name}-gitclone.cmake" is now created in TMP_DIR specific to the project.

This script contains the following command:
 - delete source directory
 - call git clone
Jean-Christophe Fillion-Robin 15 vuotta sitten
vanhempi
commit
a20d2c34b3
1 muutettua tiedostoa jossa 21 lisäystä ja 12 poistoa
  1. 21 12
      CMake/ExternalProject.cmake

+ 21 - 12
CMake/ExternalProject.cmake

@@ -705,19 +705,28 @@ function(_ep_add_download_command name)
     get_filename_component(src_name "${source_dir}" NAME)
     get_filename_component(work_dir "${source_dir}/../" REALPATH)
 
-    # Since git doesn't allow to clone if the repository exists,
-    # let's delete it. Git will re-recreate it when the clone command will be invoked
-    execute_process(
-      COMMAND ${CMAKE_COMMAND} -E remove_directory ${source_dir}
-      RESULT_VARIABLE error_code
-      )
-    if(error_code)
-      message(FATAL_ERROR "Failed to remove directory: ${source_dir}")
-    endif()
-    
-    
+    # Since Git doesn't allow to clone if the repository exists,
+    # let's create a cmake script that will be invoked as a download command.
+    # That script will delete the source directory and call the appropriate git clone command
+    file(WRITE ${tmp_dir}/${name}-gitclone.cmake "
+execute_process(
+  COMMAND ${CMAKE_COMMAND} -E remove_directory ${source_dir}
+  RESULT_VARIABLE error_code
+  )
+if(error_code)
+  message(FATAL_ERROR "Failed to remove directory: ${source_dir}")
+endif()
+execute_process(
+  COMMAND ${Git_EXECUTABLE} clone ${git_repository} ${src_name}
+  WORKING_DIRECTORY ${work_dir}
+  RESULT_VARIABLE error_code
+  )
+if(error_code)
+  message(FATAL_ERROR 'Failed to clone repository: ${git_repository}')
+endif()
+")    
     set(comment "Performing download step (GIT clone) for '${name}'")
-    set(cmd ${Git_EXECUTABLE} clone ${git_repository} ${src_name})
+    set(cmd ${CMAKE_COMMAND} -P ${tmp_dir}/${name}-gitclone.cmake)
     list(APPEND depends ${stamp_dir}/${name}-gitinfo.txt)
   elseif(url)
     get_filename_component(work_dir "${source_dir}" PATH)