From 55b782fee15c9148a83b4df99f5266b836db9bf2 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Sat, 27 Jul 2013 02:50:19 -0700 Subject: [PATCH] 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 | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4e002778c..925392ebb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -38,6 +38,8 @@ set(SDL_VERSION "${SDL_MAJOR_VERSION}.${SDL_MINOR_VERSION}.${SDL_MICRO_VERSION}" math(EXPR LT_CURRENT "${SDL_MICRO_VERSION} - ${SDL_INTERFACE_AGE}") math(EXPR LT_AGE "${SDL_BINARY_AGE} - ${SDL_INTERFACE_AGE}") set(LT_REVISION "${SDL_INTERFACE_AGE}") +set(LT_RELEASE "${SDL_MAJOR_VERSION}.${SDL_MINOR_VERSION}") +set(LT_VERSION "${LT_CURRENT}.${LT_REVISION}.${LT_AGE}") # General settings & flags set(LIBRARY_OUTPUT_DIRECTORY "build") @@ -1144,9 +1146,17 @@ set(_INSTALL_LIBS "SDL2main") if(SDL_SHARED) add_library(SDL2 SHARED ${SOURCE_FILES}) - set_target_properties(SDL2 PROPERTIES - VERSION ${SDL_VERSION} - SOVERSION ${LT_CURRENT}) + if(UNIX) + set_target_properties(SDL2 PROPERTIES + VERSION ${LT_VERSION} + SOVERSION ${LT_CURRENT} + OUTPUT_NAME "SDL2-${LT_RELEASE}") + else(UNIX) + set_target_properties(SDL2 PROPERTIES + VERSION ${SDL_VERSION} + SOVERSION ${LT_CURRENT} + OUTPUT_NAME "SDL2") + endif(UNIX) set(_INSTALL_LIBS "SDL2" ${_INSTALL_LIBS}) target_link_libraries(SDL2 ${EXTRA_LIBS} ${EXTRA_LDFLAGS}) endif(SDL_SHARED) @@ -1174,6 +1184,13 @@ endforeach() list(APPEND INCLUDE_FILES ${BIN_INCLUDE_FILES}) install(FILES ${INCLUDE_FILES} DESTINATION include/SDL2) +if(SDL_SHARED) + install(CODE " + execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink + \"libSDL2-2.0.so\" \"libSDL2.so\")") + install(FILES ${SDL2_BINARY_DIR}/libSDL2.so DESTINATION "lib${LIB_SUFFIX}") +endif(SDL_SHARED) + if(NOT WINDOWS OR CYGWIN) if(FREEBSD) # FreeBSD uses ${PREFIX}/libdata/pkgconfig