[LLVMdev] [PATCH]: MSVC build enhancements

Óscar Fuentes ofv at wanadoo.es
Sat Mar 6 13:49:45 PST 2010


José Fonseca <jose.r.fonseca at gmail.com> writes:

> Attached are two patches with MSVC build enchancements.
>
> They are quite trivial, but were necessary to correctly link LLVM
> libraries with Mesa3D on Windows.

[snip]

>    add_llvm_definitions( -D_SCL_SECURE_NO_DEPRECATE )
> +  add_llvm_definitions( -D_SECURE_SCL=0 )

With this setting the default LLVM build becomes incompatible with
libraries compiled with _SECURE_SCL=1 (which is the default
setting). The right thing here is to use an option.

> -    add_llvm_definitions("/${LLVM_USE_CRT}")
> +    # http://www.cmake.org/Wiki/CMake_FAQ#How_can_I_build_my_MSVC_application_with_a_static_runtime.3F
> +    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" "/${LLVM_USE_CRT}" ${flag_var} "${${flag_var}}")
> +       endif(${flag_var} MATCHES "/MD")
> +    endforeach(flag_var)
>      message(STATUS "Using VC++ CRT: ${LLVM_USE_CRT}")
>    endif (NOT ${LLVM_USE_CRT} STREQUAL "")

Ugh! Well, if this is the only way... However, AFAIK the last flag is
the one that prevails, and that's the one introduced by
add_llvm_definitions. What's the problem if you don't replace the switch
everywhere? Does the replacement method above works well with debug
builds? (On debug builds, /MDd is used by default instead of /MD, so
replacing /MD with /MTd, for instance, would give /MTdd)

> --- a/include/llvm/System/DataTypes.h.cmake
> +++ b/include/llvm/System/DataTypes.h.cmake
> @@ -100,6 +100,9 @@ typedef u_int64_t uint64_t;
>  #else
>  #include <math.h>
>  #endif
> +#ifdef HAVE_STDINT_H
> +#include <stdint.h>
> +#else /* !HAVE_STDINT_H */

This looks incorrect to me. stdint.h is already included below for
non-MSVC systems. Maybe you inteded to #include it for MSVC only? Or do
intend to correct some problem with non-MSVC builds too?

>  typedef __int64 int64_t;
>  typedef unsigned __int64 uint64_t;
>  typedef signed int int32_t;
> @@ -145,6 +148,7 @@ typedef signed int ssize_t;
>  #ifndef UINT64_C
>  # define UINT64_C(C) ((uint64_t) C ## ULL)
>  #endif
> +#endif /* !HAVE_STDINT_H */
>  #endif /* _MSC_VER */
>  
>  /* Set defaults for constants which we cannot find. */




More information about the llvm-dev mailing list