ENH: Yet another attempt at warning for CMP0003.

- Give example code to avoid the warning
  - Make explanation more consise
  - Explicitly state this is for compatibility
  - Issue the warning for at most one target
This commit is contained in:
Brad King 2008-03-20 21:11:26 -04:00
parent a6a673979d
commit a86e8fa69f
3 changed files with 42 additions and 52 deletions

View File

@ -1337,23 +1337,14 @@ bool cmComputeLinkInformation::FinishLinkerSearchDirectories()
switch(this->Target->GetPolicyStatusCMP0003()) switch(this->Target->GetPolicyStatusCMP0003())
{ {
case cmPolicies::WARN: case cmPolicies::WARN:
{ if(!this->CMakeInstance->GetPropertyAsBool("CMP0003-WARNING-GIVEN"))
cmOStringStream w;
w << (this->Makefile->GetPolicies()
->GetPolicyWarning(cmPolicies::CMP0003)) << "\n";
std::string libs = "CMP0003-WARNING-FOR-";
this->PrintLinkPolicyDiagnosis(w, libs);
const char* def = this->CMakeInstance->GetCacheDefinition(libs.c_str());
if(!def)
{ {
this->CMakeInstance->SetProperty("CMP0003-WARNING-GIVEN", "1");
cmOStringStream w;
this->PrintLinkPolicyDiagnosis(w);
this->CMakeInstance->IssueMessage(cmake::AUTHOR_WARNING, w.str(), this->CMakeInstance->IssueMessage(cmake::AUTHOR_WARNING, w.str(),
this->Target->GetBacktrace()); this->Target->GetBacktrace());
this->CMakeInstance->AddCacheEntry(libs.c_str(),
"TRUE",
"",
cmCacheManager::INTERNAL);
} }
}
case cmPolicies::OLD: case cmPolicies::OLD:
// OLD behavior is to add the paths containing libraries with // OLD behavior is to add the paths containing libraries with
// known full paths as link directories. // known full paths as link directories.
@ -1367,8 +1358,7 @@ bool cmComputeLinkInformation::FinishLinkerSearchDirectories()
cmOStringStream e; cmOStringStream e;
e << (this->Makefile->GetPolicies()-> e << (this->Makefile->GetPolicies()->
GetRequiredPolicyError(cmPolicies::CMP0003)) << "\n"; GetRequiredPolicyError(cmPolicies::CMP0003)) << "\n";
std::string libs; this->PrintLinkPolicyDiagnosis(e);
this->PrintLinkPolicyDiagnosis(e, libs);
this->CMakeInstance->IssueMessage(cmake::FATAL_ERROR, e.str(), this->CMakeInstance->IssueMessage(cmake::FATAL_ERROR, e.str(),
this->Target->GetBacktrace()); this->Target->GetBacktrace());
return false; return false;
@ -1386,35 +1376,21 @@ bool cmComputeLinkInformation::FinishLinkerSearchDirectories()
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
void cmComputeLinkInformation::PrintLinkPolicyDiagnosis(std::ostream& os, void cmComputeLinkInformation::PrintLinkPolicyDiagnosis(std::ostream& os)
std::string& libs)
{ {
// Give the user some help. // Tell the user what to do.
os << "The easiest way to avoid this warning is to set policy CMP0003 " os << "Policy CMP0003 should be set before this line. "
<< "to NEW and try to build the project. " << "Add code such as\n"
<< "If any libraries in the second list below cannot be found then " << " if(COMMAND cmake_policy)\n"
<< "either convert them to be specified with a full path or use the " << " cmake_policy(SET CMP0003 NEW)\n"
<< "link_directories command to add the missing linker search path.\n"; << " endif(COMMAND cmake_policy)\n"
<< "as early as possible but after the most recent call to "
// Name the target. << "cmake_minimum_required or cmake_policy(VERSION). ";
os << "Target \"" << this->Target->GetName() << "\" ";
// List the items that would add paths in old behavior.
std::set<cmStdString> emitted;
os << " links to some items by full path not located in any linker search "
<< "directory added by a link_directories command:\n";
for(std::vector<std::string>::const_iterator
i = this->OldLinkDirItems.begin();
i != this->OldLinkDirItems.end(); ++i)
{
if(emitted.insert(cmSystemTools::GetFilenamePath(*i)).second)
{
os << " " << *i << "\n";
}
}
// List the items that might need the old-style paths. // List the items that might need the old-style paths.
os << "This is okay but it also links to some items with no path known:\n"; os << "This warning appears because target \""
<< this->Target->GetName() << "\" "
<< "links to some libraries for which the linker must search:\n";
{ {
// Format the list of unknown items to be as short as possible while // Format the list of unknown items to be as short as possible while
// still fitting in the allowed width (a true solution would be the // still fitting in the allowed width (a true solution would be the
@ -1437,7 +1413,6 @@ void cmComputeLinkInformation::PrintLinkPolicyDiagnosis(std::ostream& os,
} }
line += sep; line += sep;
line += *i; line += *i;
libs += *i;
// Convert to the other separator. // Convert to the other separator.
sep = ", "; sep = ", ";
} }
@ -1447,14 +1422,26 @@ void cmComputeLinkInformation::PrintLinkPolicyDiagnosis(std::ostream& os,
} }
} }
// Tell the user what is wrong. // List the paths old behavior is adding.
os << "This may be okay too because the linker will search for the " os << "and other libraries with known full path:\n";
<< "libraries in the second list. However, " std::set<cmStdString> emitted;
<< "finding them may depend on linker search paths earlier CMake " for(std::vector<std::string>::const_iterator
<< "versions added as an implementation detail for linking to the " i = this->OldLinkDirItems.begin();
<< "libraries in the first list. " i != this->OldLinkDirItems.end(); ++i)
<< "For compatibility CMake is including the extra linker search " {
<< "paths, but policy CMP0003 should be set by the project. "; if(emitted.insert(cmSystemTools::GetFilenamePath(*i)).second)
{
os << " " << *i << "\n";
}
}
// Explain.
os << "CMake is adding directories in the second list to the linker "
<< "search path in case they are needed to find libraries from the "
<< "first list (for backwards compatibility with CMake 2.4). "
<< "Set policy CMP0003 to OLD or NEW to enable or disable this "
<< "behavior explicitly. "
<< "Run \"cmake --help-policy CMP0003\" for more information.";
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------

