Reputation: 11
I need to use AWS SDK in a project that has four configurations "Debug, RelWithDebInfo, MinSizeRel, and Release"
If I follow the instructions to build and install the SDK from source, it seems I can only have one configuration installed at a time. The docs say:
Generate the build files by running cmake. Specify on the cmake command line whether to build a Debug or Release version. Choose Debug throughout this procedure to run a debug configuration of your application code. Choose Release throughout this procedure to run a release configuration of your application code.
What is the intended usage in situations where I need to run both debug and release configurations of my application code? My project is currently in development I am frequently switching between debug and release configurations. This seems like it would be a common use case but I'm having some difficulty getting this set up.
If I just go with release config of the sdk, then when I try to build my project in debug I get:
error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in AWSTest3.hello-world.obj
If I go with the debug sdk, when I try to build my project in release I get the reverse. That all make makes sense and is what I would expect under those conditions.
I tried installing both release and debug versions in separate directories, but linking them both in my project's cmakelists.txt is a challenge.
When I put into cmakelists.txt:
find_package(AWSSDK)
find_package(AWSSDKdebug)
Cmake finds the first one and skips the second one. The reason for this it turns out is because when it finds the package in the suggested folder the next thing it does is runs AWSSDKconfig.cmake in that folder. The first thing that file does is:
if(AWSSDK_FOUND)
return()
endif()
When the second package hits that line is quits immediately. So it's very clear they don't intend you to have two separation installations of the SDK and link to each of them independently.
If I comment out that condition in the second library and it will find both packages. Next step is to link them.
AWS recommends linking with:
target_link_libraries(${PROJECT_NAME} PUBLIC ${AWSSDK_LINK_LIBRARIES})
${AWSSDK_LINK_LIBRARIES} is a variable that is set in AWSSDKconfig.cmake. Although whenever I try to print it it seems empty. It would seem like I need to link with something like:
find_package(AWSSDK)
target_link_libraries(${PROJECT_NAME} PUBLIC optimized ${AWSSDK_LINK_LIBRARIES})
find_package(AWSSDKdebug)
target_link_libraries(${PROJECT_NAME} PUBLIC debug ${AWSSDK_LINK_LIBRARIES})
When I use the above code I get:
CMake Error at source/projects/AWSTest3.hello-world/CMakeLists.txt:59 (target_link_libraries):
The "optimized" argument must be followed by a library.
If I leave "optimized" or "debug" out, it all links just fine. But the functionality of those specifiers is exactly what I need.
I've tried hacking AWSSDKconfig.cmake in different ways to force it to work, but the further I go in that direction clearer it becomes that this is not the right way to go about it.
Any input would be much appreciated. Thank you!
Upvotes: 1
Views: 380
Reputation: 1
You should be able to do this by building and installing in separate directories. You can do this with the following cmake parameter when building the sdk:
-DCMAKE_INSTALL_PREFIX="<path-to-install>"
and then use the following to when building your application:
-DCMAKE_PREFIX_PATH="<path-of-install-folder>"
overall it might look something like this
git clone --recurse-submodules https://github.com/aws/aws-sdk-cpp
# debug install
mkdir build-debug
cd build-debug
cmake ../aws-sdk-cpp -DBUILD_ONLY="s3;s3-crt" -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX="<path-to-debug-install>/debug-install"
cmake --build . --config=Debug
cmake --install . --config=Debug
cd ..
# release install
mkdir build-release
cd build-release
cmake ../aws-sdk-cpp -DBUILD_ONLY="s3;s3-crt" -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX="<path-to-release-install>/release-install"
cmake --build . --config=Release
cmake --install . --config=Release
cd ..
# building your application in release
cd <your build dir>
cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH="/<path-to-release-install>/release-install"
cmake --build . --config Release
Upvotes: 0