Fixed bug 4593 - Respect CMake's BUILD_SHARED_LIBS default behavior
authorSam Lantinga
Sat, 08 Jun 2019 14:36:03 -0700
changeset 127924063a5ebe39b
parent 12791 74a69d4d9e9a
child 12793 26634e392a7f
Fixed bug 4593 - Respect CMake's BUILD_SHARED_LIBS default behavior

tschwinger

Respect the BUILD_SHARED_LIBS variable when defined, and build either shared or static libs, which is CMake's default behavior (See https://cmake.org/cmake/help/latest/variable/BUILD_SHARED_LIBS.html).

If the variable is not defined, the current behavior remains unchanged and both variants are built where the platform supports it. This way, it remains possible to build both in one shot, which seems convenient for distro builds and useful to promote some consistency between them.
CMakeLists.txt
     1.1 --- a/CMakeLists.txt	Sat Jun 08 14:34:38 2019 -0700
     1.2 +++ b/CMakeLists.txt	Sat Jun 08 14:36:03 2019 -0700
     1.3 @@ -264,8 +264,23 @@
     1.4    set(SDL_DLOPEN_ENABLED_BY_DEFAULT OFF)
     1.5  endif()
     1.6  
     1.7 +# When defined, respect CMake's BUILD_SHARED_LIBS setting:
     1.8 +set(SDL_STATIC_ENABLED_BY_DEFAULT ON)
     1.9  if (NOT DEFINED SDL_SHARED_ENABLED_BY_DEFAULT)
    1.10 +  # ...unless decided already (as for EMSCRIPTEN)
    1.11 +
    1.12 +  set(SDL_SHARED_ENABLED_BY_DEFAULT OFF)
    1.13 +
    1.14 +  if (NOT DEFINED BUILD_SHARED_LIBS)
    1.15 +    # No preference? Build both, just like the AC/AM configure
    1.16      set(SDL_SHARED_ENABLED_BY_DEFAULT ON)
    1.17 +
    1.18 +  elseif (BUILD_SHARED_LIBS)
    1.19 +    # In this case, we assume the user wants a shared lib and don't build
    1.20 +    # the static one
    1.21 +    set(SDL_SHARED_ENABLED_BY_DEFAULT ON)
    1.22 +    set(SDL_STATIC_ENABLED_BY_DEFAULT OFF)
    1.23 +  endif()
    1.24  endif()
    1.25  
    1.26  set(SDL_SUBSYSTEMS
    1.27 @@ -344,10 +359,8 @@
    1.28  option_string(BACKGROUNDING_SIGNAL "number to use for magic backgrounding signal or 'OFF'" "OFF")
    1.29  option_string(FOREGROUNDING_SIGNAL "number to use for magic foregrounding signal or 'OFF'" "OFF")
    1.30  
    1.31 -# TODO: We should (should we?) respect cmake's ${BUILD_SHARED_LIBS} flag here
    1.32 -# The options below are for compatibility to configure's default behaviour.
    1.33  set(SDL_SHARED ${SDL_SHARED_ENABLED_BY_DEFAULT} CACHE BOOL "Build a shared version of the library")
    1.34 -set(SDL_STATIC ON CACHE BOOL "Build a static version of the library")
    1.35 +set(SDL_STATIC ${SDL_STATIC_ENABLED_BY_DEFAULT} CACHE BOOL "Build a static version of the library")
    1.36  
    1.37  dep_option(SDL_STATIC_PIC      "Static version of the library should be built with Position Independent Code" OFF "SDL_STATIC" OFF)
    1.38  set_option(SDL_TEST            "Build the test directory" OFF)