Skip to content

Commit

Permalink
Some CMake fixes for static linking on Windows from the OpenFL project.
Browse files Browse the repository at this point in the history
  • Loading branch information
icculus committed Jan 28, 2014
1 parent f52d7f5 commit 2de3b01
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions CMakeLists.txt
Expand Up @@ -149,6 +149,19 @@ if(NOT ("$ENV{CFLAGS}" STREQUAL "")) # Hackish, but does the trick on Win32
list(APPEND EXTRA_LDFLAGS "$ENV{LDFLAGS}")
endif(NOT ("$ENV{CFLAGS}" STREQUAL ""))

if(MSVC)
option(FORCE_STATIC_VCRT "Force /MT for static VC runtimes" OFF)
if(FORCE_STATIC_VCRT)
foreach(flag_var
CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO)
if(${flag_var} MATCHES "/MD")
string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
endif()
endforeach(flag_var)
endif()
endif(MSVC)

# Those are used for pkg-config and friends, so that the SDL2.pc, sdl2-config,
# etc. are created correctly.
set(SDL_LIBS "-lSDL2")
Expand Down Expand Up @@ -1234,8 +1247,14 @@ if(SDL_SHARED)
endif(SDL_SHARED)

if(SDL_STATIC)
set (BUILD_SHARED_LIBS FALSE)
add_library(SDL2-static STATIC ${SOURCE_FILES})
set_target_properties(SDL2-static PROPERTIES OUTPUT_NAME "SDL2")
if(WINDOWS)
set_target_properties(SDL2-static PROPERTIES LINK_FLAGS_RELEASE "/NODEFAULTLIB")
set_target_properties(SDL2-static PROPERTIES LINK_FLAGS_DEBUG "/NODEFAULTLIB")
set_target_properties(SDL2-static PROPERTIES STATIC_LIBRARY_FLAGS "/NODEFAULTLIB")
endif(WINDOWS)
# TODO: Win32 platforms keep the same suffix .lib for import and static
# libraries - do we need to consider this?
set(_INSTALL_LIBS "SDL2-static" ${_INSTALL_LIBS})
Expand Down

0 comments on commit 2de3b01

Please sign in to comment.