From b6adcf4a935d7e5288546aacb75f185ed4b73141 Mon Sep 17 00:00:00 2001 From: Steven Meyer <108885656+meyertst-aws@users.noreply.github.com> Date: Wed, 1 May 2024 11:03:07 -0400 Subject: [PATCH] Cpp: CodeBuild, update legacy code (#6386) --- .doc_gen/metadata/codebuild_metadata.yaml | 48 +++++ cpp/example_code/acm/CMakeLists.txt | 2 +- cpp/example_code/acm/tests/CMakeLists.txt | 20 ++- cpp/example_code/aurora/CMakeLists.txt | 2 +- .../aurora/hello_aurora/CMakeLists.txt | 2 +- cpp/example_code/aurora/tests/CMakeLists.txt | 21 +-- cpp/example_code/autoscaling/CMakeLists.txt | 37 ++-- .../hello_autoscaling/CMakeLists.txt | 2 +- .../autoscaling/tests/CMakeLists.txt | 36 ++-- cpp/example_code/cloudwatch/CMakeLists.txt | 44 ++--- cpp/example_code/codebuild/CMakeLists.txt | 80 ++++++--- cpp/example_code/codebuild/README.md | 9 + cpp/example_code/codebuild/build_project.cpp | 47 ----- .../codebuild/codebuild_samples.h | 45 +++++ cpp/example_code/codebuild/list_builds.cpp | 138 +++++++++----- cpp/example_code/codebuild/list_projects.cpp | 134 +++++++++----- cpp/example_code/codebuild/start_build.cpp | 86 +++++++++ .../codebuild/tests/CMakeLists.txt | 128 +++++++++++++ .../codebuild/tests/codebuild_gtests.cpp | 170 ++++++++++++++++++ .../codebuild/tests/codebuild_gtests.h | 69 +++++++ .../codebuild/tests/gtest_list_builds.cpp | 25 +++ .../codebuild/tests/gtest_list_projects.cpp | 25 +++ .../codebuild/tests/gtest_start_build.cpp | 33 ++++ .../tests/mock_input/StartBuild.json | 70 ++++++++ .../codebuild/tests/test_main.cpp | 9 + cpp/example_code/cognito/CMakeLists.txt | 29 +-- .../cognito/hello_cognito/CMakeLists.txt | 2 +- cpp/example_code/cognito/tests/CMakeLists.txt | 34 ++-- .../serverless-aurora/CMakeLists.txt | 34 ++-- .../serverless-aurora/tests/CMakeLists.txt | 47 +++-- .../topics_and_queues/CMakeLists.txt | 2 +- .../topics_and_queues/tests/CMakeLists.txt | 20 ++- cpp/example_code/dynamodb/CMakeLists.txt | 42 ++--- .../dynamodb/hello_dynamodb/CMakeLists.txt | 2 +- .../dynamodb/tests/CMakeLists.txt | 32 ++-- cpp/example_code/ec2/CMakeLists.txt | 18 +- cpp/example_code/ec2/hello_ec2/CMakeLists.txt | 2 +- cpp/example_code/ec2/tests/CMakeLists.txt | 42 +++-- cpp/example_code/glue/CMakeLists.txt | 40 ++--- .../glue/hello_glue/CMakeLists.txt | 2 +- cpp/example_code/glue/tests/CMakeLists.txt | 53 +++--- cpp/example_code/iam/CMakeLists.txt | 2 +- cpp/example_code/iam/hello_iam/CMakeLists.txt | 2 +- cpp/example_code/iam/tests/CMakeLists.txt | 21 +-- cpp/example_code/iot/CMakeLists.txt | 2 +- cpp/example_code/iot/hello_iot/CMakeLists.txt | 2 +- cpp/example_code/iot/tests/CMakeLists.txt | 20 ++- .../CMakeLists.txt | 2 +- 48 files changed, 1230 insertions(+), 504 deletions(-) delete mode 100644 cpp/example_code/codebuild/build_project.cpp create mode 100644 cpp/example_code/codebuild/codebuild_samples.h create mode 100644 cpp/example_code/codebuild/start_build.cpp create mode 100644 cpp/example_code/codebuild/tests/CMakeLists.txt create mode 100644 cpp/example_code/codebuild/tests/codebuild_gtests.cpp create mode 100644 cpp/example_code/codebuild/tests/codebuild_gtests.h create mode 100644 cpp/example_code/codebuild/tests/gtest_list_builds.cpp create mode 100644 cpp/example_code/codebuild/tests/gtest_list_projects.cpp create mode 100644 cpp/example_code/codebuild/tests/gtest_start_build.cpp create mode 100644 cpp/example_code/codebuild/tests/mock_input/StartBuild.json create mode 100644 cpp/example_code/codebuild/tests/test_main.cpp diff --git a/.doc_gen/metadata/codebuild_metadata.yaml b/.doc_gen/metadata/codebuild_metadata.yaml index 308496ab4cf..16622d3b9ca 100644 --- a/.doc_gen/metadata/codebuild_metadata.yaml +++ b/.doc_gen/metadata/codebuild_metadata.yaml @@ -16,3 +16,51 @@ codebuild_CreateProject: - javascript.v3.codebuild.actions.CreateProject services: codebuild: {CreateProject} +codebuild_ListBuilds: + title: List &ACB; builds + title_abbrev: List builds + synopsis: list &ACB; builds. + category: + languages: + C++: + versions: + - sdk_version: 1 + github: cpp/example_code/codebuild + excerpts: + - description: + snippet_tags: + - cpp.example_code.codebuild.ListBuilds + services: + codebuild: {ListBuilds} +codebuild_ListProjects: + title: List &ACB; projects + title_abbrev: List projects + synopsis: list &ACB; projects. + category: + languages: + C++: + versions: + - sdk_version: 1 + github: cpp/example_code/codebuild + excerpts: + - description: + snippet_tags: + - cpp.example_code.codebuild.ListProjects + services: + codebuild: {ListProjects} +codebuild_StartBuild: + title: Start an &ACB; build + title_abbrev: Start a build + synopsis: start an &ACB; build. + category: + languages: + C++: + versions: + - sdk_version: 1 + github: cpp/example_code/codebuild + excerpts: + - description: + snippet_tags: + - cpp.example_code.codebuild.StartBuild + services: + codebuild: {StartBuild} diff --git a/cpp/example_code/acm/CMakeLists.txt b/cpp/example_code/acm/CMakeLists.txt index 2edeca92c1d..5234e0eb7b7 100644 --- a/cpp/example_code/acm/CMakeLists.txt +++ b/cpp/example_code/acm/CMakeLists.txt @@ -29,7 +29,7 @@ endif () find_package(AWSSDK REQUIRED COMPONENTS ${SERVICE_COMPONENTS}) -if (WINDOWS_BUILD) +if (WINDOWS_BUILD AND AWSSDK_INSTALL_AS_SHARED_LIBS) # Copy relevant AWS SDK for C++ libraries into the current binary directory for running and debugging. # set(BIN_SUB_DIR "/Debug") # If you are building from the command line, you may need to uncomment this diff --git a/cpp/example_code/acm/tests/CMakeLists.txt b/cpp/example_code/acm/tests/CMakeLists.txt index e3cef6d297f..be8980475e8 100644 --- a/cpp/example_code/acm/tests/CMakeLists.txt +++ b/cpp/example_code/acm/tests/CMakeLists.txt @@ -51,15 +51,17 @@ add_executable( ) if (WINDOWS_BUILD) - # set(BIN_SUB_DIR "/Debug") # If you are building from the command line, you may need to uncomment this - # and set the proper subdirectory to the executables' location. - - # Copy relevant AWS SDK for C++ libraries into the current binary directory for running and debugging. - AWSSDK_CPY_DYN_LIBS( - CURRENT_TARGET_AWS_DEPENDENCIES - "" - ${CMAKE_CURRENT_BINARY_DIR} ${BIN_SUB_DIR} - ) + if (AWSSDK_INSTALL_AS_SHARED_LIBS) + # set(BIN_SUB_DIR "/Debug") # If you are building from the command line, you may need to uncomment this + # and set the proper subdirectory to the executables' location. + + # Copy relevant AWS SDK for C++ libraries into the current binary directory for running and debugging. + AWSSDK_CPY_DYN_LIBS( + CURRENT_TARGET_AWS_DEPENDENCIES + "" + ${CMAKE_CURRENT_BINARY_DIR} ${BIN_SUB_DIR} + ) + endif() add_custom_command( TARGET diff --git a/cpp/example_code/aurora/CMakeLists.txt b/cpp/example_code/aurora/CMakeLists.txt index f6cc48533af..d13e4a16296 100644 --- a/cpp/example_code/aurora/CMakeLists.txt +++ b/cpp/example_code/aurora/CMakeLists.txt @@ -34,7 +34,7 @@ find_package(AWSSDK REQUIRED COMPONENTS ${SERVICE_COMPONENTS}) # If the compiler is some version of Microsoft Visual C++, or another compiler simulating C++, # and building as shared libraries, then dynamically link to those shared libraries. -if(MSVC AND BUILD_SHARED_LIBS) +if(WINDOWS_BUILD AND AWSSDK_INSTALL_AS_SHARED_LIBS) add_definitions(-DUSE_IMPORT_EXPORT) # Copy relevant AWS SDK for C++ libraries into the current binary directory for running and debugging. diff --git a/cpp/example_code/aurora/hello_aurora/CMakeLists.txt b/cpp/example_code/aurora/hello_aurora/CMakeLists.txt index 3c893483d12..e3021d30417 100644 --- a/cpp/example_code/aurora/hello_aurora/CMakeLists.txt +++ b/cpp/example_code/aurora/hello_aurora/CMakeLists.txt @@ -26,7 +26,7 @@ endif () # Find the AWS SDK for C++ package. find_package(AWSSDK REQUIRED COMPONENTS ${SERVICE_COMPONENTS}) -if (WINDOWS_BUILD) +if (WINDOWS_BUILD AND AWSSDK_INSTALL_AS_SHARED_LIBS) # Copy relevant AWS SDK for C++ libraries into the current binary directory for running and debugging. # set(BIN_SUB_DIR "/Debug") # If you are building from the command line, you may need to uncomment this diff --git a/cpp/example_code/aurora/tests/CMakeLists.txt b/cpp/example_code/aurora/tests/CMakeLists.txt index 651fab92ca2..0e47d58fb32 100644 --- a/cpp/example_code/aurora/tests/CMakeLists.txt +++ b/cpp/example_code/aurora/tests/CMakeLists.txt @@ -48,16 +48,17 @@ add_executable( # If the compiler is some version of Microsoft Visual C++, or another compiler simulating C++, # and building as shared libraries, then dynamically link to those shared libraries. if (MSVC AND BUILD_SHARED_LIBS) - add_definitions(-DUSE_IMPORT_EXPORT) - - set(CMAKE_BUILD_TYPE Debug) #Explicitly setting CMAKE_BUILD_TYPE is necessary in Windows to copy DLLs. - - # Copy relevant AWS SDK for C++ libraries into the current binary directory for running and debugging. - AWSSDK_CPY_DYN_LIBS( - CURRENT_TARGET_AWS_DEPENDENCIES - "" - ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE} - ) + if (AWSSDK_INSTALL_AS_SHARED_LIBS) + # set(BIN_SUB_DIR "/Debug") # If you are building from the command line, you may need to uncomment this + # and set the proper subdirectory to the executables' location. + + # Copy relevant AWS SDK for C++ libraries into the current binary directory for running and debugging. + AWSSDK_CPY_DYN_LIBS( + CURRENT_TARGET_AWS_DEPENDENCIES + "" + ${CMAKE_CURRENT_BINARY_DIR} ${BIN_SUB_DIR} + ) + endif () add_custom_command( TARGET diff --git a/cpp/example_code/autoscaling/CMakeLists.txt b/cpp/example_code/autoscaling/CMakeLists.txt index efa094f0def..8647eee2537 100644 --- a/cpp/example_code/autoscaling/CMakeLists.txt +++ b/cpp/example_code/autoscaling/CMakeLists.txt @@ -10,11 +10,17 @@ set(SERVICE_COMPONENTS autoscaling ec2 monitoring) # Set this project's name. project("${SERVICE_NAME}-examples") +# Build shared libraries by default. +set(BUILD_SHARED_LIBS ON) + +# Use the MSVC variable to determine if this is a Windows build. +set(WINDOWS_BUILD ${MSVC}) + # Set the location of where Windows can find the installed libraries of the SDK. -if(MSVC) +if (WINDOWS_BUILD) string(REPLACE ";" "/aws-cpp-sdk-all;" SYSTEM_MODULE_PATH "${CMAKE_SYSTEM_PREFIX_PATH}/aws-cpp-sdk-all") list(APPEND CMAKE_PREFIX_PATH ${SYSTEM_MODULE_PATH}) -endif() +endif () # Set the C++ standard to use to build this target. set(CMAKE_CXX_STANDARD 11) @@ -24,26 +30,17 @@ if(BUILD_TESTS) include(CTest) endif() -# Build shared libraries by default. -if(NOT DEFINED BUILD_SHARED_LIBS) - set(BUILD_SHARED_LIBS ON) -endif() - # Find the AWS SDK for C++ package. find_package(AWSSDK REQUIRED COMPONENTS ${SERVICE_COMPONENTS}) -# If the compiler is some version of Microsoft Visual C++, or another compiler simulating C++, -# and building as shared libraries, then dynamically link to those shared libraries. -if(MSVC AND BUILD_SHARED_LIBS) - add_definitions(-DUSE_IMPORT_EXPORT) +if (WINDOWS_BUILD AND AWSSDK_INSTALL_AS_SHARED_LIBS) # Copy relevant AWS SDK for C++ libraries into the current binary directory for running and debugging. - set(CMAKE_BUILD_TYPE Debug) # Explicitly setting CMAKE_BUILD_TYPE is necessary in Windows to copy DLLs. - - list(APPEND SERVICE_LIST ${SERVICE_COMPONENTS}) + # set(BIN_SUB_DIR "/Debug") # If you are building from the command line, you may need to uncomment this + # and set the proper subdirectory to the executables' location. - AWSSDK_CPY_DYN_LIBS(SERVICE_LIST "" ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE}) -endif() + AWSSDK_CPY_DYN_LIBS(SERVICE_COMPONENTS "" ${CMAKE_CURRENT_BINARY_DIR} ${BIN_SUB_DIR}) +endif () # AWSDOC_SOURCE can be defined in the command line to limit the files in a build. For example, # you can limit files to one action. @@ -53,14 +50,6 @@ if(NOT DEFINED AWSDOC_SOURCE) ) endif() -# Check whether the target system is Windows, including Win64. -if(WIN32) - # Check whether the compiler is some version of Microsoft Visual C++, or another compiler simulating C++. - if(MSVC) - source_group("Source Files" FILES ${AWSDOC_SOURCE}) - endif(MSVC) -endif() - foreach(file ${AWSDOC_SOURCE}) get_filename_component(EXAMPLE ${file} NAME_WE) diff --git a/cpp/example_code/autoscaling/hello_autoscaling/CMakeLists.txt b/cpp/example_code/autoscaling/hello_autoscaling/CMakeLists.txt index dcbb7bccea6..d4c2d73cc81 100644 --- a/cpp/example_code/autoscaling/hello_autoscaling/CMakeLists.txt +++ b/cpp/example_code/autoscaling/hello_autoscaling/CMakeLists.txt @@ -26,7 +26,7 @@ endif () # Find the AWS SDK for C++ package. find_package(AWSSDK REQUIRED COMPONENTS ${SERVICE_COMPONENTS}) -if (WINDOWS_BUILD) +if (WINDOWS_BUILD AND AWSSDK_INSTALL_AS_SHARED_LIBS) # Copy relevant AWS SDK for C++ libraries into the current binary directory for running and debugging. # set(BIN_SUB_DIR "/Debug") # If you are building from the command line, you may need to uncomment this diff --git a/cpp/example_code/autoscaling/tests/CMakeLists.txt b/cpp/example_code/autoscaling/tests/CMakeLists.txt index 85e6678f50a..6998cd544bb 100644 --- a/cpp/example_code/autoscaling/tests/CMakeLists.txt +++ b/cpp/example_code/autoscaling/tests/CMakeLists.txt @@ -32,16 +32,17 @@ if(NOT GTest_FOUND) FetchContent_MakeAvailable(googletest) endif() +# Use the MSVC variable to determine if this is a Windows build. +set(WINDOWS_BUILD ${MSVC}) + # Set the location for Windows to find the installed libraries of the SDK. -if(MSVC) +if (WINDOWS_BUILD) string(REPLACE ";" "/aws-cpp-sdk-all;" SYSTEM_MODULE_PATH "${CMAKE_SYSTEM_PREFIX_PATH}/aws-cpp-sdk-all") list(APPEND CMAKE_PREFIX_PATH ${SYSTEM_MODULE_PATH}) -endif() +endif () # Build shared libraries by default. -if(NOT BUILD_SHARED_LIBS) - set(BUILD_SHARED_LIBS ON) -endif() +set(BUILD_SHARED_LIBS ON) # Find the AWS SDK for C++ package. find_package(AWSSDK REQUIRED COMPONENTS ${CURRENT_TARGET_AWS_DEPENDENCIES}) @@ -50,19 +51,18 @@ add_executable( ${CURRENT_TARGET} ) -# If the compiler is some version of Microsoft Visual C++, or another compiler simulating C++, -# and building as shared libraries, then dynamically link to those shared libraries. -if(MSVC AND BUILD_SHARED_LIBS) - add_definitions(-DUSE_IMPORT_EXPORT) - - set(CMAKE_BUILD_TYPE Debug) # Explicitly set this to support library copying and test automation. - - # Copy relevant AWS SDK for C++ libraries into the current binary directory for running and debugging. - AWSSDK_CPY_DYN_LIBS( - CURRENT_TARGET_AWS_DEPENDENCIES - "" - ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE} - ) +if (WINDOWS_BUILD) + if (AWSSDK_INSTALL_AS_SHARED_LIBS) + # set(BIN_SUB_DIR "/Debug") # If you are building from the command line, you may need to uncomment this + # and set the proper subdirectory to the executables' location. + + # Copy relevant AWS SDK for C++ libraries into the current binary directory for running and debugging. + AWSSDK_CPY_DYN_LIBS( + CURRENT_TARGET_AWS_DEPENDENCIES + "" + ${CMAKE_CURRENT_BINARY_DIR} ${BIN_SUB_DIR} + ) + endif () add_custom_command( TARGET diff --git a/cpp/example_code/cloudwatch/CMakeLists.txt b/cpp/example_code/cloudwatch/CMakeLists.txt index 2e70c1697ce..c2874f81973 100644 --- a/cpp/example_code/cloudwatch/CMakeLists.txt +++ b/cpp/example_code/cloudwatch/CMakeLists.txt @@ -16,40 +16,40 @@ set(SERVICE_COMPONENTS monitoring events logs) # Set this project's name. project("${SERVICE_NAME}-examples") -#Set the location of where Windows can find the installed libraries of the SDK. -if(MSVC) - string(REPLACE ";" "/aws-cpp-sdk-all;" SYSTEM_MODULE_PATH "${CMAKE_SYSTEM_PREFIX_PATH}/aws-cpp-sdk-all") - list(APPEND CMAKE_PREFIX_PATH ${SYSTEM_MODULE_PATH}) -endif() +# Build shared libraries by default. +set(BUILD_SHARED_LIBS ON) # Set the C++ standard to use to build this target. set(CMAKE_CXX_STANDARD 11) +# Use the MSVC variable to determine if this is a Windows build. +set(WINDOWS_BUILD ${MSVC}) + +# Set the location of where Windows can find the installed libraries of the SDK. +if (WINDOWS_BUILD) + string(REPLACE ";" "/aws-cpp-sdk-all;" SYSTEM_MODULE_PATH "${CMAKE_SYSTEM_PREFIX_PATH}/aws-cpp-sdk-all") + list(APPEND CMAKE_PREFIX_PATH ${SYSTEM_MODULE_PATH}) +endif () + # Enable CTest for testing these code examples. if(BUILD_TESTS) include(CTest) endif() -# Build shared libraries by default. -if(NOT DEFINED BUILD_SHARED_LIBS) - set(BUILD_SHARED_LIBS ON) -endif() +# Find the AWS SDK for C++ package. +find_package(AWSSDK REQUIRED COMPONENTS ${SERVICE_COMPONENTS}) # Find the AWS SDK for C++ package. find_package(AWSSDK REQUIRED COMPONENTS ${SERVICE_COMPONENTS}) -# If the compiler is some version of Microsoft Visual C++, or another compiler simulating C++, -# and building as shared libraries, then dynamically link to those shared libraries. -if(MSVC AND BUILD_SHARED_LIBS) - add_definitions(-DUSE_IMPORT_EXPORT) +if (WINDOWS_BUILD AND AWSSDK_INSTALL_AS_SHARED_LIBS) # Copy relevant AWS SDK for C++ libraries into the current binary directory for running and debugging. - set(CMAKE_BUILD_TYPE Debug) # Explicitly setting CMAKE_BUILD_TYPE is necessary in Windows to copy DLLs. + # set(BIN_SUB_DIR "/Debug") # If you are building from the command line, you may need to uncomment this + # and set the proper subdirectory to the executables' location. - list(APPEND SERVICE_LIST ${SERVICE_COMPONENTS}) - - AWSSDK_CPY_DYN_LIBS(SERVICE_LIST "" ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE}) -endif() + AWSSDK_CPY_DYN_LIBS(SERVICE_COMPONENTS "" ${CMAKE_CURRENT_BINARY_DIR} ${BIN_SUB_DIR}) +endif () # AWSDOC_SOURCE can be defined in the command line to limit the files in a build. For example, # you can limit files to one action. @@ -59,14 +59,6 @@ if(NOT DEFINED AWSDOC_SOURCE) ) endif() -# Check whether the target system is Windows, including Win64. -if(WIN32) - # Check whether the compiler is some version of Microsoft Visual C++, or another compiler simulating C++. - if(MSVC) - source_group("Source Files" FILES ${AWSDOC_SOURCE}) - endif(MSVC) -endif() - foreach(file ${AWSDOC_SOURCE}) get_filename_component(EXAMPLE ${file} NAME_WE) diff --git a/cpp/example_code/codebuild/CMakeLists.txt b/cpp/example_code/codebuild/CMakeLists.txt index 467c5d13d21..0047df3aa98 100644 --- a/cpp/example_code/codebuild/CMakeLists.txt +++ b/cpp/example_code/codebuild/CMakeLists.txt @@ -1,27 +1,67 @@ -# Copyright 2010-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. -# This file is licensed under the Apache License, Version 2.0 (the "License"). -# You may not use this file except in compliance with the License. A copy of -# the License is located at -# http://aws.amazon.com/apache2.0/ -# This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR -# CONDITIONS OF ANY KIND, either express or implied. See the License for the -# specific language governing permissions and limitations under the License. +# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +# SPDX-License-Identifier: Apache-2.0 +# Set the minimum required version of CMake for this project. cmake_minimum_required(VERSION 3.13) -project(codebuild-examples) -set (CMAKE_CXX_STANDARD 11) -# Locate the aws sdk for c++ package. -find_package(AWSSDK REQUIRED COMPONENTS codebuild) +set(SERVICE_NAME codebuild) +set(SERVICE_COMPONENTS codebuild) -set(EXAMPLES "") -list(APPEND EXAMPLES "build_project") -list(APPEND EXAMPLES "list_builds") -list(APPEND EXAMPLES "list_projects") +# Set this project's name. +project("${SERVICE_NAME}-examples") +# Build shared libraries by default. +set(BUILD_SHARED_LIBS ON) + +# Set the C++ standard to use to build this target. +set(CMAKE_CXX_STANDARD 11) + +# Use the MSVC variable to determine if this is a Windows build. +set(WINDOWS_BUILD ${MSVC}) + +# Set the location of where Windows can find the installed libraries of the SDK. +if(WINDOWS_BUILD) + string(REPLACE ";" "/aws-cpp-sdk-all;" SYSTEM_MODULE_PATH "${CMAKE_SYSTEM_PREFIX_PATH}/aws-cpp-sdk-all") + list(APPEND CMAKE_PREFIX_PATH ${SYSTEM_MODULE_PATH}) +endif() + +# Find the AWS SDK for C++ package. +find_package(AWSSDK REQUIRED COMPONENTS ${SERVICE_COMPONENTS}) + + +if(WINDOWS_BUILD AND AWSSDK_INSTALL_AS_SHARED_LIBS) + # Copy relevant AWS SDK for C++ libraries into the current binary directory for running and debugging. + + # set(BIN_SUB_DIR "/Debug") # If you are building from the command line, you may need to uncomment this + # and set the proper subdirectory to the executables' location. + + AWSSDK_CPY_DYN_LIBS(SERVICE_COMPONENTS "" ${CMAKE_CURRENT_BINARY_DIR}${BIN_SUB_DIR}) + endif() + + +# AWSDOC_SOURCE can be defined in the command line to limit the files in a build. For example, +# you can limit files to one action. +if(NOT DEFINED AWSDOC_SOURCE) + file(GLOB AWSDOC_SOURCE + "*.cpp" + ) +endif() + +foreach(file ${AWSDOC_SOURCE}) + get_filename_component(EXAMPLE ${file} NAME_WE) + + # Build the code example executables. + set(EXAMPLE_EXE run_${EXAMPLE}) + + add_executable(${EXAMPLE_EXE} ${file}) + + target_link_libraries(${EXAMPLE_EXE} ${AWSSDK_LINK_LIBRARIES} + ${AWSSDK_PLATFORM_DEPS}) -# The executables to build. -foreach(EXAMPLE IN LISTS EXAMPLES) - add_executable(${EXAMPLE} ${EXAMPLE}.cpp) - target_link_libraries(${EXAMPLE} ${AWSSDK_LINK_LIBRARIES}) endforeach() + + +if(BUILD_TESTS) + add_subdirectory(tests) +endif() + diff --git a/cpp/example_code/codebuild/README.md b/cpp/example_code/codebuild/README.md index 51bd1e263df..bce5ea0c0e9 100644 --- a/cpp/example_code/codebuild/README.md +++ b/cpp/example_code/codebuild/README.md @@ -37,6 +37,15 @@ Next, for information on code example structures and how to build and run the ex +### Single actions + +Code excerpts that show you how to call individual service functions. + +- [ListBuilds](list_builds.cpp#L25) +- [ListProjects](list_projects.cpp#L23) +- [StartBuild](start_build.cpp#L22) + + diff --git a/cpp/example_code/codebuild/build_project.cpp b/cpp/example_code/codebuild/build_project.cpp deleted file mode 100644 index 39435e6826e..00000000000 --- a/cpp/example_code/codebuild/build_project.cpp +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. -// SPDX-License-Identifier: Apache-2.0 - -#include -#include -#include -#include -#include -#include - -/** - * Starts the project build based on command line input - */ - -int main(int argc, char **argv) -{ - if (argc != 2) - { - std::cout << "Usage: build_project "; - return 1; - } - Aws::SDKOptions options; - Aws::InitAPI(options); - { - Aws::String project_name(argv[1]); - Aws::CodeBuild::CodeBuildClient codebuild; - - Aws::CodeBuild::Model::StartBuildRequest sb_req; - sb_req.SetProjectName(project_name); - - auto sb_out = codebuild.StartBuild(sb_req); - - if (sb_out.IsSuccess()) - { - std::cout << "Successfully started build" << std::endl; - } - - else - { - std::cout << "Error starting build" << sb_out.GetError().GetMessage() - << std::endl; - } - } - - Aws::ShutdownAPI(options); - return 0; -} diff --git a/cpp/example_code/codebuild/codebuild_samples.h b/cpp/example_code/codebuild/codebuild_samples.h new file mode 100644 index 00000000000..7faedcd2801 --- /dev/null +++ b/cpp/example_code/codebuild/codebuild_samples.h @@ -0,0 +1,45 @@ +// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#ifndef CODEBUILD_EXAMPLES_CODEBUILD_SAMPLES_H +#define CODEBUILD_EXAMPLES_CODEBUILD_SAMPLES_H + +#include +#include +#include + +namespace AwsDoc { + namespace CodeBuild { + //! Start an AWS CodeBuild project build. + /*! + \param projectName: A CodeBuild project name. + \param clientConfiguration: AWS client configuration. + \return bool: Function succeeded. + */ + bool startBuild(const Aws::String &projectName, + const Aws::Client::ClientConfiguration &clientConfiguration); + + //! List the CodeBuild builds. + /*! + \param sortType: 'SortOrderType' type. + \param clientConfiguration: AWS client configuration. + \return bool: Function succeeded. + */ + bool listBuilds(Aws::CodeBuild::Model::SortOrderType sortType, + const Aws::Client::ClientConfiguration &clientConfiguration); + + //! List the CodeBuild projects. + /*! + \param sortType: 'SortOrderType' type. + \param clientConfiguration: AWS client configuration. + \return bool: Function succeeded. + */ + bool listProjects(Aws::CodeBuild::Model::SortOrderType sortType, + const Aws::Client::ClientConfiguration &clientConfiguration); + } // CodeBuild +} // AwsDoc + +#endif //CODEBUILD_EXAMPLES_CODEBUILD_SAMPLES_H + diff --git a/cpp/example_code/codebuild/list_builds.cpp b/cpp/example_code/codebuild/list_builds.cpp index 8a122493ee2..44a0818ef77 100644 --- a/cpp/example_code/codebuild/list_builds.cpp +++ b/cpp/example_code/codebuild/list_builds.cpp @@ -2,78 +2,124 @@ // SPDX-License-Identifier: Apache-2.0 #include -#include #include #include #include #include #include -#include #include +#include "codebuild_samples.h" /** - * Gets the list of builds and information about each build based on command line input + * Before running this C++ code example, set up your development environment, including your credentials. + * + * For more information, see the following documentation topic: + * + * https://docs.aws.amazon.com/sdk-for-cpp/v1/developer-guide/getting-started.html + * + * For information on the structure of the code examples and how to build and run the examples, see + * https://docs.aws.amazon.com/sdk-for-cpp/v1/developer-guide/getting-started-code-examples.html. + * + **/ + +// snippet-start:[cpp.example_code.codebuild.ListBuilds] +//! List the CodeBuild builds. +/*! + \param sortType: 'SortOrderType' type. + \param clientConfiguration: AWS client configuration. + \return bool: Function succeeded. */ +bool AwsDoc::CodeBuild::listBuilds(Aws::CodeBuild::Model::SortOrderType sortType, + const Aws::Client::ClientConfiguration &clientConfiguration) { + Aws::CodeBuild::CodeBuildClient codeBuildClient(clientConfiguration); + + Aws::CodeBuild::Model::ListBuildsRequest listBuildsRequest; + listBuildsRequest.SetSortOrder(sortType); + + Aws::String nextToken; // Used for pagination. + + do { + if (!nextToken.empty()) { + listBuildsRequest.SetNextToken(nextToken); + } + + Aws::CodeBuild::Model::ListBuildsOutcome listBuildsOutcome = codeBuildClient.ListBuilds( + listBuildsRequest); + + if (listBuildsOutcome.IsSuccess()) { + std::cout << "Information about each build:" << std::endl; + Aws::CodeBuild::Model::BatchGetBuildsRequest getBuildsRequest; + getBuildsRequest.SetIds(listBuildsOutcome.GetResult().GetIds()); + Aws::CodeBuild::Model::BatchGetBuildsOutcome getBuildsOutcome = codeBuildClient.BatchGetBuilds( + getBuildsRequest); + + if (getBuildsOutcome.IsSuccess()) { + const Aws::Vector &builds = getBuildsOutcome.GetResult().GetBuilds(); + std::cout << builds.size() << " build(s) found." << std::endl; + for (auto val: builds) { + std::cout << val.GetId() << std::endl; + } + } + else { + std::cout << "Error getting builds" + << getBuildsOutcome.GetError().GetMessage() << std::endl; + return false; + } + nextToken = listBuildsOutcome.GetResult().GetNextToken(); + } + + else { + std::cerr << "Error listing builds" + << listBuildsOutcome.GetError().GetMessage() + << std::endl; + return false; + } + + } while (!nextToken.empty()); + + return true; +} +// snippet-end:[cpp.example_code.codebuild.ListBuilds] + +/* + * + * main function + * + * Usage: 'Usage: run_list_builds ' + * + */ + +#ifndef TESTING_BUILD int main(int argc, char **argv) { if (argc != 2) { - std::cout << "Usage: list_builds "; + std::cout << "Usage: run_list_builds "; return 1; } + Aws::SDKOptions options; Aws::InitAPI(options); { - Aws::CodeBuild::CodeBuildClient codebuild; - - Aws::CodeBuild::Model::ListBuildsRequest lb_req; - Aws::CodeBuild::Model::BatchGetBuildsRequest bgb_req; + Aws::String sortOrderType = argv[1]; + Aws::CodeBuild::Model::SortOrderType sortType = Aws::CodeBuild::Model::SortOrderType::NOT_SET; if (Aws::Utils::StringUtils::CaselessCompare(argv[1], "ASCENDING")) { - lb_req.SetSortOrder(Aws::CodeBuild::Model::SortOrderType::ASCENDING); + sortType = Aws::CodeBuild::Model::SortOrderType::ASCENDING; } else if (Aws::Utils::StringUtils::CaselessCompare(argv[1], "DESCENDING")) { - lb_req.SetSortOrder(Aws::CodeBuild::Model::SortOrderType::DESCENDING); + sortType = Aws::CodeBuild::Model::SortOrderType::DESCENDING; } else { - lb_req.SetSortOrder(Aws::CodeBuild::Model::SortOrderType::NOT_SET); + std::cout << "Invalid sort order type." << std::endl; } + Aws::Client::ClientConfiguration clientConfig; + // Optional: Set to the AWS Region (overrides config file). + // clientConfig.region = "us-east-1"; - Aws::String next_token; // Used for pagination. - - do { - if (!next_token.empty()) { - lb_req.SetNextToken(next_token); - } - - auto lb_out = codebuild.ListBuilds(lb_req); - - if (lb_out.IsSuccess()) { - std::cout << "Information about each build:" << std::endl; - bgb_req.SetIds(lb_out.GetResult().GetIds()); - auto bgb_out = codebuild.BatchGetBuilds(bgb_req); - - if (bgb_out.IsSuccess()) { - const auto &builds = bgb_out.GetResult().GetBuilds(); - std::cout << builds.size() << " build(s) found." << std::endl; - for (auto val: builds) { - std::cout << val.GetId() << std::endl; - } - } - - next_token = lb_out.GetResult().GetNextToken(); - } - - else { - std::cout << "Error listing builds" << lb_out.GetError().GetMessage() - << std::endl; - break; - } - - } while (!next_token.empty()); - + AwsDoc::CodeBuild::listBuilds(sortType, clientConfig); } - - Aws::ShutdownAPI(options); return 0; } + +#endif // TESTING_BUILD diff --git a/cpp/example_code/codebuild/list_projects.cpp b/cpp/example_code/codebuild/list_projects.cpp index 2ad56735aa6..d854e40126b 100644 --- a/cpp/example_code/codebuild/list_projects.cpp +++ b/cpp/example_code/codebuild/list_projects.cpp @@ -2,62 +2,110 @@ // SPDX-License-Identifier: Apache-2.0 #include -#include #include #include #include #include +#include "codebuild_samples.h" /** - * Gets the list of projects based on command line input + * Before running this C++ code example, set up your development environment, including your credentials. + * + * For more information, see the following documentation topic: + * + * https://docs.aws.amazon.com/sdk-for-cpp/v1/developer-guide/getting-started.html + * + * For information on the structure of the code examples and how to build and run the examples, see + * https://docs.aws.amazon.com/sdk-for-cpp/v1/developer-guide/getting-started-code-examples.html. + * + **/ + +// snippet-start:[cpp.example_code.codebuild.ListProjects] +//! List the CodeBuild projects. +/*! + \param sortType: 'SortOrderType' type. + \param clientConfiguration: AWS client configuration. + \return bool: Function succeeded. */ +bool AwsDoc::CodeBuild::listProjects(Aws::CodeBuild::Model::SortOrderType sortType, + const Aws::Client::ClientConfiguration &clientConfiguration) { + Aws::CodeBuild::CodeBuildClient codeBuildClient(clientConfiguration); -int main(int argc, char **argv) -{ - if (argc != 2) - { - std::cout << "Usage: list_projects "; - return 1; - } - Aws::SDKOptions options; - Aws::InitAPI(options); - { - Aws::String sort_order_type(argv[1]); - Aws::CodeBuild::CodeBuildClient codebuild; - - Aws::CodeBuild::Model::ListProjectsRequest lp_req; - - if (sort_order_type == "ASCENDING") - { - lp_req.SetSortOrder(Aws::CodeBuild::Model::SortOrderType::ASCENDING); - } - else if (sort_order_type == "DESCENDING") - { - lp_req.SetSortOrder(Aws::CodeBuild::Model::SortOrderType::DESCENDING); - } - else - { - lp_req.SetSortOrder(Aws::CodeBuild::Model::SortOrderType::NOT_SET); + Aws::CodeBuild::Model::ListProjectsRequest listProjectsRequest; + listProjectsRequest.SetSortOrder(sortType); + + Aws::String nextToken; // Next token for pagination. + Aws::Vector allProjects; + + do { + if (!nextToken.empty()) { + listProjectsRequest.SetNextToken(nextToken); + } + + Aws::CodeBuild::Model::ListProjectsOutcome outcome = codeBuildClient.ListProjects( + listProjectsRequest); + + if (outcome.IsSuccess()) { + const Aws::Vector &projects = outcome.GetResult().GetProjects(); + allProjects.insert(allProjects.end(), projects.begin(), projects.end()); + nextToken = outcome.GetResult().GetNextToken(); + } + + else { + std::cerr << "Error listing projects" << outcome.GetError().GetMessage() + << std::endl; + } + + } while (!nextToken.empty()); + + std::cout << allProjects.size() << " project(s) found." << std::endl; + for (auto project: allProjects) { + std::cout << project << std::endl; } - auto lp_out = codebuild.ListProjects(lp_req); + return true; +} +// snippet-end:[cpp.example_code.codebuild.ListProjects] + +/* + * + * main function + * + * Usage: 'Usage: run_list_projects ' + * + */ - if (lp_out.IsSuccess()) - { - std::cout << "Successfully listing projects"; - for (auto val : lp_out.GetResult().GetProjects()) - { - std::cout << " " << val << std::endl; - } +#ifndef TESTING_BUILD + +int main(int argc, char **argv) { + if (argc != 2) { + std::cout << "Usage: run_list_projects "; + return 1; } - else + Aws::SDKOptions options; + Aws::InitAPI(options); { - std::cout << "Error listing projects" << lp_out.GetError().GetMessage() - << std::endl; - } - } + Aws::String sortOrderType = argv[1]; + + Aws::CodeBuild::Model::SortOrderType sortType = Aws::CodeBuild::Model::SortOrderType::NOT_SET; + if (Aws::Utils::StringUtils::CaselessCompare(argv[1], "ASCENDING")) { + sortType = Aws::CodeBuild::Model::SortOrderType::ASCENDING; + } + else if (Aws::Utils::StringUtils::CaselessCompare(argv[1], "DESCENDING")) { + sortType = Aws::CodeBuild::Model::SortOrderType::DESCENDING; + } + else { + std::cout << "Invalid sort order type." << std::endl; + } + Aws::Client::ClientConfiguration clientConfig; + // Optional: Set to the AWS Region (overrides config file). + // clientConfig.region = "us-east-1"; - Aws::ShutdownAPI(options); - return 0; + AwsDoc::CodeBuild::listProjects(sortType, clientConfig); + } + Aws::ShutdownAPI(options); + return 0; } + +#endif // TESTING_BUILD diff --git a/cpp/example_code/codebuild/start_build.cpp b/cpp/example_code/codebuild/start_build.cpp new file mode 100644 index 00000000000..eba2a511124 --- /dev/null +++ b/cpp/example_code/codebuild/start_build.cpp @@ -0,0 +1,86 @@ +// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +// SPDX-License-Identifier: Apache-2.0 + +#include +#include +#include +#include +#include "codebuild_samples.h" + +/** + * Before running this C++ code example, set up your development environment, including your credentials. + * + * For more information, see the following documentation topic: + * + * https://docs.aws.amazon.com/sdk-for-cpp/v1/developer-guide/getting-started.html + * + * For information on the structure of the code examples and how to build and run the examples, see + * https://docs.aws.amazon.com/sdk-for-cpp/v1/developer-guide/getting-started-code-examples.html. + * + **/ + +// snippet-start:[cpp.example_code.codebuild.StartBuild] +//! Start an AWS CodeBuild project build. +/*! + \param projectName: A CodeBuild project name. + \param clientConfiguration: AWS client configuration. + \return bool: Function succeeded. + */ +bool AwsDoc::CodeBuild::startBuild(const Aws::String &projectName, + const Aws::Client::ClientConfiguration &clientConfiguration) { + Aws::CodeBuild::CodeBuildClient codeBuildClient(clientConfiguration); + + Aws::CodeBuild::Model::StartBuildRequest startBuildRequest; + startBuildRequest.SetProjectName(projectName); + + Aws::CodeBuild::Model::StartBuildOutcome outcome = codeBuildClient.StartBuild( + startBuildRequest); + + if (outcome.IsSuccess()) { + std::cout << "Successfully started build" << std::endl; + std::cout << "Build ID: " << outcome.GetResult().GetBuild().GetId() + << std::endl; + } + + else { + std::cerr << "Error starting build" << outcome.GetError().GetMessage() + << std::endl; + } + + return outcome.IsSuccess(); +} +// snippet-end:[cpp.example_code.codebuild.StartBuild] + +/* + * + * main function + * + * Usage: 'Usage: run_start_build ' + * + */ + +#ifndef TESTING_BUILD + +int main(int argc, char **argv) { + if (argc != 2) { + std::cout << "Usage: run_start_build " << std::endl; + return 1; + } + + Aws::SDKOptions options; + options.loggingOptions.logLevel = Aws::Utils::Logging::LogLevel::Trace; + Aws::InitAPI(options); + { + Aws::String projectName = argv[1]; + Aws::Client::ClientConfiguration clientConfig; + // Optional: Set to the AWS Region (overrides config file). + // clientConfig.region = "us-east-1"; + + AwsDoc::CodeBuild::startBuild(projectName, clientConfig); + } + Aws::ShutdownAPI(options); + return 0; +} + +#endif // TESTING_BUILD + diff --git a/cpp/example_code/codebuild/tests/CMakeLists.txt b/cpp/example_code/codebuild/tests/CMakeLists.txt new file mode 100644 index 00000000000..e4f58814599 --- /dev/null +++ b/cpp/example_code/codebuild/tests/CMakeLists.txt @@ -0,0 +1,128 @@ +# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +# SPDX-License-Identifier: Apache-2.0 + +# Set the minimum required version of CMake for this project. +cmake_minimum_required(VERSION 3.14) + +set(EXAMPLE_SERVICE_NAME "codebuild") +set(CURRENT_TARGET "${EXAMPLE_SERVICE_NAME}_gtest") +set(CURRENT_TARGET_AWS_DEPENDENCIES codebuild) + +# Set this project's name. +project("${EXAMPLE_SERVICE_NAME}-examples-gtests") + +# Set the C++ standard to use to build this target. +set(CMAKE_CXX_STANDARD 14) + +# Build shared libraries by default. +set(BUILD_SHARED_LIBS ON) + +enable_testing() + +find_package(GTest) + +if (NOT GTest_FOUND) + include(FetchContent) + FetchContent_Declare( + googletest + GIT_REPOSITORY https://github.com/google/googletest.git + GIT_TAG release-1.12.1 + ) + + # For Windows: Prevent overriding the parent project's compiler/linker settings. + set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) + FetchContent_MakeAvailable(googletest) +endif () + +# Use the MSVC variable to determine if this is a Windows build. +set(WINDOWS_BUILD ${MSVC}) + +# Set the location for Windows to find the installed libraries of the SDK. +if (WINDOWS_BUILD) + string(REPLACE ";" "/aws-cpp-sdk-all;" SYSTEM_MODULE_PATH "${CMAKE_SYSTEM_PREFIX_PATH}/aws-cpp-sdk-all") + list(APPEND CMAKE_PREFIX_PATH ${SYSTEM_MODULE_PATH}) +endif () + +# Find the AWS SDK for C++ package. +find_package(AWSSDK REQUIRED COMPONENTS ${CURRENT_TARGET_AWS_DEPENDENCIES}) + +add_executable( + ${CURRENT_TARGET} +) + +if (WINDOWS_BUILD) + if (AWSSDK_INSTALL_AS_SHARED_LIBS) + # set(BIN_SUB_DIR "/Debug") # If you are building from the command line, you may need to uncomment this + # and set the proper subdirectory to the executables' location. + + # Copy relevant AWS SDK for C++ libraries into the current binary directory for running and debugging. + AWSSDK_CPY_DYN_LIBS( + CURRENT_TARGET_AWS_DEPENDENCIES + "" + ${CMAKE_CURRENT_BINARY_DIR} ${BIN_SUB_DIR} + ) + endif () + + add_custom_command( + TARGET + ${CURRENT_TARGET} + POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy + ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_BINDIR} ${BIN_SUB_DIR}/gtest.dll + ${CMAKE_CURRENT_BINARY_DIR} ${BIN_SUB_DIR} + ) +endif () + +# GTEST_SOURCE_FILES can be defined in the command line to limit the files in a build, for example to one action. +if (NOT DEFINED GTEST_SOURCE_FILES) + file( + GLOB + GTEST_SOURCE_FILES + "gtest_*.cpp" + ) +endif () + +foreach (TEST_FILE ${GTEST_SOURCE_FILES}) + string(REPLACE "gtest_" "../" SOURCE_FILE ${TEST_FILE}) + if (EXISTS ${SOURCE_FILE}) + list(APPEND GTEST_SOURCE ${SOURCE_FILE} ${TEST_FILE}) + else () + message("Error: no associated source file found for ${TEST_FILE}") + endif () +endforeach () + +target_sources( + ${CURRENT_TARGET} + PUBLIC + ${GTEST_SOURCE} + test_main.cpp + ${EXAMPLE_SERVICE_NAME}_gtests.cpp +) + +target_include_directories( + ${CURRENT_TARGET} + PUBLIC + $ + $ +) + +target_compile_definitions( + ${CURRENT_TARGET} + PUBLIC + TESTING_BUILD + SRC_DIR="${CMAKE_CURRENT_SOURCE_DIR}" +) + +target_link_libraries( + ${CURRENT_TARGET} + GTest::gtest + ${AWSSDK_LINK_LIBRARIES} + ${AWSSDK_PLATFORM_DEPS} +) + +include(GoogleTest) + +gtest_add_tests( + TARGET + ${CURRENT_TARGET} +) diff --git a/cpp/example_code/codebuild/tests/codebuild_gtests.cpp b/cpp/example_code/codebuild/tests/codebuild_gtests.cpp new file mode 100644 index 00000000000..50f08874a77 --- /dev/null +++ b/cpp/example_code/codebuild/tests/codebuild_gtests.cpp @@ -0,0 +1,170 @@ +// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +// SPDX-License-Identifier: Apache-2.0 + +#include "codebuild_gtests.h" +#include +#include + +Aws::SDKOptions AwsDocTest::CodeBuild_GTests::s_options; +std::unique_ptr AwsDocTest::CodeBuild_GTests::s_clientConfig; +static const char ALLOCATION_TAG[] = "CodeBuild_GTEST"; + +/* + * Subclass MockHTTPCLient to respond to credential requests. + * Otherwise, the stored responses are returned for credential requests + * and not the service API calls. + */ +class CustomMockHTTPClient : public MockHttpClient { +public: + explicit CustomMockHTTPClient( + const std::shared_ptr &requestTmp) { + std::shared_ptr goodResponse = Aws::MakeShared( + ALLOCATION_TAG, requestTmp); + goodResponse->AddHeader("Content-Type", "text/json"); + goodResponse->SetResponseCode(Aws::Http::HttpResponseCode::OK); + Aws::Utils::DateTime expiration = + Aws::Utils::DateTime::Now() + std::chrono::milliseconds(60000); + + goodResponse->GetResponseBody() << "{" + << R"("RoleArn":"arn:aws:iam::123456789012:role/MockRole",)" + << R"("AccessKeyId":"ABCDEFGHIJK",)" + << R"("SecretAccessKey":"ABCDEFGHIJK",)" + << R"(Token":"ABCDEFGHIJK==","Expiration":")" + << expiration.ToGmtString( + Aws::Utils::DateFormat::ISO_8601) + << "\"" + << "}"; + this->AddResponseToReturn(goodResponse); + + mCredentialsResponse = MockHttpClient::MakeRequest(requestTmp); + } + + std::shared_ptr + MakeRequest(const std::shared_ptr &request, + Aws::Utils::RateLimits::RateLimiterInterface *readLimiter, + Aws::Utils::RateLimits::RateLimiterInterface *writeLimiter) const override { + + // Do not use stored responses for a credentials request. + if (request->GetURIString().find("/credentials/") != std::string::npos) { + std::cout << "CustomMockHTTPClient returning credentials request." + << std::endl; + return mCredentialsResponse; + } + else { + return MockHttpClient::MakeRequest(request, readLimiter, writeLimiter);; + } + } + +private: + std::shared_ptr mCredentialsResponse; +}; + +void AwsDocTest::CodeBuild_GTests::SetUpTestSuite() { + InitAPI(s_options); + + // s_clientConfig must be a pointer because the client config must be initialized + // after InitAPI. + s_clientConfig = std::make_unique(); +} + +void AwsDocTest::CodeBuild_GTests::TearDownTestSuite() { + ShutdownAPI(s_options); + +} + +void AwsDocTest::CodeBuild_GTests::SetUp() { + if (suppressStdOut()) { + m_savedBuffer = std::cout.rdbuf(); + std::cout.rdbuf(&m_coutBuffer); + } + + m_savedInBuffer = std::cin.rdbuf(); + std::cin.rdbuf(&m_cinBuffer); + + // The following code is needed for the AwsDocTest::MyStringBuffer::underflow exception. + // Otherwise, an infinite loop occurs when looping for a result on an empty buffer. + std::cin.exceptions(std::ios_base::badbit); +} + +void AwsDocTest::CodeBuild_GTests::TearDown() { + if (m_savedBuffer != nullptr) { + std::cout.rdbuf(m_savedBuffer); + m_savedBuffer = nullptr; + } + + if (m_savedInBuffer != nullptr) { + std::cin.rdbuf(m_savedInBuffer); + std::cin.exceptions(std::ios_base::goodbit); + m_savedInBuffer = nullptr; + } +} + +Aws::String AwsDocTest::CodeBuild_GTests::preconditionError() { + return "Failed to meet precondition."; +} + +void AwsDocTest::CodeBuild_GTests::AddCommandLineResponses( + const std::vector &responses) { + + std::stringstream stringStream; + for (auto &response: responses) { + stringStream << response << "\n"; + } + m_cinBuffer.str(stringStream.str()); +} + + +bool AwsDocTest::CodeBuild_GTests::suppressStdOut() { + return std::getenv("EXAMPLE_TESTS_LOG_ON") == nullptr; +} + + +int AwsDocTest::MyStringBuffer::underflow() { + int result = basic_stringbuf::underflow(); + if (result == EOF) { + std::cerr << "Error AwsDocTest::MyStringBuffer::underflow." << std::endl; + throw std::underflow_error("AwsDocTest::MyStringBuffer::underflow"); + } + + return result; +} + + +AwsDocTest::MockHTTP::MockHTTP() { + requestTmp = CreateHttpRequest(Aws::Http::URI("https://test.com/"), + Aws::Http::HttpMethod::HTTP_GET, + Aws::Utils::Stream::DefaultResponseStreamFactoryMethod); + mockHttpClient = Aws::MakeShared( + ALLOCATION_TAG, requestTmp); + mockHttpClientFactory = Aws::MakeShared(ALLOCATION_TAG); + mockHttpClientFactory->SetClient(mockHttpClient); + SetHttpClientFactory(mockHttpClientFactory); +} + +AwsDocTest::MockHTTP::~MockHTTP() { + Aws::Http::CleanupHttp(); + Aws::Http::InitHttp(); +} + +bool AwsDocTest::MockHTTP::addResponseWithBody(const std::string &fileName, + Aws::Http::HttpResponseCode httpResponseCode) { + std::string filePath = std::string(SRC_DIR) + "/" + fileName; + + std::ifstream inStream(filePath); + if (inStream) { + std::shared_ptr goodResponse = Aws::MakeShared( + ALLOCATION_TAG, requestTmp); + goodResponse->AddHeader("Content-Type", "text/json"); + goodResponse->SetResponseCode(httpResponseCode); + goodResponse->GetResponseBody() << inStream.rdbuf(); + mockHttpClient->AddResponseToReturn(goodResponse); + + return true; + } + + std::cerr << "MockHTTP::addResponseWithBody open file error '" << filePath << "'." + << std::endl; + + return false; +} + diff --git a/cpp/example_code/codebuild/tests/codebuild_gtests.h b/cpp/example_code/codebuild/tests/codebuild_gtests.h new file mode 100644 index 00000000000..6a0b6c32d94 --- /dev/null +++ b/cpp/example_code/codebuild/tests/codebuild_gtests.h @@ -0,0 +1,69 @@ +// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +// SPDX-License-Identifier: Apache-2.0 + +#pragma once +#ifndef CODEBUILD_EXAMPLES_CODEBUILD_GTESTS_H +#define CODEBUILD_EXAMPLES_CODEBUILD_GTESTS_H + +#include +#include +#include +#include + +namespace AwsDocTest { + + class MyStringBuffer : public std::stringbuf { + int underflow() override; + }; + + class CodeBuild_GTests : public testing::Test { + protected: + + void SetUp() override; + + void TearDown() override; + + static void SetUpTestSuite(); + + static void TearDownTestSuite(); + + static Aws::String preconditionError(); + + void AddCommandLineResponses(const std::vector &responses); + + // s_clientConfig must be a pointer because the client config must be initialized + // after InitAPI. + static std::unique_ptr s_clientConfig; + + private: + + static bool suppressStdOut(); + + static Aws::SDKOptions s_options; + + std::stringbuf m_coutBuffer; // Used to silence cout. + std::streambuf *m_savedBuffer = nullptr; + + MyStringBuffer m_cinBuffer; + std::streambuf *m_savedInBuffer = nullptr; + }; // CodeBuild_GTests + + + class MockHTTP { + public: + MockHTTP(); + + virtual ~MockHTTP(); + + bool addResponseWithBody(const std::string &fileName, + Aws::Http::HttpResponseCode httpResponseCode = Aws::Http::HttpResponseCode::OK); + + private: + + std::shared_ptr mockHttpClient; + std::shared_ptr mockHttpClientFactory; + std::shared_ptr requestTmp; + }; // MockHTTP +} // AwsDocTest + +#endif //CODEBUILD_EXAMPLES_CODEBUILD_GTESTS_H diff --git a/cpp/example_code/codebuild/tests/gtest_list_builds.cpp b/cpp/example_code/codebuild/tests/gtest_list_builds.cpp new file mode 100644 index 00000000000..154243ebd6c --- /dev/null +++ b/cpp/example_code/codebuild/tests/gtest_list_builds.cpp @@ -0,0 +1,25 @@ +// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +// SPDX-License-Identifier: Apache-2.0 +/* + * Test types are indicated by the test label ending. + * + * _1_ Requires credentials, permissions, and AWS resources. + * _2_ Requires credentials and permissions. + * _3_ Does not require credentials. + * + */ + +#include +#include "codebuild_samples.h" +#include "codebuild_gtests.h" + +namespace AwsDocTest { + // NOLINTNEXTLINE(readability-named-parameter) + TEST_F(CodeBuild_GTests, list_builds_2_ + ) { + + auto result = AwsDoc::CodeBuild::listBuilds( + Aws::CodeBuild::Model::SortOrderType::ASCENDING, *s_clientConfig); + ASSERT_TRUE(result); +} +} // namespace AwsDocTest diff --git a/cpp/example_code/codebuild/tests/gtest_list_projects.cpp b/cpp/example_code/codebuild/tests/gtest_list_projects.cpp new file mode 100644 index 00000000000..a414211ff70 --- /dev/null +++ b/cpp/example_code/codebuild/tests/gtest_list_projects.cpp @@ -0,0 +1,25 @@ +// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +// SPDX-License-Identifier: Apache-2.0 +/* + * Test types are indicated by the test label ending. + * + * _1_ Requires credentials, permissions, and AWS resources. + * _2_ Requires credentials and permissions. + * _3_ Does not require credentials. + * + */ + +#include +#include "codebuild_samples.h" +#include "codebuild_gtests.h" + +namespace AwsDocTest { + // NOLINTNEXTLINE(readability-named-parameter) + TEST_F(CodeBuild_GTests, list_projects_2_ + ) { + + auto result = AwsDoc::CodeBuild::listProjects( + Aws::CodeBuild::Model::SortOrderType::ASCENDING, *s_clientConfig); + ASSERT_TRUE(result); +} +} // namespace AwsDocTest diff --git a/cpp/example_code/codebuild/tests/gtest_start_build.cpp b/cpp/example_code/codebuild/tests/gtest_start_build.cpp new file mode 100644 index 00000000000..0a18ca6965d --- /dev/null +++ b/cpp/example_code/codebuild/tests/gtest_start_build.cpp @@ -0,0 +1,33 @@ +// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +// SPDX-License-Identifier: Apache-2.0 +/* + * Test types are indicated by the test label ending. + * + * _1_ Requires credentials, permissions, and AWS resources. + * _2_ Requires credentials and permissions. + * _3_ Does not require credentials. + * + */ + +#include +#include "codebuild_samples.h" +#include "codebuild_gtests.h" + +namespace AwsDocTest { + // NOLINTNEXTLINE(readability-named-parameter) + TEST_F(CodeBuild_GTests, start_build_3_ + ) { + MockHTTP mockHttp; + bool result = mockHttp.addResponseWithBody("mock_input/StartBuild.json"); + ASSERT_TRUE(result) + << + + preconditionError() + + << + std::endl; + + result = AwsDoc::CodeBuild::startBuild("test-project", *s_clientConfig); + ASSERT_TRUE(result); +} +} // namespace AwsDocTest diff --git a/cpp/example_code/codebuild/tests/mock_input/StartBuild.json b/cpp/example_code/codebuild/tests/mock_input/StartBuild.json new file mode 100644 index 00000000000..b9110389dde --- /dev/null +++ b/cpp/example_code/codebuild/tests/mock_input/StartBuild.json @@ -0,0 +1,70 @@ +{ + "build": { + "arn": "arn:aws:codebuild:us-east-1:123456789012:build/test-project:2e7cc8d4-5658-48ec-b3e6-e4072f495178", + "artifacts": { + "location": "", + "type": "no_artifacts" + }, + "buildComplete": false, + "buildNumber": 2, + "buildStatus": "IN_PROGRESS", + "cache": { + "type": "NO_CACHE" + }, + "currentPhase": "QUEUED", + "encryptionKey": "arn:aws:kms:us-east-1:123456789012:alias/aws/s3", + "environment": { + "computeType": "BUILD_GENERAL1_SMALL", + "environmentVariables": [], + "image": "aws/codebuild/amazonlinux2-x86_64-standard:5.0", + "imagePullCredentialsType": "CODEBUILD", + "privilegedMode": false, + "type": "LINUX_CONTAINER" + }, + "id": "test-project:2e7cc8d4-5658-48ec-b3e6-e4072f495178", + "initiator": "UnitTester", + "logs": { + "cloudWatchLogs": { + "status": "ENABLED" + }, + "cloudWatchLogsArn": "arn:aws:logs:us-east-1:123456789012:log-group:null:log-stream:null", + "deepLink": "https://console.aws.amazon.com/cloudwatch/home?region=us-east-1#logsV2:log-groups", + "s3Logs": { + "encryptionDisabled": false, + "status": "DISABLED" + } + }, + "phases": [ + { + "durationInSeconds": 0, + "endTime": 1.71416124029E9, + "phaseStatus": "SUCCEEDED", + "phaseType": "SUBMITTED", + "startTime": 1.714161240198E9 + }, + { + "phaseType": "QUEUED", + "startTime": 1.71416124029E9 + } + ], + "projectName": "test-project", + "queuedTimeoutInMinutes": 480, + "secondaryArtifacts": [], + "secondarySourceVersions": [], + "secondarySources": [], + "serviceRole": "arn:aws:iam::123456789012:role/service-role/codebuild-test-project-service-role", + "source": { + "buildspec": "version: 0.2\n\nphases:\n build:\n commands:\n - echo \"Hello World\"", + "gitCloneDepth": 1, + "gitSubmodulesConfig": { + "fetchSubmodules": false + }, + "insecureSsl": false, + "location": "https://github.com/awsdocs/aws-doc-sdk-examples.git", + "reportBuildStatus": false, + "type": "GITHUB" + }, + "startTime": 1.714161240198E9, + "timeoutInMinutes": 60 + } +} \ No newline at end of file diff --git a/cpp/example_code/codebuild/tests/test_main.cpp b/cpp/example_code/codebuild/tests/test_main.cpp new file mode 100644 index 00000000000..656f92cb221 --- /dev/null +++ b/cpp/example_code/codebuild/tests/test_main.cpp @@ -0,0 +1,9 @@ +// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +// SPDX-License-Identifier: Apache-2.0 + +#include "gtest/gtest.h" + +int main(int argc, char **argv) { + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} diff --git a/cpp/example_code/cognito/CMakeLists.txt b/cpp/example_code/cognito/CMakeLists.txt index a5e49b96b3a..abf7d11b0be 100644 --- a/cpp/example_code/cognito/CMakeLists.txt +++ b/cpp/example_code/cognito/CMakeLists.txt @@ -21,8 +21,11 @@ else () endif () +# Use the MSVC variable to determine if this is a Windows build. +set(WINDOWS_BUILD ${MSVC}) + # Set the location of where Windows can find the installed libraries of the SDK. -if (MSVC) +if (WINDOWS_BUILD) string(REPLACE ";" "/aws-cpp-sdk-all;" SYSTEM_MODULE_PATH "${CMAKE_SYSTEM_PREFIX_PATH}/aws-cpp-sdk-all") list(APPEND CMAKE_PREFIX_PATH ${SYSTEM_MODULE_PATH}) endif () @@ -36,24 +39,18 @@ if (BUILD_TESTS) endif () # Build shared libraries by default. -if (NOT DEFINED BUILD_SHARED_LIBS) - set(BUILD_SHARED_LIBS ON) -endif () +set(BUILD_SHARED_LIBS ON) # Find the AWS SDK for C++ package. find_package(AWSSDK REQUIRED COMPONENTS ${SERVICE_COMPONENTS}) -# If the compiler is some version of Microsoft Visual C++, or another compiler simulating C++, -# and building as shared libraries, then dynamically link to those shared libraries. -if (MSVC AND BUILD_SHARED_LIBS) - add_definitions(-DUSE_IMPORT_EXPORT) +if (WINDOWS_BUILD AND AWSSDK_INSTALL_AS_SHARED_LIBS) # Copy relevant AWS SDK for C++ libraries into the current binary directory for running and debugging. - set(CMAKE_BUILD_TYPE Debug) # Explicitly setting CMAKE_BUILD_TYPE is necessary in Windows to copy DLLs. - - list(APPEND SERVICE_LIST ${SERVICE_COMPONENTS}) + # set(BIN_SUB_DIR "/Debug") # If you are building from the command line, you may need to uncomment this + # and set the proper subdirectory to the executables' location. - AWSSDK_CPY_DYN_LIBS(SERVICE_LIST "" ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE}) + AWSSDK_CPY_DYN_LIBS(SERVICE_COMPONENTS "" ${CMAKE_CURRENT_BINARY_DIR} ${BIN_SUB_DIR}) endif () # AWSDOC_SOURCE can be defined in the command line to limit the files in a build. For example, @@ -64,14 +61,6 @@ if (NOT DEFINED AWSDOC_SOURCE) ) endif () -# Check whether the target system is Windows, including Win64. -if (WIN32) - # Check whether the compiler is some version of Microsoft Visual C++, or another compiler simulating C++. - if (MSVC) - source_group("Source Files" FILES ${AWSDOC_SOURCE}) - endif (MSVC) -endif () - foreach (file ${AWSDOC_SOURCE}) get_filename_component(EXAMPLE ${file} NAME_WE) diff --git a/cpp/example_code/cognito/hello_cognito/CMakeLists.txt b/cpp/example_code/cognito/hello_cognito/CMakeLists.txt index 269e9cf590f..51e370ab847 100644 --- a/cpp/example_code/cognito/hello_cognito/CMakeLists.txt +++ b/cpp/example_code/cognito/hello_cognito/CMakeLists.txt @@ -26,7 +26,7 @@ endif () # Find the AWS SDK for C++ package. find_package(AWSSDK REQUIRED COMPONENTS ${SERVICE_COMPONENTS}) -if (WINDOWS_BUILD) +if (WINDOWS_BUILD AND AWSSDK_INSTALL_AS_SHARED_LIBS) # Copy relevant AWS SDK for C++ libraries into the current binary directory for running and debugging. # set(BIN_SUB_DIR "/Debug") # If you are building from the command line, you may need to uncomment this diff --git a/cpp/example_code/cognito/tests/CMakeLists.txt b/cpp/example_code/cognito/tests/CMakeLists.txt index 1e4ee0a04d0..d1ded580b1e 100644 --- a/cpp/example_code/cognito/tests/CMakeLists.txt +++ b/cpp/example_code/cognito/tests/CMakeLists.txt @@ -35,8 +35,11 @@ if(NOT GTest_FOUND) FetchContent_MakeAvailable(googletest) endif() +# Use the MSVC variable to determine if this is a Windows build. +set(WINDOWS_BUILD ${MSVC}) + # Set the location for Windows to find the installed libraries of the SDK. -if (MSVC) +if (WINDOWS_BUILD) string(REPLACE ";" "/aws-cpp-sdk-all;" SYSTEM_MODULE_PATH "${CMAKE_SYSTEM_PREFIX_PATH}/aws-cpp-sdk-all") list(APPEND CMAKE_PREFIX_PATH ${SYSTEM_MODULE_PATH}) endif () @@ -51,16 +54,17 @@ add_executable( # If the compiler is some version of Microsoft Visual C++, or another compiler simulating C++, # and building as shared libraries, then dynamically link to those shared libraries. if (MSVC AND BUILD_SHARED_LIBS) - add_definitions(-DUSE_IMPORT_EXPORT) - - set(CMAKE_BUILD_TYPE Debug) # Explicitly set this to support library copying and test automation. - - # Copy relevant AWS SDK for C++ libraries into the current binary directory for running and debugging. - AWSSDK_CPY_DYN_LIBS( - CURRENT_TARGET_AWS_DEPENDENCIES - "" - ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE} - ) + if (AWSSDK_INSTALL_AS_SHARED_LIBS) + # set(BIN_SUB_DIR "/Debug") # If you are building from the command line, you may need to uncomment this + # and set the proper subdirectory to the executables' location. + + # Copy relevant AWS SDK for C++ libraries into the current binary directory for running and debugging. + AWSSDK_CPY_DYN_LIBS( + CURRENT_TARGET_AWS_DEPENDENCIES + "" + ${CMAKE_CURRENT_BINARY_DIR} ${BIN_SUB_DIR} + ) + endif () add_custom_command( TARGET @@ -82,14 +86,6 @@ if (NOT DEFINED GTEST_SOURCE_FILES) ) endif () -# Check whether the target system is Windows, including Win64. -if (WIN32) - # Check whether the compiler is some version of Microsoft Visual C++, or another compiler simulating C++. - if (MSVC) - source_group("Source Files" FILES ${GTEST_SOURCE_FILES}) - endif (MSVC) -endif () - enable_testing() foreach (TEST_FILE ${GTEST_SOURCE_FILES}) diff --git a/cpp/example_code/cross-service/serverless-aurora/CMakeLists.txt b/cpp/example_code/cross-service/serverless-aurora/CMakeLists.txt index 70c02e0c0a1..c60feccbce1 100644 --- a/cpp/example_code/cross-service/serverless-aurora/CMakeLists.txt +++ b/cpp/example_code/cross-service/serverless-aurora/CMakeLists.txt @@ -15,19 +15,20 @@ set(USING_CONAN TRUE) # True if using Conan. project("ServerlessAurora") set(EXECUTABLE run_serverless_aurora) +# Use the MSVC variable to determine if this is a Windows build. +set(WINDOWS_BUILD ${MSVC}) + # Set the location of where Windows can find the installed libraries of the SDK. -if(MSVC) +if (WINDOWS_BUILD) string(REPLACE ";" "/aws-cpp-sdk-all;" SYSTEM_MODULE_PATH "${CMAKE_SYSTEM_PREFIX_PATH}/aws-cpp-sdk-all") list(APPEND CMAKE_PREFIX_PATH ${SYSTEM_MODULE_PATH}) -endif() +endif () # Set the C++ standard to use to build this target. set(CMAKE_CXX_STANDARD 11) # Build shared libraries by default. -if(NOT DEFINED BUILD_SHARED_LIBS) - set(BUILD_SHARED_LIBS ON) -endif() +set(BUILD_SHARED_LIBS ON) # Find the AWS SDK for C++ package. find_package(AWSSDK REQUIRED COMPONENTS ${SERVICE_COMPONENTS}) @@ -43,27 +44,14 @@ else() PocoFoundation) endif() -# If the compiler is some version of Microsoft Visual C++, or another compiler simulating C++, -# and building as shared libraries, then dynamically link to those shared libraries. -if(MSVC AND BUILD_SHARED_LIBS) - add_definitions(-DUSE_IMPORT_EXPORT) +if (WINDOWS_BUILD AND AWSSDK_INSTALL_AS_SHARED_LIBS) # Copy relevant AWS SDK for C++ libraries into the current binary directory for running and debugging. - set(CMAKE_BUILD_TYPE Debug) # Explicitly setting CMAKE_BUILD_TYPE is necessary in Windows to copy DLLs. - - list(APPEND SERVICE_LIST ${SERVICE_COMPONENTS}) + # set(BIN_SUB_DIR "/Debug") # If you are building from the command line, you may need to uncomment this + # and set the proper subdirectory to the executables' location. - AWSSDK_CPY_DYN_LIBS(SERVICE_LIST "" ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE}) -endif() - - -# Check whether the target system is Windows, including Win64. -if(WIN32) - # Check whether the compiler is some version of Microsoft Visual C++, or another compiler simulating C++. - if(MSVC) - source_group("Source Files" FILES ${AWSDOC_SOURCE}) - endif(MSVC) -endif() + AWSSDK_CPY_DYN_LIBS(SERVICE_COMPONENTS "" ${CMAKE_CURRENT_BINARY_DIR} ${BIN_SUB_DIR}) +endif () add_executable(${EXECUTABLE} serverless_aurora.cpp diff --git a/cpp/example_code/cross-service/serverless-aurora/tests/CMakeLists.txt b/cpp/example_code/cross-service/serverless-aurora/tests/CMakeLists.txt index 5b6619585c2..bb42619466c 100644 --- a/cpp/example_code/cross-service/serverless-aurora/tests/CMakeLists.txt +++ b/cpp/example_code/cross-service/serverless-aurora/tests/CMakeLists.txt @@ -11,11 +11,14 @@ set(BUILD_SHARED_LIBS ON) project("ServerlessAuroraGTest") set(EXECUTABLE serverless_aurora_gtest) -# Set the location of where Windows can find the installed libraries of the SDK. -if(MSVC) +# Use the MSVC variable to determine if this is a Windows build. +set(WINDOWS_BUILD ${MSVC}) + +# Set the location for Windows to find the installed libraries of the SDK. +if (WINDOWS_BUILD) string(REPLACE ";" "/aws-cpp-sdk-all;" SYSTEM_MODULE_PATH "${CMAKE_SYSTEM_PREFIX_PATH}/aws-cpp-sdk-all") list(APPEND CMAKE_PREFIX_PATH ${SYSTEM_MODULE_PATH}) -endif() +endif () # Set the C++ standard to use to build this target. set(CMAKE_CXX_STANDARD 14) @@ -40,37 +43,29 @@ endif() find_package(AWSSDK REQUIRED COMPONENTS ${SERVICE_COMPONENTS}) add_executable(${EXECUTABLE}) -# If the compiler is some version of Microsoft Visual C++, or another compiler simulating C++, -# and building as shared libraries, then dynamically link to those shared libraries. -if(MSVC AND BUILD_SHARED_LIBS) - add_definitions(-DUSE_IMPORT_EXPORT) - # Copy relevant AWS SDK for C++ libraries into the current binary directory for running and debugging. - - set(CMAKE_BUILD_TYPE Debug) # Explicitly setting CMAKE_BUILD_TYPE is necessary in Windows to copy DLLs. - list(APPEND SERVICE_LIST ${SERVICE_COMPONENTS}) +if (WINDOWS_BUILD) + if (AWSSDK_INSTALL_AS_SHARED_LIBS) + # set(BIN_SUB_DIR "/Debug") # If you are building from the command line, you may need to uncomment this + # and set the proper subdirectory to the executables' location. - AWSSDK_CPY_DYN_LIBS(SERVICE_LIST "" ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE}) + # Copy relevant AWS SDK for C++ libraries into the current binary directory for running and debugging. + AWSSDK_CPY_DYN_LIBS( + CURRENT_TARGET_AWS_DEPENDENCIES + "" + ${CMAKE_CURRENT_BINARY_DIR} ${BIN_SUB_DIR} + ) + endif () add_custom_command( TARGET - ${EXECUTABLE} + ${CURRENT_TARGET} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy - ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_BINDIR}/${CMAKE_BUILD_TYPE}/gtest.dll - ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_BINDIR}/${CMAKE_BUILD_TYPE}/gtest_main.dll - ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE} + ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_BINDIR} ${BIN_SUB_DIR}/gtest.dll + ${CMAKE_CURRENT_BINARY_DIR} ${BIN_SUB_DIR} ) - endif() - - -# Check whether the target system is Windows, including Win64. -if(WIN32) - # Check whether the compiler is some version of Microsoft Visual C++, or another compiler simulating C++. - if(MSVC) - source_group("Source Files" FILES ${AWSDOC_SOURCE}) - endif(MSVC) -endif() +endif () enable_testing() diff --git a/cpp/example_code/cross-service/topics_and_queues/CMakeLists.txt b/cpp/example_code/cross-service/topics_and_queues/CMakeLists.txt index af3595f3861..8bd091ff83d 100644 --- a/cpp/example_code/cross-service/topics_and_queues/CMakeLists.txt +++ b/cpp/example_code/cross-service/topics_and_queues/CMakeLists.txt @@ -29,7 +29,7 @@ endif () # Find the AWS SDK for C++ package. find_package(AWSSDK REQUIRED COMPONENTS ${SERVICE_COMPONENTS}) -if (WINDOWS_BUILD) +if (WINDOWS_BUILD AND AWSSDK_INSTALL_AS_SHARED_LIBS) # Copy relevant AWS SDK for C++ libraries into the current binary directory for running and debugging. # set(BIN_SUB_DIR "/Debug") # If you are building from the command line you may need to uncomment this diff --git a/cpp/example_code/cross-service/topics_and_queues/tests/CMakeLists.txt b/cpp/example_code/cross-service/topics_and_queues/tests/CMakeLists.txt index d6c9dd0a8c1..5e812af0c23 100644 --- a/cpp/example_code/cross-service/topics_and_queues/tests/CMakeLists.txt +++ b/cpp/example_code/cross-service/topics_and_queues/tests/CMakeLists.txt @@ -48,15 +48,17 @@ add_executable( ) if (WINDOWS_BUILD) - # set(BIN_SUB_DIR "/Debug") # If you are building from the command line you may need to uncomment this - # and set the proper subdirectory to the executables' location. - - # Copy relevant AWS SDK for C++ libraries into the current binary directory for running and debugging. - AWSSDK_CPY_DYN_LIBS( - CURRENT_TARGET_AWS_DEPENDENCIES - "" - ${CMAKE_CURRENT_BINARY_DIR}${BIN_SUB_DIR} - ) + if (AWSSDK_INSTALL_AS_SHARED_LIBS) + # set(BIN_SUB_DIR "/Debug") # If you are building from the command line, you may need to uncomment this + # and set the proper subdirectory to the executables' location. + + # Copy relevant AWS SDK for C++ libraries into the current binary directory for running and debugging. + AWSSDK_CPY_DYN_LIBS( + CURRENT_TARGET_AWS_DEPENDENCIES + "" + ${CMAKE_CURRENT_BINARY_DIR} ${BIN_SUB_DIR} + ) + endif () add_custom_command( TARGET diff --git a/cpp/example_code/dynamodb/CMakeLists.txt b/cpp/example_code/dynamodb/CMakeLists.txt index fec456cdce4..8c5ff0046b5 100644 --- a/cpp/example_code/dynamodb/CMakeLists.txt +++ b/cpp/example_code/dynamodb/CMakeLists.txt @@ -10,41 +10,32 @@ set(SERVICE_COMPONENTS dynamodb s3) # s3 is required for tests, and it must be i # Set this project's name. project("${SERVICE_NAME}-examples") +# Use the MSVC variable to determine if this is a Windows build. +set(WINDOWS_BUILD ${MSVC}) + # Set the location of where Windows can find the installed libraries of the SDK. -if(MSVC) +if (WINDOWS_BUILD) string(REPLACE ";" "/aws-cpp-sdk-all;" SYSTEM_MODULE_PATH "${CMAKE_SYSTEM_PREFIX_PATH}/aws-cpp-sdk-all") list(APPEND CMAKE_PREFIX_PATH ${SYSTEM_MODULE_PATH}) -endif() +endif () # Set the C++ standard to use to build this target. set(CMAKE_CXX_STANDARD 11) -# Enable CTest for testing these code examples. -if(BUILD_TESTS) - include(CTest) -endif() - # Build shared libraries by default. -if(NOT BUILD_SHARED_LIBS) - set(BUILD_SHARED_LIBS ON) -endif() +set(BUILD_SHARED_LIBS ON) # Find the AWS SDK for C++ package. find_package(AWSSDK REQUIRED COMPONENTS ${SERVICE_COMPONENTS}) -# If the compiler is some version of Microsoft Visual C++, or another compiler simulating C++, -# and building as shared libraries, then dynamically link to those shared libraries. -if(MSVC AND BUILD_SHARED_LIBS) - add_definitions(-DUSE_IMPORT_EXPORT) +if (WINDOWS_BUILD AND AWSSDK_INSTALL_AS_SHARED_LIBS) # Copy relevant AWS SDK for C++ libraries into the current binary directory for running and debugging. - set(CMAKE_BUILD_TYPE Debug) # Explicitly setting CMAKE_BUILD_TYPE is necessary in windows to copy dlls. - - list(APPEND SERVICE_LIST ${SERVICE_COMPONENTS}) - - AWSSDK_CPY_DYN_LIBS(SERVICE_LIST "" ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE}) -endif() + # set(BIN_SUB_DIR "/Debug") # If you are building from the command line, you may need to uncomment this + # and set the proper subdirectory to the executables' location. + AWSSDK_CPY_DYN_LIBS(SERVICE_COMPONENTS "" ${CMAKE_CURRENT_BINARY_DIR} ${BIN_SUB_DIR}) +endif () # AWSDOC_${SERVICE_COMPONENTS}_SOURCE can be defined in the command line to limit the files in a build, for example to one action. if(NOT DEFINED AWSDOC_SOURCE) @@ -54,17 +45,6 @@ if(NOT DEFINED AWSDOC_SOURCE) list(FILTER AWSDOC_SOURCE EXCLUDE REGEX "/dynamodb_utils.cpp$") endif() -# Check whether the target system is Windows, including Win64. -if(WIN32) - list(FILTER AWSDOC_SOURCE EXCLUDE REGEX "/list_buckets_disabling_dns_cache.cpp$") # Not supported in windows, see file for details - - # Check whether the compiler is some version of Microsoft Visual C++, or another compiler simulating C++. - if(MSVC) - source_group("Source Files" FILES ${AWSDOC_SOURCE}) - endif(MSVC) -endif() - - foreach(file ${AWSDOC_SOURCE}) get_filename_component(EXAMPLE ${file} NAME_WE) diff --git a/cpp/example_code/dynamodb/hello_dynamodb/CMakeLists.txt b/cpp/example_code/dynamodb/hello_dynamodb/CMakeLists.txt index 477ff5006c6..b3889f1238b 100644 --- a/cpp/example_code/dynamodb/hello_dynamodb/CMakeLists.txt +++ b/cpp/example_code/dynamodb/hello_dynamodb/CMakeLists.txt @@ -26,7 +26,7 @@ endif () # Find the AWS SDK for C++ package. find_package(AWSSDK REQUIRED COMPONENTS ${SERVICE_COMPONENTS}) -if (WINDOWS_BUILD) +if (WINDOWS_BUILD AND AWSSDK_INSTALL_AS_SHARED_LIBS) # Copy relevant AWS SDK for C++ libraries into the current binary directory for running and debugging. # set(BIN_SUB_DIR "/Debug") # if you are building from the command line you may need to uncomment this diff --git a/cpp/example_code/dynamodb/tests/CMakeLists.txt b/cpp/example_code/dynamodb/tests/CMakeLists.txt index adb74ebf1c3..3a1a7189376 100644 --- a/cpp/example_code/dynamodb/tests/CMakeLists.txt +++ b/cpp/example_code/dynamodb/tests/CMakeLists.txt @@ -32,11 +32,14 @@ if(NOT GTest_FOUND) FetchContent_MakeAvailable(googletest) endif() +# Use the MSVC variable to determine if this is a Windows build. +set(WINDOWS_BUILD ${MSVC}) + # Set the location for Windows to find the installed libraries of the SDK. -if(MSVC) +if (WINDOWS_BUILD) string(REPLACE ";" "/aws-cpp-sdk-all;" SYSTEM_MODULE_PATH "${CMAKE_SYSTEM_PREFIX_PATH}/aws-cpp-sdk-all") list(APPEND CMAKE_PREFIX_PATH ${SYSTEM_MODULE_PATH}) -endif() +endif () # Find the AWS SDK for C++ package. find_package(AWSSDK REQUIRED COMPONENTS ${CURRENT_TARGET_AWS_DEPENDENCIES}) @@ -45,19 +48,18 @@ add_executable( ${CURRENT_TARGET} ) -# If the compiler is some version of Microsoft Visual C++, or another compiler simulating C++, -# and building as shared libraries, then dynamically link to those shared libraries. -if(MSVC AND BUILD_SHARED_LIBS) - add_definitions(-DUSE_IMPORT_EXPORT) - - set(CMAKE_BUILD_TYPE Debug) # Explicitly set this to support library copying and test automation. - - # Copy relevant AWS SDK for C++ libraries into the current binary directory for running and debugging. - AWSSDK_CPY_DYN_LIBS( - CURRENT_TARGET_AWS_DEPENDENCIES - "" - ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE} - ) +if (WINDOWS_BUILD) + if (AWSSDK_INSTALL_AS_SHARED_LIBS) + # set(BIN_SUB_DIR "/Debug") # If you are building from the command line, you may need to uncomment this + # and set the proper subdirectory to the executables' location. + + # Copy relevant AWS SDK for C++ libraries into the current binary directory for running and debugging. + AWSSDK_CPY_DYN_LIBS( + CURRENT_TARGET_AWS_DEPENDENCIES + "" + ${CMAKE_CURRENT_BINARY_DIR} ${BIN_SUB_DIR} + ) + endif () add_custom_command( TARGET diff --git a/cpp/example_code/ec2/CMakeLists.txt b/cpp/example_code/ec2/CMakeLists.txt index aab8e5522dc..04391431aa4 100644 --- a/cpp/example_code/ec2/CMakeLists.txt +++ b/cpp/example_code/ec2/CMakeLists.txt @@ -21,8 +21,11 @@ if (BUILD_TESTS) include(CTest) endif () -# Set the location of where Windows can find the installed libraries of the SDK. -if (MSVC) +# Use the MSVC variable to determine if this is a Windows build. +set(WINDOWS_BUILD ${MSVC}) + +# Set the location for Windows to find the installed libraries of the SDK. +if (WINDOWS_BUILD) string(REPLACE ";" "/aws-cpp-sdk-all;" SYSTEM_MODULE_PATH "${CMAKE_SYSTEM_PREFIX_PATH}/aws-cpp-sdk-all") list(APPEND CMAKE_PREFIX_PATH ${SYSTEM_MODULE_PATH}) endif () @@ -30,14 +33,13 @@ endif () # Find the AWS SDK for C++ package. find_package(AWSSDK REQUIRED COMPONENTS ${SERVICE_COMPONENTS}) -# If the compiler is some version of Microsoft Visual C++, or another compiler simulating C++, -# and building as shared libraries, then dynamically link to those shared libraries. -if (MSVC AND BUILD_SHARED_LIBS) - set(CMAKE_BUILD_TYPE Debug) # Explicitly setting CMAKE_BUILD_TYPE is necessary in Windows to copy DLLs. +if (WINDOWS_BUILD AND AWSSDK_INSTALL_AS_SHARED_LIBS) + # Copy relevant AWS SDK for C++ libraries into the current binary directory for running and debugging. - list(APPEND SERVICE_LIST ${SERVICE_COMPONENTS}) + # set(BIN_SUB_DIR "/Debug") # If you are building from the command line, you may need to uncomment this + # and set the proper subdirectory to the executables' location. - AWSSDK_CPY_DYN_LIBS(SERVICE_LIST "" ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE}) + AWSSDK_CPY_DYN_LIBS(SERVICE_COMPONENTS "" ${CMAKE_CURRENT_BINARY_DIR} ${BIN_SUB_DIR}) endif () # AWSDOC_SOURCE can be defined in the command line to limit the files in a build. For example, diff --git a/cpp/example_code/ec2/hello_ec2/CMakeLists.txt b/cpp/example_code/ec2/hello_ec2/CMakeLists.txt index 03854950d62..e9ae74a2fda 100644 --- a/cpp/example_code/ec2/hello_ec2/CMakeLists.txt +++ b/cpp/example_code/ec2/hello_ec2/CMakeLists.txt @@ -26,7 +26,7 @@ endif () # Find the AWS SDK for C++ package. find_package(AWSSDK REQUIRED COMPONENTS ${SERVICE_COMPONENTS}) -if (WINDOWS_BUILD) +if (WINDOWS_BUILD AND AWSSDK_INSTALL_AS_SHARED_LIBS) # Copy relevant AWS SDK for C++ libraries into the current binary directory for running and debugging. # set(BIN_SUB_DIR "/Debug") # If you are building from the command line, you may need to uncomment this diff --git a/cpp/example_code/ec2/tests/CMakeLists.txt b/cpp/example_code/ec2/tests/CMakeLists.txt index 081f8975123..dd05c535c41 100644 --- a/cpp/example_code/ec2/tests/CMakeLists.txt +++ b/cpp/example_code/ec2/tests/CMakeLists.txt @@ -31,11 +31,14 @@ if(NOT GTest_FOUND) FetchContent_MakeAvailable(googletest) endif() +# Use the MSVC variable to determine if this is a Windows build. +set(WINDOWS_BUILD ${MSVC}) + # Set the location for Windows to find the installed libraries of the SDK. -if(MSVC) +if (WINDOWS_BUILD) string(REPLACE ";" "/aws-cpp-sdk-all;" SYSTEM_MODULE_PATH "${CMAKE_SYSTEM_PREFIX_PATH}/aws-cpp-sdk-all") list(APPEND CMAKE_PREFIX_PATH ${SYSTEM_MODULE_PATH}) -endif() +endif () # Find the AWS SDK for C++ package. find_package(AWSSDK REQUIRED COMPONENTS ${CURRENT_TARGET_AWS_DEPENDENCIES}) @@ -44,27 +47,28 @@ add_executable( ${CURRENT_TARGET} ) -# If the compiler is some version of Microsoft Visual C++, or another compiler simulating C++, -# and building as shared libraries, then dynamically link to those shared libraries. -if(MSVC AND BUILD_SHARED_LIBS) - set(CMAKE_BUILD_TYPE Debug) # Explicitly setting CMAKE_BUILD_TYPE is necessary in Windows to copy DLLs. +if (WINDOWS_BUILD) + if (AWSSDK_INSTALL_AS_SHARED_LIBS) + # set(BIN_SUB_DIR "/Debug") # If you are building from the command line, you may need to uncomment this + # and set the proper subdirectory to the executables' location. - # Copy relevant AWS SDK for C++ libraries into the current binary directory for running and debugging. - AWSSDK_CPY_DYN_LIBS( - CURRENT_TARGET_AWS_DEPENDENCIES - "" - ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE} - ) + # Copy relevant AWS SDK for C++ libraries into the current binary directory for running and debugging. + AWSSDK_CPY_DYN_LIBS( + CURRENT_TARGET_AWS_DEPENDENCIES + "" + ${CMAKE_CURRENT_BINARY_DIR} ${BIN_SUB_DIR} + ) + endif () add_custom_command( - TARGET - ${CURRENT_TARGET} - POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy - ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_BINDIR}/${CMAKE_BUILD_TYPE}/gtest.dll - ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE} + TARGET + ${CURRENT_TARGET} + POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy + ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_BINDIR} ${BIN_SUB_DIR}/gtest.dll + ${CMAKE_CURRENT_BINARY_DIR} ${BIN_SUB_DIR} ) - endif() +endif () # GTEST_SOURCE_FILES can be defined in the command line to limit the files in a build. For example, # you can limit files to one action. diff --git a/cpp/example_code/glue/CMakeLists.txt b/cpp/example_code/glue/CMakeLists.txt index 635ddb6db43..c45462610d1 100644 --- a/cpp/example_code/glue/CMakeLists.txt +++ b/cpp/example_code/glue/CMakeLists.txt @@ -10,40 +10,32 @@ set(SERVICE_COMPONENTS glue s3 iam) # Set this project's name. project("${SERVICE_NAME}-examples") -# Set the location of where Windows can find the installed libraries of the SDK. -if(MSVC) +# Use the MSVC variable to determine if this is a Windows build. +set(WINDOWS_BUILD ${MSVC}) + +# Set the location for Windows to find the installed libraries of the SDK. +if (WINDOWS_BUILD) string(REPLACE ";" "/aws-cpp-sdk-all;" SYSTEM_MODULE_PATH "${CMAKE_SYSTEM_PREFIX_PATH}/aws-cpp-sdk-all") list(APPEND CMAKE_PREFIX_PATH ${SYSTEM_MODULE_PATH}) -endif() +endif () # Set the C++ standard to use to build this target. set(CMAKE_CXX_STANDARD 11) -# Enable CTest for testing these code examples. -if(BUILD_TESTS) - include(CTest) -endif() - # Build shared libraries by default. -if(NOT DEFINED BUILD_SHARED_LIBS) - set(BUILD_SHARED_LIBS ON) -endif() +set(BUILD_SHARED_LIBS ON) # Find the AWS SDK for C++ package. find_package(AWSSDK REQUIRED COMPONENTS ${SERVICE_COMPONENTS}) -# If the compiler is some version of Microsoft Visual C++, or another compiler simulating C++, -# and building as shared libraries, then dynamically link to those shared libraries. -if(MSVC AND BUILD_SHARED_LIBS) - add_definitions(-DUSE_IMPORT_EXPORT) +if (WINDOWS_BUILD AND AWSSDK_INSTALL_AS_SHARED_LIBS) # Copy relevant AWS SDK for C++ libraries into the current binary directory for running and debugging. - set(CMAKE_BUILD_TYPE Debug) # Explicitly setting CMAKE_BUILD_TYPE is necessary in Windows to copy DLLs. - - list(APPEND SERVICE_LIST ${SERVICE_COMPONENTS}) + # set(BIN_SUB_DIR "/Debug") # If you are building from the command line, you may need to uncomment this + # and set the proper subdirectory to the executables' location. - AWSSDK_CPY_DYN_LIBS(SERVICE_LIST "" ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE}) -endif() + AWSSDK_CPY_DYN_LIBS(SERVICE_COMPONENTS "" ${CMAKE_CURRENT_BINARY_DIR} ${BIN_SUB_DIR}) +endif () # AWSDOC_SOURCE can be defined in the command line to limit the files in a build. For example, # you can limit files to one action. @@ -55,14 +47,6 @@ if(NOT DEFINED AWSDOC_SOURCE) list(FILTER AWSDOC_SOURCE EXCLUDE REGEX "/glue_utilities.cpp$") endif() -# Check whether the target system is Windows, including Win64. -if(WIN32) - # Check whether the compiler is some version of Microsoft Visual C++, or another compiler simulating C++. - if(MSVC) - source_group("Source Files" FILES ${AWSDOC_SOURCE}) - endif(MSVC) -endif() - foreach(file ${AWSDOC_SOURCE}) get_filename_component(EXAMPLE ${file} NAME_WE) diff --git a/cpp/example_code/glue/hello_glue/CMakeLists.txt b/cpp/example_code/glue/hello_glue/CMakeLists.txt index 99b0f97b470..07c4d82dd59 100644 --- a/cpp/example_code/glue/hello_glue/CMakeLists.txt +++ b/cpp/example_code/glue/hello_glue/CMakeLists.txt @@ -26,7 +26,7 @@ endif () # Find the AWS SDK for C++ package. find_package(AWSSDK REQUIRED COMPONENTS ${SERVICE_COMPONENTS}) -if (WINDOWS_BUILD) +if (WINDOWS_BUILD AND AWSSDK_INSTALL_AS_SHARED_LIBS) # Copy relevant AWS SDK for C++ libraries into the current binary directory for running and debugging. # set(BIN_SUB_DIR "/Debug") # if you are building from the command line you may need to uncomment this diff --git a/cpp/example_code/glue/tests/CMakeLists.txt b/cpp/example_code/glue/tests/CMakeLists.txt index 70c61cc028d..d980835359c 100644 --- a/cpp/example_code/glue/tests/CMakeLists.txt +++ b/cpp/example_code/glue/tests/CMakeLists.txt @@ -32,11 +32,14 @@ if(NOT GTest_FOUND) FetchContent_MakeAvailable(googletest) endif() +# Use the MSVC variable to determine if this is a Windows build. +set(WINDOWS_BUILD ${MSVC}) + # Set the location for Windows to find the installed libraries of the SDK. -if(MSVC) +if (WINDOWS_BUILD) string(REPLACE ";" "/aws-cpp-sdk-all;" SYSTEM_MODULE_PATH "${CMAKE_SYSTEM_PREFIX_PATH}/aws-cpp-sdk-all") list(APPEND CMAKE_PREFIX_PATH ${SYSTEM_MODULE_PATH}) -endif() +endif () # Find the AWS SDK for C++ package. find_package(AWSSDK REQUIRED COMPONENTS ${CURRENT_TARGET_AWS_DEPENDENCIES}) @@ -45,29 +48,28 @@ add_executable( ${CURRENT_TARGET} ) -# If the compiler is some version of Microsoft Visual C++, or another compiler simulating C++, -# and building as shared libraries, then dynamically link to those shared libraries. -if(MSVC AND BUILD_SHARED_LIBS) - add_definitions(-DUSE_IMPORT_EXPORT) +if (WINDOWS_BUILD) + if (AWSSDK_INSTALL_AS_SHARED_LIBS) + # set(BIN_SUB_DIR "/Debug") # If you are building from the command line, you may need to uncomment this + # and set the proper subdirectory to the executables' location. - set(CMAKE_BUILD_TYPE Debug) # Explicitly setting CMAKE_BUILD_TYPE is necessary in Windows to copy DLLs. - - # Copy relevant AWS SDK for C++ libraries into the current binary directory for running and debugging. - AWSSDK_CPY_DYN_LIBS( - CURRENT_TARGET_AWS_DEPENDENCIES - "" - ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE} - ) + # Copy relevant AWS SDK for C++ libraries into the current binary directory for running and debugging. + AWSSDK_CPY_DYN_LIBS( + CURRENT_TARGET_AWS_DEPENDENCIES + "" + ${CMAKE_CURRENT_BINARY_DIR} ${BIN_SUB_DIR} + ) + endif () add_custom_command( - TARGET - ${CURRENT_TARGET} - POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy - ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_BINDIR}/${CMAKE_BUILD_TYPE}/gtest.dll - ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE} + TARGET + ${CURRENT_TARGET} + POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy + ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_BINDIR} ${BIN_SUB_DIR}/gtest.dll + ${CMAKE_CURRENT_BINARY_DIR} ${BIN_SUB_DIR} ) - endif() +endif () # GTEST_SOURCE_FILES can be defined in the command line to limit the files in a build. For example, # you can limit files to one action. @@ -79,17 +81,8 @@ if (NOT DEFINED GTEST_SOURCE_FILES) ) endif() -# Check whether the target system is Windows, including Win64. -if(WIN32) - # Check whether the compiler is some version of Microsoft Visual C++, or another compiler simulating C++. - if(MSVC) - source_group("Source Files" FILES ${GTEST_SOURCE_FILES}) - endif(MSVC) -endif() - enable_testing() - foreach(TEST_FILE ${GTEST_SOURCE_FILES}) string(REPLACE "gtest_" "../" SOURCE_FILE ${TEST_FILE}) if (EXISTS ${SOURCE_FILE}) diff --git a/cpp/example_code/iam/CMakeLists.txt b/cpp/example_code/iam/CMakeLists.txt index d0a916d64d5..38085340431 100644 --- a/cpp/example_code/iam/CMakeLists.txt +++ b/cpp/example_code/iam/CMakeLists.txt @@ -29,7 +29,7 @@ endif() find_package(AWSSDK REQUIRED COMPONENTS ${SERVICE_COMPONENTS}) -if(WINDOWS_BUILD) +if(WINDOWS_BUILD AND AWSSDK_INSTALL_AS_SHARED_LIBS) # Copy relevant AWS SDK for C++ libraries into the current binary directory for running and debugging. # set(BIN_SUB_DIR "/Debug") # if you are building from the command line you may need to uncomment this diff --git a/cpp/example_code/iam/hello_iam/CMakeLists.txt b/cpp/example_code/iam/hello_iam/CMakeLists.txt index 6dec17b8c69..3b5dd343767 100644 --- a/cpp/example_code/iam/hello_iam/CMakeLists.txt +++ b/cpp/example_code/iam/hello_iam/CMakeLists.txt @@ -26,7 +26,7 @@ endif () # Find the AWS SDK for C++ package. find_package(AWSSDK REQUIRED COMPONENTS ${SERVICE_COMPONENTS}) -if (WINDOWS_BUILD) +if (WINDOWS_BUILD AND AWSSDK_INSTALL_AS_SHARED_LIBS) # Copy relevant AWS SDK for C++ libraries into the current binary directory for running and debugging. # set(BIN_SUB_DIR "/Debug") # if you are building from the command line you may need to uncomment this diff --git a/cpp/example_code/iam/tests/CMakeLists.txt b/cpp/example_code/iam/tests/CMakeLists.txt index 31467d9a845..c912dd7995e 100644 --- a/cpp/example_code/iam/tests/CMakeLists.txt +++ b/cpp/example_code/iam/tests/CMakeLists.txt @@ -34,7 +34,6 @@ if(NOT GTest_FOUND) FetchContent_MakeAvailable(googletest) endif() - # Use the MSVC variable to determine if this is a Windows build. set(WINDOWS_BUILD ${MSVC}) @@ -54,15 +53,17 @@ add_executable( # If the compiler is some version of Microsoft Visual C++, or another compiler simulating C++, # and building as shared libraries, then dynamically link to those shared libraries. if(WINDOWS_BUILD) - # set(BIN_SUB_DIR "/Debug") # if you are building from the command line you may need to uncomment this - # and set the proper subdirectory to the executables' location. - - # Copy relevant AWS SDK for C++ libraries into the current binary directory for running and debugging. - AWSSDK_CPY_DYN_LIBS( - CURRENT_TARGET_AWS_DEPENDENCIES - "" - ${CMAKE_CURRENT_BINARY_DIR}${BIN_SUB_DIR} - ) + if (AWSSDK_INSTALL_AS_SHARED_LIBS) + # set(BIN_SUB_DIR "/Debug") # If you are building from the command line, you may need to uncomment this + # and set the proper subdirectory to the executables' location. + + # Copy relevant AWS SDK for C++ libraries into the current binary directory for running and debugging. + AWSSDK_CPY_DYN_LIBS( + CURRENT_TARGET_AWS_DEPENDENCIES + "" + ${CMAKE_CURRENT_BINARY_DIR} ${BIN_SUB_DIR} + ) + endif () add_custom_command( TARGET diff --git a/cpp/example_code/iot/CMakeLists.txt b/cpp/example_code/iot/CMakeLists.txt index 119ac90fdc6..5fcc5fc8cbc 100644 --- a/cpp/example_code/iot/CMakeLists.txt +++ b/cpp/example_code/iot/CMakeLists.txt @@ -29,7 +29,7 @@ endif () find_package(AWSSDK REQUIRED COMPONENTS ${SERVICE_COMPONENTS}) -if (WINDOWS_BUILD) +if (WINDOWS_BUILD AND AWSSDK_INSTALL_AS_SHARED_LIBS) # Copy relevant AWS SDK for C++ libraries into the current binary directory for running and debugging. # set(BIN_SUB_DIR "/Debug") # If you are building from the command line, you may need to uncomment this diff --git a/cpp/example_code/iot/hello_iot/CMakeLists.txt b/cpp/example_code/iot/hello_iot/CMakeLists.txt index 37bf9c022c8..29906e27f0d 100644 --- a/cpp/example_code/iot/hello_iot/CMakeLists.txt +++ b/cpp/example_code/iot/hello_iot/CMakeLists.txt @@ -26,7 +26,7 @@ endif () # Find the AWS SDK for C++ package. find_package(AWSSDK REQUIRED COMPONENTS ${SERVICE_COMPONENTS}) -if (WINDOWS_BUILD) +if (WINDOWS_BUILD AND AWSSDK_INSTALL_AS_SHARED_LIBS) # Copy relevant AWS SDK for C++ libraries into the current binary directory for running and debugging. # set(BIN_SUB_DIR "/Debug") # If you are building from the command line, you may need to uncomment this diff --git a/cpp/example_code/iot/tests/CMakeLists.txt b/cpp/example_code/iot/tests/CMakeLists.txt index cf1a2808c14..e470018d425 100644 --- a/cpp/example_code/iot/tests/CMakeLists.txt +++ b/cpp/example_code/iot/tests/CMakeLists.txt @@ -51,15 +51,17 @@ add_executable( ) if (WINDOWS_BUILD) - # set(BIN_SUB_DIR "/Debug") # If you are building from the command line, you may need to uncomment this - # and set the proper subdirectory to the executables' location. - - # Copy relevant AWS SDK for C++ libraries into the current binary directory for running and debugging. - AWSSDK_CPY_DYN_LIBS( - CURRENT_TARGET_AWS_DEPENDENCIES - "" - ${CMAKE_CURRENT_BINARY_DIR} ${BIN_SUB_DIR} - ) + if (AWSSDK_INSTALL_AS_SHARED_LIBS) + # set(BIN_SUB_DIR "/Debug") # If you are building from the command line, you may need to uncomment this + # and set the proper subdirectory to the executables' location. + + # Copy relevant AWS SDK for C++ libraries into the current binary directory for running and debugging. + AWSSDK_CPY_DYN_LIBS( + CURRENT_TARGET_AWS_DEPENDENCIES + "" + ${CMAKE_CURRENT_BINARY_DIR} ${BIN_SUB_DIR} + ) + endif () add_custom_command( TARGET diff --git a/cpp/example_code/iot/things_and_shadows_workflow/CMakeLists.txt b/cpp/example_code/iot/things_and_shadows_workflow/CMakeLists.txt index be2dde924d4..03c6ded5785 100644 --- a/cpp/example_code/iot/things_and_shadows_workflow/CMakeLists.txt +++ b/cpp/example_code/iot/things_and_shadows_workflow/CMakeLists.txt @@ -28,7 +28,7 @@ endif () # Find the AWS SDK for C++ package. find_package(AWSSDK REQUIRED COMPONENTS ${SERVICE_COMPONENTS}) -if (WINDOWS_BUILD) +if (WINDOWS_BUILD AND AWSSDK_INSTALL_AS_SHARED_LIBS) # Copy relevant AWS SDK for C++ libraries into the current binary directory for running and debugging. # set(BIN_SUB_DIR "/Debug") # If you are building from the command line, you may need to uncomment this