Skip to content

Commit

Permalink
Merge pull request #1191 from prince-chrismc/add/cpprestsdk
Browse files Browse the repository at this point in the history
adding cpprestsdk/v2.10.15
  • Loading branch information
danimtb authored Apr 23, 2020
2 parents 82ec709 + 5acbdad commit 41f9410
Show file tree
Hide file tree
Showing 9 changed files with 315 additions and 0 deletions.
7 changes: 7 additions & 0 deletions recipes/cpprestsdk/all/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
cmake_minimum_required(VERSION 2.8.12)
project(cmake_wrapper)

include(conanbuildinfo.cmake)
conan_basic_setup()

add_subdirectory("source_subfolder")
10 changes: 10 additions & 0 deletions recipes/cpprestsdk/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
sources:
"2.10.15":
sha256: 1c027a53457e87b0b3a475e5c8045b94400c475898c8bd51b0fbd218b99a7f7b
url: https://github.com/Microsoft/cpprestsdk/archive/v2.10.15.tar.gz
patches:
"2.10.15":
- patch_file: "patches/0001-find-cmake-targets.patch"
base_path: "source_subfolder"
- patch_file: "patches/0002-remove-wconversion.patch"
base_path: "source_subfolder"
116 changes: 116 additions & 0 deletions recipes/cpprestsdk/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
from conans import ConanFile, CMake, tools
import os


class CppRestSDKConan(ConanFile):
name = "cpprestsdk"
description = "A project for cloud-based client-server communication in native code using a modern asynchronous " \
"C++ API design"
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://github.com/Microsoft/cpprestsdk"
topics = ("conan", "cpprestsdk", "rest", "client", "http", "https")
license = "MIT"
exports_sources = ["CMakeLists.txt", "patches/**"]
generators = "cmake", "cmake_find_package"
settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
"fPIC": [True, False],
"with_websockets": [True, False],
"with_compression": [True, False]
}
default_options = {
"shared": False,
"fPIC": True,
"with_websockets": True,
"with_compression": True
}
short_paths = True

_cmake = None

@property
def _source_subfolder(self):
return "source_subfolder"

@property
def _build_subfolder(self):
return "build_subfolder"

def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC

def configure(self):
if self.options.shared:
del self.options.fPIC

def requirements(self):
self.requires("openssl/1.1.1f")
if self.options.with_compression:
self.requires("zlib/1.2.11")
if self.options.with_websockets:
self.requires("websocketpp/0.8.1")
self.requires("boost/1.72.0")

def source(self):
tools.get(**self.conan_data["sources"][self.version])
extracted_dir = self.name + "-" + self.version
os.rename(extracted_dir, self._source_subfolder)

def _configure_cmake(self):
if self._cmake:
return self._cmake

self._cmake = CMake(self, set_cmake_flags=True)
self._cmake.definitions["BUILD_TESTS"] = False
self._cmake.definitions["BUILD_SAMPLES"] = False
self._cmake.definitions["WERROR"] = False
self._cmake.definitions["CPPREST_EXCLUDE_WEBSOCKETS"] = not self.options.with_websockets
self._cmake.definitions["CPPREST_EXCLUDE_COMPRESSION"] = not self.options.with_compression
self._cmake.configure(build_folder=self._build_subfolder)
return self._cmake

def _patch_clang_libcxx(self):
if self.settings.compiler == 'clang' and str(self.settings.compiler.libcxx) in ['libstdc++', 'libstdc++11']:
tools.replace_in_file(os.path.join(self._source_subfolder, 'Release', 'CMakeLists.txt'),
'libc++', 'libstdc++')

def build(self):
for patch in self.conan_data["patches"][self.version]:
tools.patch(**patch)
self._patch_clang_libcxx()
cmake = self._configure_cmake()
cmake.build()

def package(self):
self.copy("license.txt", dst="licenses", src=self._source_subfolder)
cmake = self._configure_cmake()
cmake.install()
tools.rmdir(os.path.join(self.package_folder, "lib", "cmake"))
tools.rmdir(os.path.join(self.package_folder, "lib", "cpprestsdk"))

