Browse Source

Combine c runtime linkage with build type

When compiling as a shared lib, link against the dynamic c-runtime
version.
Additionally, clean up the compile flags to append /MT to /MD and rather
replace it. This fixes warnings from the compiler.
Maurice Kalinowski 7 years ago
parent
commit
b86938501a
1 changed files with 8 additions and 2 deletions
  1. 8 2
      CMakeLists.txt

+ 8 - 2
CMakeLists.txt

@@ -224,8 +224,14 @@ endif()
 
 if(MSVC)
   set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W3 /WX") # Compiler warnings, error on warning
-  set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /MT")
-  set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /MTd")
+
+  if(NOT BUILD_SHARED_LIB)
+    set(CompilerFlags CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE CMAKE_C_FLAGS
+        CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE)
+    foreach(CompilerFlag ${CompilerFlags})
+      string(REPLACE "/MD" "/MT" ${CompilerFlag} "${${CompilerFlag}}")
+    endforeach()
+  endif()
 endif()
 
 #########################