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?