fixes: https://github.com/Azure/azure-sdk-for-cpp/issues/1041

Make nlohmann a 3rd party required lib. Do not fetch it with CMake if it is not found
This commit is contained in:
Victor Vazquez 2020-12-02 17:52:56 -08:00 коммит произвёл GitHub
Родитель 46ce66d150
Коммит c3afb7798f
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
4 изменённых файлов: 26 добавлений и 45 удалений

Просмотреть файл

@ -1,27 +0,0 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# SPDX-License-Identifier: MIT
#
# Azure Core can expose the Nlohmann Json header by fetching a release version and including the header to the include path.
#
# Azure Core will try to find the json header first. This is for an application that is already using Nlohmann header.
# When it is not found it, Azure Core will fetch it.
# Storage requires 3.6.0 version for using `contains` feature
# Using QUIET to avoid warning message if lib is not found
find_package(nlohmann_json 3.6.0 EXACT QUIET)
if (NOT nlohmann_json_FOUND)
include(FetchContent)
# release code only. This save us from getting the entire nlohmann source code.
FetchContent_Declare(json
GIT_REPOSITORY https://github.com/ArthurSonzogni/nlohmann_json_cmake_fetchcontent
GIT_TAG v3.8.0)
FetchContent_GetProperties(json)
if (NOT json_POPULATED)
FetchContent_Populate(json)
add_subdirectory(${json_SOURCE_DIR} ${json_BINARY_DIR} EXCLUDE_FROM_ALL)
endif()
endif()

Просмотреть файл

@ -13,46 +13,46 @@ jobs:
matrix:
Linux_x64_gcc8:
OSVmImage: 'ubuntu-18.04'
VcpkgInstall: 'curl[ssl] libxml2 openssl'
VcpkgInstall: 'curl[ssl] libxml2 openssl nlohmann-json'
VCPKG_DEFAULT_TRIPLET: 'x64-linux'
CC: '/usr/bin/gcc-8'
CXX: '/usr/bin/g++-8'
BuildArgs: '-j 10'
Linux_x64_gcc9:
OSVmImage: 'ubuntu-18.04'
VcpkgInstall: 'curl[ssl] libxml2 openssl'
VcpkgInstall: 'curl[ssl] libxml2 openssl nlohmann-json'
VCPKG_DEFAULT_TRIPLET: 'x64-linux'
CC: '/usr/bin/gcc-9'
CXX: '/usr/bin/g++-9'
BuildArgs: '-j 10'
Linux_x64:
OSVmImage: 'ubuntu-18.04'
VcpkgInstall: 'curl[ssl] libxml2 openssl'
VcpkgInstall: 'curl[ssl] libxml2 openssl nlohmann-json'
VCPKG_DEFAULT_TRIPLET: 'x64-linux'
BuildArgs: '-j 10'
Win_x86:
OSVmImage: 'windows-2019'
VcpkgInstall: 'curl[winssl] libxml2'
VcpkgInstall: 'curl[winssl] libxml2 nlohmann-json'
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'
VcpkgInstall: 'curl[winssl] libxml2 nlohmann-json'
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'
VcpkgInstall: 'curl[ssl] libxml2 openssl nlohmann-json'
VCPKG_DEFAULT_TRIPLET: 'x64-osx'
# Unit testing ON
Linux_x64_with_unit_test:
OSVmImage: 'ubuntu-18.04'
VcpkgInstall: 'curl[ssl] libxml2 openssl'
VcpkgInstall: 'curl[ssl] libxml2 openssl nlohmann-json'
VCPKG_DEFAULT_TRIPLET: 'x64-linux'
CmakeArgs: ' -DBUILD_TESTING=ON -DRUN_LONG_UNIT_TESTS=ON -DCMAKE_BUILD_TYPE=Debug -DBUILD_CODE_COVERAGE=ON'
AptDependencies: 'gcovr lcov'
@ -62,21 +62,21 @@ jobs:
BuildArgs: '-j 10'
Win_x86_with_unit_test:
OSVmImage: 'windows-2019'
VcpkgInstall: 'curl[winssl] libxml2'
VcpkgInstall: 'curl[winssl] libxml2 nlohmann-json'
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 -DBUILD_TRANSPORT_CURL=ON'
Win_x64_with_unit_test:
OSVmImage: 'windows-2019'
VcpkgInstall: 'curl[winssl] libxml2'
VcpkgInstall: 'curl[winssl] libxml2 nlohmann-json'
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 -DBUILD_TRANSPORT_CURL=ON'
MacOS_x64_with_unit_test:
OSVmImage: 'macOS-10.14'
VcpkgInstall: 'curl[ssl] libxml2 openssl'
VcpkgInstall: 'curl[ssl] libxml2 openssl nlohmann-json'
VCPKG_DEFAULT_TRIPLET: 'x64-osx'
CmakeArgs: ' -DBUILD_TESTING=ON -DRUN_LONG_UNIT_TESTS=ON -DBUILD_TRANSPORT_CURL=ON'
pool:
@ -139,7 +139,7 @@ jobs:
vmImage: $(OSVmImage)
variables:
OSVmImage: windows-2019
VcpkgDependencies: curl[winssl] libxml2
VcpkgDependencies: curl[winssl] libxml2 nlohmann-json
VCPKG_DEFAULT_TRIPLET: 'x64-windows-static'
steps:
- template: /eng/common/pipelines/templates/steps/verify-links.yml

