smcdow
smcdow

Reputation: 739

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

Upvotes: 12

Views: 10350

Answers (1)

arrowd
arrowd

Reputation: 34411

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.

Upvotes: 19

Related Questions