cmGlobalGenerator: Split CreateDefaultGlobalTargets implementation

Divide this long method into multiple helpers each dedicated to one of
the targets.  This also avoids having to clear/re-use local structures.
This commit is contained in:
Brad King 2016-09-15 15:11:02 -04:00
parent 7a2e114dd8
commit 916d84450d
2 changed files with 57 additions and 35 deletions

View File

@ -2070,11 +2070,19 @@ inline std::string removeQuotes(const std::string& s)
} }
void cmGlobalGenerator::CreateDefaultGlobalTargets(cmTargets* targets) void cmGlobalGenerator::CreateDefaultGlobalTargets(cmTargets* targets)
{
this->AddGlobalTarget_Package(targets);
this->AddGlobalTarget_PackageSource(targets);
this->AddGlobalTarget_Test(targets);
this->AddGlobalTarget_EditCache(targets);
this->AddGlobalTarget_RebuildCache(targets);
this->AddGlobalTarget_Install(targets);
}
void cmGlobalGenerator::AddGlobalTarget_Package(cmTargets* targets)
{ {
cmMakefile* mf = this->Makefiles[0]; cmMakefile* mf = this->Makefiles[0];
const char* cmakeCfgIntDir = this->GetCMakeCFGIntDir(); const char* cmakeCfgIntDir = this->GetCMakeCFGIntDir();
// CPack
std::string workingDir = mf->GetCurrentBinaryDirectory(); std::string workingDir = mf->GetCurrentBinaryDirectory();
cmCustomCommandLines cpackCommandLines; cmCustomCommandLines cpackCommandLines;
std::vector<std::string> depends; std::vector<std::string> depends;
@ -2086,7 +2094,6 @@ void cmGlobalGenerator::CreateDefaultGlobalTargets(cmTargets* targets)
} }
singleLine.push_back("--config"); singleLine.push_back("--config");
std::string configFile = mf->GetCurrentBinaryDirectory(); std::string configFile = mf->GetCurrentBinaryDirectory();
;
configFile += "/CPackConfig.cmake"; configFile += "/CPackConfig.cmake";
std::string relConfigFile = "./CPackConfig.cmake"; std::string relConfigFile = "./CPackConfig.cmake";
singleLine.push_back(relConfigFile); singleLine.push_back(relConfigFile);
@ -2108,19 +2115,22 @@ void cmGlobalGenerator::CreateDefaultGlobalTargets(cmTargets* targets)
&cpackCommandLines, depends, workingDir.c_str(), &cpackCommandLines, depends, workingDir.c_str(),
/*uses_terminal*/ true))); /*uses_terminal*/ true)));
} }
// CPack source }
void cmGlobalGenerator::AddGlobalTarget_PackageSource(cmTargets* targets)
{
cmMakefile* mf = this->Makefiles[0];
const char* packageSourceTargetName = this->GetPackageSourceTargetName(); const char* packageSourceTargetName = this->GetPackageSourceTargetName();
if (packageSourceTargetName) { if (packageSourceTargetName) {
cpackCommandLines.erase(cpackCommandLines.begin(), std::string workingDir = mf->GetCurrentBinaryDirectory();
cpackCommandLines.end()); cmCustomCommandLines cpackCommandLines;
singleLine.erase(singleLine.begin(), singleLine.end()); std::vector<std::string> depends;
depends.erase(depends.begin(), depends.end()); cmCustomCommandLine singleLine;
singleLine.push_back(cmSystemTools::GetCPackCommand()); singleLine.push_back(cmSystemTools::GetCPackCommand());
singleLine.push_back("--config"); singleLine.push_back("--config");
configFile = mf->GetCurrentBinaryDirectory(); std::string configFile = mf->GetCurrentBinaryDirectory();
;
configFile += "/CPackSourceConfig.cmake"; configFile += "/CPackSourceConfig.cmake";
relConfigFile = "./CPackSourceConfig.cmake"; std::string relConfigFile = "./CPackSourceConfig.cmake";
singleLine.push_back(relConfigFile); singleLine.push_back(relConfigFile);
if (cmSystemTools::FileExists(configFile.c_str())) { if (cmSystemTools::FileExists(configFile.c_str())) {
singleLine.push_back(configFile); singleLine.push_back(configFile);
@ -2133,13 +2143,16 @@ void cmGlobalGenerator::CreateDefaultGlobalTargets(cmTargets* targets)
/*uses_terminal*/ true))); /*uses_terminal*/ true)));
} }
} }
}
// Test void cmGlobalGenerator::AddGlobalTarget_Test(cmTargets* targets)
{
cmMakefile* mf = this->Makefiles[0];
const char* cmakeCfgIntDir = this->GetCMakeCFGIntDir();
if (mf->IsOn("CMAKE_TESTING_ENABLED")) { if (mf->IsOn("CMAKE_TESTING_ENABLED")) {
cpackCommandLines.erase(cpackCommandLines.begin(), cmCustomCommandLines cpackCommandLines;
cpackCommandLines.end()); std::vector<std::string> depends;
singleLine.erase(singleLine.begin(), singleLine.end()); cmCustomCommandLine singleLine;
depends.erase(depends.begin(), depends.end());
singleLine.push_back(cmSystemTools::GetCTestCommand()); singleLine.push_back(cmSystemTools::GetCTestCommand());
singleLine.push_back("--force-new-ctest-process"); singleLine.push_back("--force-new-ctest-process");
if (cmakeCfgIntDir && *cmakeCfgIntDir && cmakeCfgIntDir[0] != '.') { if (cmakeCfgIntDir && *cmakeCfgIntDir && cmakeCfgIntDir[0] != '.') {
@ -2157,14 +2170,15 @@ void cmGlobalGenerator::CreateDefaultGlobalTargets(cmTargets* targets)
&cpackCommandLines, depends, CM_NULLPTR, &cpackCommandLines, depends, CM_NULLPTR,
/*uses_terminal*/ true))); /*uses_terminal*/ true)));
} }
}
// Edit Cache void cmGlobalGenerator::AddGlobalTarget_EditCache(cmTargets* targets)
{
const char* editCacheTargetName = this->GetEditCacheTargetName(); const char* editCacheTargetName = this->GetEditCacheTargetName();
if (editCacheTargetName) { if (editCacheTargetName) {
cpackCommandLines.erase(cpackCommandLines.begin(), cmCustomCommandLines cpackCommandLines;
cpackCommandLines.end()); std::vector<std::string> depends;
singleLine.erase(singleLine.begin(), singleLine.end()); cmCustomCommandLine singleLine;
depends.erase(depends.begin(), depends.end());
// Use generator preference for the edit_cache rule if it is defined. // Use generator preference for the edit_cache rule if it is defined.
std::string edit_cmd = this->GetEditCacheCommand(); std::string edit_cmd = this->GetEditCacheCommand();
@ -2191,14 +2205,15 @@ void cmGlobalGenerator::CreateDefaultGlobalTargets(cmTargets* targets)
&cpackCommandLines, depends, CM_NULLPTR, /*uses_terminal*/ false))); &cpackCommandLines, depends, CM_NULLPTR, /*uses_terminal*/ false)));
} }
} }
}
// Rebuild Cache void cmGlobalGenerator::AddGlobalTarget_RebuildCache(cmTargets* targets)
{
const char* rebuildCacheTargetName = this->GetRebuildCacheTargetName(); const char* rebuildCacheTargetName = this->GetRebuildCacheTargetName();
if (rebuildCacheTargetName) { if (rebuildCacheTargetName) {
cpackCommandLines.erase(cpackCommandLines.begin(), cmCustomCommandLines cpackCommandLines;
cpackCommandLines.end()); std::vector<std::string> depends;
singleLine.erase(singleLine.begin(), singleLine.end()); cmCustomCommandLine singleLine;
depends.erase(depends.begin(), depends.end());
singleLine.push_back(cmSystemTools::GetCMakeCommand()); singleLine.push_back(cmSystemTools::GetCMakeCommand());
singleLine.push_back("-H$(CMAKE_SOURCE_DIR)"); singleLine.push_back("-H$(CMAKE_SOURCE_DIR)");
singleLine.push_back("-B$(CMAKE_BINARY_DIR)"); singleLine.push_back("-B$(CMAKE_BINARY_DIR)");
@ -2209,8 +2224,12 @@ void cmGlobalGenerator::CreateDefaultGlobalTargets(cmTargets* targets)
rebuildCacheTargetName, "Running CMake to regenerate build system...", rebuildCacheTargetName, "Running CMake to regenerate build system...",
&cpackCommandLines, depends, CM_NULLPTR, /*uses_terminal*/ true))); &cpackCommandLines, depends, CM_NULLPTR, /*uses_terminal*/ true)));
} }
}
// Install void cmGlobalGenerator::AddGlobalTarget_Install(cmTargets* targets)
{
cmMakefile* mf = this->Makefiles[0];
const char* cmakeCfgIntDir = this->GetCMakeCFGIntDir();
bool skipInstallRules = mf->IsOn("CMAKE_SKIP_INSTALL_RULES"); bool skipInstallRules = mf->IsOn("CMAKE_SKIP_INSTALL_RULES");
if (this->InstallTargetEnabled && skipInstallRules) { if (this->InstallTargetEnabled && skipInstallRules) {
this->CMakeInstance->IssueMessage( this->CMakeInstance->IssueMessage(
@ -2220,9 +2239,8 @@ void cmGlobalGenerator::CreateDefaultGlobalTargets(cmTargets* targets)
} else if (this->InstallTargetEnabled && !skipInstallRules) { } else if (this->InstallTargetEnabled && !skipInstallRules) {
if (!cmakeCfgIntDir || !*cmakeCfgIntDir || cmakeCfgIntDir[0] == '.') { if (!cmakeCfgIntDir || !*cmakeCfgIntDir || cmakeCfgIntDir[0] == '.') {
std::set<std::string>* componentsSet = &this->InstallComponents; std::set<std::string>* componentsSet = &this->InstallComponents;
cpackCommandLines.erase(cpackCommandLines.begin(), cmCustomCommandLines cpackCommandLines;
cpackCommandLines.end()); std::vector<std::string> depends;
depends.erase(depends.begin(), depends.end());
std::ostringstream ostr; std::ostringstream ostr;
if (!componentsSet->empty()) { if (!componentsSet->empty()) {
ostr << "Available install components are: "; ostr << "Available install components are: ";
@ -2230,7 +2248,6 @@ void cmGlobalGenerator::CreateDefaultGlobalTargets(cmTargets* targets)
} else { } else {
ostr << "Only default component available"; ostr << "Only default component available";
} }
singleLine.push_back(ostr.str());
targets->insert(cmTargets::value_type( targets->insert(cmTargets::value_type(
"list_install_components", "list_install_components",
this->CreateGlobalTarget("list_install_components", ostr.str().c_str(), this->CreateGlobalTarget("list_install_components", ostr.str().c_str(),
@ -2238,10 +2255,9 @@ void cmGlobalGenerator::CreateDefaultGlobalTargets(cmTargets* targets)
/*uses_terminal*/ false))); /*uses_terminal*/ false)));
} }
std::string cmd = cmSystemTools::GetCMakeCommand(); std::string cmd = cmSystemTools::GetCMakeCommand();
cpackCommandLines.erase(cpackCommandLines.begin(), cmCustomCommandLines cpackCommandLines;
cpackCommandLines.end()); std::vector<std::string> depends;
singleLine.erase(singleLine.begin(), singleLine.end()); cmCustomCommandLine singleLine;
depends.erase(depends.begin(), depends.end());
if (this->GetPreinstallTargetName()) { if (this->GetPreinstallTargetName()) {
depends.push_back(this->GetPreinstallTargetName()); depends.push_back(this->GetPreinstallTargetName());
} else { } else {

View File

@ -403,6 +403,12 @@ protected:
bool IsExcluded(cmLocalGenerator* root, cmGeneratorTarget* target) const; bool IsExcluded(cmLocalGenerator* root, cmGeneratorTarget* target) const;
virtual void InitializeProgressMarks() {} virtual void InitializeProgressMarks() {}
void CreateDefaultGlobalTargets(cmTargets* targets); void CreateDefaultGlobalTargets(cmTargets* targets);
void AddGlobalTarget_Package(cmTargets* targets);
void AddGlobalTarget_PackageSource(cmTargets* targets);
void AddGlobalTarget_Test(cmTargets* targets);
void AddGlobalTarget_EditCache(cmTargets* targets);
void AddGlobalTarget_RebuildCache(cmTargets* targets);
void AddGlobalTarget_Install(cmTargets* targets);
cmTarget CreateGlobalTarget(const std::string& name, const char* message, cmTarget CreateGlobalTarget(const std::string& name, const char* message,
const cmCustomCommandLines* commandLines, const cmCustomCommandLines* commandLines,
std::vector<std::string> depends, std::vector<std::string> depends,