'Downloading only specific AWS C++ SDKs using CMake's FetchContent

I'm trying to link-in the AWS C++ SDK for my CMake C++ Project. However, I'm only going to be using a subset of the SDK modules (lambda) and I don't want FetchContent_Declare to clone the entire repository. I know that I can configure the FetchContent_Declare with CMAKE_ARGS and build only the required Lambda SDK by setting the -DBUILD_ONLY=lambda, but is there a way to configure FetchContent to only download a single directory, i.e. only required Lambda SDK? I'm not working on storage-constrained device, but the entire repo is ~400mb which is really a waste if I only need a single client.

Here is the declaration for reference:

# AWS CPP SDK
FetchContent_Declare(
        awscppsdk
        GIT_REPOSITORY https://github.com/aws/aws-sdk-cpp
        GIT_TAG master
        CMAKE_ARGS -DBUILD_ONLY=lambda
)


Solution 1:[1]

You can't really avoid downloading of aws-sdk-cpp, however it's sub-modules could be controlled. See GIT_SUBMODULES .This approach is working for me (have not personally tested lambda module though)

# AWS CPP SDK
fetchcontent_declare(
  awscppsdk
  GIT_REPOSITORY https://github.com/aws/aws-sdk-cpp
  GIT_PROGRESS TRUE
  GIT_SUBMODULES crt/aws-crt-cpp aws-cpp-sdk-core aws-cpp-sdk-lambda
  GIT_TAG master
)

if(NOT awscppsdk_POPULATED)
  fetchcontent_populate(awscppsdk)
  set(BUILD_ONLY "lambda")
  set(ENABLE_TESTING OFF)
  add_subdirectory(${awscppsdk_SOURCE_DIR} ${awscppsdk_BUILD_DIR})
endif()

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Kamath