Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: I get shared libraries when setting SFML_USE_STATIC_STD_LIBS on Linux  (Read 2365 times)

0 Members and 1 Guest are viewing this topic.

sharethis

  • Jr. Member
  • **
  • Posts: 65
    • View Profile
I want automate building SFML. It already works with Visual Studio on Windows. However, on a Ubuntu 14 LTS virtual machine, specifying "SFML_USE_STATIC_STD_LIBS" results in building shared libraries in release mode, regardless of "BUILD_SHARED_LIBS" being set to false. It works fine for debug mode though.

cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS:BOOL=FALSE -DSFML_USE_STATIC_STD_LIBS:BOOL=TRUE
cmake --build . --config Release

What I expected was that SFML would ignore this variable completely here, since it is a Windows only feature. Do I make the wrong call or is this a bug?
« Last Edit: October 23, 2014, 12:10:57 am by sharethis »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: I get shared libraries when setting SFML_USE_STATIC_STD_LIBS on Linux
« Reply #1 on: October 23, 2014, 08:14:08 am »
So you mean that BUILD_SHARED_LIBS=FALSE works as expected, unless DSFML_USE_STATIC_STD_LIBS=TRUE is used?
Laurent Gomila - SFML developer

sharethis

  • Jr. Member
  • **
  • Posts: 65
    • View Profile
Re: I get shared libraries when setting SFML_USE_STATIC_STD_LIBS on Linux
« Reply #2 on: October 23, 2014, 12:37:41 pm »
Right, and the issue only occurs in release variant. In debug variant everything is fine.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: I get shared libraries when setting SFML_USE_STATIC_STD_LIBS on Linux
« Reply #3 on: October 23, 2014, 12:43:33 pm »
This doesn't make sense, because SFML_USE_STATIC_STD_LIBS is used only at two locations:

# define an option for choosing between static and dynamic C runtime (Windows only)
if(SFML_OS_WINDOWS)
    sfml_set_option(SFML_USE_STATIC_STD_LIBS FALSE BOOL "TRUE to statically link to the standard libraries, FALSE to use them as DLLs")

    # the following combination of flags is not valid
    if (BUILD_SHARED_LIBS AND SFML_USE_STATIC_STD_LIBS)
        message(FATAL_ERROR "BUILD_SHARED_LIBS and SFML_USE_STATIC_STD_LIBS cannot be used together")
    endif()

    # for VC++, we can apply it globally by modifying the compiler flags
    if(SFML_COMPILER_MSVC AND SFML_USE_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()

    # for gcc >= 4.0 on Windows, apply the SFML_USE_STATIC_STD_LIBS option if it is enabled
    if(SFML_OS_WINDOWS AND SFML_COMPILER_GCC AND NOT SFML_GCC_VERSION VERSION_LESS "4")
        if(SFML_USE_STATIC_STD_LIBS AND NOT SFML_COMPILER_GCC_TDM)
            set_target_properties(${target} PROPERTIES LINK_FLAGS "-static-libgcc -static-libstdc++")
        elseif(NOT SFML_USE_STATIC_STD_LIBS AND SFML_COMPILER_GCC_TDM)
            set_target_properties(${target} PROPERTIES LINK_FLAGS "-shared-libgcc -shared-libstdc++")
        endif()
    endif()

... and as you can see, both apply on Windows only. On Linux it should have no effect at all.

Make sure that you clear your CMake cache and build directory between two different builds.
Laurent Gomila - SFML developer

sharethis

  • Jr. Member
  • **
  • Posts: 65
    • View Profile
Re: I get shared libraries when setting SFML_USE_STATIC_STD_LIBS on Linux
« Reply #4 on: October 25, 2014, 08:13:01 pm »
Thank you. I think it was a cache issue.