Search code examples
permissionscmakeinstallationshared

CMake shared library executable permission missing at install location


Currently I am creating a simple project which will install a utility shared library.

Here's my CMakeLists:

cmake_minimum_required (VERSION 2.6)
project(MathLibs CXX)
add_library (${PROJECT_NAME} SHARED
    fact.cpp
    fibo.cpp
    isPrime.cpp
    )
install (TARGETS ${PROJECT_NAME}
    RUNTIME DESTINATION ${PROJECT_NAME}/bin
    LIBRARY DESTINATION ${PROJECT_NAME}/lib
    ARCHIVE DESTINATION ${PROJECT_NAME}/lib)

Since I do not have root privileges I cannot install the shared library in system lib folder. I override the CMAKE_INSTALL_PREFIX to $HOME/apps.

When I build the shared library it had the executable permissions. Here's the build folder with the shared library:

-rw-rw-r-- 1 ameya ameya 9714 Jun 18 20:02 CMakeCache.txt
drwxrwxr-x 5 ameya ameya 4096 Jun 18 20:02 CMakeFiles
-rw-rw-r-- 1 ameya ameya 2701 Jun 18 20:02 cmake_install.cmake
-rw-rw-r-- 1 ameya ameya   84 Jun 18 20:02 install_manifest.txt
-rwxrwxr-x 1 ameya ameya 6808 Jun 18 20:02 libMathLibs.so
-rw-rw-r-- 1 ameya ameya 7748 Jun 18 20:02 Makefile
drwxrwxr-x 3 ameya ameya 4096 Jun 18 20:02 test

After installing the executable permissions disappears. Here's the install folder location:

-rw-r--r-- 1 ameya ameya 6808 Jun 18 20:02 libMathLibs.so

What am I missing in the CMakeLists.txt to correct this?


Solution

  • After looking for more details online I found this referenced in the CMake bugs report.

    The handling of shared library on different systems is different I tried using Ubuntu and a Fedora workstation.
    On Ubuntu system the system installed shared libraries do not have the executable bit set, but on the Fedora Workstation the same library had the executable bit set.

    One can have look at the ${CMAKE_ROOT}/cmake/Modules/Platform/Linux.cmake, which has the CMAKE_INSTALL_SO_NO_EXE macro defined(sorry for the typo in my earlier reply).