SetLibtoolAbiVersion.cmake raw

   1  #[=[
   2  This emulates Libtool to make sure Libtool and CMake agree on
   3  the ABI version and file naming for shared libraries.
   4  
   5  The `version_type` variable is set in `libtool.m4` (installed
   6  by autoreconf into autotools-aux/m4/).
   7  For the `major` and `versuffix` variables, see below "Calculate
   8  the version variables" in `ltmain.sh` (installed by autoreconf
   9  into autotools-aux/).
  10  ]=]
  11  function(set_libtool_abi_version target current revision age)
  12    if(CMAKE_SYSTEM_NAME MATCHES "^(Linux|FreeBSD)$")
  13      # version_type = linux | freebsd-elf
  14      # major = $current - $age
  15      # versuffix = $major.$age.$revision
  16      math(EXPR _major "${current} - ${age}")
  17      set_target_properties(${target} PROPERTIES
  18        SOVERSION ${_major}
  19        VERSION ${_major}.${age}.${revision}
  20      )
  21    elseif(CMAKE_SYSTEM_NAME STREQUAL "NetBSD")
  22      # version_type = sunos
  23      # major = $current
  24      # versuffix = $current.$revision
  25      set_target_properties(${target} PROPERTIES
  26        SOVERSION ${current}
  27        VERSION ${current}.${revision}
  28      )
  29    elseif(CMAKE_SYSTEM_NAME STREQUAL "OpenBSD")
  30      # version_type = sunos
  31      # major = $current
  32      # versuffix = $current.$revision
  33      set_target_properties(${target} PROPERTIES
  34        # OpenBSD has no `soname_spec` defined in `libtool.m4`.
  35        VERSION ${current}.${revision}
  36      )
  37    elseif(APPLE)
  38      # version_type = darwin
  39      # major = $current - $age
  40      math(EXPR _major "${current} - ${age}")
  41      math(EXPR _compatibility "${current} + 1")
  42      set_target_properties(${target} PROPERTIES
  43        SOVERSION ${_major}
  44        MACHO_COMPATIBILITY_VERSION ${_compatibility}
  45        MACHO_CURRENT_VERSION ${_compatibility}.${revision}
  46      )
  47    elseif(CMAKE_SYSTEM_NAME STREQUAL "Windows")
  48      # version_type = windows
  49      # major = $current - $age
  50      # versuffix = $major
  51      math(EXPR _major "${current} - ${age}")
  52      set(_windows_name "secp256k1")
  53      if(MSVC)
  54        set(_windows_name "${PROJECT_NAME}")
  55      endif()
  56      set_target_properties(${target} PROPERTIES
  57        ARCHIVE_OUTPUT_NAME "${_windows_name}"
  58        RUNTIME_OUTPUT_NAME "${_windows_name}-${_major}"
  59      )
  60    endif()
  61  endfunction()
  62