def package_info(self):
if self.settings.compiler == "Visual Studio":
debug_suffix = 'd' if self.settings.build_type == 'Debug' else ''
toolset = {'12': '120',
'14': '140',
'15': '141',
'16': '142'}.get(str(self.settings.compiler.version))
version_tokens = self.version.split(".")
versioned_name = "cpprest%s_%s_%s%s" % (toolset, version_tokens[0], version_tokens[1], debug_suffix)
# CppRestSDK uses different library name depends on CMAKE_VS_PLATFORM_TOOLSET
if not os.path.isfile(os.path.join(self.package_folder, 'lib', '%s.lib' % versioned_name)):
versioned_name = "cpprest_%s_%s%s" % (version_tokens[0], version_tokens[1], debug_suffix)
lib_name = versioned_name
else:
lib_name = 'cpprest'
self.cpp_info.libs.append(lib_name)
if self.settings.os == "Linux":
self.cpp_info.system_libs.append("pthread")
elif self.settings.os == "Windows":
self.cpp_info.system_libs.extend(["winhttp", "httpapi", "bcrypt"])
elif self.settings.os == "Macos":
self.cpp_info.frameworks.extend(["CoreFoundation", "Security"])
if not self.options.shared:
self.cpp_info.defines.append("_NO_ASYNCRTIMP")
119 changes: 119 additions & 0 deletions recipes/cpprestsdk/all/patches/0001-find-cmake-targets.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
diff --git a/Release/cmake/cpprest_find_openssl.cmake b/Release/cmake/cpprest_find_openssl.cmake
index 0b49a7e..ed5c24b 100644
--- a/Release/cmake/cpprest_find_openssl.cmake
+++ b/Release/cmake/cpprest_find_openssl.cmake
@@ -1,70 +1,7 @@
function(cpprest_find_openssl)
- if(TARGET cpprestsdk_openssl_internal)
- return()
- endif()
-
- if(IOS)
- set(IOS_SOURCE_DIR "${PROJECT_SOURCE_DIR}/../Build_iOS")
-
- set(OPENSSL_INCLUDE_DIR "${IOS_SOURCE_DIR}/openssl/include" CACHE INTERNAL "")
- set(OPENSSL_LIBRARIES
- "${IOS_SOURCE_DIR}/openssl/lib/libcrypto.a"
- "${IOS_SOURCE_DIR}/openssl/lib/libssl.a"
- CACHE INTERNAL ""
- )
- set(_SSL_LEAK_SUPPRESS_AVAILABLE ON CACHE INTERNAL "")
- elseif(ANDROID)
- if(ARM)
- set(OPENSSL_INCLUDE_DIR "${CMAKE_BINARY_DIR}/../openssl/armeabi-v7a/include" CACHE INTERNAL "")
- set(OPENSSL_LIBRARIES
- "${CMAKE_BINARY_DIR}/../openssl/armeabi-v7a/lib/libssl.a"
- "${CMAKE_BINARY_DIR}/../openssl/armeabi-v7a/lib/libcrypto.a"
- CACHE INTERNAL ""
- )
- else()
- set(OPENSSL_INCLUDE_DIR "${CMAKE_BINARY_DIR}/../openssl/x86/include" CACHE INTERNAL "")
- set(OPENSSL_LIBRARIES
- "${CMAKE_BINARY_DIR}/../openssl/x86/lib/libssl.a"
- "${CMAKE_BINARY_DIR}/../openssl/x86/lib/libcrypto.a"
- CACHE INTERNAL ""
- )
+ if(NOT TARGET cpprestsdk_openssl_internal)
+ add_library(cpprestsdk_openssl_internal INTERFACE)
+ target_include_directories(cpprestsdk_openssl_internal INTERFACE "${CONAN_INCLUDE_DIRS_OPENSSL}")
+ target_link_libraries(cpprestsdk_openssl_internal INTERFACE "${CONAN_LIBS_OPENSSL}")
endif()
- set(_SSL_LEAK_SUPPRESS_AVAILABLE ON CACHE INTERNAL "")
- else()
- if(APPLE)
- if(NOT DEFINED OPENSSL_ROOT_DIR)
- # Prefer a homebrew version of OpenSSL over the one in /usr/lib
- file(GLOB OPENSSL_ROOT_DIR /usr/local/Cellar/openssl/*)
- # Prefer the latest (make the latest one first)
- list(REVERSE OPENSSL_ROOT_DIR)
- endif()
- # This should prevent linking against the system provided 0.9.8y
- set(_OPENSSL_VERSION "")
- endif()
- find_package(OpenSSL 1.0.0 REQUIRED)
-
- INCLUDE(CheckCXXSourceCompiles)
- set(CMAKE_REQUIRED_INCLUDES "${OPENSSL_INCLUDE_DIR}")
- set(CMAKE_REQUIRED_LIBRARIES "${OPENSSL_LIBRARIES}")
- CHECK_CXX_SOURCE_COMPILES("
- #include <openssl/ssl.h>
- int main()
- {
- ::SSL_COMP_free_compression_methods();
- }
- " _SSL_LEAK_SUPPRESS_AVAILABLE)
- endif()
-
- add_library(cpprestsdk_openssl_internal INTERFACE)
- if(TARGET OpenSSL::SSL)
- target_link_libraries(cpprestsdk_openssl_internal INTERFACE OpenSSL::SSL)
- else()
- target_link_libraries(cpprestsdk_openssl_internal INTERFACE "$<BUILD_INTERFACE:${OPENSSL_LIBRARIES}>")
- target_include_directories(cpprestsdk_openssl_internal INTERFACE "$<BUILD_INTERFACE:${OPENSSL_INCLUDE_DIR}>")
- endif()
-
- if (NOT _SSL_LEAK_SUPPRESS_AVAILABLE)
- # libressl doesn't ship with the cleanup method being used in ws_client_wspp
- target_compile_definitions(cpprestsdk_openssl_internal INTERFACE -DCPPREST_NO_SSL_LEAK_SUPPRESS)
- endif()
endfunction()
\ No newline at end of file
diff --git a/Release/cmake/cpprest_find_websocketpp.cmake b/Release/cmake/cpprest_find_websocketpp.cmake
index 94ea81a..f83a777 100644
--- a/Release/cmake/cpprest_find_websocketpp.cmake
+++ b/Release/cmake/cpprest_find_websocketpp.cmake
@@ -1,27 +1,7 @@
function(cpprest_find_websocketpp)
- if(TARGET cpprestsdk_websocketpp_internal)
- return()
- endif()
-
- find_package(WEBSOCKETPP CONFIG QUIET)
- if(WEBSOCKETPP_FOUND)
- message("-- Found websocketpp version " ${WEBSOCKETPP_VERSION} " on system")
- set(WEBSOCKETPP_INCLUDE_DIR ${WEBSOCKETPP_INCLUDE_DIR} CACHE INTERNAL "")
- elseif(EXISTS ${PROJECT_SOURCE_DIR}/libs/websocketpp/CMakeLists.txt)
- message("-- websocketpp not found, using the embedded version")
- set(WEBSOCKETPP_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/libs/websocketpp CACHE INTERNAL "")
- else()
- message(FATAL_ERROR "-- websocketpp not found and embedded version not present; try `git submodule update --init` and run CMake again")
- endif()
-
- cpprest_find_boost()
- cpprest_find_openssl()
-
- add_library(cpprestsdk_websocketpp_internal INTERFACE)
- target_include_directories(cpprestsdk_websocketpp_internal INTERFACE "$<BUILD_INTERFACE:${WEBSOCKETPP_INCLUDE_DIR}>")
- target_link_libraries(cpprestsdk_websocketpp_internal
- INTERFACE
- cpprestsdk_boost_internal
- cpprestsdk_openssl_internal
- )
-endfunction()
+ if(NOT TARGET cpprestsdk_websocketpp_internal)
+ add_library(cpprestsdk_websocketpp_internal INTERFACE)
+ target_include_directories(cpprestsdk_websocketpp_internal INTERFACE "${CONAN_INCLUDE_DIRS_WEBSOCKETPP}")
+ target_link_libraries(cpprestsdk_websocketpp_internal INTERFACE "${CONAN_LIBS_WEBSOCKETPP}")
+ endif()
+endfunction()
\ No newline at end of file
28 changes: 28 additions & 0 deletions recipes/cpprestsdk/all/patches/0002-remove-wconversion.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
diff --git a/Release/CMakeLists.txt b/Release/CMakeLists.txt
index 18b0cb3..03d16a1 100644
--- a/Release/CMakeLists.txt
+++ b/Release/CMakeLists.txt
@@ -146,12 +146,12 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR IOS)
if(ANDROID)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-pedantic -Wno-attributes -Wno-pointer-arith")
elseif(CMAKE_SYSTEM_NAME MATCHES "Linux")
- set(WARNINGS -Wall -Wextra -Wcast-qual -Wconversion -Wformat=2 -Winit-self -Winvalid-pch -Wmissing-format-attribute -Wmissing-include-dirs -Wpacked -Wredundant-decls)
+ set(WARNINGS -Wall -Wextra -Wcast-qual -Wformat=2 -Winit-self -Winvalid-pch -Wmissing-format-attribute -Wmissing-include-dirs -Wpacked -Wredundant-decls)
set(LINUX_SUPPRESSIONS -Wno-overloaded-virtual -Wno-sign-conversion -Wno-deprecated -Wno-unknown-pragmas -Wno-reorder -Wno-char-subscripts -Wno-switch -Wno-unused-parameter -Wno-unused-variable -Wno-deprecated -Wno-unused-value -Wno-unknown-warning-option -Wno-return-type-c-linkage -Wno-unused-function -Wno-sign-compare -Wno-shorten-64-to-32 -Wno-unused-local-typedefs)
set(WARNINGS ${WARNINGS} ${LINUX_SUPPRESSIONS})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-return-type-c-linkage -Wno-unneeded-internal-declaration")
else()
- set(WARNINGS -Wall -Wextra -Wcast-qual -Wconversion -Wformat=2 -Winit-self -Winvalid-pch -Wmissing-format-attribute -Wmissing-include-dirs -Wpacked -Wredundant-decls)
+ set(WARNINGS -Wall -Wextra -Wcast-qual -Wformat=2 -Winit-self -Winvalid-pch -Wmissing-format-attribute -Wmissing-include-dirs -Wpacked -Wredundant-decls)
set(OSX_SUPPRESSIONS -Wno-overloaded-virtual -Wno-sign-conversion -Wno-deprecated -Wno-unknown-pragmas -Wno-reorder -Wno-char-subscripts -Wno-switch -Wno-unused-parameter -Wno-unused-variable -Wno-deprecated -Wno-unused-value -Wno-unknown-warning-option -Wno-return-type-c-linkage -Wno-unused-function -Wno-sign-compare -Wno-shorten-64-to-32 -Wno-unused-local-typedefs)
set(WARNINGS ${WARNINGS} ${OSX_SUPPRESSIONS})

@@ -165,7 +165,7 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR IOS)
elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
message("-- Setting gcc options")

- set(WARNINGS -Wall -Wextra -Wunused-parameter -Wcast-align -Wcast-qual -Wconversion -Wformat=2 -Winit-self -Winvalid-pch -Wmissing-format-attribute -Wmissing-include-dirs -Wpacked -Wredundant-decls -Wunreachable-code)
+ set(WARNINGS -Wall -Wextra -Wunused-parameter -Wcast-align -Wcast-qual -Wformat=2 -Winit-self -Winvalid-pch -Wmissing-format-attribute -Wmissing-include-dirs -Wpacked -Wredundant-decls -Wunreachable-code)
set(LD_FLAGS "${LD_FLAGS} -Wl,-z,defs")

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -fno-strict-aliasing")
9 changes: 9 additions & 0 deletions recipes/cpprestsdk/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
cmake_minimum_required(VERSION 2.8.11)
project(test_package)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()

add_executable(${PROJECT_NAME} test_package.cpp)
target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS})
set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 11)
17 changes: 17 additions & 0 deletions recipes/cpprestsdk/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import os
from conans import ConanFile, CMake, tools


class TestPackageConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "cmake"

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def test(self):
if not tools.cross_building(self.settings):
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)
6 changes: 6 additions & 0 deletions recipes/cpprestsdk/all/test_package/test_package.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include <cpprest/json.h>

int main()
{
const auto parsed_value = web::json::value::parse(U("-22"));
}
3 changes: 3 additions & 0 deletions recipes/cpprestsdk/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
versions:
"2.10.15":
folder: "all"

0 comments on commit 41f9410

Please sign in to comment.