Skip to content

Commit

Permalink
add temporary libcurl_vendor and use it to get curl
Browse files Browse the repository at this point in the history
  • Loading branch information
wjwwood committed Dec 2, 2017
1 parent 5a3fdde commit 290ff82
Show file tree
Hide file tree
Showing 4 changed files with 123 additions and 2 deletions.
60 changes: 60 additions & 0 deletions libcurl_vendor/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
cmake_minimum_required(VERSION 3.5)

project(libcurl_vendor)

set(PACKAGE_VERSION "1.0.0")

macro(build_libcurl)
set(extra_cxx_flags)
set(extra_c_flags)
if(NOT WIN32)
list(APPEND extra_cxx_flags "-std=c++14 -w")
list(APPEND extra_c_flags "-w")
endif()

set(PKGCONFIG_FOR_OPENSSL)
if(APPLE)
set(PKGCONFIG_FOR_OPENSSL "/usr/local/opt/openssl/lib/pkgconfig")
endif()

include(ExternalProject)
ExternalProject_Add(curl-7.57.0
URL https://github.com/curl/curl/releases/download/curl-7_57_0/curl-7.57.0.tar.gz
URL_MD5 c7aab73aaf5e883ca1d7518f93649dc2
CONFIGURE_COMMAND
<SOURCE_DIR>/configure
CFLAGS=${extra_c_flags}
CXXFLAGS=${extra_cxx_flags}
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:${PKGCONFIG_FOR_OPENSSL}
--prefix=${CMAKE_CURRENT_BINARY_DIR}/libcurl_install
--with-ssl
BUILD_COMMAND ${MAKE}
INSTALL_COMMAND make install
TIMEOUT 600
)

# The external project will install to the build folder, but we'll install that on make install.
install(
DIRECTORY
${CMAKE_CURRENT_BINARY_DIR}/libcurl_install/
DESTINATION
${CMAKE_INSTALL_PREFIX}/opt/libcurl_vendor
)
endmacro()

find_package(CURL QUIET)

if(NOT CURL_FOUND)
# System curl not found, build one locally.
build_libcurl()
endif()

configure_file(libcurl_vendorConfig.cmake.in
"${PROJECT_BINARY_DIR}/libcurl_vendorConfig.cmake" @ONLY)
configure_file(libcurl_vendorConfig-version.cmake.in
"${PROJECT_BINARY_DIR}/libcurl_vendorConfig-version.cmake" @ONLY)

install(FILES
"${PROJECT_BINARY_DIR}/libcurl_vendorConfig.cmake"
"${PROJECT_BINARY_DIR}/libcurl_vendorConfig-version.cmake"
DESTINATION share/${PROJECT_NAME}/cmake)
13 changes: 13 additions & 0 deletions libcurl_vendor/libcurl_vendorConfig-version.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
set(PACKAGE_VERSION @PACKAGE_VERSION@)

set(PACKAGE_VERSION_EXACT False)
set(PACKAGE_VERSION_COMPATIBLE False)

if("${PACKAGE_FIND_VERSION}" VERSION_EQUAL "${PACKAGE_VERSION}")
set(PACKAGE_VERSION_EXACT True)
set(PACKAGE_VERSION_COMPATIBLE True)
endif()

if("${PACKAGE_FIND_VERSION}" VERSION_LESS "${PACKAGE_VERSION}")
set(PACKAGE_VERSION_COMPATIBLE True)
endif()
47 changes: 47 additions & 0 deletions libcurl_vendor/libcurl_vendorConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# prevent multiple inclusion
if(_@PROJECT_NAME@_CONFIG_INCLUDED)
return()
endif()
set(_@PROJECT_NAME@_CONFIG_INCLUDED TRUE)

# output package information
if(NOT @PROJECT_NAME@_FIND_QUIETLY)
message(STATUS "Found @PROJECT_NAME@: @PACKAGE_VERSION@ (${@PROJECT_NAME@_DIR})")
endif()

# Look for system curl first.
find_package(CURL QUIET)

if(NOT CURL_FOUND)
# In this case, the vendor package should have built and installed a local copy.
include(FindPkgConfig)
if(NOT PKG_CONFIG_FOUND)
message(FATAL_ERROR "Could not find pkg-config")
endif()
# Put the local copy's pkgconfig dir on the PKG_CONFIG_PATH.
set(ENV{PKG_CONFIG_PATH}
"$ENV{PKG_CONFIG_PATH}:${@PROJECT_NAME@_DIR}/../../../opt/libcurl_vendor/lib/pkgconfig")
pkg_search_module(CURL REQUIRED libcurl)
endif()

# message(STATUS "CURL_FOUND: ${CURL_FOUND}")
# message(STATUS "CURL_LIBRARIES: ${CURL_LIBRARIES}")
# message(STATUS "CURL_LIBRARY_DIRS: ${CURL_LIBRARY_DIRS}")
# message(STATUS "CURL_INCLUDE_DIRS: ${CURL_INCLUDE_DIRS}")

set(libcurl_vendor_LIBRARIES)
foreach(library IN LISTS CURL_LIBRARIES)
message(STATUS "library: ${library}")
if(IS_ABSOLUTE "${library}")
list(APPEND libcurl_vendor_LIBRARIES "${library}")
else()
find_library(library_abs ${library} PATHS "${CURL_LIBRARY_DIRS}" NO_DEFAULT_PATH)
list(APPEND libcurl_vendor_LIBRARIES "${library_abs}")
endif()
endforeach()
set(libcurl_vendor_LIBRARY_DIRS ${CURL_LIBRARY_DIRS})
set(libcurl_vendor_INCLUDE_DIRS ${CURL_INCLUDE_DIRS})

# message(STATUS "libcurl_vendor_LIBRARIES: ${libcurl_vendor_LIBRARIES}")
# message(STATUS "libcurl_vendor_LIBRARY_DIRS: ${libcurl_vendor_LIBRARY_DIRS}")
# message(STATUS "libcurl_vendor_INCLUDE_DIRS: ${libcurl_vendor_INCLUDE_DIRS}")
5 changes: 3 additions & 2 deletions resource_retriever/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ endif()

find_package(ament_cmake REQUIRED)
find_package(ament_index_cpp REQUIRED)
find_package(rviz_libcurl_vendor REQUIRED)
# TODO(wjwwood): remove libcurl_vendor and just use system curl when possible
find_package(libcurl_vendor REQUIRED)

add_library(${PROJECT_NAME} src/retriever.cpp)
target_include_directories(${PROJECT_NAME}
Expand All @@ -22,7 +23,7 @@ target_include_directories(${PROJECT_NAME}
)
ament_target_dependencies(${PROJECT_NAME}
ament_index_cpp
rviz_libcurl_vendor
libcurl_vendor
)

ament_export_interfaces(${PROJECT_NAME})
Expand Down

0 comments on commit 290ff82

Please sign in to comment.