mirror of
https://github.com/Kitware/CMake.git
synced 2025-10-17 15:32:10 +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:
@@ -2235,6 +2235,12 @@ void cmGlobalGenerator::AddGlobalTarget_Package(
|
|||||||
std::vector<GlobalTargetInfo>& targets)
|
std::vector<GlobalTargetInfo>& targets)
|
||||||
{
|
{
|
||||||
cmMakefile* mf = this->Makefiles[0];
|
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();
|
const char* cmakeCfgIntDir = this->GetCMakeCFGIntDir();
|
||||||
GlobalTargetInfo gti;
|
GlobalTargetInfo gti;
|
||||||
gti.Name = this->GetPackageTargetName();
|
gti.Name = this->GetPackageTargetName();
|
||||||
@@ -2248,8 +2254,6 @@ void cmGlobalGenerator::AddGlobalTarget_Package(
|
|||||||
singleLine.push_back(cmakeCfgIntDir);
|
singleLine.push_back(cmakeCfgIntDir);
|
||||||
}
|
}
|
||||||
singleLine.push_back("--config");
|
singleLine.push_back("--config");
|
||||||
std::string configFile = mf->GetCurrentBinaryDirectory();
|
|
||||||
configFile += "/CPackConfig.cmake";
|
|
||||||
std::string relConfigFile = "./CPackConfig.cmake";
|
std::string relConfigFile = "./CPackConfig.cmake";
|
||||||
singleLine.push_back(relConfigFile);
|
singleLine.push_back(relConfigFile);
|
||||||
gti.CommandLines.push_back(singleLine);
|
gti.CommandLines.push_back(singleLine);
|
||||||
@@ -2262,17 +2266,24 @@ void cmGlobalGenerator::AddGlobalTarget_Package(
|
|||||||
gti.Depends.push_back(this->GetAllTargetName());
|
gti.Depends.push_back(this->GetAllTargetName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (cmSystemTools::FileExists(configFile.c_str())) {
|
|
||||||
targets.push_back(gti);
|
targets.push_back(gti);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void cmGlobalGenerator::AddGlobalTarget_PackageSource(
|
void cmGlobalGenerator::AddGlobalTarget_PackageSource(
|
||||||
std::vector<GlobalTargetInfo>& targets)
|
std::vector<GlobalTargetInfo>& targets)
|
||||||
{
|
{
|
||||||
cmMakefile* mf = this->Makefiles[0];
|
|
||||||
const char* packageSourceTargetName = this->GetPackageSourceTargetName();
|
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;
|
GlobalTargetInfo gti;
|
||||||
gti.Name = packageSourceTargetName;
|
gti.Name = packageSourceTargetName;
|
||||||
gti.Message = "Run CPack packaging tool for source...";
|
gti.Message = "Run CPack packaging tool for source...";
|
||||||
@@ -2281,24 +2292,22 @@ void cmGlobalGenerator::AddGlobalTarget_PackageSource(
|
|||||||
cmCustomCommandLine singleLine;
|
cmCustomCommandLine singleLine;
|
||||||
singleLine.push_back(cmSystemTools::GetCPackCommand());
|
singleLine.push_back(cmSystemTools::GetCPackCommand());
|
||||||
singleLine.push_back("--config");
|
singleLine.push_back("--config");
|
||||||
std::string configFile = mf->GetCurrentBinaryDirectory();
|
|
||||||
configFile += "/CPackSourceConfig.cmake";
|
|
||||||
std::string relConfigFile = "./CPackSourceConfig.cmake";
|
std::string relConfigFile = "./CPackSourceConfig.cmake";
|
||||||
singleLine.push_back(relConfigFile);
|
singleLine.push_back(relConfigFile);
|
||||||
if (cmSystemTools::FileExists(configFile.c_str())) {
|
|
||||||
singleLine.push_back(configFile);
|
singleLine.push_back(configFile);
|
||||||
gti.CommandLines.push_back(singleLine);
|
gti.CommandLines.push_back(singleLine);
|
||||||
targets.push_back(gti);
|
targets.push_back(gti);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void cmGlobalGenerator::AddGlobalTarget_Test(
|
void cmGlobalGenerator::AddGlobalTarget_Test(
|
||||||
std::vector<GlobalTargetInfo>& targets)
|
std::vector<GlobalTargetInfo>& targets)
|
||||||
{
|
{
|
||||||
cmMakefile* mf = this->Makefiles[0];
|
cmMakefile* mf = this->Makefiles[0];
|
||||||
|
if (!mf->IsOn("CMAKE_TESTING_ENABLED")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const char* cmakeCfgIntDir = this->GetCMakeCFGIntDir();
|
const char* cmakeCfgIntDir = this->GetCMakeCFGIntDir();
|
||||||
if (mf->IsOn("CMAKE_TESTING_ENABLED")) {
|
|
||||||
GlobalTargetInfo gti;
|
GlobalTargetInfo gti;
|
||||||
gti.Name = this->GetTestTargetName();
|
gti.Name = this->GetTestTargetName();
|
||||||
gti.Message = "Running tests...";
|
gti.Message = "Running tests...";
|
||||||
@@ -2317,7 +2326,6 @@ void cmGlobalGenerator::AddGlobalTarget_Test(
|
|||||||
gti.CommandLines.push_back(singleLine);
|
gti.CommandLines.push_back(singleLine);
|
||||||
targets.push_back(gti);
|
targets.push_back(gti);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void cmGlobalGenerator::AddGlobalTarget_EditCache(
|
void cmGlobalGenerator::AddGlobalTarget_EditCache(
|
||||||
std::vector<GlobalTargetInfo>& targets)
|
std::vector<GlobalTargetInfo>& targets)
|
||||||
|
Reference in New Issue
Block a user