AWS SDK for C++
Developer Guide

 AWS Documentation » AWS SDK for C++ » Developer Guide » Getting Started » Building Your Application with CMake

# Building Your Application with CMake

CMake is a build tool that can manage your application's dependencies and create native makefiles suitable for the platform you're building on. It's an easy way to create and build projects using the AWS SDK for C++.

## Setting Up a CMake Project

To set up a CMake project for use with the AWS SDK for C++

1. Create a directory to hold your source files.:

mkdir my_example_project
2. Open the directory and add a CMakeLists.txt file that specifies your project's name, executables, source files, and linked libraries. The following is a minimal example:

# minimal CMakeLists.txt for the AWS SDK for C++
cmake_minimum_required(VERSION 2.8)

# "my-example" is just an example value.
project(my-example)

# Locate the AWS SDK for C++ package.
# Requires that you build with:
#   -Daws-sdk-cpp_DIR=/path/to/sdk_build
# or export/set:
#   CMAKE_PREFIX_PATH=/path/to/sdk_build
find_package(aws-sdk-cpp)

# Link to the SDK shared libraries.

# The executable name and its sourcefiles

# The libraries used by your executable.
# "aws-cpp-sdk-s3" is just an example.



Note

You can set many options in your CMakeLists.txt build configuration file. For an introduction to the file's features, see the CMake tutorial on the CMake website.

## Setting CMAKE_PREFIX_PATH (Optional)

CMake needs to know the location of the aws-sdk-cpp-config.cmake so that it can properly resolve the AWS SDK libraries that your application uses. You can find this file in the build directory that you used to build the SDK.

By setting the path in CMAKE_PREFIX_PATH, you won't need to type this path every time you rebuild your application.

You can set it on Linux, macOS, or Unix like this.:

export CMAKE_PREFIX_PATH=/path/to/sdk_build_dir

On Windows, use set instead.:

set CMAKE_PREFIX_PATH=C:\path\to\sdk_build_dir

## Building with CMake

Create a directory into which cmake will build your application.:

mkdir my_project_build

Open the directory and run cmake using the path to your project's source directory.:

cd my_project_build
cmake ../my_example_project

If you didn't set CMAKE_PREFIX_PATH, you must add the path to the SDK's build directory using -Daws-sdk-cpp_DIR.:

cmake -Daws-sdk-cpp_DIR=/path/to/sdk_build_dir ../my_example_project

After cmake generates your build directory, you can use make (or nmake on Windows) to build your application.:

make