目前我的一个项目中有一些代码:
find_package(CURL REQUIRED)
if(${CURL_FOUND})
else(${CURL_FOUND})
message(STATUS "Could not find libcURL. This dependency will be downloaded.")
ExternalProject_Add(
libcurl
GIT_REPOSITORY "git://github.com/bagder/curl.git"
GIT_TAG "1b6bc02fb926403f04061721f9159e9887202a96"
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/lib/curl
PATCH_COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/lib/cURL/buildconf
CONFIGURE_COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/lib/cURL/configure --prefix=<INSTALL_DIR>
BUILD_COMMAND ${MAKE}
UPDATE_COMMAND ""
INSTALL_COMMAND ""
LOG_DOWNLOAD ON
LOG_UPDATE ON
LOG_CONFIGURE ON
LOG_BUILD ON
LOG_TEST ON
LOG_INSTALL ON
)
ExternalProject_Get_Property(libcurl source_dir)
ExternalProject_Get_Property(libcurl binary_dir)
set(CURL_SOURCE_DIR ${source_dir})
set(CURL_BINARY_DIR ${binary_dir})
set(CURL_LIBRARIES ${CURL_BINARY_DIR}/lib/.libs/libcurl.dylib)
include_directories(${CURL_SOURCE_DIR})
set(DEPENDENCIES ${DEPENDENCIES} libcurl)
endif(${CURL_FOUND})
该项目的主要优先事项之一是尽可能简单地为最终用户安装,同时仍然从头开始编译。我遇到这个代码时遇到的一个错误是运行CMake时产生了以下错误:
CMake Error at /usr/share/cmake-2.8/Modules/FindPackageHandleStandardArgs.cmake:97 (MESSAGE):
Could NOT find CURL (missing: CURL_LIBRARY CURL_INCLUDE_DIR)
Call Stack (most recent call first):
/usr/share/cmake-2.8/Modules/FindPackageHandleStandardArgs.cmake:288 (_FPHSA_FAILURE_MESSAGE)
/usr/share/cmake-2.8/Modules/FindCURL.cmake:52 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
CMakeLists.txt:29 (find_package)
发生此错误是因为运行CMake的系统上未安装libcurl4-openssl-dev
。我想知道如何使用CMake安装此依赖项。有什么建议吗?
答案 0 :(得分:2)
REQUIRED
的{{1}}参数意味着如果找不到包裹,CMake会报告错误并停止。看起来你想要的是允许curl包在你运行find_package
时不存在,而是在必要时下载它。
你可能想要更像的东西:
find_package