diff --git a/aws-cpp-sdk-core/CMakeLists.txt b/aws-cpp-sdk-core/CMakeLists.txt index 03e16b54a53..ec7acece361 100644 --- a/aws-cpp-sdk-core/CMakeLists.txt +++ b/aws-cpp-sdk-core/CMakeLists.txt @@ -1,5 +1,7 @@ add_project(aws-cpp-sdk-core "Core http and utility library for the AWS C++ SDK") +include(AwsFindPackage) + if(VERSION_STRING) set(AWSSDK_VERSION_STRING ${VERSION_STRING}) message(STATUS "Updating version info to ${VERSION_STRING}") @@ -493,9 +495,9 @@ endif() target_link_libraries(${PROJECT_NAME} PRIVATE ${PLATFORM_DEP_LIBS} ${CLIENT_LIBS} ${CRYPTO_LIBS} ${AWS_SDK_ADDITIONAL_LIBRARIES}) -find_package(aws-c-event-stream REQUIRED) +aws_use_package(aws-c-event-stream) -target_link_libraries(${PROJECT_NAME} PUBLIC AWS::aws-c-event-stream) +target_link_libraries(${PROJECT_NAME} PUBLIC ${DEP_AWS_LIBS}) if(USE_WINDOWS_DLL_SEMANTICS) diff --git a/cmake/AwsFindPackage.cmake b/cmake/AwsFindPackage.cmake new file mode 100644 index 00000000000..f7abd14e14b --- /dev/null +++ b/cmake/AwsFindPackage.cmake @@ -0,0 +1,22 @@ +# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +# SPDX-License-Identifier: Apache-2.0. + +option(IN_SOURCE_BUILD "If the CRT libs are being built from your source tree (add_subdirectory), set this to ON" OFF) + +# This function handles dependency list building based on if traditional CMAKE modules via. find_package should be +# used, vs if this is an in source build via. something like git submodules and add_subdirectory. +# This is largely because CMake was not well planned out, and as a result, in-source and modules don't play well +# together. Only use this on CRT libraries (including S2N), libcrypto will stay as an assumed external dependency. +# +# package_name: is the name of the package to find +# DEP_AWS_LIBS: output variable will be appended after each call to this function. You don't have to use it, +# but it can be passed directly target_link_libraries and it will be the properly qualified library +# name and namespace based on configuration. +function(aws_use_package package_name) + if (IN_SOURCE_BUILD) + set(DEP_AWS_LIBS ${DEP_AWS_LIBS} ${package_name} PARENT_SCOPE) + else() + find_package(${package_name} REQUIRED) + set(DEP_AWS_LIBS ${DEP_AWS_LIBS} AWS::${package_name} PARENT_SCOPE) + endif() +endfunction()