summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Help/command/configure_file.rst6
-rw-r--r--Help/release/dev/configure_file-permission-control.rst5
-rw-r--r--Source/CPack/cmCPackGenerator.cxx2
-rw-r--r--Source/cmConfigureFileCommand.cxx6
-rw-r--r--Source/cmCreateTestSourceList.cxx2
-rw-r--r--Source/cmLocalGenerator.cxx4
-rw-r--r--Source/cmMakefile.cxx17
-rw-r--r--Source/cmMakefile.h1
-rw-r--r--Source/cmVisualStudio10TargetGenerator.cxx2
-rw-r--r--Tests/RunCMake/configure_file/NoSourcePermissions.cmake10
-rwxr-xr-xTests/RunCMake/configure_file/NoSourcePermissions.sh3
-rw-r--r--Tests/RunCMake/configure_file/RunCMakeTest.cmake1
12 files changed, 52 insertions, 7 deletions
diff --git a/Help/command/configure_file.rst b/Help/command/configure_file.rst
index 29e85bd16c..46d1a05954 100644
--- a/Help/command/configure_file.rst
+++ b/Help/command/configure_file.rst
@@ -7,6 +7,7 @@ Copy a file to another location and modify its contents.
configure_file(<input> <output>
[COPYONLY] [ESCAPE_QUOTES] [@ONLY]
+ [NO_SOURCE_PERMISSIONS]
[NEWLINE_STYLE [UNIX|DOS|WIN32|LF|CRLF] ])
Copies an ``<input>`` file to an ``<output>`` file and substitutes
@@ -82,6 +83,11 @@ The arguments are:
Restrict variable replacement to references of the form ``@VAR@``.
This is useful for configuring scripts that use ``${VAR}`` syntax.
+ ``NO_SOURCE_PERMISSIONS``
+ Does not transfer the file permissions of the original file to the copy.
+ The copied file permissions default to the standard 644 value
+ (-rw-r--r--).
+
``NEWLINE_STYLE <style>``
Specify the newline style for the output file. Specify
``UNIX`` or ``LF`` for ``\n`` newlines, or specify
diff --git a/Help/release/dev/configure_file-permission-control.rst b/Help/release/dev/configure_file-permission-control.rst
new file mode 100644
index 0000000000..54b52b7dc0
--- /dev/null
+++ b/Help/release/dev/configure_file-permission-control.rst
@@ -0,0 +1,5 @@
+configure_file-permission-control
+---------------------------------
+
+* The :command:`configure_file` command gained a ``NO_SOURCE_PERMISSIONS``
+ option to suppress copying the input file's permissions to the output file.
diff --git a/Source/CPack/cmCPackGenerator.cxx b/Source/CPack/cmCPackGenerator.cxx
index 7990504fd4..fd8149503c 100644
--- a/Source/CPack/cmCPackGenerator.cxx
+++ b/Source/CPack/cmCPackGenerator.cxx
@@ -1326,7 +1326,7 @@ bool cmCPackGenerator::ConfigureFile(const std::string& inName,
bool copyOnly /* = false */)
{
return this->MakefileMap->ConfigureFile(inName, outName, copyOnly, true,
- false) == 1;
+ false, true) == 1;
}
int cmCPackGenerator::CleanTemporaryDirectory()
diff --git a/Source/cmConfigureFileCommand.cxx b/Source/cmConfigureFileCommand.cxx
index 5b3045db1a..68322cc0ea 100644
--- a/Source/cmConfigureFileCommand.cxx
+++ b/Source/cmConfigureFileCommand.cxx
@@ -60,6 +60,7 @@ bool cmConfigureFileCommand(std::vector<std::string> const& args,
}
bool copyOnly = false;
bool escapeQuotes = false;
+ bool use_source_permissions = true;
static std::set<cm::string_view> noopOptions = {
/* Legacy. */
@@ -87,6 +88,8 @@ bool cmConfigureFileCommand(std::vector<std::string> const& args,
escapeQuotes = true;
} else if (args[i] == "@ONLY") {
atOnly = true;
+ } else if (args[i] == "NO_SOURCE_PERMISSIONS") {
+ use_source_permissions = false;
} else if (noopOptions.find(args[i]) != noopOptions.end()) {
/* Ignore no-op options. */
} else {
@@ -102,7 +105,8 @@ bool cmConfigureFileCommand(std::vector<std::string> const& args,
}
if (!status.GetMakefile().ConfigureFile(
- inputFile, outputFile, copyOnly, atOnly, escapeQuotes, newLineStyle)) {
+ inputFile, outputFile, copyOnly, atOnly, escapeQuotes,
+ use_source_permissions, newLineStyle)) {
status.SetError("Problem configuring file");
return false;
}
diff --git a/Source/cmCreateTestSourceList.cxx b/Source/cmCreateTestSourceList.cxx
index 9d492ba845..9c4deea1e2 100644
--- a/Source/cmCreateTestSourceList.cxx
+++ b/Source/cmCreateTestSourceList.cxx
@@ -127,7 +127,7 @@ bool cmCreateTestSourceList(std::vector<std::string> const& args,
mf.AddDefinition("CMAKE_FORWARD_DECLARE_TESTS", forwardDeclareCode);
mf.AddDefinition("CMAKE_FUNCTION_TABLE_ENTIRES", functionMapCode);
bool res = true;
- if (!mf.ConfigureFile(configFile, driver, false, true, false)) {
+ if (!mf.ConfigureFile(configFile, driver, false, true, false, true)) {
res = false;
}
diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx
index 95caa30e3f..42a5780726 100644
--- a/Source/cmLocalGenerator.cxx
+++ b/Source/cmLocalGenerator.cxx
@@ -3845,7 +3845,7 @@ void cmLocalGenerator::GenerateAppleInfoPList(cmGeneratorTarget* target,
cmLGInfoProp(mf, target, "MACOSX_BUNDLE_SHORT_VERSION_STRING");
cmLGInfoProp(mf, target, "MACOSX_BUNDLE_BUNDLE_VERSION");
cmLGInfoProp(mf, target, "MACOSX_BUNDLE_COPYRIGHT");
- mf->ConfigureFile(inFile, fname, false, false, false);
+ mf->ConfigureFile(inFile, fname, false, false, false, true);
}
void cmLocalGenerator::GenerateFrameworkInfoPList(
@@ -3881,7 +3881,7 @@ void cmLocalGenerator::GenerateFrameworkInfoPList(
cmLGInfoProp(mf, target, "MACOSX_FRAMEWORK_IDENTIFIER");
cmLGInfoProp(mf, target, "MACOSX_FRAMEWORK_SHORT_VERSION_STRING");
cmLGInfoProp(mf, target, "MACOSX_FRAMEWORK_BUNDLE_VERSION");
- mf->ConfigureFile(inFile, fname, false, false, false);
+ mf->ConfigureFile(inFile, fname, false, false, false, true);
}
namespace {
diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx
index d34259f3f5..283f57d3b1 100644
--- a/Source/cmMakefile.cxx
+++ b/Source/cmMakefile.cxx
@@ -34,6 +34,7 @@
#include "cmExecutionStatus.h"
#include "cmExpandedCommandArgument.h" // IWYU pragma: keep
#include "cmExportBuildFileGenerator.h"
+#include "cmFSPermissions.h"
#include "cmFileLockPool.h"
#include "cmFunctionBlocker.h"
#include "cmGeneratedFileStream.h"
@@ -69,6 +70,8 @@
class cmMessenger;
+using namespace cmFSPermissions;
+
cmDirectoryId::cmDirectoryId(std::string s)
: String(std::move(s))
{
@@ -3997,6 +4000,7 @@ void cmMakefile::ConfigureString(const std::string& input, std::string& output,
int cmMakefile::ConfigureFile(const std::string& infile,
const std::string& outfile, bool copyonly,
bool atOnly, bool escapeQuotes,
+ bool use_source_permissions,
cmNewLineStyle newLine)
{
int res = 1;
@@ -4020,7 +4024,13 @@ int cmMakefile::ConfigureFile(const std::string& infile,
this->AddCMakeOutputFile(soutfile);
mode_t perm = 0;
- cmSystemTools::GetPermissions(sinfile, perm);
+ if (!use_source_permissions) {
+ perm = perm | mode_owner_read | mode_owner_write | mode_group_read |
+ mode_world_read;
+ } else {
+ cmSystemTools::GetPermissions(sinfile, perm);
+ }
+
std::string::size_type pos = soutfile.rfind('/');
if (pos != std::string::npos) {
std::string path = soutfile.substr(0, pos);
@@ -4033,6 +4043,11 @@ int cmMakefile::ConfigureFile(const std::string& infile,
cmSystemTools::GetLastSystemError());
return 0;
}
+ if (!cmSystemTools::SetPermissions(soutfile, perm)) {
+ this->IssueMessage(MessageType::FATAL_ERROR,
+ cmSystemTools::GetLastSystemError());
+ return 0;
+ }
} else {
std::string newLineCharacters;
std::ios::openmode omode = std::ios::out | std::ios::trunc;
diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h
index 332554e454..8219eb386d 100644
--- a/Source/cmMakefile.h
+++ b/Source/cmMakefile.h
@@ -687,6 +687,7 @@ public:
*/
int ConfigureFile(const std::string& infile, const std::string& outfile,
bool copyonly, bool atOnly, bool escapeQuotes,
+ bool use_source_permissions,
cmNewLineStyle = cmNewLineStyle());
/**
diff --git a/Source/cmVisualStudio10TargetGenerator.cxx b/Source/cmVisualStudio10TargetGenerator.cxx
index 10a4a0c66d..31754f4a08 100644
--- a/Source/cmVisualStudio10TargetGenerator.cxx
+++ b/Source/cmVisualStudio10TargetGenerator.cxx
@@ -670,7 +670,7 @@ void cmVisualStudio10TargetGenerator::Generate()
cmStrCat(this->DefaultArtifactDir, "\\nasm.props");
ConvertToWindowsSlash(propsLocal);
this->Makefile->ConfigureFile(propsTemplate, propsLocal, false, true,
- true);
+ true, true);
Elem(e1, "Import").Attribute("Project", propsLocal);
}
}
diff --git a/Tests/RunCMake/configure_file/NoSourcePermissions.cmake b/Tests/RunCMake/configure_file/NoSourcePermissions.cmake
new file mode 100644
index 0000000000..c6ad1311ea
--- /dev/null
+++ b/Tests/RunCMake/configure_file/NoSourcePermissions.cmake
@@ -0,0 +1,10 @@
+configure_file(NoSourcePermissions.sh NoSourcePermissions.sh.out
+ NO_SOURCE_PERMISSIONS)
+
+if (UNIX)
+ execute_process(COMMAND ${CMAKE_CURRENT_BINARY_DIR}/NoSourcePermissions.sh.out
+ RESULT_VARIABLE result)
+ if (result EQUAL "0")
+ message(FATAL_ERROR "Copied file has executable permissions")
+ endif()
+endif()
diff --git a/Tests/RunCMake/configure_file/NoSourcePermissions.sh b/Tests/RunCMake/configure_file/NoSourcePermissions.sh
new file mode 100755
index 0000000000..0aa8f412e7
--- /dev/null
+++ b/Tests/RunCMake/configure_file/NoSourcePermissions.sh
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+#Testing NO_SOURCE_PERMISSIONS option of configure_file.
diff --git a/Tests/RunCMake/configure_file/RunCMakeTest.cmake b/Tests/RunCMake/configure_file/RunCMakeTest.cmake
index 32a0770b9f..71694fb0b5 100644
--- a/Tests/RunCMake/configure_file/RunCMakeTest.cmake
+++ b/Tests/RunCMake/configure_file/RunCMakeTest.cmake
@@ -15,6 +15,7 @@ run_cmake(NewLineStyle-NoArg)
run_cmake(NewLineStyle-WrongArg)
run_cmake(NewLineStyle-ValidArg)
run_cmake(NewLineStyle-COPYONLY)
+run_cmake(NoSourcePermissions)
if(RunCMake_GENERATOR MATCHES "Make")
# Use a single build tree for a few tests without cleaning.