Fixed bug 5112 - CMake won't compile in VS2019
authorSam Lantinga <slouken@libsdl.org>
Sat, 02 May 2020 14:43:17 -0700
changeset 13785d5fe4ad4d29c
parent 13784 cd8794af675f
child 13786 b176e7ebf6c5
Fixed bug 5112 - CMake won't compile in VS2019

dark_sylinc

Trying to build SDL with VS2019 using CMake will encounter a linking error

More specifically:

1>SDL_string.obj : error LNK2019: unresolved external symbol memset referenced in function SDL_vsnprintf_REAL
src/stdlib/SDL_stdlib.c
     1.1 --- a/src/stdlib/SDL_stdlib.c	Wed Apr 29 15:32:08 2020 +0000
     1.2 +++ b/src/stdlib/SDL_stdlib.c	Sat May 02 14:43:17 2020 -0700
     1.3 @@ -486,42 +486,22 @@
     1.4  __declspec(selectany) int _fltused = 1;
     1.5  #endif
     1.6  
     1.7 -/* The optimizer on Visual Studio 2005 and later generates memcpy() calls */
     1.8 -#if (_MSC_VER >= 1400) && defined(_WIN64) && !defined(_DEBUG) && !(_MSC_VER >= 1900 && defined(_MT))
     1.9 -#include <intrin.h>
    1.10 -
    1.11 +/* The optimizer on Visual Studio 2005 and later generates memcpy() and memset() calls */
    1.12 +#if _MSC_VER >= 1400
    1.13  #pragma function(memcpy)
    1.14 -void * memcpy ( void * destination, const void * source, size_t num )
    1.15 +void *
    1.16 +memcpy(void *dst, const void *src, size_t len)
    1.17  {
    1.18 -    const Uint8 *src = (const Uint8 *)source;
    1.19 -    Uint8 *dst = (Uint8 *)destination;
    1.20 -    size_t i;
    1.21 -    
    1.22 -    /* All WIN64 architectures have SSE, right? */
    1.23 -    if (!((uintptr_t) src & 15) && !((uintptr_t) dst & 15)) {
    1.24 -        __m128 values[4];
    1.25 -        for (i = num / 64; i--;) {
    1.26 -            _mm_prefetch(src, _MM_HINT_NTA);
    1.27 -            values[0] = *(__m128 *) (src + 0);
    1.28 -            values[1] = *(__m128 *) (src + 16);
    1.29 -            values[2] = *(__m128 *) (src + 32);
    1.30 -            values[3] = *(__m128 *) (src + 48);
    1.31 -            _mm_stream_ps((float *) (dst + 0), values[0]);
    1.32 -            _mm_stream_ps((float *) (dst + 16), values[1]);
    1.33 -            _mm_stream_ps((float *) (dst + 32), values[2]);
    1.34 -            _mm_stream_ps((float *) (dst + 48), values[3]);
    1.35 -            src += 64;
    1.36 -            dst += 64;
    1.37 -        }
    1.38 -        num &= 63;
    1.39 -    }
    1.40 +    return SDL_memcpy(dst, src, len);
    1.41 +}
    1.42  
    1.43 -    while (num--) {
    1.44 -        *dst++ = *src++;
    1.45 -    }
    1.46 -    return destination;
    1.47 +#pragma function(memset)
    1.48 +void *
    1.49 +memset(void *dst, int c, size_t len)
    1.50 +{
    1.51 +    return SDL_memset(dst, c, len);
    1.52  }
    1.53 -#endif /* _MSC_VER == 1600 && defined(_WIN64) && !defined(_DEBUG) */
    1.54 +#endif
    1.55  
    1.56  #ifdef _M_IX86
    1.57