Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Install libcurl4-openssl-dev using CMake's External Project

Currently I have this bit of code in one of my projects:

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})

One of the main priorities of the project is to be as easy as possible to install for an end user while still compiling from scratch. One error I'm running into with this bit of code is the following error gets generated when running 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)

This error occurs because libcurl4-openssl-dev is not installed on the system where CMake is running. I was wondering how I might go about installing this dependency using CMake. Any suggestions?

like image 889
syb0rg Avatar asked Nov 08 '15 19:11

syb0rg


People also ask

What is libcurl4 Openssl Dev?

libcurl is an easy-to-use client-side URL transfer library, supporting DICT, FILE, FTP, FTPS, GOPHER, HTTP, HTTPS, IMAP, IMAPS, LDAP, LDAPS, POP3, POP3S, RTMP, RTSP, SCP, SFTP, SMTP, SMTPS, TELNET and TFTP.


1 Answers

The REQUIRED argument to find_package means that if the package isn't found CMake will report an error and stop. It looks like what you want is to allow the curl package to not be present when you run find_package, but to download it if necessary.

You probably want something more like:

find_package(CURL)

if(NOT ${CURL_FOUND})
    message(WARNING "Could not find libcURL.  This dependency will be downloaded. To avoid this you can install curl yourself using the standard methods for your platform.")

    ...

endif()
like image 160
bames53 Avatar answered Oct 05 '22 11:10

bames53