From 47d59c9dd7888b7a53bb86e3d583b0197bb7ed33 Mon Sep 17 00:00:00 2001 From: Jason Felds Date: Tue, 27 Oct 2015 19:31:04 -0400 Subject: [PATCH] Default to linking with /MT instead of /MD for VS. --- CMake/CMakeMacros.cmake | 28 ++++++++++++++++++++++++++++ CMake/DefineOptions.cmake | 2 ++ StepmaniaCore.cmake | 3 +++ 3 files changed, 33 insertions(+) diff --git a/CMake/CMakeMacros.cmake b/CMake/CMakeMacros.cmake index 9c3683f859..82428a840f 100644 --- a/CMake/CMakeMacros.cmake +++ b/CMake/CMakeMacros.cmake @@ -82,3 +82,31 @@ macro(check_compile_features BIN_DIR SOURCE_FILE GREETER GREET_SUCCESS GREET_FAI endif() endmacro() +# Borrowed from http://stackoverflow.com/q/10113017 +macro(configure_msvc_runtime) + if(MSVC) + # Get the compiler options generally used. + list(APPEND COMPILER_VARIABLES + CMAKE_C_FLAGS_DEBUG + CMAKE_C_FLAGS_MINSIZEREL + CMAKE_C_FLAGS_RELEASE + CMAKE_C_FLAGS_RELWITHDEBINFO + CMAKE_CXX_FLAGS_DEBUG + CMAKE_CXX_FLAGS_MINSIZEREL + CMAKE_CXX_FLAGS_RELEASE + CMAKE_CXX_FLAGS_RELWITHDEBINFO + ) + if (WITH_STATIC_LINKING) + set(TO_REPLACE "/MD") + set(REPLACE_WITH "/MT") + else() + set(TO_REPLACE "/MT") + set(REPLACE_WITH "/MD") + endif() + foreach(COMPILER_VARIABLE ${COMPILER_VARIABLES}) + if (${COMPILER_VARIABLE} MATCHES "${TO_REPLACE}") + string(REGEX REPLACE "${TO_REPLACE}" "${REPLACE_WITH}" ${COMPILER_VARIABLE} "${${COMPILER_VARIABLE}}") + endif() + endforeach() + endif() +endmacro() diff --git a/CMake/DefineOptions.cmake b/CMake/DefineOptions.cmake index 39535b7325..d9f626e354 100644 --- a/CMake/DefineOptions.cmake +++ b/CMake/DefineOptions.cmake @@ -46,6 +46,8 @@ if(NOT MSVC) else() # Turn this option on to enable using the Texture Font Generator. option(WITH_TEXTURE_GENERATOR "Build with the Texture Font Generator. Ensure the MFC library is installed." OFF) + # Turn this option off to use dynamic linking instead of static linking. + option(WITH_STATIC_LINKING "Build StepMania with static linking." ON) endif() if(WIN32) diff --git a/StepmaniaCore.cmake b/StepmaniaCore.cmake index 5a62bba8c0..6e33ee2531 100644 --- a/StepmaniaCore.cmake +++ b/StepmaniaCore.cmake @@ -45,6 +45,9 @@ include("${SM_CMAKE_DIR}/SMDefs.cmake") # Put the predefined targets in separate groups. set_property(GLOBAL PROPERTY USE_FOLDERS ON) +# Set up the linker flags for MSVC builds. +configure_msvc_runtime() + # Checks the standard include directories for c-style headers. # We may use C++ in this project, but the check works better with plain C headers. include(CheckIncludeFiles)