cmake updates for building transport adapters (#706)

Adding CMake module to enable/disable transport adapters

TRANSPORT ADAPTER BUILD  
Default: If no option is explicitly added, curl will be used for POSIX and WIN HTTP for WIndows 
 Windows: Both CURL and WIN_HTTP can be build to be used.                                        
POSIX: Only CURL is acceptable. If WIN_HTTP is set, generate step will fail for user            

Defines `BUILD_WIN_HTTP_TRANSPORT_ADAPTER` and `BUILD_CURL_HTTP_TRANSPORT_ADAPTER` for source code
 
Fixes #350
This commit is contained in:
Victor Vazquez 2020-10-09 17:08:57 -07:00 committed by GitHub
parent 2cc4ecdea8
commit cd2a8a3812
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 67 additions and 14 deletions

View File

@ -6,11 +6,14 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake-modules")
# Compile Options
option(WARNINGS_AS_ERRORS "Treat compiler warnings as errors" ON)
option(BUILD_CURL_TRANSPORT "Build internal http transport implementation with CURL for HTTP Pipeline" OFF)
option(BUILD_TRANSPORT_CURL "Build an HTTP transport implementation with CURL" OFF)
option(BUILD_TRANSPORT_WINHTTP "Build an HTTP transport implementation with WIN HTTP" OFF)
option(BUILD_TESTING "Build test cases" OFF)
option(BUILD_DOCUMENTATION "Create HTML based API documentation (requires Doxygen)" OFF)
option(RUN_LONG_UNIT_TESTS "Tests that takes more than 5 minutes to complete. No effect if BUILD_TESTING is OFF" OFF)
include(DefineTransportAdapter)
if(BUILD_TESTING)
# define a symbol that enables some test hooks in code
add_compile_definitions(TESTING_BUILD)
@ -58,8 +61,10 @@ include(${CMAKE_CURRENT_SOURCE_DIR}/cmake-modules/az_version.cmake)
# sub-projects
# add_subdirectory(sdk/core/performance-stress)
add_subdirectory(sdk/core/azure-core)
if(BUILD_CURL_TRANSPORT)
add_subdirectory(sdk/core/azure-core/test/e2e) # will work only if BUILD_CURL_TRANSPORT=ON
if(BUILD_TESTING)
add_subdirectory(sdk/core/azure-core/test/e2e)
endif()
add_subdirectory(sdk/storage)
add_subdirectory(sdk/template/azure-template)

View File

@ -4,10 +4,12 @@
"name": "x64-DebugWithTests",
"generator": "Ninja",
"configurationType": "Debug",
"inheritEnvironments": [ "msvc_x64_x64" ],
"inheritEnvironments": [
"msvc_x64_x64"
],
"buildRoot": "${projectDir}\\out\\build\\${name}",
"installRoot": "${projectDir}\\out\\install\\${name}",
"cmakeCommandArgs": "-DINSTALL_GTEST=OFF -DBUILD_TESTING=ON -DBUILD_CURL_TRANSPORT=ON -DBUILD_STORAGE_SAMPLES=ON",
"cmakeCommandArgs": "-DINSTALL_GTEST=OFF -DBUILD_TESTING=ON -DBUILD_TRANSPORT_CURL=ON -DBUILD_STORAGE_SAMPLES=ON",
"buildCommandArgs": "-v",
"ctestCommandArgs": "",
"variables": [
@ -27,7 +29,9 @@
"cmakeCommandArgs": "",
"buildCommandArgs": "",
"ctestCommandArgs": "",
"inheritEnvironments": [ "msvc_x86" ],
"inheritEnvironments": [
"msvc_x86"
],
"variables": [
{
"name": "VCPKG_TARGET_TRIPLET",

View File

@ -122,7 +122,7 @@ cmake --build .
```
If you want to run tests also, generate build files using below command and then build.
```sh
cmake -DBUILD_TESTING=ON -DBUILD_CURL_TRANSPORT=ON ..
cmake -DBUILD_TESTING=ON ..
cmake --build .
```
#### Testing the project

View File

@ -0,0 +1,29 @@
## Copyright (c) Microsoft Corporation. All rights reserved.
## SPDX-License-Identifier: MIT
############# TRANSPORT ADAPTER BUILD #####################
# Default: If no option is explicitly added, curl will be used for POSIX and WIN HTTP for Windows #
# Windows: Both CURL and WIN_HTTP can be built to be used. #
# POSIX: Only CURL is acceptable. If WIN_HTTP is set, generate step will fail for user #
# Defines `BUILD_TRANSPORT_WINHTTP_ADAPTER` and `BUILD_CURL_HTTP_TRANSPORT_ADAPTER` for source code
if (WIN32 OR MINGW OR MSYS OR CYGWIN)
if(BUILD_TRANSPORT_CURL)
add_compile_definitions(BUILD_CURL_HTTP_TRANSPORT_ADAPTER)
endif()
# Make sure to build WinHTTP either if was user-requested or no transport was selected at all
if(BUILD_TRANSPORT_WINHTTP OR NOT BUILD_TRANSPORT_CURL)
add_compile_definitions(BUILD_TRANSPORT_WINHTTP_ADAPTER)
SET(BUILD_TRANSPORT_WINHTTP ON)
endif()
elseif(UNIX)
if(BUILD_TRANSPORT_WINHTTP)
message(FATAL_ERROR "Win HTTP transport adapter is not supported for Unix platforms")
endif()
# regardless if CURL transport is set or not, it is always added for UNIX as default
add_compile_definitions(BUILD_CURL_HTTP_TRANSPORT_ADAPTER)
SET(BUILD_TRANSPORT_CURL ON)
else()
message(FATAL_ERROR "Unsupported platform")
endif ()

View File

@ -31,12 +31,14 @@ jobs:
VCPKG_DEFAULT_TRIPLET: 'x86-windows-static'
CMAKE_GENERATOR: 'Visual Studio 16 2019'
CMAKE_GENERATOR_PLATFORM: Win32
CmakeArgs: ' -DBUILD_TRANSPORT_CURL=ON' #ToBeRemoved once we have WinHttp Transport and Storage makes HTTP stack user-config
Win_x64:
OSVmImage: 'windows-2019'
VcpkgInstall: 'curl[winssl] libxml2'
VCPKG_DEFAULT_TRIPLET: 'x64-windows-static'
CMAKE_GENERATOR: 'Visual Studio 16 2019'
CMAKE_GENERATOR_PLATFORM: x64
CmakeArgs: ' -DBUILD_TRANSPORT_CURL=ON' #ToBeRemoved once we have WinHttp Transport and Storage makes HTTP stack user-config
MacOS_x64:
OSVmImage: 'macOS-10.14'
VcpkgInstall: 'curl[ssl] libxml2 openssl'
@ -54,19 +56,19 @@ jobs:
VCPKG_DEFAULT_TRIPLET: 'x86-windows-static'
CMAKE_GENERATOR: 'Visual Studio 16 2019'
CMAKE_GENERATOR_PLATFORM: Win32
CmakeArgs: ' -DBUILD_TESTING=ON -DRUN_LONG_UNIT_TESTS=ON'
CmakeArgs: ' -DBUILD_TESTING=ON -DRUN_LONG_UNIT_TESTS=ON -DBUILD_TRANSPORT_CURL=ON'
Win_x64_with_unit_test:
OSVmImage: 'windows-2019'
VcpkgInstall: 'curl[winssl] libxml2'
VCPKG_DEFAULT_TRIPLET: 'x64-windows-static'
CMAKE_GENERATOR: 'Visual Studio 16 2019'
CMAKE_GENERATOR_PLATFORM: x64
CmakeArgs: ' -DBUILD_TESTING=ON -DRUN_LONG_UNIT_TESTS=ON'
CmakeArgs: ' -DBUILD_TESTING=ON -DRUN_LONG_UNIT_TESTS=ON -DBUILD_TRANSPORT_CURL=ON'
MacOS_x64_with_unit_test:
OSVmImage: 'macOS-10.14'
VcpkgInstall: 'curl[ssl] libxml2 openssl'
VCPKG_DEFAULT_TRIPLET: 'x64-osx'
CmakeArgs: ' -DBUILD_TESTING=ON -DRUN_LONG_UNIT_TESTS=ON'
CmakeArgs: ' -DBUILD_TESTING=ON -DRUN_LONG_UNIT_TESTS=ON -DBUILD_TRANSPORT_CURL=ON'
pool:
vmImage: $(OSVmImage)
variables:
@ -130,7 +132,7 @@ jobs:
GenerateArgs: >-
-DINSTALL_GTEST=OFF
-DBUILD_TESTING=OFF
-DBUILD_CURL_TRANSPORT=OFF
-DBUILD_TRANSPORT_CURL=OFF
-DBUILD_DOCUMENTATION=YES
- pwsh: npm install -g moxygen

View File

@ -14,13 +14,20 @@ if(NOT CURL_FOUND)
find_package(CURL ${CURL_MIN_REQUIRED_VERSION} REQUIRED)
endif()
if(BUILD_TRANSPORT_CURL)
SET(CURL_TRANSPORT_ADAPTER_SRC src/http/curl/curl.cpp)
endif()
if(BUILD_TRANSPORT_WINHTTP)
SET(WIN_TRANSPORT_ADAPTER_SRC src/http/winhttp/win_http_transport.cpp)
endif()
add_library (
${TARGET_NAME}
src/context.cpp
src/credentials/credentials.cpp
src/credentials/policy/policies.cpp
src/http/body_stream.cpp
src/http/curl/curl.cpp
${CURL_TRANSPORT_ADAPTER_SRC}
src/http/http.cpp
src/http/logging_policy.cpp
src/http/policy.cpp
@ -30,7 +37,7 @@ add_library (
src/http/transport_policy.cpp
src/http/telemetry_policy.cpp
src/http/url.cpp
src/http/winhttp/win_http_transport.cpp
${BUILD_WIN_TRANSPORT}
src/logging/logging.cpp
src/strings.cpp
src/version.cpp)

View File

@ -6,6 +6,7 @@
*/
#pragma once
#ifdef BUILD_CURL_HTTP_TRANSPORT_ADAPTER
#include "azure/core/http/http.hpp"
#include "azure/core/http/policy.hpp"
@ -606,3 +607,5 @@ namespace Azure { namespace Core { namespace Http {
};
}}} // namespace Azure::Core::Http
#endif

View File

@ -6,6 +6,7 @@
*/
#pragma once
#ifdef BUILD_TRANSPORT_WINHTTP_ADAPTER
#include "azure/core/http/http.hpp"
#include "azure/core/http/policy.hpp"
@ -29,3 +30,5 @@ namespace Azure { namespace Core { namespace Http {
};
}}} // namespace Azure::Core::Http
#endif

View File

@ -1,7 +1,7 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# SPDX-License-Identifier: MIT
if (BUILD_CURL_TRANSPORT)
if (BUILD_TRANSPORT_CURL)
cmake_minimum_required (VERSION 3.13)
set(TARGET_NAME "azure_core_with_curl")