mirror of
https://github.com/libevent/libevent.git
synced 2025-01-09 00:56:20 +08:00
cmake: set library names to be the same as with autotools
libtool has VERSION_INFO [1], cmake has SOVERSION/VERSION instead (although it has different format). Also libtool has RELEASE [2] while cmake do not have analog yet [3], hence manual symlinks should be created. [1]: https://www.gnu.org/software/libtool/manual/html_node/Libtool-versioning.html [2]: https://www.gnu.org/software/libtool/manual/html_node/Release-numbers.html [3]: https://gitlab.kitware.com/cmake/cmake/issues/17652 Plus osx has compatibility_version/current_version dylib properties and cmake do not have separate properties for them [4], hence manual LINK_FLAGS. And also there INSTALL_NAME_DIR property which should be adjusted too. [4]: https://public.kitware.com/Bug/view.php?id=4383 So after all changes, here is an example before/after for osx and linux: # osx # autotools .libs/libevent_pthreads-2.2.1.dylib .libs/libevent_pthreads.dylib -> libevent_pthreads-2.2.1.dylib /usr/local/lib/libevent_pthreads-2.2.1.dylib (compatibility version 2.0.0, current version 2.0.0) # cmake # before patch lib/libevent_pthreads.2.2.0.dylib lib/libevent_pthreads.dylib -> libevent_pthreads.2.2.0.dylib @rpath/libevent_pthreads.2.2.0.dylib (compatibility version 2.2.0, current version 0.0.0) # after patch lib/libevent_pthreads-2.2.1.dylib lib/libevent_pthreads.dylib -> libevent_pthreads-2.2.1.dylib /vagrant/.cmake/inst/lib/libevent_pthreads-2.2.1.dylib (compatibility version 2.0.0, current version 2.0.0) # linux # autotools .libs/libevent_pthreads-2.2.so.1 -> libevent_pthreads-2.2.so.1.0.0 .libs/libevent_pthreads-2.2.so.1.0.0 .libs/libevent_pthreads.so -> libevent_pthreads-2.2.so.1.0.0 # cmake # before patch lib/libevent_pthreads.so -> libevent_pthreads.so.2.2.0 lib/libevent_pthreads.so.2.2.0 # after patch lib/libevent_pthreads-2.2.so -> libevent_pthreads-2.2.so.1 lib/libevent_pthreads-2.2.so.1 -> libevent_pthreads-2.2.so.1.0.0 lib/libevent_pthreads-2.2.so.1.0.0 lib/libevent_pthreads.so -> libevent_pthreads-2.2.so.1.0.0 Closes: #838 (cherry-picked) Closes: #760
This commit is contained in:
parent
41c95abb99
commit
669a53f341
@ -84,6 +84,14 @@ set(EVENT_ABI_LIBVERSION
|
||||
set(EVENT_PACKAGE_VERSION
|
||||
"${EVENT_VERSION_MAJOR}.${EVENT_VERSION_MINOR}.${EVENT_VERSION_PATCH}")
|
||||
|
||||
# equals to VERSION_INFO in Makefile.am
|
||||
set(EVENT_ABI_LIBVERSION_CURRENT 1)
|
||||
set(EVENT_ABI_LIBVERSION_REVISION 0)
|
||||
set(EVENT_ABI_LIBVERSION_AGE 0)
|
||||
|
||||
# equals to RELEASE in Makefile.am
|
||||
set(EVENT_PACKAGE_RELEASE 2.2)
|
||||
|
||||
set(EVENT_NUMERIC_VERSION 0x02020001)
|
||||
|
||||
# only a subset of names can be used, defaults to "beta"
|
||||
|
@ -38,6 +38,10 @@ endmacro()
|
||||
|
||||
# Global variables that it uses:
|
||||
# - EVENT_ABI_LIBVERSION
|
||||
# - EVENT_ABI_LIBVERSION_CURRENT
|
||||
# - EVENT_ABI_LIBVERSION_REVISION
|
||||
# - EVENT_ABI_LIBVERSION_AGE
|
||||
# - EVENT_PACKAGE_RELEASE
|
||||
# - CMAKE_THREAD_LIBS_INIT LIB_PLATFORM
|
||||
# - OPENSSL_LIBRARIES
|
||||
# - HDR_PUBLIC
|
||||
@ -87,16 +91,44 @@ macro(add_event_library LIB_NAME)
|
||||
set_event_shared_lib_flags("${LIB_NAME}" "${EVENT_SHARED_FLAGS}")
|
||||
endif()
|
||||
|
||||
set_target_properties("${LIB_NAME}_shared" PROPERTIES
|
||||
if (WIN32)
|
||||
set_target_properties(
|
||||
"${LIB_NAME}_shared" PROPERTIES
|
||||
OUTPUT_NAME "${LIB_NAME}"
|
||||
SOVERSION ${EVENT_ABI_LIBVERSION})
|
||||
elseif (APPLE)
|
||||
math(EXPR COMPATIBILITY_VERSION "${EVENT_ABI_LIBVERSION_CURRENT}+1")
|
||||
math(EXPR CURRENT_MINUS_AGE "${EVENT_ABI_LIBVERSION_CURRENT}-${EVENT_ABI_LIBVERSION_AGE}")
|
||||
set_target_properties(
|
||||
"${LIB_NAME}_shared" PROPERTIES
|
||||
OUTPUT_NAME "${LIB_NAME}-${EVENT_PACKAGE_RELEASE}.${CURRENT_MINUS_AGE}"
|
||||
INSTALL_NAME_DIR "${CMAKE_INSTALL_PREFIX}/lib"
|
||||
LINK_FLAGS "-compatibility_version ${COMPATIBILITY_VERSION} -current_version ${COMPATIBILITY_VERSION}.${EVENT_ABI_LIBVERSION_REVISION}")
|
||||
else()
|
||||
math(EXPR CURRENT_MINUS_AGE "${EVENT_ABI_LIBVERSION_CURRENT}-${EVENT_ABI_LIBVERSION_AGE}")
|
||||
set_target_properties(
|
||||
"${LIB_NAME}_shared" PROPERTIES
|
||||
OUTPUT_NAME "${LIB_NAME}-${EVENT_PACKAGE_RELEASE}"
|
||||
VERSION "${CURRENT_MINUS_AGE}.${EVENT_ABI_LIBVERSION_AGE}.${EVENT_ABI_LIBVERSION_REVISION}"
|
||||
SOVERSION "${CURRENT_MINUS_AGE}")
|
||||
endif()
|
||||
|
||||
set_target_properties(
|
||||
"${LIB_NAME}_shared" PROPERTIES
|
||||
PUBLIC_HEADER "${HDR_PUBLIC}"
|
||||
CLEAN_DIRECT_OUTPUT 1)
|
||||
set_target_properties(
|
||||
"${LIB_NAME}_shared" PROPERTIES
|
||||
PUBLIC_HEADER "${HDR_PUBLIC}")
|
||||
set_target_properties(
|
||||
"${LIB_NAME}_shared" PROPERTIES
|
||||
SOVERSION ${EVENT_ABI_LIBVERSION}
|
||||
)
|
||||
|
||||
if (NOT WIN32)
|
||||
set(LIB_LINK_NAME
|
||||
"${CMAKE_SHARED_LIBRARY_PREFIX}${LIB_NAME}${CMAKE_SHARED_LIBRARY_SUFFIX}")
|
||||
|
||||
add_custom_command(TARGET ${LIB_NAME}_shared
|
||||
POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E create_symlink
|
||||
"$<TARGET_FILE_NAME:${LIB_NAME}_shared>"
|
||||
"${LIB_LINK_NAME}"
|
||||
WORKING_DIRECTORY "lib")
|
||||
endif()
|
||||
|
||||
list(APPEND LIBEVENT_SHARED_LIBRARIES "${LIB_NAME}_shared")
|
||||
list(APPEND ADD_EVENT_LIBRARY_TARGETS "${LIB_NAME}_shared")
|
||||
@ -117,6 +149,12 @@ macro(add_event_library LIB_NAME)
|
||||
PUBLIC_HEADER DESTINATION "include/event2"
|
||||
COMPONENT dev
|
||||
)
|
||||
if (NOT WIN32)
|
||||
install(FILES
|
||||
"$<TARGET_FILE_DIR:${LIB_NAME}_shared>/${LIB_LINK_NAME}"
|
||||
DESTINATION "lib"
|
||||
COMPONENT lib)
|
||||
endif()
|
||||
|
||||
add_library(${LIB_NAME} INTERFACE)
|
||||
target_link_libraries(${LIB_NAME} INTERFACE ${ADD_EVENT_LIBRARY_INTERFACE})
|
||||
|
Loading…
x
Reference in New Issue
Block a user