1
0
mirror of https://github.com/Kitware/CMake.git synced 2025-10-16 22:37:30 +08:00

cmGlobalGenerator: Refactor test and package target conditions

In `AddGlobalTarget_{Test,Package,PackageSource}`, check conditions up
front and return early if the targets are not needed.  This reduces the
indentation of the main logic.
This commit is contained in:
Brad King
2017-10-25 09:35:22 -04:00
parent 8b10098598
commit 2d0b3e6ed2

View File

@@ -2235,6 +2235,12 @@ void cmGlobalGenerator::AddGlobalTarget_Package(
std::vector<GlobalTargetInfo>& targets)
{
cmMakefile* mf = this->Makefiles[0];
std::string configFile = mf->GetCurrentBinaryDirectory();
configFile += "/CPackConfig.cmake";
if (!cmSystemTools::FileExists(configFile.c_str())) {
return;
}
const char* cmakeCfgIntDir = this->GetCMakeCFGIntDir();
GlobalTargetInfo gti;
gti.Name = this->GetPackageTargetName();
@@ -2248,8 +2254,6 @@ void cmGlobalGenerator::AddGlobalTarget_Package(
singleLine.push_back(cmakeCfgIntDir);
}
singleLine.push_back("--config");
std::string configFile = mf->GetCurrentBinaryDirectory();
configFile += "/CPackConfig.cmake";
std::string relConfigFile = "./CPackConfig.cmake";
singleLine.push_back(relConfigFile);
gti.CommandLines.push_back(singleLine);
@@ -2262,17 +2266,24 @@ void cmGlobalGenerator::AddGlobalTarget_Package(
gti.Depends.push_back(this->GetAllTargetName());
}
}
if (cmSystemTools::FileExists(configFile.c_str())) {
targets.push_back(gti);
}
}
void cmGlobalGenerator::AddGlobalTarget_PackageSource(
std::vector<GlobalTargetInfo>& targets)
{
cmMakefile* mf = this->Makefiles[0];
const char* packageSourceTargetName = this->GetPackageSourceTargetName();
if (packageSourceTargetName) {
if (!packageSourceTargetName) {
return;
}
cmMakefile* mf = this->Makefiles[0];
std::string configFile = mf->GetCurrentBinaryDirectory();
configFile += "/CPackSourceConfig.cmake";
if (!cmSystemTools::FileExists(configFile.c_str())) {
return;
}
GlobalTargetInfo gti;
gti.Name = packageSourceTargetName;
gti.Message = "Run CPack packaging tool for source...";
@@ -2281,24 +2292,22 @@ void cmGlobalGenerator::AddGlobalTarget_PackageSource(
cmCustomCommandLine singleLine;
singleLine.push_back(cmSystemTools::GetCPackCommand());
singleLine.push_back("--config");
std::string configFile = mf->GetCurrentBinaryDirectory();
configFile += "/CPackSourceConfig.cmake";
std::string relConfigFile = "./CPackSourceConfig.cmake";
singleLine.push_back(relConfigFile);
if (cmSystemTools::FileExists(configFile.c_str())) {
singleLine.push_back(configFile);
gti.CommandLines.push_back(singleLine);
targets.push_back(gti);
}
}
}
void cmGlobalGenerator::AddGlobalTarget_Test(
std::vector<GlobalTargetInfo>& targets)
{
cmMakefile* mf = this->Makefiles[0];
if (!mf->IsOn("CMAKE_TESTING_ENABLED")) {
return;
}
const char* cmakeCfgIntDir = this->GetCMakeCFGIntDir();
if (mf->IsOn("CMAKE_TESTING_ENABLED")) {
GlobalTargetInfo gti;
gti.Name = this->GetTestTargetName();
gti.Message = "Running tests...";
@@ -2317,7 +2326,6 @@ void cmGlobalGenerator::AddGlobalTarget_Test(
gti.CommandLines.push_back(singleLine);
targets.push_back(gti);
}
}
void cmGlobalGenerator::AddGlobalTarget_EditCache(
std::vector<GlobalTargetInfo>& targets)