[PATCH] cmake: link statically against run-time on windows (use /MT instead of /MD)

Alp Toker alp at nuanti.com
Tue Nov 12 16:30:24 PST 2013


I just noticed it might make sense to do this for /MDd /MTd in _DEBUG as
well.

Also the MINSIZEREL_INIT cases that slipped in shouldn't be necessary.

llvm_replace_compiler_option() does a word replace so the easier way to
handle all cases would just be to do the replacement directly, something
like the following:

if(MSVC)
  foreach(lang C CXX)
    foreach(suffix "" _DEBUG _MINSIZEREL _RELEASE _RELWITHDEBINFO)
      SET(var, "CMAKE_${lang}_FLAGS${suffix}")
      STRING(REPLACE "/MD"  "/MT" "${var}" "${${var}}")
    endforeach()
  endforeach()
endif()

Hans, what do you think?

If this works I'd go with it.

I'd suggest doing the replacement for all cases for now as above, then
remove DEBUG if the size impact turns out to be a problem in day to day
development. For now the defaults should be set to get the widest
possible debugging feedback before release.

Alp.


On 12/11/2013 23:05, Hans Wennborg wrote:
>   Do the foreach thing to handle all flag variables.
>
> Hi rnk,
>
> http://llvm-reviews.chandlerc.com/D2157
>
> CHANGE SINCE LAST DIFF
>   http://llvm-reviews.chandlerc.com/D2157?vs=5479&id=5481#toc
>
> Files:
>   cmake/modules/HandleLLVMOptions.cmake
>
> Index: cmake/modules/HandleLLVMOptions.cmake
> ===================================================================
> --- cmake/modules/HandleLLVMOptions.cmake
> +++ cmake/modules/HandleLLVMOptions.cmake
> @@ -5,6 +5,7 @@
>  include(AddLLVMDefinitions)
>  include(CheckCCompilerFlag)
>  include(CheckCXXCompilerFlag)
> +include(LLVMProcessSources)
>  
>  if( CMAKE_COMPILER_IS_GNUCXX )
>    set(LLVM_COMPILER_IS_GCC_COMPATIBLE ON)
> @@ -40,6 +41,16 @@
>    endif()
>  endif()
>  
> +if(MSVC)
> +  # Link release builds against the static runtime.
> +  foreach(flag CMAKE_C_FLAGS_RELEASE CMAKE_C_FLAGS_RELWITHDEBINFO
> +      CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_MINSIZEREL_INIT
> +      CMAKE_CXX_FLAGS_RELEASE CMAKE_CXX_FLAGS_RELWITHDEBINFO
> +      CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_MINSIZEREL_INIT)
> +    llvm_replace_compiler_option("${flag}" "/MD" "/MT")
> +  endforeach()
> +endif()  
> +
>  if(WIN32)
>    if(CYGWIN)
>      set(LLVM_ON_WIN32 0)
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits

-- 
http://www.nuanti.com
the browser experts




More information about the llvm-commits mailing list