aws/aws-sdk-cpp

Windows Cmake find_package broken without AWSSDKConfigVersion.cmake

MetaDevo opened this issue · 5 comments

Describe the bug

Using find_package in Cmake to include aws-sdk-cpp in a Windows desktop app results in finding the headers but not the binaries, giving an error message.

Expected Behavior

No Cmake errors.

Current Behavior

Running Cmake results in this error and then it stops:

CMake Error at C:/Program Files (x86)/aws-cpp-sdk-all/lib/cmake/AWSSDK/AWSSDKConfig.cmake:123 (message):
AWS SDK for C++ headers found, but we were unable to locate the binaries.
Have you deleted or moved it?

          Please make sure header files and binaries are located in INSTALL_ROOT_DIR/INCLUDE_DIR/ and INSTALL_ROOT_DIR/LIB_DIR/[PLATFORM_PREFIX]/[Debug|Config|OtherConfigs]

Call Stack (most recent call first):
CMakeLists.txt:30 (find_package)

Reproduction Steps

Build aws-sdk-cpp from source from VS Dev Cmd Prompt:

mkdir sdk_build
cd sdk_build
cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_ONLY="core;config;s3;cognito-identity;lambda" ..
msbuild ALL_BUILD.vcxproj /p:Configuration=Release
msbuild INSTALL.vcxproj /p:Configuration=Release

In my own project's CMakeLists.txt, relevant lines:

set(BUILD_SHARED_LIBS ON)
find_package(AWSSDK CONFIG REQUIRED COMPONENTS core config s3 cognito-identity)

Run CMake.

Possible Solution

This was most likely introduced with this change: 7a7591f

I was able to temporarily fix the problem by adding this line back into C:\Program Files (x86)\aws-cpp-sdk-all\lib\cmake\AWSSDK\AWSSDKConfig.cmake:

include(${CMAKE_CURRENT_LIST_DIR}/AWSSDKConfigVersion.cmake)

Cmake runs on my project without any incident from AWS after that change.

Additional Information/Context

No response

AWS CPP SDK version used

1.11.99

Compiler and Version used

VS 2022

Operating System and version

Windows 10

Hey @MetaDevo I tried replicating your bug and cannot do so if we are referring to your bug strictly as

Using find_package in Cmake to include aws-sdk-cpp in a Windows desktop app results in finding the headers but not the binaries, giving an error message.

So I might need more information from you to replicate.

On my machine using a fresh pull of the SDK and a VS toolchain, I install the SDK using

cmake -DBUILD_ONLY="s3" \
  -DAUTORUN_UNIT_TESTS=OFF \
  -DCMAKE_INSTALL_PREFIX="C:\Users\Sam\Desktop\sdk-install" \
  -DAWS_SDK_WARNINGS_ARE_ERRORS=OFF .. \
cmake --build .
cmake --install .

Then in a small sample application

main .cpp

#include <aws/core/Aws.h>
#include <aws/s3/S3Client.h>

using namespace Aws;
using namespace Aws::S3;

int main() {
    SDKOptions options;
    InitAPI(options); {
        const auto client = Aws::MakeShared<S3Client>("Test");
        const auto resp = client->ListBuckets();
        if (!resp.IsSuccess()) {
            std::cout << "ListBuckets Failed: "
                    << resp.GetError().GetMessage()
                    << "\n";
        }
        else {
            std::cout << "Found Buckets: \n";
            for (const auto &bucket: resp.GetResult().GetBuckets()) {
                std::cout << bucket.GetName() << "\n";
            }
        }
    }
    ShutdownAPI(options);
    return 0;
}

CMakeLists.txt

cmake_minimum_required(VERSION 3.27)
project(sdk_usage)
set(CMAKE_CXX_STANDARD 20)

set(SERVICE_COMPONENTS s3)
set(WINDOWS_BUILD ${MSVC})

