cmake:下载easylogging++,直接使用sources

cmake: Download easylogging++ and use sources directly

我想下载easylogging++包,提取内容然后直接在我的源中使用easylogging++.h和easylogging++.cc。

我从这个开始:

ExternalProject_Add(
        easyloggingpp
        PREFIX ${CMAKE_CURRENT_SOURCE_DIR}/downloads
        URL https://github.com/muflihun/easyloggingpp/archive/v9.96.4.tar.gz
        INSTALL_COMMAND mkdir -p ${CMAKE_CURRENT_BINARY_DIR}/external/easyloggingpp && cp src/easyloggingpp-9.96.4/src/* ${CMAKE_CURRENT_BINARY_DIR}/external/easyloggingpp/)
include_directories(${CMAKE_CURRENT_BINARY_DIR}/external/easyloggingpp) 
set(easylogging ${CMAKE_CURRENT_BINARY_DIR}/external/easyloggingpp/easylogging++.cc)

..

add_dependencies(myproject easyloggingpp)

这会在我的项目中创建 downloads/ 目录,但是它是空的并且 external/ 目录中没有文件出现,甚至没有创建目录本身。

如何实现下载这个包并直接合并源代码?我想实现类似于 bazelnew_http_archive.

的东西

似乎 ExternalProject_Add 不适用于我要实现的用例。看起来下载只在编译步骤执行,而不是配置步骤。太可惜了。

我能够通过手动编码实现类似的结果,并且效果相当好:

file(MAKE_DIRECTORY downloads external)

################################################################################
# Easylogging++
################################################################################
if(EXISTS "external/easyloggingpp")
else()
file(MAKE_DIRECTORY external/easyloggingpp)
file(DOWNLOAD
        https://github.com/muflihun/easyloggingpp/archive/v9.96.4.zip
        downloads/easyloggingpp.zip)
execute_process(COMMAND unzip downloads/easyloggingpp.zip -d downloads)
file(GLOB easyloggingpp_files downloads/easyloggingpp-9.96.4/src/easylogging++.*)
file(COPY ${easyloggingpp_files} DESTINATION external/easyloggingpp)
endif()

include_directories(external/easyloggingpp)
set(easyloggingpp external/easyloggingpp/easylogging++.cc)

这对我来说非常好用,我逐渐理解了这个过程中发生的事情。很酷的是 cmake . 步骤不会下载,除非有必要。