summaryrefslogtreecommitdiffstats
path: root/Source/cmExportFileGenerator.cxx
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2016-05-06 18:19:04 (GMT)
committerBrad King <brad.king@kitware.com>2016-05-06 18:25:55 (GMT)
commit64b5520346c75ec479042a114390a0bf71909723 (patch)
treebea1373e84594ba036fe50eea3eab86375d63aa6 /Source/cmExportFileGenerator.cxx
parent73601ff831faa80a188e5997ee048b6986b00a5c (diff)
downloadCMake-64b5520346c75ec479042a114390a0bf71909723.zip
CMake-64b5520346c75ec479042a114390a0bf71909723.tar.gz
CMake-64b5520346c75ec479042a114390a0bf71909723.tar.bz2
Isolate formatted streaming blocks with clang-format off/on
The clang-format tool can do a good job formatting most code, but well-organized streaming blocks are best left manually formatted. Find blocks of the form os << "...\n" "...\n" ; using the command $ git ls-files -z -- Source | egrep -v -z '^Source/kwsys/' | xargs -0 pcregrep -M --color=always -B 1 -A 1 -n \ '<<[^\n]*\n(^ *("[^\n]*("|<<|;)$|;)\n){2,}' Find blocks of the form os << "...\n" << "...\n" << "...\n"; using the command $ git ls-files -z -- Source | egrep -v -z '^Source/kwsys/' | xargs -0 pcregrep -M --color=always -B 1 -A 1 -n \ '<<[^\n]*\n(^ *<<[^\n]*(\\n"|<<|;)$\n){2,}' Surround such blocks with the pair /* clang-format off */ ... /* clang-format on */ in order to protect them from update by clang-format. Use the C-style `/*...*/` comments instead of C++-style `//...` comments in order to prevent them from ever being swallowed by re-formatting of surrounding comments.
Diffstat (limited to 'Source/cmExportFileGenerator.cxx')
-rw-r--r--Source/cmExportFileGenerator.cxx22
1 files changed, 22 insertions, 0 deletions
diff --git a/Source/cmExportFileGenerator.cxx b/Source/cmExportFileGenerator.cxx
index 2b3ce14..9cee308 100644
--- a/Source/cmExportFileGenerator.cxx
+++ b/Source/cmExportFileGenerator.cxx
@@ -106,17 +106,21 @@ bool cmExportFileGenerator::GenerateImportFile()
std::ostream& os = *foutPtr;
// Protect that file against use with older CMake versions.
+ /* clang-format off */
os << "# Generated by CMake " << cmVersion::GetCMakeVersion() << "\n\n";
os << "if(\"${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}\" LESS 2.5)\n"
<< " message(FATAL_ERROR \"CMake >= 2.6.0 required\")\n"
<< "endif()\n";
+ /* clang-format on */
// Isolate the file policy level.
// We use 2.6 here instead of the current version because newer
// versions of CMake should be able to export files imported by 2.6
// until the import format changes.
+ /* clang-format off */
os << "cmake_policy(PUSH)\n"
<< "cmake_policy(VERSION 2.6)\n";
+ /* clang-format on */
// Start with the import file header.
this->GenerateImportHeaderCode(os);
@@ -197,10 +201,12 @@ void cmExportFileGenerator::PopulateInterfaceProperty(
void cmExportFileGenerator::GenerateRequiredCMakeVersion(std::ostream& os,
const char *versionString)
{
+ /* clang-format off */
os << "if(CMAKE_VERSION VERSION_LESS " << versionString << ")\n"
" message(FATAL_ERROR \"This file relies on consumers using "
"CMake " << versionString << " or greater.\")\n"
"endif()\n\n";
+ /* clang-format on */
}
//----------------------------------------------------------------------------
@@ -296,9 +302,11 @@ static bool checkInterfaceDirs(const std::string &prepro,
}
if (!cmSystemTools::FileIsFullPath(li->c_str()))
{
+ /* clang-format off */
e << "Target \"" << target->GetName() << "\" " << prop <<
" property contains relative path:\n"
" \"" << *li << "\"";
+ /* clang-format on */
target->GetLocalGenerator()->IssueMessage(messageType, e.str());
}
bool inBinary = isSubDirectory(li->c_str(), topBinaryDir);
@@ -350,9 +358,11 @@ static bool checkInterfaceDirs(const std::string &prepro,
}
if (inBinary)
{
+ /* clang-format off */
e << "Target \"" << target->GetName() << "\" " << prop <<
" property contains path:\n"
" \"" << *li << "\"\nwhich is prefixed in the build directory.";
+ /* clang-format on */
target->GetLocalGenerator()->IssueMessage(messageType, e.str());
}
if (!inSourceBuild)
@@ -1016,15 +1026,18 @@ void cmExportFileGenerator::GenerateImportVersionCode(std::ostream& os)
{
// Store an import file format version. This will let us change the
// format later while still allowing old import files to work.
+ /* clang-format off */
os << "# Commands may need to know the format version.\n"
<< "set(CMAKE_IMPORT_FILE_VERSION 1)\n"
<< "\n";
+ /* clang-format on */
}
//----------------------------------------------------------------------------
void cmExportFileGenerator::GenerateExpectedTargetsCode(std::ostream& os,
const std::string &expectedTargets)
{
+ /* clang-format off */
os << "# Protect against multiple inclusion, which would fail when already "
"imported targets are added once more.\n"
"set(_targetsDefined)\n"
@@ -1053,6 +1066,7 @@ void cmExportFileGenerator::GenerateExpectedTargetsCode(std::ostream& os,
"unset(_targetsNotDefined)\n"
"unset(_expectedTargets)\n"
"\n\n";
+ /* clang-format on */
}
//----------------------------------------------------------------------------
void
@@ -1163,15 +1177,19 @@ void cmExportFileGenerator::GenerateMissingTargetsCheckCode(std::ostream& os,
{
if (missingTargets.empty())
{
+ /* clang-format off */
os << "# This file does not depend on other imported targets which have\n"
"# been exported from the same project but in a separate "
"export set.\n\n";
+ /* clang-format on */
return;
}
+ /* clang-format off */
os << "# Make sure the targets which have been exported in some other \n"
"# export set exist.\n"
"unset(${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE_targets)\n"
"foreach(_target ";
+ /* clang-format on */
std::set<std::string> emitted;
for(unsigned int i=0; i<missingTargets.size(); ++i)
{
@@ -1180,6 +1198,7 @@ void cmExportFileGenerator::GenerateMissingTargetsCheckCode(std::ostream& os,
os << "\"" << missingTargets[i] << "\" ";
}
}
+ /* clang-format off */
os << ")\n"
" if(NOT TARGET \"${_target}\" )\n"
" set(${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE_targets \""
@@ -1203,6 +1222,7 @@ void cmExportFileGenerator::GenerateMissingTargetsCheckCode(std::ostream& os,
"endif()\n"
"unset(${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE_targets)\n"
"\n";
+ /* clang-format on */
}
@@ -1217,6 +1237,7 @@ cmExportFileGenerator::GenerateImportedFileCheckLoop(std::ostream& os)
// the non-development package, something similar happened to me without
// on SUSE with a mysql pkg-config file, which claimed everything is fine,
// but the development package was not installed.).
+ /* clang-format off */
os << "# Loop over all imported files and verify that they actually exist\n"
"foreach(target ${_IMPORT_CHECK_TARGETS} )\n"
" foreach(file ${_IMPORT_CHECK_FILES_FOR_${target}} )\n"
@@ -1237,6 +1258,7 @@ cmExportFileGenerator::GenerateImportedFileCheckLoop(std::ostream& os)
"endforeach()\n"
"unset(_IMPORT_CHECK_TARGETS)\n"
"\n";
+ /* clang-format on */
}