summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2018-10-02 12:55:08 +0000
committerKitware Robot <kwrobot@kitware.com>2018-10-02 08:55:15 -0400
commit9682fa79e7f76d11fd2f00f90430e3fc628a1850 (patch)
tree48c3eda9d6a5feebb4561a3b68a0ed2c08a1f4d4
parent44de3428597671228c95939c4b509ebaa24f00fe (diff)
parent5e61b79b82ec29a33179604d70834017f58afb76 (diff)
downloadcmake-9682fa79e7f76d11fd2f00f90430e3fc628a1850.tar.gz
Merge topic 'install-directory-permissions-fix'
5e61b79b82 install: Set permissions on directories created by install(DIRECTORY) fbd89b6753 Help: Add note about CMAKE_INSTALL_DEFAULT_DIRECTORY_PERMISSIONS Acked-by: Kitware Robot <kwrobot@kitware.com> Merge-request: !2428
-rw-r--r--Help/command/install.rst7
-rw-r--r--Source/cmFileCommand.cxx56
2 files changed, 45 insertions, 18 deletions
diff --git a/Help/command/install.rst b/Help/command/install.rst
index 3a2b4da621..08c57186f7 100644
--- a/Help/command/install.rst
+++ b/Help/command/install.rst
@@ -89,6 +89,13 @@ Command signatures that install files may print messages during
installation. Use the :variable:`CMAKE_INSTALL_MESSAGE` variable
to control which messages are printed.
+Many of the ``install()`` variants implicitly create the directories
+containing the installed files. If
+:variable:`CMAKE_INSTALL_DEFAULT_DIRECTORY_PERMISSIONS` is set, these
+directories will be created with the permissions specified. Otherwise,
+they will be created according to the uname rules on Unix-like platforms.
+Windows platforms are unaffected.
+
Installing Targets
^^^^^^^^^^^^^^^^^^
diff --git a/Source/cmFileCommand.cxx b/Source/cmFileCommand.cxx
index 54af2f409e..1f7670309b 100644
--- a/Source/cmFileCommand.cxx
+++ b/Source/cmFileCommand.cxx
@@ -1275,6 +1275,33 @@ protected:
this->DirPermissions |= mode_world_read;
this->DirPermissions |= mode_world_execute;
}
+
+ bool GetDefaultDirectoryPermissions(mode_t** mode)
+ {
+ // check if default dir creation permissions were set
+ 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, **mode)) {
+ std::ostringstream e;
+ e << this->FileCommand->GetError()
+ << " Set with CMAKE_INSTALL_DEFAULT_DIRECTORY_PERMISSIONS "
+ "variable.";
+ this->FileCommand->SetError(e.str());
+ return false;
+ }
+ }
+ } else {
+ *mode = nullptr;
+ }
+
+ return true;
+ }
};
bool cmFileCopier::Parse(std::vector<std::string> const& args)
@@ -1668,8 +1695,15 @@ bool cmFileCopier::InstallDirectory(const char* source,
this->ReportCopy(destination, TypeDir,
!cmSystemTools::FileIsDirectory(destination));
+ // check if default dir creation permissions were set
+ mode_t default_dir_mode_v = 0;
+ mode_t* default_dir_mode = &default_dir_mode_v;
+ if (!this->GetDefaultDirectoryPermissions(&default_dir_mode)) {
+ return false;
+ }
+
// Make sure the destination directory exists.
- if (!cmSystemTools::MakeDirectory(destination)) {
+ if (!cmSystemTools::MakeDirectory(destination, default_dir_mode)) {
std::ostringstream e;
e << this->Name << " cannot make directory \"" << destination
<< "\": " << cmSystemTools::GetLastSystemError();
@@ -2073,23 +2107,9 @@ bool cmFileInstaller::HandleInstallDestination()
// 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;
+ mode_t* default_dir_mode = &default_dir_mode_v;
+ if (!this->GetDefaultDirectoryPermissions(&default_dir_mode)) {
+ return false;
}
if (this->InstallType != cmInstallType_DIRECTORY) {