Skip to content

FetchContent_MakeAvailable failing to retrieve git clone

I have the following trivial example in an included cmake/build.cmake under the root:

FetchContent_Declare(
        docopt
        GIT_REPOSITORY https://github.com/docopt/docopt.cpp.git
        GIT TAG 6f5de76970be94a6f1e4556d1716593100e285d2 # 16 June 2020, master
)
FetchContent_MakeAvailable(docopt)

Which results in the following (trace) output (complete output on gist):

/snap/clion/163/bin/cmake/linux/share/cmake-3.20/Modules/FetchContent.cmake(1010):  message([ 11%] Performing download step (git clone) for 'docopt-populate'
fatal: could not create work tree dir '': No such file or directory
fatal: could not create work tree dir '': No such file or directory
fatal: could not create work tree dir '': No such file or directory
-- Had to git clone more than once:
          3 times.

The auto-generated file at cmake-trace/_deps/docopt-subbuild/docopt-populate-prefix/tmp/docopt-populate-gitclone.cmake contains the following lines (starting on line 18):

while(error_code AND number_of_tries LESS 3)
  execute_process(
    COMMAND "/usr/bin/git"  clone --no-checkout --depth 1 --no-single-branch --progress --origin "TAG" "https://github.com/docopt/docopt.cpp.git" ""
    WORKING_DIRECTORY ""
    RESULT_VARIABLE error_code
    )
  math(EXPR number_of_tries "${number_of_tries} + 1")
endwhile()

The resulting git error results due to the trailing "" passed to the git clone command. These empty quotes are retrieved from ${src_name} when it is built at this line (not CLion is currently on cmake version 3.20.2).

    COMMAND \"${git_EXECUTABLE}\" ${git_options} clone ${git_clone_options} \"${git_repository}\" \"${src_name}\"

The value of ${src_name} ultimately comes from this line:

    get_filename_component(src_name "${source_dir}" NAME)

As such, I would expect it to contain docopt-src.

Issue #21498 (closed) may seem related, as, though it produces a completely different error, it too traces its roots to an empty ${src_name}, implying that ${source_dir} has a trailing \. However, my trace also contains:

/snap/clion/163/bin/cmake/linux/share/cmake-3.20/Modules/FetchContent.cmake(894):  set(docopt_SOURCE_DIR /home/thargy/source/Apocraphy/cmake-trace/_deps/docopt-src PARENT_SCOPE )

Referring to this line:

  set(${contentName}_SOURCE_DIR "${ARG_SOURCE_DIR}" PARENT_SCOPE)

As such, it does appear to be set correctly prior to calling the ExternalProject module, so I am at a loss as to the cause?

Edited by Craig Dean
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information