View File

@ -154,7 +154,7 @@ private:
// Linker search path computation. // Linker search path computation.
cmOrderDirectories* OrderLinkerSearchPath; cmOrderDirectories* OrderLinkerSearchPath;
bool FinishLinkerSearchDirectories(); bool FinishLinkerSearchDirectories();
void PrintLinkPolicyDiagnosis(std::ostream&, std::string& libs); void PrintLinkPolicyDiagnosis(std::ostream&);
std::set<cmStdString> ImplicitLinkDirs; std::set<cmStdString> ImplicitLinkDirs;
// Linker search path compatibility mode. // Linker search path compatibility mode.

View File

@ -201,7 +201,10 @@ cmPolicies::cmPolicies()
" add_executable(myexe myexe.c)\n" " add_executable(myexe myexe.c)\n"
" target_link_libraries(myexe /path/to/libA.so /path/to/libB.so)\n" " target_link_libraries(myexe /path/to/libA.so /path/to/libB.so)\n"
"When all items on the link line have known paths CMake does not check " "When all items on the link line have known paths CMake does not check "
"this policy so it has no effect.", "this policy so it has no effect.\n"
"Note that the warning for this policy will be issued for at most "
"one target. This avoids flooding users with messages for every "
"target when setting the policy once will probably fix all targets.",
2,6,0, cmPolicies::WARN); 2,6,0, cmPolicies::WARN);
this->DefinePolicy( this->DefinePolicy(