summaryrefslogtreecommitdiff
path: root/Source/cmFileCommand.cxx
diff options
context:
space:
mode:
authorDomen Vrankar <domen.vrankar@gmail.com>2017-10-30 23:26:20 +0100
committerDomen Vrankar <domen.vrankar@gmail.com>2017-11-08 20:27:03 +0100
commitdeeba85f81bb031384c1c014d7adcb733da491b4 (patch)
tree8b5c9d6c2c1194a77e345bfa145b091f6f8f2b0e /Source/cmFileCommand.cxx
parent30fcf13be6680d6a4eb112f98cc2d99c6881f401 (diff)
downloadcmake-deeba85f81bb031384c1c014d7adcb733da491b4.tar.gz
CMake: enable setting default dir creation permissions
Introduces CMAKE_DEFAULT_DIRECTORY_INSTALL_PERMISSIONS variable which enables the user to specify the default permissions for directory creation. This setting is then used to auto set the permissions on directories which are implicitly created by install() and file(INSTALL) commands such as CMAKE_INSTALL_PREFIX directories.
Diffstat (limited to 'Source/cmFileCommand.cxx')
-rw-r--r--Source/cmFileCommand.cxx23
1 files changed, 22 insertions, 1 deletions
diff --git a/Source/cmFileCommand.cxx b/Source/cmFileCommand.cxx
index 191a666fe9..a9824d7f1b 100644
--- a/Source/cmFileCommand.cxx
+++ b/Source/cmFileCommand.cxx
@@ -2015,9 +2015,30 @@ bool cmFileInstaller::HandleInstallDestination()
this->DestDirLength = int(sdestdir.size());
}
+ // check if default dir creation permissions were set
+ mode_t default_dir_mode_v = 0;
+ mode_t* default_dir_mode = nullptr;
+ const char* default_dir_install_permissions = this->Makefile->GetDefinition(
+ "CMAKE_INSTALL_DEFAULT_DIRECTORY_PERMISSIONS");
+ if (default_dir_install_permissions && *default_dir_install_permissions) {
+ std::vector<std::string> items;
+ cmSystemTools::ExpandListArgument(default_dir_install_permissions, items);
+ for (const auto& arg : items) {
+ if (!this->CheckPermissions(arg, default_dir_mode_v)) {
+ std::ostringstream e;
+ e << this->FileCommand->GetError()
+ << " Set with CMAKE_INSTALL_DEFAULT_DIRECTORY_PERMISSIONS variable.";
+ this->FileCommand->SetError(e.str());
+ return false;
+ }
+ }
+
+ default_dir_mode = &default_dir_mode_v;
+ }
+
if (this->InstallType != cmInstallType_DIRECTORY) {
if (!cmSystemTools::FileExists(destination.c_str())) {
- if (!cmSystemTools::MakeDirectory(destination.c_str())) {
+ if (!cmSystemTools::MakeDirectory(destination, default_dir_mode)) {
std::string errstring = "cannot create directory: " + destination +
". Maybe need administrative privileges.";
this->FileCommand->SetError(errstring);