ENH: Added convenience rules to build targets without specifying full paths.

This commit is contained in:
Brad King 2004-11-03 08:46:17 -05:00
parent a5ae290a5b
commit 8a4c0673be
2 changed files with 83 additions and 10 deletions

View File

@ -23,6 +23,14 @@
#include <queue> #include <queue>
// Quick-switch for generating old makefiles.
#if 0
# define CMLUMG_MAKEFILE_NAME "Makefile"
#else
# define CMLUMG_WRITE_OLD_MAKEFILE
# define CMLUMG_MAKEFILE_NAME "Makefile2"
#endif
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
cmLocalUnixMakefileGenerator2::cmLocalUnixMakefileGenerator2() cmLocalUnixMakefileGenerator2::cmLocalUnixMakefileGenerator2()
{ {
@ -48,8 +56,18 @@ void cmLocalUnixMakefileGenerator2::Generate(bool fromTheTop)
{ {
// TODO: Think about unifying generation of "@" for silent commands. // TODO: Think about unifying generation of "@" for silent commands.
#ifdef CMLUMG_WRITE_OLD_MAKEFILE
// Generate old style for now. // Generate old style for now.
this->cmLocalUnixMakefileGenerator::Generate(fromTheTop); this->cmLocalUnixMakefileGenerator::Generate(fromTheTop);
#else
// Make sure we never run a local generate.
if(!fromTheTop)
{
cmSystemTools::Error("Local generate invoked in ",
m_Makefile->GetStartOutputDirectory());
return;
}
#endif
// Generate the rule files for each target. // Generate the rule files for each target.
const cmTargets& targets = m_Makefile->GetTargets(); const cmTargets& targets = m_Makefile->GetTargets();
@ -90,7 +108,7 @@ void cmLocalUnixMakefileGenerator2::GenerateMakefile()
// because the check-build-system step compares the makefile time to // because the check-build-system step compares the makefile time to
// see if the build system must be regenerated. // see if the build system must be regenerated.
std::string makefileName = m_Makefile->GetStartOutputDirectory(); std::string makefileName = m_Makefile->GetStartOutputDirectory();
makefileName += "/Makefile2"; makefileName += "/" CMLUMG_MAKEFILE_NAME;
cmGeneratedFileStream makefileStream(makefileName.c_str()); cmGeneratedFileStream makefileStream(makefileName.c_str());
if(!makefileStream) if(!makefileStream)
{ {
@ -126,10 +144,12 @@ void cmLocalUnixMakefileGenerator2::GenerateMakefile()
void cmLocalUnixMakefileGenerator2::GenerateCMakefile() void cmLocalUnixMakefileGenerator2::GenerateCMakefile()
{ {
std::string makefileName = m_Makefile->GetStartOutputDirectory(); std::string makefileName = m_Makefile->GetStartOutputDirectory();
makefileName += "/Makefile2"; makefileName += "/" CMLUMG_MAKEFILE_NAME;
std::string cmakefileName = makefileName; std::string cmakefileName = makefileName;
cmakefileName += ".cmake"; cmakefileName += ".cmake";
// TODO: Use relative paths in this generated file.
// Open the output file. // Open the output file.
cmGeneratedFileStream cmakefileStream(cmakefileName.c_str()); cmGeneratedFileStream cmakefileStream(cmakefileName.c_str());
if(!cmakefileStream) if(!cmakefileStream)
@ -169,6 +189,7 @@ void cmLocalUnixMakefileGenerator2::GenerateCMakefile()
<< "# The corresponding makefile is:\n" << "# The corresponding makefile is:\n"
<< "SET(CMAKE_MAKEFILE_OUTPUTS\n" << "SET(CMAKE_MAKEFILE_OUTPUTS\n"
<< " \"" << makefileName.c_str() << "\"\n" << " \"" << makefileName.c_str() << "\"\n"
<< " \"" << m_Makefile->GetHomeOutputDirectory() << "/cmake.check_cache\"\n"
<< " )\n\n"; << " )\n\n";
// Set the set of files to check for dependency integrity. // Set the set of files to check for dependency integrity.
@ -816,7 +837,7 @@ cmLocalUnixMakefileGenerator2
// Build command to run CMake to check if anything needs regenerating. // Build command to run CMake to check if anything needs regenerating.
std::string cmakefileName = m_Makefile->GetStartOutputDirectory(); std::string cmakefileName = m_Makefile->GetStartOutputDirectory();
cmakefileName += "/Makefile2.cmake"; cmakefileName += "/" CMLUMG_MAKEFILE_NAME ".cmake";
std::string runRule = std::string runRule =
"@$(CMAKE_COMMAND) -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)"; "@$(CMAKE_COMMAND) -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)";
runRule += " --check-build-system "; runRule += " --check-build-system ";
@ -1204,6 +1225,8 @@ cmLocalUnixMakefileGenerator2
::WriteRequiresRule(std::ostream& ruleFileStream, const cmTarget& target, ::WriteRequiresRule(std::ostream& ruleFileStream, const cmTarget& target,
const char* targetFullPath) const char* targetFullPath)
{ {
// TODO: Avoid using requires target except when needed for
// Fortran/Java dependencies.
std::vector<std::string> depends; std::vector<std::string> depends;
std::vector<std::string> no_commands; std::vector<std::string> no_commands;
std::string reqComment = "Requirements for target "; std::string reqComment = "Requirements for target ";
@ -1215,6 +1238,49 @@ cmLocalUnixMakefileGenerator2
reqTarget.c_str(), depends, no_commands); reqTarget.c_str(), depends, no_commands);
} }
//----------------------------------------------------------------------------
void
cmLocalUnixMakefileGenerator2
::WriteConvenienceRules(std::ostream& ruleFileStream, const cmTarget& target,
const char* targetFullPath)
{
// Add a rule to build the target by name.
std::string localName = this->GetFullTargetName(target.GetName(), target);
localName = this->ConvertToRelativeOutputPath(localName.c_str());
this->WriteConvenienceRule(ruleFileStream, targetFullPath,
localName.c_str());
// Add a target with the canonical name (no prefix, suffix or path).
if(localName != target.GetName())
{
this->WriteConvenienceRule(ruleFileStream, targetFullPath,
target.GetName());
}
}
//----------------------------------------------------------------------------
void
cmLocalUnixMakefileGenerator2
::WriteConvenienceRule(std::ostream& ruleFileStream,
const char* realTarget,
const char* helpTarget)
{
// A rule is only needed if the names are different.
if(strcmp(realTarget, helpTarget) != 0)
{
// The helper target depends on the real target.
std::vector<std::string> depends;
depends.push_back(realTarget);
// There are no commands.
std::vector<std::string> no_commands;
// Write the rule.
this->WriteMakeRule(ruleFileStream, "Convenience name for target.", 0,
helpTarget, depends, no_commands);
}
}
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
void void
cmLocalUnixMakefileGenerator2 cmLocalUnixMakefileGenerator2
@ -1269,14 +1335,12 @@ cmLocalUnixMakefileGenerator2
depends.push_back(ruleFileName); depends.push_back(ruleFileName);
// Construct the full path to the executable that will be generated. // Construct the full path to the executable that will be generated.
// TODO: Try to convert this to use a relative path.
std::string targetFullPath = m_ExecutableOutputPath; std::string targetFullPath = m_ExecutableOutputPath;
if(targetFullPath.length() == 0) if(targetFullPath.length() == 0)
{ {
targetFullPath = m_Makefile->GetStartOutputDirectory(); targetFullPath = m_Makefile->GetStartOutputDirectory();
if(targetFullPath.size() && targetFullPath[targetFullPath.size()-1] != '/') targetFullPath += "/";
{
targetFullPath += "/";
}
} }
#ifdef __APPLE__ #ifdef __APPLE__
if(target.GetPropertyAsBool("MACOSX_BUNDLE")) if(target.GetPropertyAsBool("MACOSX_BUNDLE"))
@ -1381,7 +1445,9 @@ cmLocalUnixMakefileGenerator2
buildEcho += "..."; buildEcho += "...";
this->WriteMakeRule(ruleFileStream, 0, buildEcho.c_str(), this->WriteMakeRule(ruleFileStream, 0, buildEcho.c_str(),
targetFullPath.c_str(), depends, commands); targetFullPath.c_str(), depends, commands);
// TODO: Add "local" target and canonical target name as rules.
// Write convenience targets.
this->WriteConvenienceRules(ruleFileStream, target, targetFullPath.c_str());
// Write driver rule for this target. // Write driver rule for this target.
this->WriteRequiresRule(ruleFileStream, target, targetFullPath.c_str()); this->WriteRequiresRule(ruleFileStream, target, targetFullPath.c_str());
@ -1634,7 +1700,8 @@ cmLocalUnixMakefileGenerator2
this->WriteMakeRule(ruleFileStream, 0, buildEcho.c_str(), this->WriteMakeRule(ruleFileStream, 0, buildEcho.c_str(),
targetFullPath.c_str(), depends, commands); targetFullPath.c_str(), depends, commands);
// TODO: Add "local" target and canonical target name as rules. // Write convenience targets.
this->WriteConvenienceRules(ruleFileStream, target, targetFullPath.c_str());
// Write driver rule for this target. // Write driver rule for this target.
this->WriteRequiresRule(ruleFileStream, target, targetFullPath.c_str()); this->WriteRequiresRule(ruleFileStream, target, targetFullPath.c_str());
@ -1966,7 +2033,7 @@ cmLocalUnixMakefileGenerator2
{ {
cmd += "@"; cmd += "@";
} }
cmd += "$(MAKE) -f Makefile2 "; cmd += "$(MAKE) -f " CMLUMG_MAKEFILE_NAME " ";
// Pass down verbosity level. // Pass down verbosity level.
if(m_MakeSilentFlag.size()) if(m_MakeSilentFlag.size())

View File

@ -89,6 +89,12 @@ protected:
const char* order, const std::string& last); const char* order, const std::string& last);
void WriteRequiresRule(std::ostream& ruleFileStream, const cmTarget& target, void WriteRequiresRule(std::ostream& ruleFileStream, const cmTarget& target,
const char* targetFullPath); const char* targetFullPath);
void WriteConvenienceRules(std::ostream& ruleFileStream,
const cmTarget& target,
const char* targetFullPath);
void WriteConvenienceRule(std::ostream& ruleFileStream,
const char* realTarget,
const char* helpTarget);
void WriteExecutableRule(std::ostream& ruleFileStream, void WriteExecutableRule(std::ostream& ruleFileStream,
const char* ruleFileName, const char* ruleFileName,
const cmTarget& target, const cmTarget& target,