diff --git a/CMakeLists.txt b/CMakeLists.txt index a4a433a5d..8375ea518 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,7 +2,6 @@ # SPDX-License-Identifier: Apache-2.0. cmake_minimum_required(VERSION 3.0) -option(STATIC_CRT "Windows specific option that to specify static/dynamic run-time library" OFF) option(ALLOW_CROSS_COMPILED_TESTS "Allow tests to be compiled via cross compile, for use with qemu" OFF) project(aws-c-common LANGUAGES C VERSION 0.1.0) diff --git a/cmake/AwsCFlags.cmake b/cmake/AwsCFlags.cmake index fb4b14e1a..a4415c937 100644 --- a/cmake/AwsCFlags.cmake +++ b/cmake/AwsCFlags.cmake @@ -11,6 +11,7 @@ option(LEGACY_COMPILER_SUPPORT "This enables builds with compiler versions such option(AWS_SUPPORT_WIN7 "Restricts WINAPI calls to Win7 and older (This will have implications in downstream libraries that use TLS especially)" OFF) option(AWS_WARNINGS_ARE_ERRORS "Compiler warning is treated as an error. Try turning this off when observing errors on a new or uncommon compiler" OFF) option(AWS_ENABLE_TRACING "Enable tracing macros" OFF) +option(STATIC_CRT "Windows-specific option to specify static/dynamic run-time library" OFF) # Check for Posix Large Files Support (LFS). # On most 64bit systems, LFS is enabled by default. @@ -80,17 +81,17 @@ function(aws_set_common_properties target) list(APPEND AWS_C_FLAGS /DAWS_SUPPORT_WIN7=1) endif() - string(TOUPPER "${CMAKE_BUILD_TYPE}" _CMAKE_BUILD_TYPE) - if(STATIC_CRT) - string(REPLACE "/MD" "/MT" _FLAGS "${CMAKE_C_FLAGS_${_CMAKE_BUILD_TYPE}}") + # Set MSVC runtime libary. + # Note, there are better ways of doing this if we bump our CMake minimum to 3.14+ + # See: https://cmake.org/cmake/help/latest/policy/CMP0091.html + if (STATIC_CRT) + list(APPEND AWS_C_FLAGS "/MT$<$:d>") else() - string(REPLACE "/MT" "/MD" _FLAGS "${CMAKE_C_FLAGS_${_CMAKE_BUILD_TYPE}}") + list(APPEND AWS_C_FLAGS "/MD$<$:d>") endif() - string(REPLACE " " ";" _FLAGS "${_FLAGS}") - list(APPEND AWS_C_FLAGS "${_FLAGS}") else() - list(APPEND AWS_C_FLAGS -Wall -Wstrict-prototypes) + lisD(APPEND AWS_C_FLAGS -Wall -Wstrict-prototypes) if (NOT CMAKE_BUILD_TYPE STREQUAL Release) list(APPEND AWS_C_FLAGS -fno-omit-frame-pointer)