Permalink
Browse files

A windows patch to r446 from Hume.

  • Loading branch information...
1 parent 03a42b0 commit 5bd47b154b07ffb97c258e17b5d492f50e8dc152 Trevor Hansen committed Jun 9, 2011
View
@@ -0,0 +1,2 @@
+This patch to revision 446 was provided by Hume and tested under cygwin/mingw/centos 5.4/msvc9.0.
+
@@ -0,0 +1,41 @@
+# version 1.00
+# usage of macro is tricky, so you may refer to the .orig file for inline form
+
+# here we must use macro because only macro can modify the arg in outer scope
+macro(replace_msvs_mtmd_flags the_cflags bflag)
+ set(loc_flag ${bflag})
+ if(loc_flag)
+ if(${the_cflags} MATCHES "/MD")
+ #message("before replace :", "${${the_cflags}}")
+ string(REGEX REPLACE "/MD" "/MT" ${the_cflags} "${${the_cflags}}")
+ #message("After replace :", "${${the_cflags}}")
+ endif(${the_cflags} MATCHES "/MD")
+ else(loc_flag)
+ # pass
+ if(${the_cflags} MATCHES "/MT")
+ string(REGEX REPLACE "/MT" "/MD" ${the_cflags} "${${the_cflags}}")
+ endif(${the_cflags} MATCHES "/MT")
+ endif(loc_flag)
+endmacro(replace_msvs_mtmd_flags the_cflags bflag)
+
+if(WIN32 AND MSVC)
+ # using macro or function wpn't do the correct thing
+ option(MSVC_MD "Using /MD when compiling using msvc toolchains" OFF)
+
+ # get all CMAKE_CXX_FLAGS CMAKE_C_FLAGS variants
+ set(BldList CMAKE_CXX_FLAGS CMAKE_C_FLAGS)
+ foreach(build_typ DEBUG RELEASE MINSIZEREL RELWITHDEBINFO)
+ list(APPEND BldList CMAKE_CXX_FLAGS_${build_typ} CMAKE_C_FLAGS_${build_typ})
+ endforeach(build_typ DEBUG RELEASE MINSIZEREL RELWITHDEBINFO)
+
+ # note that function or macro won't work must use global code
+ if(NOT MSVC_MD)
+ foreach(flag_var ${BldList})
+ replace_msvs_mtmd_flags(${flag_var} ON)
+ endforeach(flag_var ${BldList})
+ else(NOT MSVC_MD)
+ foreach(flag_var ${BldList})
+ replace_msvs_mtmd_flags(${flag_var} OFF)
+ endforeach(flag_var ${BldList})
+ endif(NOT MSVC_MD)
+endif(WIN32 AND MSVC)
@@ -0,0 +1,45 @@
+# version 1.00
+# gcc -static-libgcc should be specified
+
+# here we must use macro because only macro can modify the arg in outer scope
+macro(replace_gcc_flags the_cflags bflag)
+ set(loc_flag ${bflag})
+ if(loc_flag)
+ if(${the_cflags} MATCHES "-shared-libgcc")
+ string(REGEX REPLACE "-shared-libgcc" "-static-libgcc" ${the_cflags} "${${the_cflags}}")
+ else(${the_cflags} MATCHES "-shared-libgcc")
+ set(${the_cflags} "${${the_cflags}} -static-libgcc")
+ endif(${the_cflags} MATCHES "-shared-libgcc")
+ else(loc_flag)
+ # pass
+ if(${the_cflags} MATCHES "-static-libgcc")
+ string(REGEX REPLACE "-static-libgcc" "-shared-libgcc" ${the_cflags} "${${the_cflags}}")
+ else(${the_cflags} MATCHES "-static-libgcc")
+ set(${the_cflags} "${${the_cflags}} -shared-libgcc")
+ endif(${the_cflags} MATCHES "-static-libgcc")
+ endif(loc_flag)
+endmacro(replace_gcc_flags the_cflags bflag)
+
+if(UNIX)
+ # using macro or function wpn't do the correct thing
+ option(USING_GCC_SHARED_RUNTIME_LIB "Using -shared-libgcc not -static-libgcc when compiling using gcc toolchains" OFF)
+
+ # get all CMAKE_CXX_FLAGS CMAKE_C_FLAGS variants
+ set(BldList CMAKE_CXX_FLAGS CMAKE_C_FLAGS)
+ foreach(build_typ DEBUG RELEASE MINSIZEREL RELWITHDEBINFO)
+ list(APPEND BldList CMAKE_CXX_FLAGS_${build_typ} CMAKE_C_FLAGS_${build_typ})
+ endforeach(build_typ DEBUG RELEASE MINSIZEREL RELWITHDEBINFO)
+
+ # note that if function or macro not work we must use global code
+ if(NOT USING_GCC_SHARED_RUNTIME_LIB)
+ foreach(flag_var ${BldList})
+ replace_gcc_flags(${flag_var} ON)
+ endforeach(flag_var ${BldList})
+ else(NOT USING_GCC_SHARED_RUNTIME_LIB)
+ foreach(flag_var ${BldList})
+ replace_gcc_flags(${flag_var} OFF)
+ endforeach(flag_var ${BldList})
+ endif(NOT USING_GCC_SHARED_RUNTIME_LIB)
+endif(UNIX)
+
+
@@ -0,0 +1,6 @@
+# version 1.00
+# to make msvc/gcc to link statically the runtime libraries
+get_filename_component(MYMODESDIR ${CMAKE_CURRENT_LIST_FILE} PATH)
+include("${MYMODESDIR}/msvcmt.cmake")
+include("${MYMODESDIR}/slibgcc.cmake")
+
Oops, something went wrong.

0 comments on commit 5bd47b1

Please sign in to comment.