Search code examples
androidwindowsflutterdartcmake

CMake Error: At least one entry of URL is a path (invalid in a list)


I am using CMake to configure a flutter plugin I am creating.

I have this macro to download a zip file from github repo:

# Download the zipped folder of dart-sdk-api from the dependencies repo
set(dart_sdk_api_zip_url "https://github.com/Haidar0096/image_magick_ffi_deps/raw/master/dart_sdk_api.zip")
message(STATUS "Downloading dart-sdk-api from ${dart_sdk_api_zip_url}")
FetchContent_Declare(
        dart_sdk_api
        URL ${dart_sdk_api_zip_url}
        DOWNLOAD_EXTRACT_TIMESTAMP TRUE
)
FetchContent_MakeAvailable(dart_sdk_api)

# Include the include folder of dart_sdk_api from the downloaded zip
include_directories(${dart_sdk_api_SOURCE_DIR}/include)

# Create a target from the sources of the downloaded zip and link it to the executable
file(GLOB_RECURSE DART_SDK_API_SOURCES "${dart_sdk_api_SOURCE_DIR}/src/*.c")
add_library(dart_sdk_api STATIC ${DART_SDK_API_SOURCES})
target_link_libraries(image_magick_ffi dart_sdk_api)

It works well if I build for windows, and downloads normally.

However if I build for android, I get this error and build fails:

[        ] Successfully started process 'command 'C:\Users\haidar\AppData\Local\Android\Sdk\cmake\3.18.1\bin\cmake.exe''
[        ] C/C++: debug|arm64-v8a :CMake Error at C:/Users/haidar/AppData/Local/Android/Sdk/cmake/3.18.1/share/cmake-3.18/Modules/ExternalProject.cmake:2480 (message):
[        ] C/C++: debug|arm64-v8a :  At least one entry of URL is a path (invalid in a list)
[        ] C/C++: debug|arm64-v8a :Call Stack (most recent call first):
[        ] C/C++: debug|arm64-v8a :  C:/Users/haidar/AppData/Local/Android/Sdk/cmake/3.18.1/share/cmake-3.18/Modules/ExternalProject.cmake:3228 (_ep_add_download_command)
[        ] C/C++: debug|arm64-v8a :  CMakeLists.txt:13 (ExternalProject_Add)
[        ] C/C++: debug|arm64-v8a :-- Configuring incomplete, errors occurred!
[        ] C/C++: debug|arm64-v8a :See also "D:/dev_haidar/flutter/image_magick_ffi/android/.cxx/Debug/42552b6e/arm64-v8a/_deps/dart_sdk_api-subbuild/CMakeFiles/CMakeOutput.log".

I don't understand what does this error mean and how should I solve it?

(The whole CMakeLists.txt is here but didn't include it because it is quite large)


Solution

  • Digging into the CMake Source Code, I found the error was originating from this part of file ExternalProject.cmake:

        list(LENGTH url url_list_length)
        if(NOT "${url_list_length}" STREQUAL "1")
          foreach(entry ${url})
            if(NOT "${entry}" MATCHES "^[a-z]+://")
              message(FATAL_ERROR "At least one entry of URL is a path (invalid in a list)")
            endif()
          endforeach()
          if("x${fname}" STREQUAL "x")
            list(GET url 0 fname)
          endif()
        endif()
    

    printing the value of url I found that for some reason it was reading it as: https://github.com/Haidar0096/image_magick_ffi_deps/raw/master/dart_sdk_api.zipDOWNLOAD_EXTRACT_TIMESTAMP TRUE

    So it was appending DOWNLOAD_EXTRACT_TIMESTAMP TRUE to the url.

    So the solution was to swap the lines like this:

    FetchContent_Declare(
            dart_sdk_api
            DOWNLOAD_EXTRACT_TIMESTAMP TRUE
            URL "${dart_sdk_api_zip_url}"
    )