Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# SPDX-License-Identifier: Apache-2.0.
#

cmake_minimum_required(VERSION 3.13 FATAL_ERROR)
cmake_minimum_required(VERSION 3.15 FATAL_ERROR)

option(LEGACY_BUILD "If enabled, the SDK will use 1.11.0 version of CMake files to build" ON)
if (LEGACY_BUILD)
Expand All @@ -16,6 +16,7 @@ if (LEGACY_BUILD)
if (POLICY CMP0077)
cmake_policy(SET CMP0077 OLD) # CMP0077: option() honors normal variables. Introduced in 3.13
endif ()
cmake_policy(SET CMP0091 NEW)

get_filename_component(AWS_NATIVE_SDK_ROOT "${CMAKE_CURRENT_SOURCE_DIR}" ABSOLUTE)

Expand Down Expand Up @@ -147,6 +148,12 @@ if (LEGACY_BUILD)
else ()
set(STATIC_CRT ON)
endif ()

if (${STATIC_CRT})
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
else ()
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")
endif ()

# Add Linker search paths to RPATH so as to fix the problem where some linkers can't find cross-compiled dependent libraries in customer paths when linking executables.
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH true)
Expand Down
12 changes: 0 additions & 12 deletions cmake/compiler_settings.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -75,18 +75,6 @@ endmacro()

macro(set_msvc_flags)
if(MSVC)
# Based on the FORCE_SHARED_CRT and BUILD_SHARED_LIBS options, make sure our compile/link flags bring in the right CRT library
# modified from gtest's version; while only the else clause is actually necessary, do both for completeness/future-proofing
foreach (var
CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
if(BUILD_SHARED_LIBS OR FORCE_SHARED_CRT)
string(REPLACE "/MT" "/MD" ${var} "${${var}}")
else()
string(REPLACE "/MD" "/MT" ${var} "${${var}}")
endif()
endforeach()

# enable parallel builds
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")
# some of the clients are exceeding the 16-bit code section limit when building x64 debug, so use /bigobj when we build
Expand Down