How to force CMake not add major/minor version in shared library filename and soname?

4

I'm compiling libclang with Cmake for Android (with Android NDK).

Here is the part of CMake configuration that configure filename and soname:

set_target_properties(libclang
    PROPERTIES
    VERSION ${LIBCLANG_LIBRARY_VERSION}
    DEFINE_SYMBOL _CINDEX_LIB_)

In different file:

set(LIBCLANG_LIBRARY_VERSION
    "${CLANG_VERSION_MAJOR}" CACHE STRING
    "Major version number that will be appended to the libclang library")

and

if(NOT DEFINED CLANG_VERSION_MAJOR)
  set(CLANG_VERSION_MAJOR ${LLVM_VERSION_MAJOR})
endif()

Since i compile llvm/clang of version "7.0.0" libclang filename and soname is libclang.so.7 which is not desired for Android.

~/llvm/build anton$ls -l lib/libclang.so
lrwxrwxrwx 1 anton anton 13 Nov 30 12:13 lib/libclang.so -> libclang.so.7
~/llvm/build anton$arm-linux-androideabi-readelf --dynamic lib/libclang.so.7 | grep SONAME
 0x0000000e (SONAME)                     Library soname: [libclang.so.7]

How can i avoid adding of ".7" in both filename and soname (to make it just libclang.so)?

I've tried to:

1) comment property like follows:

set_target_properties(libclang
  PROPERTIES
  #VERSION ${LIBCLANG_LIBRARY_VERSION}
  DEFINE_SYMBOL _CINDEX_LIB_)

and the filename and soname is still ".so.7" for some reason

2) set it empty:

set_target_properties(libclang
  PROPERTIES
  VERSION ""
  DEFINE_SYMBOL _CINDEX_LIB_)

and the filename and soname is ".so." (with dot at the end).

What can i do?

android
cmake
clang
llvm
asked on Stack Overflow Nov 30, 2018 by 4ntoine • edited Nov 30, 2018 by 4ntoine

2 Answers

3

I wasn't able to test this but try setting the NO_SONAME property instead of the other modifications.

set_target_properties(libclang
  PROPERTIES NO_SONAME 1
)
answered on Stack Overflow Nov 30, 2018 by fdk1342 • edited Oct 3, 2019 by YSC
2

Thanks to @Fred I was able to get it with the following (really dirty-dirty trick):

set_target_properties(libclang
  PROPERTIES
  #VERSION ${LIBCLANG_LIBRARY_VERSION}
  SUFFIX ""
  VERSION "so"
  SOVERSION "so"
  DEFINE_SYMBOL _CINDEX_LIB_)

I've checked it to have proper filename and soname:

~/llvm/build anton$ls -l lib/libclang.so
-rwxrwxr-x 1 anton anton 33590456 Nov 30 12:54 lib/libclang.so
~/llvm/build anton$arm-linux-androideabi-readelf --dynamic lib/libclang.so | grep SONAME
 0x0000000e (SONAME)                     Library soname: [libclang.so]

However i'm not sure if smth is wrong as i did not try to load it yet.

Please let me know if there is proper way to do it.

answered on Stack Overflow Nov 30, 2018 by 4ntoine

User contributions licensed under CC BY-SA 3.0