AmeyaVS
AmeyaVS

Reputation: 1054

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?

Upvotes: 0

Views: 2234

Answers (2)

AmeyaVS
AmeyaVS

Reputation: 1054

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).

Upvotes: 1

Tsyvarev
Tsyvarev

Reputation: 66061

They said that CMake doesn't set execute permissions on installed library because on Linux libraries don't need to be executable.

As for library's permissions in build tree, these are set not by CMake but by the linker.

If you want executable permissions of installed library for some reason, use PERMISSIONS option in install() command.

Upvotes: 1

Related Questions