From 442d5c1b543d94b1902a17da597891104bab170e Mon Sep 17 00:00:00 2001 From: Youngho Kim Date: Fri, 10 May 2019 09:14:27 +0900 Subject: [PATCH] [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 --- ports/cpr/001-cpr-config.patch | 94 ++++++++++++++++++++++++++++++++++ ports/cpr/CONTROL | 2 +- ports/cpr/cprConfig.cmake | 27 ++++++++++ ports/cpr/portfile.cmake | 8 ++- 4 files changed, 129 insertions(+), 2 deletions(-) create mode 100644 ports/cpr/001-cpr-config.patch create mode 100644 ports/cpr/cprConfig.cmake diff --git a/ports/cpr/001-cpr-config.patch b/ports/cpr/001-cpr-config.patch new file mode 100644 index 00000000000..9b9b11352d5 --- /dev/null +++ b/ports/cpr/001-cpr-config.patch @@ -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 ++ $ ++ $ ++ PRIVATE ++ $ ++) ++ + +- # 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() diff --git a/ports/cpr/CONTROL b/ports/cpr/CONTROL index a8cdbf052d2..2bf591cc25e 100644 --- a/ports/cpr/CONTROL +++ b/ports/cpr/CONTROL @@ -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] diff --git a/ports/cpr/cprConfig.cmake b/ports/cpr/cprConfig.cmake new file mode 100644 index 00000000000..501fcd96a82 --- /dev/null +++ b/ports/cpr/cprConfig.cmake @@ -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") diff --git a/ports/cpr/portfile.cmake b/ports/cpr/portfile.cmake index 56e9c6cf49c..f6ea8e9af50 100644 --- a/ports/cpr/portfile.cmake +++ b/ports/cpr/portfile.cmake @@ -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)