ExternalProject_Add fails with trailing slash for SOURCE_DIR
Using CMake 3.18 with ExternalProject_Add(name SOURCE_DIR "${CMAKE_BINARY_DIR}/name-src/"
I get the error:
CMake Error at C:/Program Files/CMake/share/cmake-3.18/Modules/ExternalProject.cmake:2411 (_ep_write_gitclone_script):
_ep_write_gitclone_script Function invoked with incorrect arguments for
function named: _ep_write_gitclone_script
Call Stack (most recent call first):
C:/Program Files/CMake/share/cmake-3.18/Modules/ExternalProject.cmake:3213 (_ep_add_download_command)
CMakeLists.txt:50 (ExternalProject_Add)
Looking into that file I found:
get_filename_component(src_name "${source_dir}" NAME) #<-- this is empty if source_dir has trailing slash
get_filename_component(work_dir "${source_dir}" PATH)
...
_ep_write_gitclone_script(${tmp_dir}/${name}-gitclone.cmake ${source_dir}
${GIT_EXECUTABLE} ${git_repository} ${git_tag} ${git_remote_name} ${git_init_submodules} "${git_submodules_recurse}" "${git_submodules}" "${git_shallow}" "${git_progress}" "${git_config}" ${src_name} ${work_dir}
${stamp_dir}/${name}-gitinfo.txt ${stamp_dir}/${name}-gitclone-lastrun.txt "${tls_verify}"
) #<-- then ${src_name} resolves to nothing and the error occures
In the ExternalProject_Add doku I found no hint about this. Also, by checking for empty ${src_name} a helpful error message could be thrown.
maybe related: #19969
Edited by Warmy