diff --git a/cpp/.gitignore b/cpp/.gitignore index 21c144c5685..52f25f0968e 100644 --- a/cpp/.gitignore +++ b/cpp/.gitignore @@ -1,4 +1,5 @@ build/ cmake-build*/ .vs/ -build_tests \ No newline at end of file +build_tests +CMakeSettings.json \ No newline at end of file diff --git a/cpp/build_all_examples.sh b/cpp/build_all_examples.sh index b7fb56ae2bc..4f25f5db2ec 100755 --- a/cpp/build_all_examples.sh +++ b/cpp/build_all_examples.sh @@ -3,8 +3,11 @@ CMAKE_FILES=$(ls example_code/*/CMakeLists.txt) +HELLO_CMAKE_FILES=$(ls example_code/*/hello_*/CMakeLists.txt) +CMAKE_FILES="$CMAKE_FILES $HELLO_CMAKE_FILES" + CMAKE_FILES=($CMAKE_FILES) -echo "CMAKE_FILES ${CMAKE_FILES}" +echo "CMAKE_FILES ${CMAKE_FILES[@]}" len=${#CMAKE_FILES[@]} echo "len ${len}" diff --git a/cpp/example_code/acm/CMakeLists.txt b/cpp/example_code/acm/CMakeLists.txt index afceb4ea842..36b3c5b3679 100644 --- a/cpp/example_code/acm/CMakeLists.txt +++ b/cpp/example_code/acm/CMakeLists.txt @@ -2,7 +2,7 @@ # SPDX-License-Identifier: Apache-2.0 # Set the minimum required version of CMake for this project. -cmake_minimum_required(VERSION 3.8) +cmake_minimum_required(VERSION 3.13) # Set this project's name. project("acm-examples") diff --git a/cpp/example_code/aurora/CMakeLists.txt b/cpp/example_code/aurora/CMakeLists.txt index 13750c4e426..f6cc48533af 100644 --- a/cpp/example_code/aurora/CMakeLists.txt +++ b/cpp/example_code/aurora/CMakeLists.txt @@ -2,7 +2,7 @@ # SPDX-License-Identifier: Apache-2.0 # Set the minimum required version of CMake for this project. -cmake_minimum_required(VERSION 3.11) +cmake_minimum_required(VERSION 3.13) set(SERVICE_NAME aurora) set(SERVICE_COMPONENTS rds) diff --git a/cpp/example_code/aurora/getting_started_with_db_clusters.cpp b/cpp/example_code/aurora/getting_started_with_db_clusters.cpp index a5f57fde003..7aee4246cb5 100644 --- a/cpp/example_code/aurora/getting_started_with_db_clusters.cpp +++ b/cpp/example_code/aurora/getting_started_with_db_clusters.cpp @@ -767,8 +767,6 @@ bool AwsDoc::Aurora::describeDBCluster(const Aws::String &dbClusterIdentifier, if (outcome.IsSuccess()) { clusterResult = outcome.GetResult().GetDBClusters()[0]; } - // This example does not log an error if the DB cluster does not exist. - // Instead, it returns false. else if (outcome.GetError().GetErrorType() != Aws::RDS::RDSErrors::D_B_CLUSTER_NOT_FOUND_FAULT) { result = false; @@ -776,6 +774,11 @@ bool AwsDoc::Aurora::describeDBCluster(const Aws::String &dbClusterIdentifier, << outcome.GetError().GetMessage() << std::endl; } + // This example does not log an error if the DB cluster does not exist. + // Instead, clusterResult is set to empty. + else { + clusterResult = Aws::RDS::Model::DBCluster(); + } return result; @@ -902,8 +905,6 @@ bool AwsDoc::Aurora::describeDBInstance(const Aws::String &dbInstanceIdentifier, if (outcome.IsSuccess()) { instanceResult = outcome.GetResult().GetDBInstances()[0]; } - // This example does not log an error if the DB instance does not exist. - // Instead, it returns false. else if (outcome.GetError().GetErrorType() != Aws::RDS::RDSErrors::D_B_INSTANCE_NOT_FOUND_FAULT) { result = false; @@ -911,6 +912,11 @@ bool AwsDoc::Aurora::describeDBInstance(const Aws::String &dbInstanceIdentifier, << outcome.GetError().GetMessage() << std::endl; } + // This example does not log an error if the DB instance does not exist. + // Instead, instanceResult is set to empty. + else { + instanceResult = Aws::RDS::Model::DBInstance(); + } return result; } diff --git a/cpp/example_code/aurora/hello_aurora/CMakeLists.txt b/cpp/example_code/aurora/hello_aurora/CMakeLists.txt index 86dcda5ac86..3c893483d12 100644 --- a/cpp/example_code/aurora/hello_aurora/CMakeLists.txt +++ b/cpp/example_code/aurora/hello_aurora/CMakeLists.txt @@ -3,7 +3,7 @@ # snippet-start:[cpp.example_code.aurora.hello_aurora.cmake] # Set the minimum required version of CMake for this project. -cmake_minimum_required(VERSION 3.8) +cmake_minimum_required(VERSION 3.13) # Set the AWS service components used by this project. set(SERVICE_COMPONENTS rds) diff --git a/cpp/example_code/autoscaling/CMakeLists.txt b/cpp/example_code/autoscaling/CMakeLists.txt index 654623e7703..efa094f0def 100644 --- a/cpp/example_code/autoscaling/CMakeLists.txt +++ b/cpp/example_code/autoscaling/CMakeLists.txt @@ -2,7 +2,7 @@ # SPDX-License-Identifier: Apache-2.0 # Set the minimum required version of CMake for this project. -cmake_minimum_required(VERSION 3.8) +cmake_minimum_required(VERSION 3.13) set(SERVICE_NAME auto_scaling) set(SERVICE_COMPONENTS autoscaling ec2 monitoring) diff --git a/cpp/example_code/autoscaling/hello_autoscaling/CMakeLists.txt b/cpp/example_code/autoscaling/hello_autoscaling/CMakeLists.txt index d0240154fb6..dcbb7bccea6 100644 --- a/cpp/example_code/autoscaling/hello_autoscaling/CMakeLists.txt +++ b/cpp/example_code/autoscaling/hello_autoscaling/CMakeLists.txt @@ -3,7 +3,7 @@ # snippet-start:[cpp.example_code.autoscaling.hello_autoscaling.cmake] # Set the minimum required version of CMake for this project. -cmake_minimum_required(VERSION 3.8) +cmake_minimum_required(VERSION 3.13) # Set the AWS service components used by this project. set(SERVICE_COMPONENTS autoscaling) diff --git a/cpp/example_code/cloudtrail/CMakeLists.txt b/cpp/example_code/cloudtrail/CMakeLists.txt index 8093ecdf79c..640cb421118 100644 --- a/cpp/example_code/cloudtrail/CMakeLists.txt +++ b/cpp/example_code/cloudtrail/CMakeLists.txt @@ -7,7 +7,7 @@ # CONDITIONS OF ANY KIND, either express or implied. See the License for the # specific language governing permissions and limitations under the License. -cmake_minimum_required(VERSION 3.2) +cmake_minimum_required(VERSION 3.13) project(cloudtrail-examples) set (CMAKE_CXX_STANDARD 11) diff --git a/cpp/example_code/cloudwatch/CMakeLists.txt b/cpp/example_code/cloudwatch/CMakeLists.txt index 7fe394f4497..2e70c1697ce 100644 --- a/cpp/example_code/cloudwatch/CMakeLists.txt +++ b/cpp/example_code/cloudwatch/CMakeLists.txt @@ -8,7 +8,7 @@ # SPDX-License-Identifier: Apache-2.0 # Set the minimum required version of CMake for this project. -cmake_minimum_required(VERSION 3.8) +cmake_minimum_required(VERSION 3.13) set(SERVICE_NAME cloudwatch) set(SERVICE_COMPONENTS monitoring events logs) diff --git a/cpp/example_code/codebuild/CMakeLists.txt b/cpp/example_code/codebuild/CMakeLists.txt index 081d5d99ad8..467c5d13d21 100644 --- a/cpp/example_code/codebuild/CMakeLists.txt +++ b/cpp/example_code/codebuild/CMakeLists.txt @@ -7,7 +7,7 @@ # CONDITIONS OF ANY KIND, either express or implied. See the License for the # specific language governing permissions and limitations under the License. -cmake_minimum_required(VERSION 3.2) +cmake_minimum_required(VERSION 3.13) project(codebuild-examples) set (CMAKE_CXX_STANDARD 11) diff --git a/cpp/example_code/codecommit/CMakeLists.txt b/cpp/example_code/codecommit/CMakeLists.txt index 653bc8251fc..85a88d08c36 100644 --- a/cpp/example_code/codecommit/CMakeLists.txt +++ b/cpp/example_code/codecommit/CMakeLists.txt @@ -7,7 +7,7 @@ # CONDITIONS OF ANY KIND, either express or implied. See the License for the # specific language governing permissions and limitations under the License. -cmake_minimum_required(VERSION 3.2) +cmake_minimum_required(VERSION 3.13) project(codecommit-examples) set (CMAKE_CXX_STANDARD 11) diff --git a/cpp/example_code/cognito/CMakeLists.txt b/cpp/example_code/cognito/CMakeLists.txt index d50d8a751d1..a5e49b96b3a 100644 --- a/cpp/example_code/cognito/CMakeLists.txt +++ b/cpp/example_code/cognito/CMakeLists.txt @@ -2,7 +2,7 @@ # SPDX-License-Identifier: Apache-2.0 # Set the minimum required version of CMake for this project. -cmake_minimum_required(VERSION 3.8) +cmake_minimum_required(VERSION 3.13) set(SERVICE_NAME cognito) set(SERVICE_COMPONENTS cognito-idp) diff --git a/cpp/example_code/cognito/hello_cognito/CMakeLists.txt b/cpp/example_code/cognito/hello_cognito/CMakeLists.txt index 7e5b8f6c340..269e9cf590f 100644 --- a/cpp/example_code/cognito/hello_cognito/CMakeLists.txt +++ b/cpp/example_code/cognito/hello_cognito/CMakeLists.txt @@ -3,7 +3,7 @@ # snippet-start:[cpp.example_code.cognito.hello_cognito.cmake] # Set the minimum required version of CMake for this project. -cmake_minimum_required(VERSION 3.8) +cmake_minimum_required(VERSION 3.13) # Set the AWS service components used by this project. set(SERVICE_COMPONENTS cognito-idp) diff --git a/cpp/example_code/cross-service/photo_asset_manager/CMakeLists.txt b/cpp/example_code/cross-service/photo_asset_manager/CMakeLists.txt index 99231d14242..48288fe462e 100644 --- a/cpp/example_code/cross-service/photo_asset_manager/CMakeLists.txt +++ b/cpp/example_code/cross-service/photo_asset_manager/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.12) +cmake_minimum_required(VERSION 3.13) set(CMAKE_CXX_STANDARD 11) project(cpp_pam_lambdas LANGUAGES CXX) diff --git a/cpp/example_code/cross-service/serverless-aurora/CMakeLists.txt b/cpp/example_code/cross-service/serverless-aurora/CMakeLists.txt index 0d903fb4ba2..70c02e0c0a1 100644 --- a/cpp/example_code/cross-service/serverless-aurora/CMakeLists.txt +++ b/cpp/example_code/cross-service/serverless-aurora/CMakeLists.txt @@ -2,7 +2,7 @@ # SPDX-License-Identifier: Apache-2.0 # Set the minimum required version of CMake for this project. -cmake_minimum_required(VERSION 3.9) +cmake_minimum_required(VERSION 3.13) set(SERVICE_COMPONENTS sesv2 rds-data) 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 efd59ced16c..af3595f3861 100644 --- a/cpp/example_code/cross-service/topics_and_queues/CMakeLists.txt +++ b/cpp/example_code/cross-service/topics_and_queues/CMakeLists.txt @@ -2,7 +2,7 @@ # SPDX-License-Identifier: Apache-2.0 # Set the minimum required version of CMake for this project. -cmake_minimum_required(VERSION 3.8) +cmake_minimum_required(VERSION 3.13) set(SERVICE_COMPONENTS sns sqs) diff --git a/cpp/example_code/dynamodb/CMakeLists.txt b/cpp/example_code/dynamodb/CMakeLists.txt index b69f10a2fde..fec456cdce4 100644 --- a/cpp/example_code/dynamodb/CMakeLists.txt +++ b/cpp/example_code/dynamodb/CMakeLists.txt @@ -2,7 +2,7 @@ # SPDX-License-Identifier: Apache-2.0 # Set the minimum required version of CMake for this project. -cmake_minimum_required(VERSION 3.8) +cmake_minimum_required(VERSION 3.13) set(SERVICE_NAME dynamodb) set(SERVICE_COMPONENTS dynamodb s3) # s3 is required for tests, and it must be included here because of caching. diff --git a/cpp/example_code/dynamodb/hello_dynamodb/CMakeLists.txt b/cpp/example_code/dynamodb/hello_dynamodb/CMakeLists.txt index 7a31e5280ad..477ff5006c6 100644 --- a/cpp/example_code/dynamodb/hello_dynamodb/CMakeLists.txt +++ b/cpp/example_code/dynamodb/hello_dynamodb/CMakeLists.txt @@ -3,7 +3,7 @@ # snippet-start:[cpp.example_code.dynamodb.hello_dynamodb.cmake] # Set the minimum required version of CMake for this project. -cmake_minimum_required(VERSION 3.8) +cmake_minimum_required(VERSION 3.13) # Set the AWS service components used by this project. set(SERVICE_COMPONENTS dynamodb) diff --git a/cpp/example_code/ebs/CMakeLists.txt b/cpp/example_code/ebs/CMakeLists.txt index 496c727389c..2df6ad4d254 100644 --- a/cpp/example_code/ebs/CMakeLists.txt +++ b/cpp/example_code/ebs/CMakeLists.txt @@ -7,7 +7,7 @@ # CONDITIONS OF ANY KIND, either express or implied. See the License for the # specific language governing permissions and limitations under the License. -cmake_minimum_required(VERSION 3.2) +cmake_minimum_required(VERSION 3.13) project(ebs-examples) set (CMAKE_CXX_STANDARD 11) diff --git a/cpp/example_code/ec2/CMakeLists.txt b/cpp/example_code/ec2/CMakeLists.txt index 9c8a52cc0bf..aab8e5522dc 100644 --- a/cpp/example_code/ec2/CMakeLists.txt +++ b/cpp/example_code/ec2/CMakeLists.txt @@ -2,7 +2,7 @@ # SPDX-License-Identifier: Apache-2.0 # Set the minimum required version of CMake for this project. -cmake_minimum_required(VERSION 3.8) +cmake_minimum_required(VERSION 3.13) set(SERVICE_NAME ec2) set(SERVICE_COMPONENTS ec2) diff --git a/cpp/example_code/ec2/hello_ec2/CMakeLists.txt b/cpp/example_code/ec2/hello_ec2/CMakeLists.txt index 3cf13f46195..03854950d62 100644 --- a/cpp/example_code/ec2/hello_ec2/CMakeLists.txt +++ b/cpp/example_code/ec2/hello_ec2/CMakeLists.txt @@ -3,7 +3,7 @@ # snippet-start:[cpp.example_code.ec2.hello_ec2.cmake] # Set the minimum required version of CMake for this project. -cmake_minimum_required(VERSION 3.8) +cmake_minimum_required(VERSION 3.13) # Set the AWS service components used by this project. set(SERVICE_COMPONENTS ec2) diff --git a/cpp/example_code/efs/CMakeLists.txt b/cpp/example_code/efs/CMakeLists.txt index 854f3f2c234..e295848ee42 100644 --- a/cpp/example_code/efs/CMakeLists.txt +++ b/cpp/example_code/efs/CMakeLists.txt @@ -7,7 +7,7 @@ # CONDITIONS OF ANY KIND, either express or implied. See the License for the # specific language governing permissions and limitations under the License. -cmake_minimum_required(VERSION 3.2) +cmake_minimum_required(VERSION 3.13) project(efs-examples) set (CMAKE_CXX_STANDARD 11) diff --git a/cpp/example_code/elasticache/CMakeLists.txt b/cpp/example_code/elasticache/CMakeLists.txt index 08ffced6187..39a495352b8 100644 --- a/cpp/example_code/elasticache/CMakeLists.txt +++ b/cpp/example_code/elasticache/CMakeLists.txt @@ -7,7 +7,7 @@ # CONDITIONS OF ANY KIND, either express or implied. See the License for the # specific language governing permissions and limitations under the License. -cmake_minimum_required(VERSION 3.2) +cmake_minimum_required(VERSION 3.13) project(elasticache-examples) set (CMAKE_CXX_STANDARD 11) diff --git a/cpp/example_code/elasticfilesystem/CMakeLists.txt b/cpp/example_code/elasticfilesystem/CMakeLists.txt index db30938f0d9..abdebfe7b41 100644 --- a/cpp/example_code/elasticfilesystem/CMakeLists.txt +++ b/cpp/example_code/elasticfilesystem/CMakeLists.txt @@ -7,7 +7,7 @@ # CONDITIONS OF ANY KIND, either express or implied. See the License for the # specific language governing permissions and limitations under the License. -cmake_minimum_required(VERSION 3.2) +cmake_minimum_required(VERSION 3.13) project(elasticfilesystem-examples) set (CMAKE_CXX_STANDARD 11) diff --git a/cpp/example_code/general/CMakeLists.txt b/cpp/example_code/general/CMakeLists.txt index 5fc5cab4700..c0fbe23cb5c 100644 --- a/cpp/example_code/general/CMakeLists.txt +++ b/cpp/example_code/general/CMakeLists.txt @@ -3,7 +3,7 @@ # snippet-start:[general.cpp.starter.cmakelists] -cmake_minimum_required(VERSION 3.3) +cmake_minimum_required(VERSION 3.13) set(CMAKE_CXX_STANDARD 11) project(app LANGUAGES CXX) diff --git a/cpp/example_code/glacier/CMakeLists.txt b/cpp/example_code/glacier/CMakeLists.txt index 38ba4119a36..d6967fe906f 100644 --- a/cpp/example_code/glacier/CMakeLists.txt +++ b/cpp/example_code/glacier/CMakeLists.txt @@ -7,7 +7,7 @@ # CONDITIONS OF ANY KIND, either express or implied. See the License for the # specific language governing permissions and limitations under the License. -cmake_minimum_required(VERSION 3.2) +cmake_minimum_required(VERSION 3.13) project(glacier-examples) set (CMAKE_CXX_STANDARD 11) diff --git a/cpp/example_code/glue/CMakeLists.txt b/cpp/example_code/glue/CMakeLists.txt index 26172fc4181..635ddb6db43 100644 --- a/cpp/example_code/glue/CMakeLists.txt +++ b/cpp/example_code/glue/CMakeLists.txt @@ -2,7 +2,7 @@ # SPDX-License-Identifier: Apache-2.0 # Set the minimum required version of CMake for this project. -cmake_minimum_required(VERSION 3.8) +cmake_minimum_required(VERSION 3.13) set(SERVICE_NAME glue) set(SERVICE_COMPONENTS glue s3 iam) diff --git a/cpp/example_code/glue/hello_glue/CMakeLists.txt b/cpp/example_code/glue/hello_glue/CMakeLists.txt index 5e1000ba5f8..99b0f97b470 100644 --- a/cpp/example_code/glue/hello_glue/CMakeLists.txt +++ b/cpp/example_code/glue/hello_glue/CMakeLists.txt @@ -3,7 +3,7 @@ # snippet-start:[cpp.example_code.glue.hello_glue.cmake] # Set the minimum required version of CMake for this project. -cmake_minimum_required(VERSION 3.8) +cmake_minimum_required(VERSION 3.13) # Set the AWS service components used by this project. set(SERVICE_COMPONENTS glue) diff --git a/cpp/example_code/guardduty/CMakeLists.txt b/cpp/example_code/guardduty/CMakeLists.txt index e90cc181f30..fdf2028b8d9 100644 --- a/cpp/example_code/guardduty/CMakeLists.txt +++ b/cpp/example_code/guardduty/CMakeLists.txt @@ -7,7 +7,7 @@ # CONDITIONS OF ANY KIND, either express or implied. See the License for the # specific language governing permissions and limitations under the License. -cmake_minimum_required(VERSION 3.2) +cmake_minimum_required(VERSION 3.13) project(guardduty-examples) set (CMAKE_CXX_STANDARD 11) diff --git a/cpp/example_code/iam/CMakeLists.txt b/cpp/example_code/iam/CMakeLists.txt index fc21bd2a540..d0a916d64d5 100644 --- a/cpp/example_code/iam/CMakeLists.txt +++ b/cpp/example_code/iam/CMakeLists.txt @@ -2,7 +2,7 @@ # SPDX-License-Identifier: Apache-2.0 # Set the minimum required version of CMake for this project. -cmake_minimum_required(VERSION 3.8) +cmake_minimum_required(VERSION 3.13) set(SERVICE_NAME iam) set(SERVICE_COMPONENTS iam s3 sts) @@ -10,41 +10,33 @@ set(SERVICE_COMPONENTS iam s3 sts) # 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() - # 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) +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(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 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) + # Copy relevant AWS SDK for C++ libraries into the current binary directory for running and debugging. - 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_SOURCE can be defined in the command line to limit the files in a build. For example, # you can limit files to one action. @@ -79,6 +71,6 @@ endforeach() if(BUILD_TESTS) - add_subdirectory(gtests) + add_subdirectory(tests) endif() diff --git a/cpp/example_code/iam/hello_iam/CMakeLists.txt b/cpp/example_code/iam/hello_iam/CMakeLists.txt index 44339bd84e8..6dec17b8c69 100644 --- a/cpp/example_code/iam/hello_iam/CMakeLists.txt +++ b/cpp/example_code/iam/hello_iam/CMakeLists.txt @@ -3,7 +3,7 @@ # snippet-start:[cpp.example_code.iam.hello_iam.cmake] # Set the minimum required version of CMake for this project. -cmake_minimum_required(VERSION 3.8) +cmake_minimum_required(VERSION 3.13) # Set the AWS service components used by this project. set(SERVICE_COMPONENTS iam) diff --git a/cpp/example_code/iam/iam_create_user_assume_role_scenario.cpp b/cpp/example_code/iam/iam_create_user_assume_role_scenario.cpp index 11bfb909259..2742e400ab2 100644 --- a/cpp/example_code/iam/iam_create_user_assume_role_scenario.cpp +++ b/cpp/example_code/iam/iam_create_user_assume_role_scenario.cpp @@ -55,6 +55,7 @@ // snippet-start:[cpp.example_code.iam.Scenario_CreateUserAssumeRole] namespace AwsDoc { namespace IAM { + //! Cleanup by deleting created entities. /*! \sa DeleteCreatedEntities @@ -69,6 +70,8 @@ namespace AwsDoc { const Aws::IAM::Model::Policy &policy); } + static const int LIST_BUCKETS_WAIT_SEC = 20; + static const char ALLOCATION_TAG[] = "example_code"; } @@ -320,7 +323,7 @@ bool AwsDoc::IAM::iamCreateUserAssumeRoleScenario( // 7. List objects in the bucket (this should succeed). // Repeatedly call ListBuckets, because there is often a delay // before the policy with ListBucket permissions has been applied to the role. - // Repeat at most 20 times when access is denied. + // Repeat at most LIST_BUCKETS_WAIT_SEC times when access is denied. while (true) { Aws::S3::S3Client s3Client( Aws::Auth::AWSCredentials(credentials.GetAccessKeyId(), @@ -330,10 +333,10 @@ bool AwsDoc::IAM::iamCreateUserAssumeRoleScenario( clientConfig); Aws::S3::Model::ListBucketsOutcome listBucketsOutcome = s3Client.ListBuckets(); if (!listBucketsOutcome.IsSuccess()) { - if ((count > 20) || + if ((count > LIST_BUCKETS_WAIT_SEC) || listBucketsOutcome.GetError().GetErrorType() != Aws::S3::S3Errors::ACCESS_DENIED) { - std::cerr << "Could not lists buckets after 20 seconds. " << + std::cerr << "Could not lists buckets after " << LIST_BUCKETS_WAIT_SEC << " seconds. " << listBucketsOutcome.GetError().GetMessage() << std::endl; DeleteCreatedEntities(client, role, user, policy); return false; diff --git a/cpp/example_code/iam/gtests/CMakeLists.txt b/cpp/example_code/iam/tests/CMakeLists.txt similarity index 83% rename from cpp/example_code/iam/gtests/CMakeLists.txt rename to cpp/example_code/iam/tests/CMakeLists.txt index 72c25bf682e..fcd57ec0313 100644 --- a/cpp/example_code/iam/gtests/CMakeLists.txt +++ b/cpp/example_code/iam/tests/CMakeLists.txt @@ -17,6 +17,8 @@ set(CMAKE_CXX_STANDARD 14) # Build shared libraries by default. set(BUILD_SHARED_LIBS ON) +enable_testing() + find_package(GTest) if(NOT GTest_FOUND) @@ -32,8 +34,12 @@ 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() @@ -47,15 +53,15 @@ 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) - - set(CMAKE_BUILD_TYPE Debug) # Explicitly setting CMAKE_BUILD_TYPE is necessary in Windows to copy DLLs. +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 + CURRENT_TARGET_AWS_DEPENDENCIES "" - ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE} + ${CMAKE_CURRENT_BINARY_DIR}${BIN_SUB_DIR} ) add_custom_command( @@ -63,10 +69,11 @@ if(MSVC AND BUILD_SHARED_LIBS) ${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} + ${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/iam/gtests/gtest_access_key_last_used.cpp b/cpp/example_code/iam/tests/gtest_access_key_last_used.cpp similarity index 100% rename from cpp/example_code/iam/gtests/gtest_access_key_last_used.cpp rename to cpp/example_code/iam/tests/gtest_access_key_last_used.cpp diff --git a/cpp/example_code/iam/gtests/gtest_attach_role_policy.cpp b/cpp/example_code/iam/tests/gtest_attach_role_policy.cpp similarity index 100% rename from cpp/example_code/iam/gtests/gtest_attach_role_policy.cpp rename to cpp/example_code/iam/tests/gtest_attach_role_policy.cpp diff --git a/cpp/example_code/iam/gtests/gtest_create_access_key.cpp b/cpp/example_code/iam/tests/gtest_create_access_key.cpp similarity index 100% rename from cpp/example_code/iam/gtests/gtest_create_access_key.cpp rename to cpp/example_code/iam/tests/gtest_create_access_key.cpp diff --git a/cpp/example_code/iam/gtests/gtest_create_account_alias.cpp b/cpp/example_code/iam/tests/gtest_create_account_alias.cpp similarity index 100% rename from cpp/example_code/iam/gtests/gtest_create_account_alias.cpp rename to cpp/example_code/iam/tests/gtest_create_account_alias.cpp diff --git a/cpp/example_code/iam/gtests/gtest_create_policy.cpp b/cpp/example_code/iam/tests/gtest_create_policy.cpp similarity index 100% rename from cpp/example_code/iam/gtests/gtest_create_policy.cpp rename to cpp/example_code/iam/tests/gtest_create_policy.cpp diff --git a/cpp/example_code/iam/gtests/gtest_create_role.cpp b/cpp/example_code/iam/tests/gtest_create_role.cpp similarity index 100% rename from cpp/example_code/iam/gtests/gtest_create_role.cpp rename to cpp/example_code/iam/tests/gtest_create_role.cpp diff --git a/cpp/example_code/iam/gtests/gtest_create_user.cpp b/cpp/example_code/iam/tests/gtest_create_user.cpp similarity index 100% rename from cpp/example_code/iam/gtests/gtest_create_user.cpp rename to cpp/example_code/iam/tests/gtest_create_user.cpp diff --git a/cpp/example_code/iam/gtests/gtest_delete_access_key.cpp b/cpp/example_code/iam/tests/gtest_delete_access_key.cpp similarity index 100% rename from cpp/example_code/iam/gtests/gtest_delete_access_key.cpp rename to cpp/example_code/iam/tests/gtest_delete_access_key.cpp diff --git a/cpp/example_code/iam/gtests/gtest_delete_account_alias.cpp b/cpp/example_code/iam/tests/gtest_delete_account_alias.cpp similarity index 100% rename from cpp/example_code/iam/gtests/gtest_delete_account_alias.cpp rename to cpp/example_code/iam/tests/gtest_delete_account_alias.cpp diff --git a/cpp/example_code/iam/gtests/gtest_delete_policy.cpp b/cpp/example_code/iam/tests/gtest_delete_policy.cpp similarity index 100% rename from cpp/example_code/iam/gtests/gtest_delete_policy.cpp rename to cpp/example_code/iam/tests/gtest_delete_policy.cpp diff --git a/cpp/example_code/iam/gtests/gtest_delete_server_certificate.cpp b/cpp/example_code/iam/tests/gtest_delete_server_certificate.cpp similarity index 100% rename from cpp/example_code/iam/gtests/gtest_delete_server_certificate.cpp rename to cpp/example_code/iam/tests/gtest_delete_server_certificate.cpp diff --git a/cpp/example_code/iam/gtests/gtest_delete_user.cpp b/cpp/example_code/iam/tests/gtest_delete_user.cpp similarity index 100% rename from cpp/example_code/iam/gtests/gtest_delete_user.cpp rename to cpp/example_code/iam/tests/gtest_delete_user.cpp diff --git a/cpp/example_code/iam/gtests/gtest_detach_role_policy.cpp b/cpp/example_code/iam/tests/gtest_detach_role_policy.cpp similarity index 100% rename from cpp/example_code/iam/gtests/gtest_detach_role_policy.cpp rename to cpp/example_code/iam/tests/gtest_detach_role_policy.cpp diff --git a/cpp/example_code/iam/gtests/gtest_get_policy.cpp b/cpp/example_code/iam/tests/gtest_get_policy.cpp similarity index 100% rename from cpp/example_code/iam/gtests/gtest_get_policy.cpp rename to cpp/example_code/iam/tests/gtest_get_policy.cpp diff --git a/cpp/example_code/iam/gtests/gtest_get_server_certificate.cpp b/cpp/example_code/iam/tests/gtest_get_server_certificate.cpp similarity index 100% rename from cpp/example_code/iam/gtests/gtest_get_server_certificate.cpp rename to cpp/example_code/iam/tests/gtest_get_server_certificate.cpp diff --git a/cpp/example_code/iam/gtests/gtest_iam_create_user_assume_role_scenario.cpp b/cpp/example_code/iam/tests/gtest_iam_create_user_assume_role_scenario.cpp similarity index 100% rename from cpp/example_code/iam/gtests/gtest_iam_create_user_assume_role_scenario.cpp rename to cpp/example_code/iam/tests/gtest_iam_create_user_assume_role_scenario.cpp diff --git a/cpp/example_code/iam/gtests/gtest_list_access_keys.cpp b/cpp/example_code/iam/tests/gtest_list_access_keys.cpp similarity index 100% rename from cpp/example_code/iam/gtests/gtest_list_access_keys.cpp rename to cpp/example_code/iam/tests/gtest_list_access_keys.cpp diff --git a/cpp/example_code/iam/gtests/gtest_list_account_aliases.cpp b/cpp/example_code/iam/tests/gtest_list_account_aliases.cpp similarity index 100% rename from cpp/example_code/iam/gtests/gtest_list_account_aliases.cpp rename to cpp/example_code/iam/tests/gtest_list_account_aliases.cpp diff --git a/cpp/example_code/iam/gtests/gtest_list_policies.cpp b/cpp/example_code/iam/tests/gtest_list_policies.cpp similarity index 100% rename from cpp/example_code/iam/gtests/gtest_list_policies.cpp rename to cpp/example_code/iam/tests/gtest_list_policies.cpp diff --git a/cpp/example_code/iam/gtests/gtest_list_server_certificates.cpp b/cpp/example_code/iam/tests/gtest_list_server_certificates.cpp similarity index 100% rename from cpp/example_code/iam/gtests/gtest_list_server_certificates.cpp rename to cpp/example_code/iam/tests/gtest_list_server_certificates.cpp diff --git a/cpp/example_code/iam/gtests/gtest_list_users.cpp b/cpp/example_code/iam/tests/gtest_list_users.cpp similarity index 100% rename from cpp/example_code/iam/gtests/gtest_list_users.cpp rename to cpp/example_code/iam/tests/gtest_list_users.cpp diff --git a/cpp/example_code/iam/gtests/gtest_put_role_policy.cpp b/cpp/example_code/iam/tests/gtest_put_role_policy.cpp similarity index 100% rename from cpp/example_code/iam/gtests/gtest_put_role_policy.cpp rename to cpp/example_code/iam/tests/gtest_put_role_policy.cpp diff --git a/cpp/example_code/iam/gtests/gtest_update_access_key.cpp b/cpp/example_code/iam/tests/gtest_update_access_key.cpp similarity index 100% rename from cpp/example_code/iam/gtests/gtest_update_access_key.cpp rename to cpp/example_code/iam/tests/gtest_update_access_key.cpp diff --git a/cpp/example_code/iam/gtests/gtest_update_server_certificate.cpp b/cpp/example_code/iam/tests/gtest_update_server_certificate.cpp similarity index 100% rename from cpp/example_code/iam/gtests/gtest_update_server_certificate.cpp rename to cpp/example_code/iam/tests/gtest_update_server_certificate.cpp diff --git a/cpp/example_code/iam/gtests/gtest_update_user.cpp b/cpp/example_code/iam/tests/gtest_update_user.cpp similarity index 100% rename from cpp/example_code/iam/gtests/gtest_update_user.cpp rename to cpp/example_code/iam/tests/gtest_update_user.cpp diff --git a/cpp/example_code/iam/gtests/iam_gtests.cpp b/cpp/example_code/iam/tests/iam_gtests.cpp similarity index 100% rename from cpp/example_code/iam/gtests/iam_gtests.cpp rename to cpp/example_code/iam/tests/iam_gtests.cpp diff --git a/cpp/example_code/iam/gtests/iam_gtests.h b/cpp/example_code/iam/tests/iam_gtests.h similarity index 100% rename from cpp/example_code/iam/gtests/iam_gtests.h rename to cpp/example_code/iam/tests/iam_gtests.h diff --git a/cpp/example_code/iam/gtests/test_main.cpp b/cpp/example_code/iam/tests/test_main.cpp similarity index 100% rename from cpp/example_code/iam/gtests/test_main.cpp rename to cpp/example_code/iam/tests/test_main.cpp diff --git a/cpp/example_code/kinesis/CMakeLists.txt b/cpp/example_code/kinesis/CMakeLists.txt index d94d7f5e34a..2e4df0175ba 100644 --- a/cpp/example_code/kinesis/CMakeLists.txt +++ b/cpp/example_code/kinesis/CMakeLists.txt @@ -7,7 +7,7 @@ # CONDITIONS OF ANY KIND, either express or implied. See the License for the # specific language governing permissions and limitations under the License. -cmake_minimum_required(VERSION 3.2) +cmake_minimum_required(VERSION 3.13) project(kinesis-examples) set (CMAKE_CXX_STANDARD 11) diff --git a/cpp/example_code/lambda/CMakeLists.txt b/cpp/example_code/lambda/CMakeLists.txt index 8c2923d615c..cdfcca74808 100644 --- a/cpp/example_code/lambda/CMakeLists.txt +++ b/cpp/example_code/lambda/CMakeLists.txt @@ -2,7 +2,7 @@ # SPDX-License-Identifier: Apache-2.0 # Set the minimum required version of CMake for this project. -cmake_minimum_required(VERSION 3.8) +cmake_minimum_required(VERSION 3.13) set(SERVICE_NAME lambda) set(SERVICE_COMPONENTS lambda iam) diff --git a/cpp/example_code/lambda/cpp_lambda/calculator/CMakeLists.txt b/cpp/example_code/lambda/cpp_lambda/calculator/CMakeLists.txt index 42b665c344f..28e496f256d 100644 --- a/cpp/example_code/lambda/cpp_lambda/calculator/CMakeLists.txt +++ b/cpp/example_code/lambda/cpp_lambda/calculator/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.12) +cmake_minimum_required(VERSION 3.13) set(CMAKE_CXX_STANDARD 11) project(cpp_lambda_calculator LANGUAGES CXX) diff --git a/cpp/example_code/lambda/cpp_lambda/increment/CMakeLists.txt b/cpp/example_code/lambda/cpp_lambda/increment/CMakeLists.txt index 52d33bcde33..aefd013c65a 100644 --- a/cpp/example_code/lambda/cpp_lambda/increment/CMakeLists.txt +++ b/cpp/example_code/lambda/cpp_lambda/increment/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.12) +cmake_minimum_required(VERSION 3.13) set(CMAKE_CXX_STANDARD 11) project(cpp_lambda_increment LANGUAGES CXX) diff --git a/cpp/example_code/lambda/hello_lambda/CMakeLists.txt b/cpp/example_code/lambda/hello_lambda/CMakeLists.txt index ba0675d51ce..597e22b7426 100644 --- a/cpp/example_code/lambda/hello_lambda/CMakeLists.txt +++ b/cpp/example_code/lambda/hello_lambda/CMakeLists.txt @@ -3,7 +3,7 @@ # snippet-start:[cpp.example_code.lambda.hello_lambda.cmake] # Set the minimum required version of CMake for this project. -cmake_minimum_required(VERSION 3.8) +cmake_minimum_required(VERSION 3.13) # Set the AWS service components used by this project. set(SERVICE_COMPONENTS lambda) diff --git a/cpp/example_code/mediaconvert/CMakeLists.txt b/cpp/example_code/mediaconvert/CMakeLists.txt index c9a16789dc0..652a9b08945 100644 --- a/cpp/example_code/mediaconvert/CMakeLists.txt +++ b/cpp/example_code/mediaconvert/CMakeLists.txt @@ -2,7 +2,7 @@ # SPDX-License-Identifier: Apache-2.0 # Set the minimum required version of CMake for this project. -cmake_minimum_required(VERSION 3.8) +cmake_minimum_required(VERSION 3.13) set(SERVICE_NAME mediaconvert) set(SERVICE_COMPONENTS mediaconvert) diff --git a/cpp/example_code/neptune/CMakeLists.txt b/cpp/example_code/neptune/CMakeLists.txt index e74421bb1a7..8e1084b61ec 100644 --- a/cpp/example_code/neptune/CMakeLists.txt +++ b/cpp/example_code/neptune/CMakeLists.txt @@ -7,7 +7,7 @@ # CONDITIONS OF ANY KIND, either express or implied. See the License for the # specific language governing permissions and limitations under the License. -cmake_minimum_required(VERSION 3.2) +cmake_minimum_required(VERSION 3.13) project(neptune-examples) set (CMAKE_CXX_STANDARD 11) diff --git a/cpp/example_code/rds/CMakeLists.txt b/cpp/example_code/rds/CMakeLists.txt index 21105724e15..88479d69f60 100644 --- a/cpp/example_code/rds/CMakeLists.txt +++ b/cpp/example_code/rds/CMakeLists.txt @@ -2,7 +2,7 @@ # SPDX-License-Identifier: Apache-2.0 # Set the minimum required version of CMake for this project. -cmake_minimum_required(VERSION 3.11) +cmake_minimum_required(VERSION 3.13) set(SERVICE_NAME rds) set(SERVICE_COMPONENTS rds) diff --git a/cpp/example_code/rds/getting_started_with_db_instances.cpp b/cpp/example_code/rds/getting_started_with_db_instances.cpp index 2bd19117521..38ddf17b377 100644 --- a/cpp/example_code/rds/getting_started_with_db_instances.cpp +++ b/cpp/example_code/rds/getting_started_with_db_instances.cpp @@ -758,8 +758,6 @@ bool AwsDoc::RDS::describeDBInstance(const Aws::String &dbInstanceIdentifier, if (outcome.IsSuccess()) { instanceResult = outcome.GetResult().GetDBInstances()[0]; } - // This example does not log an error if the DB instance does not exist. - // Instead, it returns false. else if (outcome.GetError().GetErrorType() != Aws::RDS::RDSErrors::D_B_INSTANCE_NOT_FOUND_FAULT) { result = false; @@ -767,6 +765,11 @@ bool AwsDoc::RDS::describeDBInstance(const Aws::String &dbInstanceIdentifier, << outcome.GetError().GetMessage() << std::endl; } + // This example does not log an error if the DB instance does not exist. + // Instead, instanceResult is set to empty. + else { + instanceResult = Aws::RDS::Model::DBInstance(); + } return result; } diff --git a/cpp/example_code/rds/hello_rds/CMakeLists.txt b/cpp/example_code/rds/hello_rds/CMakeLists.txt index 5ac9798e5ef..14873b620a3 100644 --- a/cpp/example_code/rds/hello_rds/CMakeLists.txt +++ b/cpp/example_code/rds/hello_rds/CMakeLists.txt @@ -3,7 +3,7 @@ # snippet-start:[cpp.example_code.rds.hello_rds.cmake] # Set the minimum required version of CMake for this project. -cmake_minimum_required(VERSION 3.8) +cmake_minimum_required(VERSION 3.13) # Set the AWS service components used by this project. set(SERVICE_COMPONENTS rds) diff --git a/cpp/example_code/redshift/CMakeLists.txt b/cpp/example_code/redshift/CMakeLists.txt index 793c6fb0a8e..be3aee30a9a 100644 --- a/cpp/example_code/redshift/CMakeLists.txt +++ b/cpp/example_code/redshift/CMakeLists.txt @@ -7,7 +7,7 @@ # CONDITIONS OF ANY KIND, either express or implied. See the License for the # specific language governing permissions and limitations under the License. -cmake_minimum_required(VERSION 3.2) +cmake_minimum_required(VERSION 3.13) project(redshift-examples) set (CMAKE_CXX_STANDARD 11) diff --git a/cpp/example_code/s3-crt/CMakeLists.txt b/cpp/example_code/s3-crt/CMakeLists.txt index 653898897ec..e146b070240 100644 --- a/cpp/example_code/s3-crt/CMakeLists.txt +++ b/cpp/example_code/s3-crt/CMakeLists.txt @@ -2,7 +2,7 @@ # SPDX-License-Identifier: Apache-2.0 # Set the minimum required version of CMake for this project. -cmake_minimum_required(VERSION 3.8) +cmake_minimum_required(VERSION 3.13) # Set this project's name. project("s3-crt-examples") diff --git a/cpp/example_code/s3/CMakeLists.txt b/cpp/example_code/s3/CMakeLists.txt index 4c5ee8804a0..c6361665014 100644 --- a/cpp/example_code/s3/CMakeLists.txt +++ b/cpp/example_code/s3/CMakeLists.txt @@ -2,44 +2,41 @@ # SPDX-License-Identifier: Apache-2.0 # Set the minimum required version of CMake for this project. -cmake_minimum_required(VERSION 3.8) +cmake_minimum_required(VERSION 3.13) + +set(SERVICE_NAME) +set(SERVICE_COMPONENTS s3 sts iam) # Set this project's name. -project("s3-examples") +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) -# Enable CTest for testing these code examples. -if(BUILD_TESTS) - include(CTest) -endif() +# Use the MSVC variable to determine if this is a Windows build. +set(WINDOWS_BUILD ${MSVC}) -# Build shared libraries by default. -if(NOT BUILD_SHARED_LIBS) - set(BUILD_SHARED_LIBS ON) +# 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 s3 sts iam) +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) - # 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. +if(WINDOWS_BUILD) + # Copy relevant AWS SDK for C++ libraries into the current binary directory for running and debugging. - list(APPEND SERVICE_LIST s3 sts iam) + # 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() # Add the code example-specific header files. diff --git a/cpp/example_code/s3/hello_s3/CMakeLists.txt b/cpp/example_code/s3/hello_s3/CMakeLists.txt index 476834f2fc9..51a35d06585 100644 --- a/cpp/example_code/s3/hello_s3/CMakeLists.txt +++ b/cpp/example_code/s3/hello_s3/CMakeLists.txt @@ -3,7 +3,7 @@ # snippet-start:[cpp.example_code.s3.hello_s3.cmake] # Set the minimum required version of CMake for this project. -cmake_minimum_required(VERSION 3.8) +cmake_minimum_required(VERSION 3.13) # Set the AWS service components used by this project. set(SERVICE_COMPONENTS s3) diff --git a/cpp/example_code/s3/list_objects.cpp b/cpp/example_code/s3/list_objects.cpp index 10a5abe9124..8f72be1d4d8 100644 --- a/cpp/example_code/s3/list_objects.cpp +++ b/cpp/example_code/s3/list_objects.cpp @@ -78,7 +78,7 @@ int main() //TODO(user): Name of a bucket in your account. //The bucket must have at least one object in it. One way to achieve //this is to configure and run put_object.cpp's executable first. - const Aws::String bucket_name = "my-bucket-2f2730dd-0f5d-4dfa-b55d-8d36a3bfea39"; + const Aws::String bucket_name = ""; Aws::Client::ClientConfiguration clientConfig; // Optional: Set to the AWS Region in which the bucket was created (overrides config file). diff --git a/cpp/example_code/s3/tests/CMakeLists.txt b/cpp/example_code/s3/tests/CMakeLists.txt index de4335de35a..46922aab065 100644 --- a/cpp/example_code/s3/tests/CMakeLists.txt +++ b/cpp/example_code/s3/tests/CMakeLists.txt @@ -17,6 +17,8 @@ set(CMAKE_CXX_STANDARD 14) # Build shared libraries by default. set(BUILD_SHARED_LIBS ON) +enable_testing() + find_package(GTest) if(NOT GTest_FOUND) @@ -33,8 +35,11 @@ if(NOT GTest_FOUND) 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() @@ -46,28 +51,26 @@ 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. +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 + CURRENT_TARGET_AWS_DEPENDENCIES "" - ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE} - ) + ${CMAKE_CURRENT_BINARY_DIR}${BIN_SUB_DIR} + ) 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} + ${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/s3encryption/CMakeLists.txt b/cpp/example_code/s3encryption/CMakeLists.txt index 5b23fb7f8fa..5b1dba22241 100644 --- a/cpp/example_code/s3encryption/CMakeLists.txt +++ b/cpp/example_code/s3encryption/CMakeLists.txt @@ -2,7 +2,7 @@ # SPDX-License-Identifier: Apache-2.0 # Set the minimum required version of CMake for this project. -cmake_minimum_required(VERSION 3.8) +cmake_minimum_required(VERSION 3.13) # Set this project's name. project("s3-encryption-examples") diff --git a/cpp/example_code/secretsmanager/CMakeLists.txt b/cpp/example_code/secretsmanager/CMakeLists.txt index e48c29c879a..14540c71841 100644 --- a/cpp/example_code/secretsmanager/CMakeLists.txt +++ b/cpp/example_code/secretsmanager/CMakeLists.txt @@ -9,7 +9,7 @@ # Minimal CMakeLists.txt for the AWS SDK for C++. -cmake_minimum_required(VERSION 3.3) +cmake_minimum_required(VERSION 3.13) set(CMAKE_CXX_STANDARD 11) project(secretsmanager-example LANGUAGES CXX) diff --git a/cpp/example_code/ses/CMakeLists.txt b/cpp/example_code/ses/CMakeLists.txt index e36da98fd13..ffe7f8b91ea 100644 --- a/cpp/example_code/ses/CMakeLists.txt +++ b/cpp/example_code/ses/CMakeLists.txt @@ -7,7 +7,7 @@ # CONDITIONS OF ANY KIND, either express or implied. See the License for the # specific language governing permissions and limitations under the License. -cmake_minimum_required(VERSION 3.2) +cmake_minimum_required(VERSION 3.13) project(ses-examples) set (CMAKE_CXX_STANDARD 11) diff --git a/cpp/example_code/sns/CMakeLists.txt b/cpp/example_code/sns/CMakeLists.txt index 9b54bdd8062..809f288324f 100644 --- a/cpp/example_code/sns/CMakeLists.txt +++ b/cpp/example_code/sns/CMakeLists.txt @@ -2,7 +2,7 @@ # SPDX-License-Identifier: Apache-2.0 # Set the minimum required version of CMake for this project. -cmake_minimum_required(VERSION 3.8) +cmake_minimum_required(VERSION 3.13) set(SERVICE_NAME sns) set(SERVICE_COMPONENTS sns) diff --git a/cpp/example_code/sns/hello_sns/CMakeLists.txt b/cpp/example_code/sns/hello_sns/CMakeLists.txt index 6e5dc688a54..316af3e065f 100644 --- a/cpp/example_code/sns/hello_sns/CMakeLists.txt +++ b/cpp/example_code/sns/hello_sns/CMakeLists.txt @@ -3,7 +3,7 @@ # snippet-start:[cpp.example_code.sns.hello_sns.cmake] # Set the minimum required version of CMake for this project. -cmake_minimum_required(VERSION 3.8) +cmake_minimum_required(VERSION 3.13) # Set the AWS service components used by this project. set(SERVICE_COMPONENTS sns) diff --git a/cpp/example_code/sqs/CMakeLists.txt b/cpp/example_code/sqs/CMakeLists.txt index 0d03de7fef9..4a7fa859bac 100644 --- a/cpp/example_code/sqs/CMakeLists.txt +++ b/cpp/example_code/sqs/CMakeLists.txt @@ -2,7 +2,7 @@ # SPDX-License-Identifier: Apache-2.0 # Set the minimum required version of CMake for this project. -cmake_minimum_required(VERSION 3.8) +cmake_minimum_required(VERSION 3.13) set(SERVICE_NAME sqs) set(SERVICE_COMPONENTS sqs) diff --git a/cpp/example_code/sqs/hello_sqs/CMakeLists.txt b/cpp/example_code/sqs/hello_sqs/CMakeLists.txt index b736943685a..be7ce136b41 100644 --- a/cpp/example_code/sqs/hello_sqs/CMakeLists.txt +++ b/cpp/example_code/sqs/hello_sqs/CMakeLists.txt @@ -3,7 +3,7 @@ # snippet-start:[cpp.example_code.sqs.hello_sqs.cmake] # Set the minimum required version of CMake for this project. -cmake_minimum_required(VERSION 3.8) +cmake_minimum_required(VERSION 3.13) # Set the AWS service components used by this project. set(SERVICE_COMPONENTS sqs) diff --git a/cpp/example_code/storage_gateway/CMakeLists.txt b/cpp/example_code/storage_gateway/CMakeLists.txt index 1977d539c02..f99b14a0e56 100644 --- a/cpp/example_code/storage_gateway/CMakeLists.txt +++ b/cpp/example_code/storage_gateway/CMakeLists.txt @@ -7,7 +7,7 @@ # CONDITIONS OF ANY KIND, either express or implied. See the License for the # specific language governing permissions and limitations under the License. -cmake_minimum_required(VERSION 3.2) +cmake_minimum_required(VERSION 3.13) project(sg-examples) set (CMAKE_CXX_STANDARD 11) diff --git a/cpp/example_code/sts/CMakeLists.txt b/cpp/example_code/sts/CMakeLists.txt index a9132eecdb2..36decf4c35f 100644 --- a/cpp/example_code/sts/CMakeLists.txt +++ b/cpp/example_code/sts/CMakeLists.txt @@ -2,7 +2,7 @@ # SPDX-License-Identifier: Apache-2.0 # Set the minimum required version of CMake for this project. -cmake_minimum_required(VERSION 3.8) +cmake_minimum_required(VERSION 3.13) set(SERVICE_NAME sts) set(SERVICE_COMPONENTS sts iam s3) diff --git a/cpp/example_code/sts/gtests/CMakeLists.txt b/cpp/example_code/sts/tests/CMakeLists.txt similarity index 100% rename from cpp/example_code/sts/gtests/CMakeLists.txt rename to cpp/example_code/sts/tests/CMakeLists.txt diff --git a/cpp/example_code/sts/gtests/gtest_assume_role.cpp b/cpp/example_code/sts/tests/gtest_assume_role.cpp similarity index 100% rename from cpp/example_code/sts/gtests/gtest_assume_role.cpp rename to cpp/example_code/sts/tests/gtest_assume_role.cpp diff --git a/cpp/example_code/sts/gtests/sts_gtests.cpp b/cpp/example_code/sts/tests/sts_gtests.cpp similarity index 100% rename from cpp/example_code/sts/gtests/sts_gtests.cpp rename to cpp/example_code/sts/tests/sts_gtests.cpp diff --git a/cpp/example_code/sts/gtests/sts_gtests.h b/cpp/example_code/sts/tests/sts_gtests.h similarity index 100% rename from cpp/example_code/sts/gtests/sts_gtests.h rename to cpp/example_code/sts/tests/sts_gtests.h diff --git a/cpp/example_code/sts/gtests/test_main.cpp b/cpp/example_code/sts/tests/test_main.cpp similarity index 100% rename from cpp/example_code/sts/gtests/test_main.cpp rename to cpp/example_code/sts/tests/test_main.cpp diff --git a/cpp/example_code/transcribe/CMakeLists.txt b/cpp/example_code/transcribe/CMakeLists.txt index c0f4f7ce4c8..11279c91ca7 100644 --- a/cpp/example_code/transcribe/CMakeLists.txt +++ b/cpp/example_code/transcribe/CMakeLists.txt @@ -1,5 +1,5 @@ # CMakeLists.txt -cmake_minimum_required(VERSION 3.11) +cmake_minimum_required(VERSION 3.13) set(CMAKE_CXX_STANDARD 11) project(get_transcript LANGUAGES CXX) diff --git a/cpp/example_code/transfer-manager/CMakeLists.txt b/cpp/example_code/transfer-manager/CMakeLists.txt index 25a2a4cb184..bf639abc476 100644 --- a/cpp/example_code/transfer-manager/CMakeLists.txt +++ b/cpp/example_code/transfer-manager/CMakeLists.txt @@ -2,7 +2,7 @@ # SPDX-License-Identifier: Apache-2.0 # Set the minimum required version of CMake for this project. -cmake_minimum_required(VERSION 3.8) +cmake_minimum_required(VERSION 3.13) # Set this project's name. project("tm-examples") diff --git a/cpp/run_automated_tests.py b/cpp/run_automated_tests.py index 668235b5c44..36096161225 100644 --- a/cpp/run_automated_tests.py +++ b/cpp/run_automated_tests.py @@ -18,6 +18,11 @@ # # 'python3 run_automated_tests.py -23 -s s3' # +# To enable parallel builds, the environment variable PARALLEL_BUILD can be set to a number. +# +# 'export PARALLEL_BUILD=$(nproc)' +# + import os @@ -27,6 +32,7 @@ import glob import re import datetime +import sys build_sub_dir = "build_tests" @@ -45,6 +51,8 @@ def build_cmake_tests(cmake_files, executable_pattern) : cmake_args = os.getenv("EXTRA_CMAKE_ARGS") + parallel_build = os.getenv("PARALLEL_BUILD") + for cmake_file in cmake_files : source_dir = os.path.dirname(cmake_file) module_build_dir = os.path.join(build_dir, source_dir) @@ -56,13 +64,21 @@ def build_cmake_tests(cmake_files, executable_pattern) : cmake_command.append(cmake_args) cmake_command.append(os.path.join(base_dir, source_dir)) + if sys.platform == "win32": + cmake_command.append('-DBIN_SUB_DIR=/Debug') + result_code = subprocess.call(cmake_command, shell=False) if result_code != 0 : print(f"Error with cmake for {source_dir}") has_error = True continue - result_code = subprocess.call(['cmake', '--build', '.'], shell=False) + if parallel_build is not None: + print("building parallel") + result_code = subprocess.call(['cmake', '--build', '.', '--parallel', f'{parallel_build}'], shell=False) + else: + result_code = subprocess.call(['cmake', '--build', '.'], shell=False) + if result_code != 0 : has_error = True continue