2023-07-13 08:37:36 +03:00
|
|
|
# Copyright (c) Microsoft Corporation.
|
|
|
|
# Licensed under the MIT License.
|
2020-02-20 23:10:01 +03:00
|
|
|
|
2020-10-10 02:26:01 +03:00
|
|
|
cmake_minimum_required (VERSION 3.13)
|
2020-08-13 19:37:55 +03:00
|
|
|
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake-modules")
|
2020-02-20 23:10:01 +03:00
|
|
|
|
2020-12-11 22:53:37 +03:00
|
|
|
# Variable to indicate whether the entire SDK is being built, as opposed to an individual library.
|
|
|
|
set(AZ_ALL_LIBRARIES ON)
|
|
|
|
|
2020-03-18 20:58:28 +03:00
|
|
|
# Compile Options
|
2022-01-22 00:13:15 +03:00
|
|
|
include(FolderList)
|
|
|
|
SetGlobalOptions()
|
|
|
|
|
|
|
|
if(FETCH_SOURCE_DEPS)
|
|
|
|
message(FATAL_ERROR, "FETCH_SOURCE_DEPS flag not for global use, instead use when building individual components")
|
|
|
|
return()
|
|
|
|
endif()
|
2020-02-20 23:10:01 +03:00
|
|
|
|
2021-01-28 05:55:46 +03:00
|
|
|
include(AzureTransportAdapters)
|
2021-02-06 08:19:28 +03:00
|
|
|
include(AzureVcpkg)
|
2022-01-20 21:09:06 +03:00
|
|
|
include(AzureBuildTargetForCI)
|
2020-10-10 03:08:57 +03:00
|
|
|
|
2021-02-06 08:19:28 +03:00
|
|
|
az_vcpkg_integrate()
|
2020-02-20 23:10:01 +03:00
|
|
|
|
2020-03-18 20:58:28 +03:00
|
|
|
# Project definition
|
2020-12-09 15:02:29 +03:00
|
|
|
project(azure-sdk LANGUAGES CXX)
|
2020-03-26 21:38:07 +03:00
|
|
|
set(CMAKE_CXX_STANDARD 14)
|
2020-02-20 23:10:01 +03:00
|
|
|
set(CMAKE_CXX_STANDARD_REQUIRED True)
|
|
|
|
|
2023-05-10 23:58:39 +03:00
|
|
|
# Enable a build configuration to disable features when building for Windows Store.
|
|
|
|
message(STATUS "CMAKE_SYSTEM_NAME=" ${CMAKE_SYSTEM_NAME} ";")
|
|
|
|
message(STATUS "VCPKG_TARGET_TRIPLET=" ${VCPKG_TARGET_TRIPLET} ";")
|
|
|
|
|
|
|
|
# In the CI pipeline, for <reasons>, CMAKE_SYSTEM_NAME is set to "Windows" even when building for Windows Store.
|
|
|
|
# use the CMAKE triplet to detect the windows store build.
|
|
|
|
if ((${VCPKG_TARGET_TRIPLET} MATCHES ".*-uwp"))
|
|
|
|
set(BUILD_WINDOWS_UWP True)
|
|
|
|
message(STATUS "Building for Windows Store, CMAKE_SYSTEM_NAME=" ${CMAKE_SYSTEM_NAME})
|
|
|
|
endif()
|
|
|
|
|
2021-02-23 20:38:24 +03:00
|
|
|
if(MSVC_USE_STATIC_CRT AND MSVC)
|
|
|
|
# 1. More about static/shared CRT:
|
|
|
|
# https://docs.microsoft.com/cpp/build/reference/md-mt-ld-use-run-time-library?view=msvc-160
|
|
|
|
#
|
|
|
|
# 2. MSVC_USE_STATIC_CRT build flag approach is used/inspired by libcurl
|
|
|
|
# (https://github.com/curl/curl/blob/master/CMakeLists.txt) and some other projects.
|
|
|
|
#
|
|
|
|
# 3. GTest would emit the following warning:
|
|
|
|
# warning LNK4098: defaultlib 'LIBCMTD' conflicts with use of other libs; use /NODEFAULTLIB:library
|
|
|
|
# AddGoogleTest.cmake uses gtest_force_shared_crt
|
|
|
|
# (see https://github.com/google/googletest/blob/master/googletest/README.md),
|
|
|
|
# which respects linker settings that we set below, and our settings below are all in sync.
|
|
|
|
#
|
|
|
|
# 4. Sometimes, the following approach is recommended instead:
|
|
|
|
# +-----------------------------------------------------------------------------------+
|
|
|
|
# | # Use the static runtime libraries when building statically |
|
Fix true spelling errors across all source and header files within the SDK and add exceptions for false positives. (#2209)
Part of https://github.com/Azure/azure-sdk-for-cpp/issues/1277, checking what types of warnings the CI emits.
Verified all SDK product `.cpp`, `.hpp`, `.txt`, and `.md` files, primarily focused on azure-core. They are all clean now. There are some exceptions that needs to be added for keyvault and storage, but they are false positives, so not a concern.
> `cspell lint --config .vscode/cspell.json *.hpp */**/*.hpp`
CSpell: Files checked: 188, Issues found: 0 in 0 files
> `cspell lint --config .vscode/cspell.json *.cpp */**/*.cpp`
CSpell: Files checked: 186, Issues found: 88 in 15 files (keyvault and storage false positives, or tests)
> `cspell lint --config .vscode/cspell.json *.md */**/*.md`
CSpell: Files checked: 45, Issues found: 5 in 2 files (eng/common)
> `cspell lint --config .vscode/cspell.json *.txt */**/*.txt`
CSpell: Files checked: 44, Issues found: 0 in 0 files
> `cspell lint --config .vscode/cspell.json *.* */**/*`
CSpell: Files checked: 646, Issues found: 328 in 69 files (most of these are in eng\docs\api\assets\style.css or eng/common)
Deprioritize and ignored the errors from the test files (including test resource json files), and `eng/common` since those need to be centrally fixed.
2021-05-08 00:04:58 +03:00
|
|
|
# | # for consistency with the vcpkg arch-windows-static triplets: |
|
2021-02-23 20:38:24 +03:00
|
|
|
# | cmake_policy(SET CMP0091 NEW) |
|
|
|
|
# | # see https://cmake.org/cmake/help/v3.15/variable/CMAKE_MSVC_RUNTIME_LIBRARY.html |
|
|
|
|
# | if (NOT DEFINED CMAKE_MSVC_RUNTIME_LIBRARY) |
|
|
|
|
# | set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>") |
|
|
|
|
# | endif() |
|
|
|
|
# +-----------------------------------------------------------------------------------+
|
|
|
|
# However, it only works when cmake installed is 3.15+;
|
|
|
|
# we have to require a minimum of 3.13.
|
|
|
|
#
|
|
|
|
# 5. We "replace with empty string" (i.e. remove) first, then add, so that '/MT'
|
|
|
|
# will be present (and present once) even if '/MD' was not.
|
2022-05-24 02:44:22 +03:00
|
|
|
message(STATUS "Configuring Static Runtime Library.")
|
|
|
|
if(${CMAKE_CXX_FLAGS} MATCHES ".*/MD.*")
|
2021-02-23 20:38:24 +03:00
|
|
|
string(REGEX REPLACE "/MD" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MT")
|
2022-05-24 02:44:22 +03:00
|
|
|
endif()
|
2021-02-23 20:38:24 +03:00
|
|
|
|
2022-05-24 02:44:22 +03:00
|
|
|
if(${CMAKE_CXX_FLAGS_RELEASE} MATCHES ".*/MD.*")
|
2021-02-23 20:38:24 +03:00
|
|
|
string(REGEX REPLACE "/MD" "" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
|
|
|
|
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT")
|
2022-05-24 02:44:22 +03:00
|
|
|
endif()
|
|
|
|
|
|
|
|
if(${CMAKE_CXX_FLAGS_RELWITHDEBINFO} MATCHES ".*/MD.*")
|
2021-02-23 20:38:24 +03:00
|
|
|
string(REGEX REPLACE "/MD" "" CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
|
|
|
|
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} /MT")
|
2022-05-24 02:44:22 +03:00
|
|
|
endif()
|
2021-02-23 20:38:24 +03:00
|
|
|
|
2022-05-24 02:44:22 +03:00
|
|
|
if(${CMAKE_CXX_FLAGS_MINSIZEREL} MATCHES ".*/MD.*")
|
2021-02-23 20:38:24 +03:00
|
|
|
string(REGEX REPLACE "/MD" "" CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL}")
|
|
|
|
set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} /MT")
|
2022-05-24 02:44:22 +03:00
|
|
|
endif()
|
2021-02-23 20:38:24 +03:00
|
|
|
|
2022-05-24 02:44:22 +03:00
|
|
|
if(${CMAKE_CXX_FLAGS_DEBUG} MATCHES ".*/MD.*")
|
2021-02-23 20:38:24 +03:00
|
|
|
string(REGEX REPLACE "/MDd" "" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")
|
|
|
|
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd")
|
2022-05-24 02:44:22 +03:00
|
|
|
endif()
|
2021-02-23 20:38:24 +03:00
|
|
|
endif()
|
|
|
|
|
2020-03-26 21:38:07 +03:00
|
|
|
if(BUILD_TESTING)
|
2021-02-23 08:55:12 +03:00
|
|
|
include(AddGoogleTest)
|
|
|
|
enable_testing ()
|
2020-03-26 21:38:07 +03:00
|
|
|
endif()
|
|
|
|
|
|
|
|
# compiler warning flags globally
|
2021-01-28 05:55:46 +03:00
|
|
|
include(AzureGlobalCompileOptions)
|
2020-03-18 20:58:28 +03:00
|
|
|
|
2022-01-04 00:56:41 +03:00
|
|
|
# Add create_map_file function
|
|
|
|
include(CreateMapFile)
|
|
|
|
|
2020-06-26 20:42:48 +03:00
|
|
|
# Documentation automation function
|
2021-01-28 05:55:46 +03:00
|
|
|
include(AzureDoxygen)
|
2020-06-26 20:42:48 +03:00
|
|
|
|
2020-09-03 04:53:46 +03:00
|
|
|
# Functions for library versions
|
2021-01-28 05:55:46 +03:00
|
|
|
include(AzureVersion)
|
2020-09-03 04:53:46 +03:00
|
|
|
|
Encapsulate getenv(), and make it work on UWP (#3275)
It all started with UWP. The [docs](https://docs.microsoft.com/en-us/cpp/cppcx/crt-functions-not-supported-in-universal-windows-platform-apps?view=msvc-170) say: "`Environment variables are not available to UWP apps.`". And it truly won't work, I tried: linker error, the function is simply not present.
So, for a year or so, we were `ifdef`ing everything enivoronment-related: console logger, environment credential, managed identity credential.
And then just recently we wanted to enable our CI for UWP, including tests and samples. And it required to do more ifdefs (in vcpkg, we don't build samples or tests, so that problem did not exist).
It just became more messy. Especially in samples - you can see how we would disable warning with `#pragma warning(disable : 4996)` or defining `_CRT_SECURE_NO_WARNINGS` already, but now came UWP, so we would have to add comment that `getenv()` is not available and make the sample compilation to either fail with clear message, or throw an exception. Plus we would have to detect that we are being compiled on UWP, which also adds visual clutter for reader. You can see how such an irrelevant (for a sample) thing as `getenv` was consuming more and more lines of sample code and reader's attention.
But then! I read docs on more APIs for UWP. And I noticed that on .NET you can read environment variables. So I went and checked Win32 API docs for [GetEnvironmentVariable()](https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-getenvironmentvariable) - it says: "`Minimum supported client: ... UWP apps`".
**GetEnvironmentVariable() works on UWP!**
And so does `SetEnvironmentVariable()` (our tests use it, which means we can make all of them work and execute for UWP).
That's good news, but now it would probably be more code: it usually takes more lines to invoke WinAPI, it is no more an one-liner to call `getenv()/setenv()`. So, I encapsulated that into `Azure::Core::_internal::Environment::GetVariable()` and `SetVariable()`. You can see how much less ifdefs is in our code now. Not to mention it works on UWP!
Per team request, that API is SDK-internal. Samples use their own mini-helper project, `get-env-helper` that makes is so that `getenv()` works naturally on Linux and macOS, compiles without warnings and works on Win32, and compiles and works on UWP (using `GetEnvironmentStringsA()`)
If it was for me, I would just make `Azure::Core::Environment::GetVariable()` public and simplify even further, I think it would be beneficial for sample readers (you can see that extra `get-env-helper` stuff adds just a little more visual clutter, compared to nothing). But I can see reasons against that, why team did not want to do it.
2022-01-29 11:22:33 +03:00
|
|
|
if(BUILD_SAMPLES)
|
|
|
|
add_subdirectory(samples/helpers/get-env)
|
2022-05-11 07:08:40 +03:00
|
|
|
add_subdirectory(samples/helpers/service)
|
Encapsulate getenv(), and make it work on UWP (#3275)
It all started with UWP. The [docs](https://docs.microsoft.com/en-us/cpp/cppcx/crt-functions-not-supported-in-universal-windows-platform-apps?view=msvc-170) say: "`Environment variables are not available to UWP apps.`". And it truly won't work, I tried: linker error, the function is simply not present.
So, for a year or so, we were `ifdef`ing everything enivoronment-related: console logger, environment credential, managed identity credential.
And then just recently we wanted to enable our CI for UWP, including tests and samples. And it required to do more ifdefs (in vcpkg, we don't build samples or tests, so that problem did not exist).
It just became more messy. Especially in samples - you can see how we would disable warning with `#pragma warning(disable : 4996)` or defining `_CRT_SECURE_NO_WARNINGS` already, but now came UWP, so we would have to add comment that `getenv()` is not available and make the sample compilation to either fail with clear message, or throw an exception. Plus we would have to detect that we are being compiled on UWP, which also adds visual clutter for reader. You can see how such an irrelevant (for a sample) thing as `getenv` was consuming more and more lines of sample code and reader's attention.
But then! I read docs on more APIs for UWP. And I noticed that on .NET you can read environment variables. So I went and checked Win32 API docs for [GetEnvironmentVariable()](https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-getenvironmentvariable) - it says: "`Minimum supported client: ... UWP apps`".
**GetEnvironmentVariable() works on UWP!**
And so does `SetEnvironmentVariable()` (our tests use it, which means we can make all of them work and execute for UWP).
That's good news, but now it would probably be more code: it usually takes more lines to invoke WinAPI, it is no more an one-liner to call `getenv()/setenv()`. So, I encapsulated that into `Azure::Core::_internal::Environment::GetVariable()` and `SetVariable()`. You can see how much less ifdefs is in our code now. Not to mention it works on UWP!
Per team request, that API is SDK-internal. Samples use their own mini-helper project, `get-env-helper` that makes is so that `getenv()` works naturally on Linux and macOS, compiles without warnings and works on Win32, and compiles and works on UWP (using `GetEnvironmentStringsA()`)
If it was for me, I would just make `Azure::Core::Environment::GetVariable()` public and simplify even further, I think it would be beneficial for sample readers (you can see that extra `get-env-helper` stuff adds just a little more visual clutter, compared to nothing). But I can see reasons against that, why team did not want to do it.
2022-01-29 11:22:33 +03:00
|
|
|
endif()
|
|
|
|
|
2020-03-18 20:58:28 +03:00
|
|
|
# sub-projects
|
2021-01-30 08:53:16 +03:00
|
|
|
add_subdirectory(sdk/core)
|
2022-02-16 20:15:18 +03:00
|
|
|
add_subdirectory(sdk/attestation)
|
2023-05-10 23:58:39 +03:00
|
|
|
# AMQP doesn't work for UWP yet, and eventhubs depends on AMQP, so we cannot include eventhubs on UWP.
|
|
|
|
if (NOT BUILD_WINDOWS_UWP)
|
|
|
|
add_subdirectory(sdk/eventhubs)
|
|
|
|
endif()
|
2021-01-30 08:53:16 +03:00
|
|
|
add_subdirectory(sdk/identity)
|
2021-01-16 03:50:44 +03:00
|
|
|
add_subdirectory(sdk/keyvault)
|
2021-01-30 08:53:16 +03:00
|
|
|
add_subdirectory(sdk/storage)
|
|
|
|
add_subdirectory(sdk/template)
|
Encapsulate getenv(), and make it work on UWP (#3275)
It all started with UWP. The [docs](https://docs.microsoft.com/en-us/cpp/cppcx/crt-functions-not-supported-in-universal-windows-platform-apps?view=msvc-170) say: "`Environment variables are not available to UWP apps.`". And it truly won't work, I tried: linker error, the function is simply not present.
So, for a year or so, we were `ifdef`ing everything enivoronment-related: console logger, environment credential, managed identity credential.
And then just recently we wanted to enable our CI for UWP, including tests and samples. And it required to do more ifdefs (in vcpkg, we don't build samples or tests, so that problem did not exist).
It just became more messy. Especially in samples - you can see how we would disable warning with `#pragma warning(disable : 4996)` or defining `_CRT_SECURE_NO_WARNINGS` already, but now came UWP, so we would have to add comment that `getenv()` is not available and make the sample compilation to either fail with clear message, or throw an exception. Plus we would have to detect that we are being compiled on UWP, which also adds visual clutter for reader. You can see how such an irrelevant (for a sample) thing as `getenv` was consuming more and more lines of sample code and reader's attention.
But then! I read docs on more APIs for UWP. And I noticed that on .NET you can read environment variables. So I went and checked Win32 API docs for [GetEnvironmentVariable()](https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-getenvironmentvariable) - it says: "`Minimum supported client: ... UWP apps`".
**GetEnvironmentVariable() works on UWP!**
And so does `SetEnvironmentVariable()` (our tests use it, which means we can make all of them work and execute for UWP).
That's good news, but now it would probably be more code: it usually takes more lines to invoke WinAPI, it is no more an one-liner to call `getenv()/setenv()`. So, I encapsulated that into `Azure::Core::_internal::Environment::GetVariable()` and `SetVariable()`. You can see how much less ifdefs is in our code now. Not to mention it works on UWP!
Per team request, that API is SDK-internal. Samples use their own mini-helper project, `get-env-helper` that makes is so that `getenv()` works naturally on Linux and macOS, compiles without warnings and works on Win32, and compiles and works on UWP (using `GetEnvironmentStringsA()`)
If it was for me, I would just make `Azure::Core::Environment::GetVariable()` public and simplify even further, I think it would be beneficial for sample readers (you can see that extra `get-env-helper` stuff adds just a little more visual clutter, compared to nothing). But I can see reasons against that, why team did not want to do it.
2022-01-29 11:22:33 +03:00
|
|
|
|
|
|
|
if(BUILD_SAMPLES)
|
2022-03-17 22:20:15 +03:00
|
|
|
add_subdirectory(samples/integration/vcpkg-all-smoke)
|
Encapsulate getenv(), and make it work on UWP (#3275)
It all started with UWP. The [docs](https://docs.microsoft.com/en-us/cpp/cppcx/crt-functions-not-supported-in-universal-windows-platform-apps?view=msvc-170) say: "`Environment variables are not available to UWP apps.`". And it truly won't work, I tried: linker error, the function is simply not present.
So, for a year or so, we were `ifdef`ing everything enivoronment-related: console logger, environment credential, managed identity credential.
And then just recently we wanted to enable our CI for UWP, including tests and samples. And it required to do more ifdefs (in vcpkg, we don't build samples or tests, so that problem did not exist).
It just became more messy. Especially in samples - you can see how we would disable warning with `#pragma warning(disable : 4996)` or defining `_CRT_SECURE_NO_WARNINGS` already, but now came UWP, so we would have to add comment that `getenv()` is not available and make the sample compilation to either fail with clear message, or throw an exception. Plus we would have to detect that we are being compiled on UWP, which also adds visual clutter for reader. You can see how such an irrelevant (for a sample) thing as `getenv` was consuming more and more lines of sample code and reader's attention.
But then! I read docs on more APIs for UWP. And I noticed that on .NET you can read environment variables. So I went and checked Win32 API docs for [GetEnvironmentVariable()](https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-getenvironmentvariable) - it says: "`Minimum supported client: ... UWP apps`".
**GetEnvironmentVariable() works on UWP!**
And so does `SetEnvironmentVariable()` (our tests use it, which means we can make all of them work and execute for UWP).
That's good news, but now it would probably be more code: it usually takes more lines to invoke WinAPI, it is no more an one-liner to call `getenv()/setenv()`. So, I encapsulated that into `Azure::Core::_internal::Environment::GetVariable()` and `SetVariable()`. You can see how much less ifdefs is in our code now. Not to mention it works on UWP!
Per team request, that API is SDK-internal. Samples use their own mini-helper project, `get-env-helper` that makes is so that `getenv()` works naturally on Linux and macOS, compiles without warnings and works on Win32, and compiles and works on UWP (using `GetEnvironmentStringsA()`)
If it was for me, I would just make `Azure::Core::Environment::GetVariable()` public and simplify even further, I think it would be beneficial for sample readers (you can see that extra `get-env-helper` stuff adds just a little more visual clutter, compared to nothing). But I can see reasons against that, why team did not want to do it.
2022-01-29 11:22:33 +03:00
|
|
|
endif()
|