Просмотреть файл

@ -25,7 +25,7 @@ jobs:
matrix:
Linux_x64_with_unit_test:
OSVmImage: 'ubuntu-18.04'
VcpkgInstall: 'curl[ssl] libxml2 openssl'
VcpkgInstall: 'curl[ssl] libxml2 openssl nlohmann-json'
VCPKG_DEFAULT_TRIPLET: 'x64-linux'
CmakeArgs: ' -DBUILD_TESTING=ON -DRUN_LONG_UNIT_TESTS=ON -DCMAKE_BUILD_TYPE=Debug -DBUILD_CODE_COVERAGE=ON'
AptDependencies: 'gcovr lcov'
@ -34,21 +34,21 @@ jobs:
CODE_COVERAGE_COLLECT_ONLY: 1
Win_x86_with_unit_test:
OSVmImage: 'windows-2019'
VcpkgInstall: 'curl[winssl] libxml2'
VcpkgInstall: 'curl[winssl] libxml2 nlohmann-json'
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'
Win_x64_with_unit_test:
OSVmImage: 'windows-2019'
VcpkgInstall: 'curl[winssl] libxml2'
VcpkgInstall: 'curl[winssl] libxml2 nlohmann-json'
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'
MacOS_x64_with_unit_test:
OSVmImage: 'macOS-10.14'
VcpkgInstall: 'curl[ssl] libxml2 openssl'
VcpkgInstall: 'curl[ssl] libxml2 openssl nlohmann-json'
VCPKG_DEFAULT_TRIPLET: 'x64-osx'
CmakeArgs: ' -DBUILD_TESTING=ON -DRUN_LONG_UNIT_TESTS=ON'
pool:

Просмотреть файл

@ -21,6 +21,17 @@ if(NOT CURL_FOUND)
endif()
message("Libcurl version ${CURL_VERSION_STRING}")
# Storage requires 3.6.0 version for using `contains` feature
set(NLOHMANN_JSON_MIN_REQUIRED_VERSION 3.6.0)
# Try to find the config cmake file. Tipically for when the integration is made at CMake level
# (CMake project available with a configuration file to consume)
find_package(nlohmann_json ${NLOHMANN_JSON_MIN_REQUIRED_VERSION} CONFIG)
if(NOT nlohmann_json_FOUND)
# If CMake project/config is not found, last option is to find the library installed. The integration is done by the linker directly.
find_package(nlohmann_json ${NLOHMANN_JSON_MIN_REQUIRED_VERSION} REQUIRED)
endif()
message("nlohmann json version ${nlohmann_json_VERSION}")
if(BUILD_TRANSPORT_CURL)
SET(CURL_TRANSPORT_ADAPTER_SRC src/http/curl/curl.cpp)
endif()
@ -31,9 +42,6 @@ endif()
# CodeCoverage will validate requirements
include(CodeCoverage)
# nlohmann JSON
include(add_nlohmann_json)
add_library (
${TARGET_NAME}
src/context.cpp