[AD] static MSVC runtime (cmake)

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


Attached is a patch that allows one to use the static MSVC runtime
(/MT) by setting STATIC_MSVC_RUNTIME=on. Generally it would be used
with release mode and shared=off, but technically it could be used for
any build type.

It creates files such as allegro-static-mt.lib and allegro-mt-4.9.dll.

Tested with MSVC 10 project files and nmake.

I'll commit it if there are no objections.

--
Matthew Leverton
Index: CMakeLists.txt
===================================================================
--- CMakeLists.txt	(revision 13486)
+++ CMakeLists.txt	(working copy)
@@ -147,7 +147,12 @@
 option(WANT_DEMO "Build demo programs" on)
 option(WANT_EXAMPLES "Build example programs" on)
 option(WANT_POPUP_EXAMPLES "Use popups instead of printf for fatal errors" on)
+option(STATIC_MSVC_RUNTIME "Use static MSVC runtime (/MD)" off)
 
+if(NOT MSVC)
+    set(STATIC_MSVC_RUNTIME off)
+endif(NOT MSVC)
+
 #-----------------------------------------------------------------------------#
 #
 #   Set up compilers
@@ -374,6 +379,23 @@
         )
 endif(COMPILER_GCC)
 
+# MSVC static runtime
+
+if(STATIC_MSVC_RUNTIME)
+    foreach(flag_var
+        CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
+        CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO
+        CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
+        CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
+        if(${flag_var} MATCHES "/MD")
+            string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
+        else(${flag_var} MATCHES "/MD")
+            set(${flag_var} "${${flag_var}} /MT")
+        endif(${flag_var} MATCHES "/MD")
+    endforeach(flag_var)
+endif(STATIC_MSVC_RUNTIME)
+
+
 #-----------------------------------------------------------------------------#
 #
 #   Begin tests
Index: cmake/Common.cmake
===================================================================
--- cmake/Common.cmake	(revision 13486)
+++ cmake/Common.cmake	(working copy)
@@ -31,9 +31,14 @@
 endfunction(append_lib_type_suffix)
 
 function(append_lib_linkage_suffix var)
+    set(tmp "${${var}}")
     if(NOT BUILD_SHARED_LIBS)
-        set(${var} "${${var}}-static" PARENT_SCOPE)
+        set(tmp "${tmp}-static")
     endif(NOT BUILD_SHARED_LIBS)
+    if(STATIC_MSVC_RUNTIME)
+        set(tmp "${tmp}-mt")
+    endif(STATIC_MSVC_RUNTIME)
+    set(${var} "${tmp}" PARENT_SCOPE)
 endfunction(append_lib_linkage_suffix)
 
 # Oh my. CMake really is bad for this - but I couldn't find a better


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/