if (WINDOWS_BUILD) # Set the location where CMake can find the installed libraries for the AWS SDK.
    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_package(AWSSDK REQUIRED COMPONENTS s3)

if (WINDOWS_BUILD)
    # Copy relevant AWS SDK for C++ libraries into the current binary directory for running and debugging.

    # 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 ()

add_executable(sdk_usage main.cpp)
target_link_libraries(${PROJECT_NAME} ${AWSSDK_LINK_LIBRARIES})

built with

cmake -DCMAKE_PREFIX_PATH="C:/Users/Sam/Desktop/sdk-install" ..
cmake --build .

And I can confirm it finds the installed binaries fines and runs and lists buckets. If it does work for you can you update it in a way to replicate what you are seeing?

I think you might just be missing the windows specific AWSSDK_CPY_DYN_LIBS bit as when that is removed i see complaints about not being able to find binaries as well. That along wither other windows cmake patterns for the SDK can be found in the example code repo.

However if you already know all of that and it still doesnt work, could you link me what isnt working for prefrably a test example the size of the one i just linked? would be interested to see what your cmake file looks like.

Some more information:

  1. This is a cmake error, as in just the initial running of cmake, not compiling or running the program.
  2. I am running this out of the IDE QtCreator, however it's still just using cmake.
  3. As with previous versions of aws that worked without this error, I am appending CMAKE_PREFIX_PATH with "C:\Program Files (x86)\aws-cpp-sdk-all\lib;C:\Program Files (x86)\aws-cpp-sdk-all\lib\cmake".

Using @sbiscigl 's test example, I reproduce the exact same cmake error. Again this is a cmake error as launched from Qt Creator. I am using CMake version 3.24.2 however—@sbiscigl specified 3.27.

C:\Program Files (x86)\aws-cpp-sdk-all\lib\cmake\AWSSDK\AWSSDKConfig.cmake:124: error: AWS SDK for C++ headers found, but we were unable to locate the binaries. Have you deleted or moved it? Please make sure header files and binaries are located in INSTALL_ROOT_DIR/INCLUDE_DIR/ and INSTALL_ROOT_DIR/LIB_DIR/[PLATFORM_PREFIX]/[Debug|Config|OtherConfigs] CMakeLists.txt:13 (find_package)

And the specific lines referenced is in AWSSDKConfig.cmake starting at line 123:

if (NOT AWSSDK_CORE_LIB_FILE)
    message(FATAL_ERROR "AWS SDK for C++ headers found, but we were unable to locate the binaries. Have you deleted or moved it?
            Please make sure header files and binaries are located in INSTALL_ROOT_DIR/INCLUDE_DIR/ and INSTALL_ROOT_DIR/LIB_DIR/[PLATFORM_PREFIX]/[Debug|Config|OtherConfigs]")
endif()

Just to get QtCreator out of the equation, I tried cmake (ver. 3.25.3) from a command line (cygwin bash)

cmake -DCMAKE_PREFIX_PATH="C:/Program Files (x86)/aws-cpp-sdk-all" ..

on the same Windows box on @sbiscigl 's test example and got the same error:

CMake Error at C:/Program Files (x86)/aws-cpp-sdk-all/lib/cmake/AWSSDK/AWSSDKConfig.cmake:124 (message):
  AWS SDK for C++ headers found, but we were unable to locate the binaries.
  Have you deleted or moved it?

              Please make sure header files and binaries are located in INSTALL_ROOT_DIR/INCLUDE_DIR/ and INSTALL_ROOT_DIR/LIB_DIR/[PLATFORM_PREFIX]/[Debug|Config|OtherConfigs]
Call Stack (most recent call first):
  CMakeLists.txt:13 (find_package)

This seems to be the same bug as #2576.
And was fixed right after the version of sdk I'm using, so if I update to > 1.11.123 it should be fixed...will try that...
Yes it is fixed in 1.11.205. I had mistakenly thought I was in the latest tag. Closing.

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.