|
@@ -2220,6 +2220,45 @@ inline std::string removeQuotes(const std::string& s)
|
|
|
return s;
|
|
|
}
|
|
|
|
|
|
+bool cmGlobalGenerator::CheckCMP0037(std::string const& targetName,
|
|
|
+ std::string const& reason) const
|
|
|
+{
|
|
|
+ cmTarget* tgt = this->FindTarget(targetName);
|
|
|
+ if (!tgt) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ cmake::MessageType messageType = cmake::AUTHOR_WARNING;
|
|
|
+ std::ostringstream e;
|
|
|
+ bool issueMessage = false;
|
|
|
+ switch (tgt->GetPolicyStatusCMP0037()) {
|
|
|
+ case cmPolicies::WARN:
|
|
|
+ e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0037) << "\n";
|
|
|
+ issueMessage = true;
|
|
|
+ CM_FALLTHROUGH;
|
|
|
+ case cmPolicies::OLD:
|
|
|
+ break;
|
|
|
+ case cmPolicies::NEW:
|
|
|
+ case cmPolicies::REQUIRED_IF_USED:
|
|
|
+ case cmPolicies::REQUIRED_ALWAYS:
|
|
|
+ issueMessage = true;
|
|
|
+ messageType = cmake::FATAL_ERROR;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ if (issueMessage) {
|
|
|
+ e << "The target name \"" << targetName << "\" is reserved " << reason
|
|
|
+ << ".";
|
|
|
+ if (messageType == cmake::AUTHOR_WARNING) {
|
|
|
+ e << " It may result in undefined behavior.";
|
|
|
+ }
|
|
|
+ this->GetCMakeInstance()->IssueMessage(messageType, e.str(),
|
|
|
+ tgt->GetBacktrace());
|
|
|
+ if (messageType == cmake::FATAL_ERROR) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+}
|
|
|
+
|
|
|
void cmGlobalGenerator::CreateDefaultGlobalTargets(
|
|
|
std::vector<GlobalTargetInfo>& targets)
|
|
|
{
|
|
@@ -2235,6 +2274,20 @@ 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* reservedTargets[] = { "package", "PACKAGE" };
|
|
|
+ for (const char* const* tn = cm::cbegin(reservedTargets);
|
|
|
+ tn != cm::cend(reservedTargets); ++tn) {
|
|
|
+ if (!this->CheckCMP0037(*tn, "when CPack packaging is enabled")) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
const char* cmakeCfgIntDir = this->GetCMakeCFGIntDir();
|
|
|
GlobalTargetInfo gti;
|
|
|
gti.Name = this->GetPackageTargetName();
|
|
@@ -2248,8 +2301,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,61 +2313,81 @@ void cmGlobalGenerator::AddGlobalTarget_Package(
|
|
|
gti.Depends.push_back(this->GetAllTargetName());
|
|
|
}
|
|
|
}
|
|
|
- if (cmSystemTools::FileExists(configFile.c_str())) {
|
|
|
- targets.push_back(gti);
|
|
|
- }
|
|
|
+ targets.push_back(gti);
|
|
|
}
|
|
|
|
|
|
void cmGlobalGenerator::AddGlobalTarget_PackageSource(
|
|
|
std::vector<GlobalTargetInfo>& targets)
|
|
|
{
|
|
|
- cmMakefile* mf = this->Makefiles[0];
|
|
|
const char* packageSourceTargetName = this->GetPackageSourceTargetName();
|
|
|
- if (packageSourceTargetName) {
|
|
|
- GlobalTargetInfo gti;
|
|
|
- gti.Name = packageSourceTargetName;
|
|
|
- gti.Message = "Run CPack packaging tool for source...";
|
|
|
- gti.WorkingDir = mf->GetCurrentBinaryDirectory();
|
|
|
- gti.UsesTerminal = true;
|
|
|
- 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);
|
|
|
+ if (!packageSourceTargetName) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ cmMakefile* mf = this->Makefiles[0];
|
|
|
+ std::string configFile = mf->GetCurrentBinaryDirectory();
|
|
|
+ configFile += "/CPackSourceConfig.cmake";
|
|
|
+ if (!cmSystemTools::FileExists(configFile.c_str())) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ const char* reservedTargets[] = { "package_source" };
|
|
|
+ for (const char* const* tn = cm::cbegin(reservedTargets);
|
|
|
+ tn != cm::cend(reservedTargets); ++tn) {
|
|
|
+ if (!this->CheckCMP0037(*tn, "when CPack source packaging is enabled")) {
|
|
|
+ return;
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ GlobalTargetInfo gti;
|
|
|
+ gti.Name = packageSourceTargetName;
|
|
|
+ gti.Message = "Run CPack packaging tool for source...";
|
|
|
+ gti.WorkingDir = mf->GetCurrentBinaryDirectory();
|
|
|
+ gti.UsesTerminal = true;
|
|
|
+ cmCustomCommandLine singleLine;
|
|
|
+ singleLine.push_back(cmSystemTools::GetCPackCommand());
|
|
|
+ singleLine.push_back("--config");
|
|
|
+ std::string relConfigFile = "./CPackSourceConfig.cmake";
|
|
|
+ singleLine.push_back(relConfigFile);
|
|
|
+ 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];
|
|
|
- const char* cmakeCfgIntDir = this->GetCMakeCFGIntDir();
|
|
|
- if (mf->IsOn("CMAKE_TESTING_ENABLED")) {
|
|
|
- GlobalTargetInfo gti;
|
|
|
- gti.Name = this->GetTestTargetName();
|
|
|
- gti.Message = "Running tests...";
|
|
|
- gti.UsesTerminal = true;
|
|
|
- cmCustomCommandLine singleLine;
|
|
|
- singleLine.push_back(cmSystemTools::GetCTestCommand());
|
|
|
- singleLine.push_back("--force-new-ctest-process");
|
|
|
- if (cmakeCfgIntDir && *cmakeCfgIntDir && cmakeCfgIntDir[0] != '.') {
|
|
|
- singleLine.push_back("-C");
|
|
|
- singleLine.push_back(cmakeCfgIntDir);
|
|
|
- } else // TODO: This is a hack. Should be something to do with the
|
|
|
- // generator
|
|
|
- {
|
|
|
- singleLine.push_back("$(ARGS)");
|
|
|
+ if (!mf->IsOn("CMAKE_TESTING_ENABLED")) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ const char* reservedTargets[] = { "test", "RUN_TESTS" };
|
|
|
+ for (const char* const* tn = cm::cbegin(reservedTargets);
|
|
|
+ tn != cm::cend(reservedTargets); ++tn) {
|
|
|
+ if (!this->CheckCMP0037(*tn, "when CTest testing is enabled")) {
|
|
|
+ return;
|
|
|
}
|
|
|
- gti.CommandLines.push_back(singleLine);
|
|
|
- targets.push_back(gti);
|
|
|
}
|
|
|
+
|
|
|
+ const char* cmakeCfgIntDir = this->GetCMakeCFGIntDir();
|
|
|
+ GlobalTargetInfo gti;
|
|
|
+ gti.Name = this->GetTestTargetName();
|
|
|
+ gti.Message = "Running tests...";
|
|
|
+ gti.UsesTerminal = true;
|
|
|
+ cmCustomCommandLine singleLine;
|
|
|
+ singleLine.push_back(cmSystemTools::GetCTestCommand());
|
|
|
+ singleLine.push_back("--force-new-ctest-process");
|
|
|
+ if (cmakeCfgIntDir && *cmakeCfgIntDir && cmakeCfgIntDir[0] != '.') {
|
|
|
+ singleLine.push_back("-C");
|
|
|
+ singleLine.push_back(cmakeCfgIntDir);
|
|
|
+ } else // TODO: This is a hack. Should be something to do with the
|
|
|
+ // generator
|
|
|
+ {
|
|
|
+ singleLine.push_back("$(ARGS)");
|
|
|
+ }
|
|
|
+ gti.CommandLines.push_back(singleLine);
|
|
|
+ targets.push_back(gti);
|
|
|
}
|
|
|
|
|
|
void cmGlobalGenerator::AddGlobalTarget_EditCache(
|
|
@@ -2582,11 +2653,10 @@ bool cmGlobalGenerator::IsReservedTarget(std::string const& name)
|
|
|
// by one or more of the cmake generators.
|
|
|
|
|
|
// Adding additional targets to this list will require a policy!
|
|
|
- const char* reservedTargets[] = {
|
|
|
- "all", "ALL_BUILD", "help", "install", "INSTALL",
|
|
|
- "preinstall", "clean", "edit_cache", "rebuild_cache", "test",
|
|
|
- "RUN_TESTS", "package", "PACKAGE", "package_source", "ZERO_CHECK"
|
|
|
- };
|
|
|
+ const char* reservedTargets[] = { "all", "ALL_BUILD", "help",
|
|
|
+ "install", "INSTALL", "preinstall",
|
|
|
+ "clean", "edit_cache", "rebuild_cache",
|
|
|
+ "ZERO_CHECK" };
|
|
|
|
|
|
return std::find(cm::cbegin(reservedTargets), cm::cend(reservedTargets),
|
|
|
name) != cm::cend(reservedTargets);
|