Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to preserve file permissions with cmake "install directory" directive?

Prolog: I'm an idiot for missing this in the documentation

cmake-2.8.10.2

How do you make cmake preserve the original file permissions when installing a directory? For the project at hand, I'd like it to essentially copy some directories from my source tree to the install tree. To wit:

install(
  DIRECTORY config runp
  DESTINATION ${CMAKE_INSTALL_PREFIX}
  PATTERN ".svn" EXCLUDE
  PATTERN ".git" EXCLUDE
  PATTERN "start_collection.snl" EXCLUDE
)

All works as expected -- except that executable scripts are getting copied in with incorrect file permissions. In fact, none of the original file permissions are preserved. Globally setting permissions using FILE_PERMISSIONS and DIRECTORY_PERMISSIONS is something I do not want to do, and frankly, would be a hack in this context.

In the shell-scripting world, I'd do something simple like this:

for i in config runp ; do
  tar cf - $i | tar -C $CMAKE_INSTALL_PREFIX -xf -
done
like image 352
smcdow Avatar asked Nov 28 '12 23:11

smcdow


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 CMake install command do?

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?

As previous answer tells, the cmake_install. 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.

What is Gnuinstalldirs?

Define GNU standard installation directories. Provides install directory variables as defined by the GNU Coding Standards.


1 Answers

Documentation suggests using USE_SOURCE_PERMISSIONS when calling install():

install(
  DIRECTORY config runp
  DESTINATION ${CMAKE_INSTALL_PREFIX}
  USE_SOURCE_PERMISSIONS
  PATTERN ".svn" EXCLUDE
  PATTERN ".git" EXCLUDE
  PATTERN "start_collection.snl" EXCLUDE
)

Alternatively, you can use install(PROGRAMS signature of this command. See docs for more info.

like image 79
arrowd Avatar answered Nov 05 '22 19:11

arrowd