Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Keep a single file's permissions when using install() in CMake

In KDE, I adjusted a macro to compile and install Python files, but I'm having problem with it keeping the files' permissions.

To be more clear, the offendling line in the macro is

install(FILES ${SOURCE_FILE} DESTINATION ${DESTINATION_DIR})

which works for 99% of the cases.

In one case, though I have a Python file marked as executable (+x, I'm talking about Linux here) in the source directory, which then is symlinked to the installation's binary dir. Since install() does not preserve permissions, the execute bit is stripped from it, and this causes all sorts of problems later on.

Is it possible to keep the file's permissions, or to read them and set them accordingly? I would hate to use a manual chmod command since it's not portable.

EDIT: I do not want to make all files installed by this macro executable, as this would be pointless.

like image 242
Einar Avatar asked Dec 29 '12 18:12

Einar


People also ask

How do I specify the install directory in CMake?

The installation directory is usually left at its default, which is /usr/local . Installing software here ensures that it is automatically available to users. It is possible to specify a different installation directory by adding -DCMAKE_INSTALL_PREFIX=/path/to/install/dir to the CMake command line.

What does install command do in CMake?

CMake provides the install command to specify how a project is to be installed. This command is invoked by a project in the CMakeLists file and tells CMake how to generate installation scripts. The scripts are executed at install time to perform the actual installation of files.

What is Cmake_install CMake file?

cmake contains the commands generated by install command from your CMakeLists. txt . You can execute it by cmake -P cmake_install. cmake and it performs the installation of your project even on windows.


1 Answers

You can install files with +x permission using

install(PROGRAMS ...

command.

Alternatively, you can install whole directory preserving file permissions:

install(DIRECTORIES ... USE_SOURCE_PERMISSIONS)

See documentation for install command for more info.

like image 59
arrowd Avatar answered Sep 18 '22 18:09

arrowd