summaryrefslogtreecommitdiffstats
path: root/Source/cmExportCommand.cxx
diff options
context:
space:
mode:
authorKitware Robot <kwrobot@kitware.com>2016-05-16 14:34:04 (GMT)
committerBrad King <brad.king@kitware.com>2016-05-16 20:05:19 (GMT)
commitd9fd2f5402eeaa345691313658e02b51038f570b (patch)
treedca71b9a7e267f4c6300da3eb770415381726785 /Source/cmExportCommand.cxx
parent82df6deaafb36cbbfd450202bb20b320f637751a (diff)
downloadCMake-d9fd2f5402eeaa345691313658e02b51038f570b.zip
CMake-d9fd2f5402eeaa345691313658e02b51038f570b.tar.gz
CMake-d9fd2f5402eeaa345691313658e02b51038f570b.tar.bz2
Revise C++ coding style using clang-format
Run the `Utilities/Scripts/clang-format.bash` script to update all our C++ code to a new style defined by `.clang-format`. Use `clang-format` version 3.8. * If you reached this commit for a line in `git blame`, re-run the blame operation starting at the parent of this commit to see older history for the content. * See the parent commit for instructions to rebase a change across this style transition commit.
Diffstat (limited to 'Source/cmExportCommand.cxx')
-rw-r--r--Source/cmExportCommand.cxx287
1 files changed, 115 insertions, 172 deletions
diff --git a/Source/cmExportCommand.cxx b/Source/cmExportCommand.cxx
index ee8865e..a0e7e45 100644
--- a/Source/cmExportCommand.cxx
+++ b/Source/cmExportCommand.cxx
@@ -26,226 +26,184 @@
#endif
cmExportCommand::cmExportCommand()
-:cmCommand()
-,ArgumentGroup()
-,Targets(&Helper, "TARGETS")
-,Append(&Helper, "APPEND", &ArgumentGroup)
-,ExportSetName(&Helper, "EXPORT", &ArgumentGroup)
-,Namespace(&Helper, "NAMESPACE", &ArgumentGroup)
-,Filename(&Helper, "FILE", &ArgumentGroup)
-,ExportOld(&Helper, "EXPORT_LINK_INTERFACE_LIBRARIES", &ArgumentGroup)
+ : cmCommand()
+ , ArgumentGroup()
+ , Targets(&Helper, "TARGETS")
+ , Append(&Helper, "APPEND", &ArgumentGroup)
+ , ExportSetName(&Helper, "EXPORT", &ArgumentGroup)
+ , Namespace(&Helper, "NAMESPACE", &ArgumentGroup)
+ , Filename(&Helper, "FILE", &ArgumentGroup)
+ , ExportOld(&Helper, "EXPORT_LINK_INTERFACE_LIBRARIES", &ArgumentGroup)
{
this->ExportSet = 0;
}
-
// cmExportCommand
-bool cmExportCommand
-::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
+bool cmExportCommand::InitialPass(std::vector<std::string> const& args,
+ cmExecutionStatus&)
{
- if(args.size() < 2 )
- {
+ if (args.size() < 2) {
this->SetError("called with too few arguments");
return false;
- }
+ }
- if(args[0] == "PACKAGE")
- {
+ if (args[0] == "PACKAGE") {
return this->HandlePackage(args);
- }
- else if (args[0] == "EXPORT")
- {
+ } else if (args[0] == "EXPORT") {
this->ExportSetName.Follows(0);
this->ArgumentGroup.Follows(&this->ExportSetName);
- }
- else
- {
+ } else {
this->Targets.Follows(0);
this->ArgumentGroup.Follows(&this->Targets);
- }
+ }
std::vector<std::string> unknownArgs;
this->Helper.Parse(&args, &unknownArgs);
- if (!unknownArgs.empty())
- {
+ if (!unknownArgs.empty()) {
this->SetError("Unknown arguments.");
return false;
- }
+ }
std::string fname;
- if(!this->Filename.WasFound())
- {
- if (args[0] != "EXPORT")
- {
+ if (!this->Filename.WasFound()) {
+ if (args[0] != "EXPORT") {
this->SetError("FILE <filename> option missing.");
return false;
- }
- fname = this->ExportSetName.GetString() + ".cmake";
}
- else
- {
+ fname = this->ExportSetName.GetString() + ".cmake";
+ } else {
// Make sure the file has a .cmake extension.
- if(cmSystemTools::GetFilenameLastExtension(this->Filename.GetCString())
- != ".cmake")
- {
+ if (cmSystemTools::GetFilenameLastExtension(this->Filename.GetCString()) !=
+ ".cmake") {
std::ostringstream e;
e << "FILE option given filename \"" << this->Filename.GetString()
<< "\" which does not have an extension of \".cmake\".\n";
this->SetError(e.str());
return false;
- }
- fname = this->Filename.GetString();
}
+ fname = this->Filename.GetString();
+ }
// Get the file to write.
- if(cmSystemTools::FileIsFullPath(fname.c_str()))
- {
- if(!this->Makefile->CanIWriteThisFile(fname.c_str()))
- {
+ if (cmSystemTools::FileIsFullPath(fname.c_str())) {
+ if (!this->Makefile->CanIWriteThisFile(fname.c_str())) {
std::ostringstream e;
e << "FILE option given filename \"" << fname
<< "\" which is in the source tree.\n";
this->SetError(e.str());
return false;
- }
}
- else
- {
+ } else {
// Interpret relative paths with respect to the current build dir.
std::string dir = this->Makefile->GetCurrentBinaryDirectory();
fname = dir + "/" + fname;
- }
+ }
std::vector<std::string> targets;
- cmGlobalGenerator *gg = this->Makefile->GetGlobalGenerator();
+ cmGlobalGenerator* gg = this->Makefile->GetGlobalGenerator();
- if(args[0] == "EXPORT")
- {
- if (this->Append.IsEnabled())
- {
+ if (args[0] == "EXPORT") {
+ if (this->Append.IsEnabled()) {
std::ostringstream e;
e << "EXPORT signature does not recognise the APPEND option.";
this->SetError(e.str());
return false;
- }
+ }
- if (this->ExportOld.IsEnabled())
- {
+ if (this->ExportOld.IsEnabled()) {
std::ostringstream e;
e << "EXPORT signature does not recognise the "
- "EXPORT_LINK_INTERFACE_LIBRARIES option.";
+ "EXPORT_LINK_INTERFACE_LIBRARIES option.";
this->SetError(e.str());
return false;
- }
+ }
- cmExportSetMap &setMap = gg->GetExportSets();
+ cmExportSetMap& setMap = gg->GetExportSets();
std::string setName = this->ExportSetName.GetString();
- if (setMap.find(setName) == setMap.end())
- {
+ if (setMap.find(setName) == setMap.end()) {
std::ostringstream e;
e << "Export set \"" << setName << "\" not found.";
this->SetError(e.str());
return false;
- }
- this->ExportSet = setMap[setName];
}
- else if (this->Targets.WasFound())
- {
- for(std::vector<std::string>::const_iterator
- currentTarget = this->Targets.GetVector().begin();
- currentTarget != this->Targets.GetVector().end();
- ++currentTarget)
- {
- if (this->Makefile->IsAlias(*currentTarget))
- {
+ this->ExportSet = setMap[setName];
+ } else if (this->Targets.WasFound()) {
+ for (std::vector<std::string>::const_iterator currentTarget =
+ this->Targets.GetVector().begin();
+ currentTarget != this->Targets.GetVector().end(); ++currentTarget) {
+ if (this->Makefile->IsAlias(*currentTarget)) {
std::ostringstream e;
e << "given ALIAS target \"" << *currentTarget
<< "\" which may not be exported.";
this->SetError(e.str());
return false;
- }
+ }
- if(cmTarget* target = gg->FindTarget(*currentTarget))
- {
- if(target->GetType() == cmState::OBJECT_LIBRARY)
- {
+ if (cmTarget* target = gg->FindTarget(*currentTarget)) {
+ if (target->GetType() == cmState::OBJECT_LIBRARY) {
std::ostringstream e;
e << "given OBJECT library \"" << *currentTarget
<< "\" which may not be exported.";
this->SetError(e.str());
return false;
- }
- if (target->GetType() == cmState::UTILITY)
- {
- this->SetError("given custom target \"" + *currentTarget
- + "\" which may not be exported.");
+ }
+ if (target->GetType() == cmState::UTILITY) {
+ this->SetError("given custom target \"" + *currentTarget +
+ "\" which may not be exported.");
return false;
- }
}
- else
- {
+ } else {
std::ostringstream e;
e << "given target \"" << *currentTarget
<< "\" which is not built by this project.";
this->SetError(e.str());
return false;
- }
- targets.push_back(*currentTarget);
}
- if (this->Append.IsEnabled())
- {
- if (cmExportBuildFileGenerator *ebfg = gg->GetExportedTargetsFile(fname))
- {
+ targets.push_back(*currentTarget);
+ }
+ if (this->Append.IsEnabled()) {
+ if (cmExportBuildFileGenerator* ebfg =
+ gg->GetExportedTargetsFile(fname)) {
ebfg->AppendTargets(targets);
return true;
- }
}
}
- else
- {
+ } else {
this->SetError("EXPORT or TARGETS specifier missing.");
return false;
- }
+ }
// Setup export file generation.
- cmExportBuildFileGenerator *ebfg = new cmExportBuildFileGenerator;
+ cmExportBuildFileGenerator* ebfg = new cmExportBuildFileGenerator;
ebfg->SetExportFile(fname.c_str());
ebfg->SetNamespace(this->Namespace.GetCString());
ebfg->SetAppendMode(this->Append.IsEnabled());
- if (this->ExportSet)
- {
+ if (this->ExportSet) {
ebfg->SetExportSet(this->ExportSet);
- }
- else
- {
+ } else {
ebfg->SetTargets(targets);
- }
+ }
this->Makefile->AddExportBuildFileGenerator(ebfg);
ebfg->SetExportOld(this->ExportOld.IsEnabled());
// Compute the set of configurations exported.
std::vector<std::string> configurationTypes;
this->Makefile->GetConfigurations(configurationTypes);
- if(configurationTypes.empty())
- {
+ if (configurationTypes.empty()) {
configurationTypes.push_back("");
- }
- for(std::vector<std::string>::const_iterator
- ci = configurationTypes.begin();
- ci != configurationTypes.end(); ++ci)
- {
+ }
+ for (std::vector<std::string>::const_iterator ci =
+ configurationTypes.begin();
+ ci != configurationTypes.end(); ++ci) {
ebfg->AddConfiguration(*ci);
- }
- if (this->ExportSet)
- {
+ }
+ if (this->ExportSet) {
gg->AddBuildExportExportSet(ebfg);
- }
- else
- {
+ } else {
gg->AddBuildExportSet(ebfg);
- }
+ }
return true;
}
@@ -253,48 +211,45 @@ bool cmExportCommand
bool cmExportCommand::HandlePackage(std::vector<std::string> const& args)
{
// Parse PACKAGE mode arguments.
- enum Doing { DoingNone, DoingPackage };
+ enum Doing
+ {
+ DoingNone,
+ DoingPackage
+ };
Doing doing = DoingPackage;
std::string package;
- for(unsigned int i=1; i < args.size(); ++i)
- {
- if(doing == DoingPackage)
- {
+ for (unsigned int i = 1; i < args.size(); ++i) {
+ if (doing == DoingPackage) {
package = args[i];
doing = DoingNone;
- }
- else
- {
+ } else {
std::ostringstream e;
e << "PACKAGE given unknown argument: " << args[i];
this->SetError(e.str());
return false;
- }
}
+ }
// Verify the package name.
- if(package.empty())
- {
+ if (package.empty()) {
this->SetError("PACKAGE must be given a package name.");
return false;
- }
+ }
const char* packageExpr = "^[A-Za-z0-9_.-]+$";
cmsys::RegularExpression packageRegex(packageExpr);
- if(!packageRegex.find(package.c_str()))
- {
+ if (!packageRegex.find(package.c_str())) {
std::ostringstream e;
e << "PACKAGE given invalid package name \"" << package << "\". "
<< "Package names must match \"" << packageExpr << "\".";
this->SetError(e.str());
return false;
- }
+ }
// If the CMAKE_EXPORT_NO_PACKAGE_REGISTRY variable is set the command
// export(PACKAGE) does nothing.
- if(this->Makefile->IsOn("CMAKE_EXPORT_NO_PACKAGE_REGISTRY"))
- {
+ if (this->Makefile->IsOn("CMAKE_EXPORT_NO_PACKAGE_REGISTRY")) {
return true;
- }
+ }
// We store the current build directory in the registry as a value
// named by a hash of its own content. This is deterministic and is
@@ -311,24 +266,21 @@ bool cmExportCommand::HandlePackage(std::vector<std::string> const& args)
}
#if defined(_WIN32) && !defined(__CYGWIN__)
-# include <windows.h>
-# undef GetCurrentDirectory
+#include <windows.h>
+#undef GetCurrentDirectory
void cmExportCommand::ReportRegistryError(std::string const& msg,
- std::string const& key,
- long err)
+ std::string const& key, long err)
{
std::ostringstream e;
e << msg << "\n"
<< " HKEY_CURRENT_USER\\" << key << "\n";
wchar_t winmsg[1024];
- if(FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM |
- FORMAT_MESSAGE_IGNORE_INSERTS, 0, err,
- MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
- winmsg, 1024, 0) > 0)
- {
+ if (FormatMessageW(
+ FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, 0, err,
+ MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), winmsg, 1024, 0) > 0) {
e << "Windows reported:\n"
<< " " << cmsys::Encoding::ToNarrow(winmsg);
- }
+ }
this->Makefile->IssueMessage(cmake::WARNING, e.str());
}
@@ -339,29 +291,26 @@ void cmExportCommand::StorePackageRegistryWin(std::string const& package,
std::string key = "Software\\Kitware\\CMake\\Packages\\";
key += package;
HKEY hKey;
- LONG err = RegCreateKeyExW(HKEY_CURRENT_USER,
- cmsys::Encoding::ToWide(key).c_str(),
- 0, 0, REG_OPTION_NON_VOLATILE,
- KEY_SET_VALUE, 0, &hKey, 0);
- if(err != ERROR_SUCCESS)
- {
- this->ReportRegistryError(
- "Cannot create/open registry key", key, err);
+ LONG err =
+ RegCreateKeyExW(HKEY_CURRENT_USER, cmsys::Encoding::ToWide(key).c_str(), 0,
+ 0, REG_OPTION_NON_VOLATILE, KEY_SET_VALUE, 0, &hKey, 0);
+ if (err != ERROR_SUCCESS) {
+ this->ReportRegistryError("Cannot create/open registry key", key, err);
return;
- }
+ }
std::wstring wcontent = cmsys::Encoding::ToWide(content);
- err = RegSetValueExW(hKey, cmsys::Encoding::ToWide(hash).c_str(),
- 0, REG_SZ, (BYTE const*)wcontent.c_str(),
- static_cast<DWORD>(wcontent.size()+1)*sizeof(wchar_t));
+ err =
+ RegSetValueExW(hKey, cmsys::Encoding::ToWide(hash).c_str(), 0, REG_SZ,
+ (BYTE const*)wcontent.c_str(),
+ static_cast<DWORD>(wcontent.size() + 1) * sizeof(wchar_t));
RegCloseKey(hKey);
- if(err != ERROR_SUCCESS)
- {
+ if (err != ERROR_SUCCESS) {
std::ostringstream msg;
msg << "Cannot set registry value \"" << hash << "\" under key";
this->ReportRegistryError(msg.str(), key, err);
return;
- }
+ }
}
#else
void cmExportCommand::StorePackageRegistryDir(std::string const& package,
@@ -371,19 +320,17 @@ void cmExportCommand::StorePackageRegistryDir(std::string const& package,
#if defined(__HAIKU__)
char dir[B_PATH_NAME_LENGTH];
if (find_directory(B_USER_SETTINGS_DIRECTORY, -1, false, dir, sizeof(dir)) !=
- B_OK)
- {
+ B_OK) {
return;
- }
+ }
std::string fname = dir;
fname += "/cmake/packages/";
fname += package;
#else
const char* home = cmSystemTools::GetEnv("HOME");
- if(!home)
- {
+ if (!home) {
return;
- }
+ }
std::string fname = home;
cmSystemTools::ConvertToUnixSlashes(fname);
fname += "/.cmake/packages/";
@@ -392,15 +339,11 @@ void cmExportCommand::StorePackageRegistryDir(std::string const& package,
cmSystemTools::MakeDirectory(fname.c_str());
fname += "/";
fname += hash;
- if(!cmSystemTools::FileExists(fname.c_str()))
- {
+ if (!cmSystemTools::FileExists(fname.c_str())) {
cmGeneratedFileStream entry(fname.c_str(), true);
- if(entry)
- {
+ if (entry) {
entry << content << "\n";
- }
- else
- {
+ } else {
std::ostringstream e;
/* clang-format off */
e << "Cannot create package registry file:\n"
@@ -408,7 +351,7 @@ void cmExportCommand::StorePackageRegistryDir(std::string const& package,
<< cmSystemTools::GetLastSystemError() << "\n";
/* clang-format on */
this->Makefile->IssueMessage(cmake::WARNING, e.str());
- }
}
+ }
}
#endif