Fixed bug 1743 - CMake produces libraries with wrong filename/SONAME
authorSam Lantinga <slouken@libsdl.org>
Sat, 27 Jul 2013 02:50:19 -0700
changeset 7525e5ae3502a25e
parent 7524 6d8fd70e1477
child 7526 6c0f0280149c
Fixed bug 1743 - CMake produces libraries with wrong filename/SONAME

David Gow

As discussed on the list, the autotools build backend uses libtool's "release" option, giving us the SONAME libSDL2-2.0.so.0, whereas CMake doesn't, giving us libSDL2.so.0

While libSDL2.so.0 has some small advantages (being simpler and matching the names on some other OSes better), many products have already been developed expecting libSDL2-2.0.so.0, which better matches SDL 1.2's SONAME. It seems clear, therefore, that most developers prefer this name.

This patch emulates libtool's functionality, making libSDL2-2.0.so.0 the name of the shared library, while leaving libSDL2.a as the filename of the static library. Unlike with libtool, no libSDL2.so symlink is yet made. I also haven't tested this on anything but Linux, so it might break other platforms. :/
CMakeLists.txt
     1.1 --- a/CMakeLists.txt	Sat Jul 27 02:45:26 2013 -0700
     1.2 +++ b/CMakeLists.txt	Sat Jul 27 02:50:19 2013 -0700
     1.3 @@ -38,6 +38,8 @@
     1.4  math(EXPR LT_CURRENT "${SDL_MICRO_VERSION} - ${SDL_INTERFACE_AGE}")
     1.5  math(EXPR LT_AGE "${SDL_BINARY_AGE} - ${SDL_INTERFACE_AGE}")
     1.6  set(LT_REVISION "${SDL_INTERFACE_AGE}")
     1.7 +set(LT_RELEASE "${SDL_MAJOR_VERSION}.${SDL_MINOR_VERSION}")
     1.8 +set(LT_VERSION "${LT_CURRENT}.${LT_REVISION}.${LT_AGE}")
     1.9  
    1.10  # General settings & flags
    1.11  set(LIBRARY_OUTPUT_DIRECTORY "build")
    1.12 @@ -1144,9 +1146,17 @@
    1.13  
    1.14  if(SDL_SHARED)
    1.15    add_library(SDL2 SHARED ${SOURCE_FILES})
    1.16 -  set_target_properties(SDL2 PROPERTIES
    1.17 -    VERSION ${SDL_VERSION}
    1.18 -    SOVERSION ${LT_CURRENT})
    1.19 +  if(UNIX)
    1.20 +    set_target_properties(SDL2 PROPERTIES
    1.21 +      VERSION ${LT_VERSION}
    1.22 +      SOVERSION ${LT_CURRENT}
    1.23 +      OUTPUT_NAME "SDL2-${LT_RELEASE}")
    1.24 +  else(UNIX)
    1.25 +    set_target_properties(SDL2 PROPERTIES
    1.26 +      VERSION ${SDL_VERSION}
    1.27 +      SOVERSION ${LT_CURRENT}
    1.28 +      OUTPUT_NAME "SDL2")
    1.29 +  endif(UNIX)
    1.30   set(_INSTALL_LIBS "SDL2" ${_INSTALL_LIBS})
    1.31   target_link_libraries(SDL2 ${EXTRA_LIBS} ${EXTRA_LDFLAGS})
    1.32  endif(SDL_SHARED)
    1.33 @@ -1174,6 +1184,13 @@
    1.34  list(APPEND INCLUDE_FILES ${BIN_INCLUDE_FILES})
    1.35  install(FILES ${INCLUDE_FILES} DESTINATION include/SDL2)
    1.36  
    1.37 +if(SDL_SHARED)
    1.38 +  install(CODE "
    1.39 +    execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink
    1.40 +    \"libSDL2-2.0.so\" \"libSDL2.so\")")
    1.41 +  install(FILES ${SDL2_BINARY_DIR}/libSDL2.so DESTINATION "lib${LIB_SUFFIX}")
    1.42 +endif(SDL_SHARED)
    1.43 +
    1.44  if(NOT WINDOWS OR CYGWIN)
    1.45    if(FREEBSD)
    1.46      # FreeBSD uses ${PREFIX}/libdata/pkgconfig