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

1

12

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
Haifa answered 28/11, 2012 at 23:3 Comment(0)
L
18

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.

Loose answered 29/11, 2012 at 10:43 Comment(2)
Well, I'm an idiot. I somehow glossed right over that option in the documentation. Thanks for pointing it out.Haifa
Thanks; just wanted to mention that USE_SOURCE_PERMISSIONS only works with install(DIRECTORY). It wasn't immediately obvious from the answer.Character

© 2022 - 2024 — McMap. All rights reserved.