From 04ae896457cd81d9c6fdb2ab6731fac7d2e36e2a Mon Sep 17 00:00:00 2001 From: Laurent Gomila Date: Mon, 16 May 2011 07:57:41 +0200 Subject: [PATCH] Added the STATIC_STD_LIBS option to CSFML makefiles --- bindings/c/CMakeLists.txt | 16 ++++++++++++++++ bindings/c/cmake/Macros.cmake | 6 +++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/bindings/c/CMakeLists.txt b/bindings/c/CMakeLists.txt index 73d5d9e45..0a13afb78 100644 --- a/bindings/c/CMakeLists.txt +++ b/bindings/c/CMakeLists.txt @@ -30,6 +30,22 @@ set(BUILD_DOC FALSE CACHE BOOL "TRUE to generate the API documentation, FALSE to # disable the rpath stuff set(CMAKE_SKIP_BUILD_RPATH TRUE) +# define an option for choosing between static and dynamic C runtime (Windows only) +if(WINDOWS) + set(STATIC_STD_LIBS TRUE CACHE BOOL "TRUE to statically link to the standard libraries, FALSE to use them as DLLs") + + # for VC++, we can apply it globally by modifying the compiler flags + if(COMPILER_MSVC AND STATIC_STD_LIBS) + foreach(flag + CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE + CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO) + if(${flag} MATCHES "/MD") + string(REGEX REPLACE "/MD" "/MT" ${flag} "${${flag}}") + endif() + endforeach() + endif() +endif() + # add the subdirectories add_subdirectory(src/SFML) if(BUILD_DOC) diff --git a/bindings/c/cmake/Macros.cmake b/bindings/c/cmake/Macros.cmake index 0e1570372..6737db1d5 100644 --- a/bindings/c/cmake/Macros.cmake +++ b/bindings/c/cmake/Macros.cmake @@ -76,10 +76,10 @@ macro(csfml_add_library target) set_target_properties(${target} PROPERTIES SOVERSION ${VERSION_MAJOR}.${VERSION_MINOR}) set_target_properties(${target} PROPERTIES VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}) - # for gcc 4.x on Windows, we add the -static-libgcc linker flag to get rid of an extra gcc DLL - if(WINDOWS AND COMPILER_GCC) + # for gcc 4.x on Windows, apply the STATIC_STD_LIBS option if it is enabled + if(WINDOWS AND COMPILER_GCC AND STATIC_STD_LIBS) if(${GCC_VERSION} MATCHES "4\\..*") - set_target_properties(${target} PROPERTIES LINK_FLAGS -static-libgcc) + set_target_properties(${target} PROPERTIES LINK_FLAGS "-static-libgcc -static-libstdc++") endif() endif()