Some CMake fixes for static linking on Windows from the OpenFL project.
authorRyan C. Gordon <icculus@icculus.org>
Tue, 28 Jan 2014 12:37:04 -0500
changeset 8136175cac5d90a6
parent 8135 dd4729596096
child 8137 6dbd80731aa0
Some CMake fixes for static linking on Windows from the OpenFL project.
CMakeLists.txt
     1.1 --- a/CMakeLists.txt	Tue Jan 28 11:39:37 2014 -0300
     1.2 +++ b/CMakeLists.txt	Tue Jan 28 12:37:04 2014 -0500
     1.3 @@ -149,6 +149,19 @@
     1.4    list(APPEND EXTRA_LDFLAGS "$ENV{LDFLAGS}")
     1.5  endif(NOT ("$ENV{CFLAGS}" STREQUAL ""))
     1.6  
     1.7 +if(MSVC)
     1.8 +  option(FORCE_STATIC_VCRT "Force /MT for static VC runtimes" OFF)
     1.9 +  if(FORCE_STATIC_VCRT)
    1.10 +    foreach(flag_var
    1.11 +        CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
    1.12 +        CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO)
    1.13 +      if(${flag_var} MATCHES "/MD")
    1.14 +        string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
    1.15 +      endif()
    1.16 +    endforeach(flag_var)
    1.17 +  endif()
    1.18 +endif(MSVC)
    1.19 +
    1.20  # Those are used for pkg-config and friends, so that the SDL2.pc, sdl2-config,
    1.21  # etc. are created correctly.
    1.22  set(SDL_LIBS "-lSDL2")
    1.23 @@ -1234,8 +1247,14 @@
    1.24  endif(SDL_SHARED)
    1.25  
    1.26  if(SDL_STATIC)
    1.27 +  set (BUILD_SHARED_LIBS FALSE)
    1.28    add_library(SDL2-static STATIC ${SOURCE_FILES})
    1.29    set_target_properties(SDL2-static PROPERTIES OUTPUT_NAME "SDL2")
    1.30 +  if(WINDOWS)
    1.31 +    set_target_properties(SDL2-static PROPERTIES LINK_FLAGS_RELEASE "/NODEFAULTLIB")
    1.32 +    set_target_properties(SDL2-static PROPERTIES LINK_FLAGS_DEBUG "/NODEFAULTLIB")
    1.33 +    set_target_properties(SDL2-static PROPERTIES STATIC_LIBRARY_FLAGS "/NODEFAULTLIB")
    1.34 +  endif(WINDOWS)
    1.35    # TODO: Win32 platforms keep the same suffix .lib for import and static
    1.36    # libraries - do we need to consider this?
    1.37    set(_INSTALL_LIBS "SDL2-static" ${_INSTALL_LIBS})