CMake: Fixed building for Windows with VS2015 (bug #3080).
authorAlex Szpakowski <slime73@gmail.com>
Thu, 31 Dec 2015 15:26:40 -0400
changeset 9994d3e4f7b44d4d
parent 9993 e05d46c27ce3
child 9995 d79480c1e151
CMake: Fixed building for Windows with VS2015 (bug #3080).

- Don't try to link with the Visual C runtime.

- Avoid code generation that would use functions from the VC runtime.
CMakeLists.txt
     1.1 --- a/CMakeLists.txt	Thu Dec 31 01:54:11 2015 -0500
     1.2 +++ b/CMakeLists.txt	Thu Dec 31 15:26:40 2015 -0400
     1.3 @@ -169,6 +169,13 @@
     1.4        endif()
     1.5      endforeach()
     1.6    endif()
     1.7 +
     1.8 +  # Make sure /RTC1 is disabled, otherwise it will use functions from the CRT
     1.9 +  foreach(flag_var
    1.10 +      CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
    1.11 +      CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO)
    1.12 +    string(REGEX REPLACE "/RTC(su|[1su])" "" ${flag_var} "${${flag_var}}")
    1.13 +  endforeach(flag_var)
    1.14  endif()
    1.15  
    1.16  # Those are used for pkg-config and friends, so that the SDL2.pc, sdl2-config,
    1.17 @@ -944,6 +951,14 @@
    1.18    file(GLOB CORE_SOURCES ${SDL2_SOURCE_DIR}/src/core/windows/*.c)
    1.19    set(SOURCE_FILES ${SOURCE_FILES} ${CORE_SOURCES})
    1.20  
    1.21 +  if(MSVC)
    1.22 +    # Prevent codegen that would use the VC runtime libraries.
    1.23 +    add_definitions(/GS-)
    1.24 +    if(NOT ARCH_64)
    1.25 +      add_definitions(/arch:SSE)
    1.26 +    endif()
    1.27 +  endif()
    1.28 +
    1.29    # Check for DirectX
    1.30    if(DIRECTX)
    1.31      if(DEFINED MSVC_VERSION AND NOT ${MSVC_VERSION} LESS 1700)
    1.32 @@ -1452,8 +1467,14 @@
    1.33        SOVERSION ${LT_REVISION}
    1.34        OUTPUT_NAME "SDL2")
    1.35    endif()
    1.36 - set(_INSTALL_LIBS "SDL2" ${_INSTALL_LIBS})
    1.37 - target_link_libraries(SDL2 ${EXTRA_LIBS} ${EXTRA_LDFLAGS})
    1.38 +  if(MSVC)
    1.39 +    # Don't try to link with the default set of libraries.
    1.40 +    set_target_properties(SDL2 PROPERTIES LINK_FLAGS_RELEASE "/NODEFAULTLIB")
    1.41 +    set_target_properties(SDL2 PROPERTIES LINK_FLAGS_DEBUG "/NODEFAULTLIB")
    1.42 +    set_target_properties(SDL2 PROPERTIES STATIC_LIBRARY_FLAGS "/NODEFAULTLIB")
    1.43 +  endif()
    1.44 +  set(_INSTALL_LIBS "SDL2" ${_INSTALL_LIBS})
    1.45 +  target_link_libraries(SDL2 ${EXTRA_LIBS} ${EXTRA_LDFLAGS})
    1.46  endif()
    1.47  
    1.48  if(SDL_STATIC)