Skip to content

Please export() the CMake targets and add include directories to them #31

Closed
@rix0rrr

Description

@rix0rrr

Hi,

I'd like to consume the SDK from my own CMake project without having to install it (I detest having to install libraries into my global system directories just to compile against them).

Fortunately, CMake makes it quite easy to consume a library that's also built with CMake from its build directory, if you prep the CMakeLists file correctly.

I'd just need two things:

  • Specify the include directories for each module--and I could live without those because I can fix those in my own CMakeLists file.
  • But the thing that I really need, is that you export() the targets in your top-level CMakeLists file.

The command looks like this:

export(TARGETS
    aws-cpp-sdk-s3
    aws-cpp-sdk-core
    ...
    FILE AwsCppSdkConfig.cmake)

Given this, if I build my project with:

cmake -DAwsCppSdk_DIR=/path/to/aws-sdk-cpp/build

Then in my own CMake file I can do this:

find_package(AwsCppSdk)
# Fix up the include directories of the targets that I found (wouldn't need to do this if you did it)
set_property(TARGET aws-cpp-sdk-core PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${AwsCppSdk_DIR}/../aws-cpp-sdk-core/include)
set_property(TARGET aws-cpp-sdk-s3 PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${AwsCppSdk_DIR}/../aws-cpp-sdk-s3/include)

And now I can simply target_link_libraries against the libraries without having to specify anything else (transitive include and linker dependencies will be taken care of for me by CMake).

I'm in the process of compiling a guide to the most effective CMake usage. You can find it here:

http://rix0r.nl/blog/2015/08/13/cmake-guide/

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions