Problems when porting a library target from ExternalProject_Add

I’m trying to import a Rust project to my C++ project, I write the CMake code as below:

include(ExternalProject)
ExternalProject_Add(
        quiche_source
        GIT_REPOSITORY https://github.com/cloudflare/quiche.git
        CONFIGURE_COMMAND ""
        BUILD_COMMAND cargo build "--$<$<CONFIG:Release>: release>"
        BUILD_IN_SOURCE true
        INSTALL_COMMAND ""
)
ExternalProject_Get_Property(quiche_source SOURCE_DIR)

add_library(quiche STATIC IMPORTED GLOBAL)
set_property(TARGET quiche
        PROPERTY IMPORTED_LOCATION ${SOURCE_DIR}/target/$<LOWER_CASE:${CMAKE_BUILD_TYPE}>/libquiche.a
        PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${SOURCE_DIR}/include)
if (APPLE)
    target_link_libraries(quiche INTERFACE "-framework Security")
endif ()
add_dependencies(quiche quiche_source)

what I want is to download the “quiche” project, build it, and export it as a CMake target for later use. But when I load the CMakeLists.txt, CMake warns me that

Imported target “quiche” includes non-existent path

"/Users/xxx/source/qunar_http3/cmake-build-debug/external/quiche/quiche_source-prefix/src/quiche_source/target/debug/libquiche.a"

My guess is that IMPORT is for prebuilt library, but at this time CMake is just processing CMakeLists, so what is the right way to export the library, which is build by ExternalProject_Add?

Imported targets must exist at the time they are configured, so this won’t work. I think if you make it an INTERFACE library which brings in the library; that may work.

Also, don’t you need to specify to make a static library manually? Or is quiche targeting a staticlib by default (all of my crates make .rlib files instead, but they use the default settings)?

INTERFACE library works for me, here’s my code, hope it could help others:

include(FetchContent)
message("downloading quiche...")
FetchContent_Declare(
        quiche_source
        GIT_REPOSITORY https://github.com/cloudflare/quiche.git
        GIT_TAG 0.8.1
        GIT_PROGRESS true
        GIT_SUBMODULES ""
        GIT_SUBMODULES_RECURSE off
)
FetchContent_Populate(quiche_source)

...

add_library(quiche INTERFACE libquiche.a)
target_include_directories(quiche INTERFACE ${quiche_source_SOURCE_DIR}/include)
target_link_libraries(quiche INTERFACE ${QUICHE_LIBRARY_PATH}/libquiche.a)

add_custom_command(
        OUTPUT libquiche.a
        COMMAND cargo ${QUICHE_BUILD_ARGS}
        WORKING_DIRECTORY ${quiche_source_SOURCE_DIR}
        COMMENT "start building quiche ${QUICHE_BUILD_ARGS}"
        VERBATIM
)

The code below only works in 3.19, I didn’t find a way to accomplish this in lower version.

what breaks in versions before 3.19, I don’t see anything relevant in the release notes