aws-sdk-cpp icon indicating copy to clipboard operation
aws-sdk-cpp copied to clipboard

Set static/shared msvc runtime flags using a CMake property instead of overwriting the flags

Open TinyTinni opened this issue 2 years ago • 1 comments

Issue #, if available: #2056

Description of changes: This PR changes how the flags for the MSVC C++ runtime linkage are set. Before this PR, the CMAKE_CXX_FLAGS were changed. WIth CMake 3.15, there exists the property CMAKE_MSVC_RUNTIME_LIBRARY. Based on the options provided by this SDK, this property is set instead of changing the flags.

Defining the property so early has 2 advantages:

  • it is close to the option handing
  • from the CMake doc This variable is used to initialize the MSVC_RUNTIME_LIBRARY property on all targets as they are created which results in that all targets have the right runtime. This solves the problem described in #2056

As you can read in the CMake documentation, any non msvc builds are not affected by defining the property.

The value is ignored on compilers not targeting the MSVC ABI, but an unsupported value will be rejected as an error when using a compiler targeting the MSVC ABI.

Please ask and/or edit, if I missed something.

Check all that applies:

  • [x] Did a review by yourself.
  • [x] Added proper tests to cover this PR. (If tests are not applicable, explain.) Changes in the buildsystem. Test would be, if the project compiled or not. I cannot see any CI builds in the .guthub/workflows. If I should add a build target, please let me know.
  • [x] Checked if this PR is a breaking (APIs have been changed) change. Requires CMake 3.15 instead of 3.12. CMake 3.15 is from 2019, so I don't see it as a big problem
  • [x] Checked if this PR will not introduce cross-platform inconsistent behavior. Only Windows is affected.
  • [x] Checked if this PR would require a ReadMe/Wiki update. No Readme changes required. Options are still the same with the same semantic.

Check which platforms you have built SDK on to verify the correctness of this PR.

  • [ ] Linux
  • [x] Windows Build and unit-tested locally with dynamic and static linkage
  • [ ] Android
  • [ ] MacOS
  • [ ] IOS
  • [ ] Other Platforms

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

TinyTinni avatar Apr 12 '23 17:04 TinyTinni