From 9772b8fed5b7714ee6fa441708aa41d960c1ab15 Mon Sep 17 00:00:00 2001 From: WolverinDEV Date: Wed, 3 Jul 2019 18:40:05 +0200 Subject: [PATCH] Added option to configure the MSVC runtime --- CMakeLists.txt | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index e6519aa..be89390 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,6 +11,42 @@ list(APPEND SOURCE_FILES tommath_superclass.h ) +macro(configure_msvc_runtime) + if(MSVC) + # Default to statically-linked runtime. + if("${MSVC_RUNTIME}" STREQUAL "") + set(MSVC_RUNTIME "static") + endif() + + # Set compiler options. + set(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(${MSVC_RUNTIME} STREQUAL "static") + foreach(variable ${variables}) + if(${variable} MATCHES "/MD") + string(REGEX REPLACE "/MD" "/MT" ${variable} "${${variable}}") + endif() + endforeach() + else() + foreach(variable ${variables}) + if(${variable} MATCHES "/MT") + string(REGEX REPLACE "/MT" "/MD" ${variable} "${${variable}}") + endif() + endforeach() + endif() + endif() +endmacro() +configure_msvc_runtime() + + add_library(tommathShared SHARED ${SOURCE_FILES}) add_library(tommathStatic STATIC ${SOURCE_FILES})