[cpr] added find_package for cpr on install (#3185)

* added find_package for cpr on install

How to use:
find_package ( CPR REQUIRED )
if ( CPR_FOUND )
message ( STATUS "CPR_INCLUDE_DIRS = ${CPR_INCLUDE_DIRS}" )
message ( STATUS "CPR_LIBRARIES = ${CPR_LIBRARIES}" )
include_directories ( ${CPR_INCLUDE_DIRS} )
endif ( CPR_FOUND )

* [cpr] Provide config and targets files
This commit is contained in:
Youngho Kim 2019-05-10 09:14:27 +09:00 committed by Victor Romero
parent 010e88c647
commit 442d5c1b54
4 changed files with 129 additions and 2 deletions

View File

@ -0,0 +1,94 @@
diff --git a/cpr/CMakeLists.txt b/cpr/CMakeLists.txt
index a6db5bd..90bec48 100644
--- a/cpr/CMakeLists.txt
+++ b/cpr/CMakeLists.txt
@@ -1,47 +1,46 @@
-message(STATUS "Using CURL_INCLUDE_DIRS: ${CURL_INCLUDE_DIRS}.")
-include_directories(
- ${CPR_INCLUDE_DIRS}
- ${CURL_INCLUDE_DIRS})
-
add_library(${CPR_LIBRARIES}
+ auth.cpp
+ cookies.cpp
+ cprtypes.cpp
+ digest.cpp
+ error.cpp
+ multipart.cpp
+ parameters.cpp
+ payload.cpp
+ proxies.cpp
+ session.cpp
+ timeout.cpp
+ util.cpp
+ ssl_options.cpp
+)
+
+target_link_libraries( ${CPR_LIBRARIES}
+ PUBLIC ${CURL_LIBRARIES}
+)
+
+target_include_directories(${CPR_LIBRARIES}
+ PUBLIC
+ $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../include>
+ $<INSTALL_INTERFACE:include>
+ PRIVATE
+ $<BUILD_INTERFACE:${CURL_INCLUDE_DIRS}>
+)
+
- # Source files
- auth.cpp
- cookies.cpp
- cprtypes.cpp
- digest.cpp
- error.cpp
- multipart.cpp
- parameters.cpp
- payload.cpp
- proxies.cpp
- session.cpp
- timeout.cpp
- util.cpp
- ssl_options.cpp
+set(TARGETS_EXPORT_NAME "${PROJECT_NAME}Targets")
+install(
+ TARGETS ${CPR_LIBRARIES}
+ EXPORT ${TARGETS_EXPORT_NAME}
+ RUNTIME DESTINATION bin
+ LIBRARY DESTINATION lib
+ ARCHIVE DESTINATION lib
+)
- # Header files (useful in IDEs)
- "${CPR_INCLUDE_DIRS}/cpr/api.h"
- "${CPR_INCLUDE_DIRS}/cpr/auth.h"
- "${CPR_INCLUDE_DIRS}/cpr/body.h"
- "${CPR_INCLUDE_DIRS}/cpr/cookies.h"
- "${CPR_INCLUDE_DIRS}/cpr/cpr.h"
- "${CPR_INCLUDE_DIRS}/cpr/cprtypes.h"
- "${CPR_INCLUDE_DIRS}/cpr/curlholder.h"
- "${CPR_INCLUDE_DIRS}/cpr/defines.h"
- "${CPR_INCLUDE_DIRS}/cpr/digest.h"
- "${CPR_INCLUDE_DIRS}/cpr/error.h"
- "${CPR_INCLUDE_DIRS}/cpr/max_redirects.h"
- "${CPR_INCLUDE_DIRS}/cpr/multipart.h"
- "${CPR_INCLUDE_DIRS}/cpr/parameters.h"
- "${CPR_INCLUDE_DIRS}/cpr/payload.h"
- "${CPR_INCLUDE_DIRS}/cpr/proxies.h"
- "${CPR_INCLUDE_DIRS}/cpr/response.h"
- "${CPR_INCLUDE_DIRS}/cpr/session.h"
- "${CPR_INCLUDE_DIRS}/cpr/timeout.h"
- "${CPR_INCLUDE_DIRS}/cpr/util.h"
- "${CPR_INCLUDE_DIRS}/cpr/ssl_options.h")
+install(
+ EXPORT ${TARGETS_EXPORT_NAME}
+ DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}"
+)
-message(STATUS "Using CURL_LIBRARIES: ${CURL_LIBRARIES}.")
-target_link_libraries(${CPR_LIBRARIES}
- ${CURL_LIBRARIES})
+if (NOT DISABLE_INSTALL_HEADERS)
+ install(DIRECTORY ${CPR_INCLUDE_DIRS}/cpr DESTINATION include)
+endif()

View File

@ -1,4 +1,4 @@
Source: cpr
Version: 1.3.0-4
Version: 1.3.0-6
Description: C++ Requests is a simple wrapper around libcurl inspired by the excellent Python Requests project.
Build-Depends: curl[core]

27
ports/cpr/cprConfig.cmake Normal file
View File

@ -0,0 +1,27 @@
####### Expanded from @PACKAGE_INIT@ by configure_package_config_file() #######
####### Any changes to this file will be overwritten by the next CMake run ####
####### The input file was Config.cmake.in ########
get_filename_component(PACKAGE_PREFIX_DIR "${CMAKE_CURRENT_LIST_DIR}/../../" ABSOLUTE)
macro(set_and_check _var _file)
set(${_var} "${_file}")
if(NOT EXISTS "${_file}")
message(FATAL_ERROR "File or directory ${_file} referenced by variable ${_var} does not exist !")
endif()
endmacro()
macro(check_required_components _NAME)
foreach(comp ${${_NAME}_FIND_COMPONENTS})
if(NOT ${_NAME}_${comp}_FOUND)
if(${_NAME}_FIND_REQUIRED_${comp})
set(${_NAME}_FOUND FALSE)
endif()
endif()
endforeach()
endmacro()
####################################################################################
include("${CMAKE_CURRENT_LIST_DIR}/cprTargets.cmake")
check_required_components("cpr")

View File

@ -8,7 +8,8 @@ vcpkg_from_github(
REF 1.3.0
SHA512 fd08f8a592a5e1fb8dc93158a4850b81575983c08527fb415f65bd9284f93c804c8680d16c548744583cd26b9353a7d4838269cfc59ccb6003da8941f620c273
HEAD_REF master
PATCHES enable-install.patch
PATCHES
001-cpr-config.patch
)
vcpkg_configure_cmake(
@ -23,8 +24,13 @@ vcpkg_configure_cmake(
vcpkg_install_cmake()
file(INSTALL ${CMAKE_CURRENT_LIST_DIR}/cprConfig.cmake DESTINATION ${CURRENT_PACKAGES_DIR}/lib/cmake/cpr)
vcpkg_fixup_cmake_targets(CONFIG_PATH lib/cmake/cpr)
vcpkg_copy_pdbs()
file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/debug/include)
# Handle copyright
file(COPY ${SOURCE_PATH}/LICENSE DESTINATION ${CURRENT_PACKAGES_DIR}/share/cpr)
file(RENAME ${CURRENT_PACKAGES_DIR}/share/cpr/LICENSE ${CURRENT_PACKAGES_DIR}/share/cpr/copyright)