2006-02-14 18:36:04 +03:00
|
|
|
/*=========================================================================
|
|
|
|
|
|
|
|
Program: CMake - Cross-Platform Makefile Generator
|
|
|
|
Module: $RCSfile$
|
|
|
|
Language: C++
|
|
|
|
Date: $Date$
|
|
|
|
Version: $Revision$
|
|
|
|
|
|
|
|
Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
|
|
|
|
See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
|
|
|
|
|
|
|
|
This software is distributed WITHOUT ANY WARRANTY; without even
|
|
|
|
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
|
|
PURPOSE. See the above copyright notices for more information.
|
|
|
|
|
|
|
|
=========================================================================*/
|
|
|
|
#include "cmMakefileTargetGenerator.h"
|
|
|
|
|
|
|
|
#include "cmGeneratedFileStream.h"
|
|
|
|
#include "cmGlobalGenerator.h"
|
2006-04-11 19:06:19 +04:00
|
|
|
#include "cmGlobalUnixMakefileGenerator3.h"
|
2006-02-14 18:36:04 +03:00
|
|
|
#include "cmLocalUnixMakefileGenerator3.h"
|
|
|
|
#include "cmMakefile.h"
|
|
|
|
#include "cmSourceFile.h"
|
|
|
|
#include "cmTarget.h"
|
2006-06-14 20:28:32 +04:00
|
|
|
#include "cmake.h"
|
2006-02-14 18:36:04 +03:00
|
|
|
|
|
|
|
#include "cmMakefileExecutableTargetGenerator.h"
|
|
|
|
#include "cmMakefileLibraryTargetGenerator.h"
|
|
|
|
#include "cmMakefileUtilityTargetGenerator.h"
|
|
|
|
|
|
|
|
|
|
|
|
cmMakefileTargetGenerator::cmMakefileTargetGenerator()
|
|
|
|
{
|
|
|
|
this->BuildFileStream = 0;
|
|
|
|
this->InfoFileStream = 0;
|
2006-02-16 00:35:16 +03:00
|
|
|
this->FlagFileStream = 0;
|
2007-05-01 21:51:25 +04:00
|
|
|
this->CustomCommandDriver = OnBuild;
|
2007-12-31 00:11:38 +03:00
|
|
|
this->FortranModuleDirectoryComputed = false;
|
2006-02-14 18:36:04 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
cmMakefileTargetGenerator *
|
|
|
|
cmMakefileTargetGenerator::New(cmLocalUnixMakefileGenerator3 *lg,
|
|
|
|
cmStdString tgtName, cmTarget *tgt)
|
|
|
|
{
|
|
|
|
cmMakefileTargetGenerator *result = 0;
|
|
|
|
|
|
|
|
switch (tgt->GetType())
|
|
|
|
{
|
|
|
|
case cmTarget::EXECUTABLE:
|
|
|
|
result = new cmMakefileExecutableTargetGenerator;
|
|
|
|
break;
|
|
|
|
case cmTarget::STATIC_LIBRARY:
|
|
|
|
case cmTarget::SHARED_LIBRARY:
|
|
|
|
case cmTarget::MODULE_LIBRARY:
|
|
|
|
result = new cmMakefileLibraryTargetGenerator;
|
|
|
|
break;
|
|
|
|
case cmTarget::UTILITY:
|
|
|
|
result = new cmMakefileUtilityTargetGenerator;
|
|
|
|
break;
|
|
|
|
default:
|
2006-02-16 21:42:58 +03:00
|
|
|
return result;
|
2006-08-01 19:38:42 +04:00
|
|
|
// break; /* unreachable */
|
2006-02-14 18:36:04 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
result->TargetName = tgtName;
|
|
|
|
result->Target = tgt;
|
|
|
|
result->LocalGenerator = lg;
|
2006-12-14 22:30:41 +03:00
|
|
|
result->GlobalGenerator =
|
|
|
|
static_cast<cmGlobalUnixMakefileGenerator3*>(lg->GetGlobalGenerator());
|
2006-02-14 18:36:04 +03:00
|
|
|
result->Makefile = lg->GetMakefile();
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
void cmMakefileTargetGenerator::CreateRuleFile()
|
|
|
|
{
|
|
|
|
// Create a directory for this target.
|
2006-07-10 15:52:35 +04:00
|
|
|
this->TargetBuildDirectory =
|
2006-02-14 18:36:04 +03:00
|
|
|
this->LocalGenerator->GetTargetDirectory(*this->Target);
|
2006-07-10 15:52:35 +04:00
|
|
|
this->TargetBuildDirectoryFull =
|
2006-02-14 18:36:04 +03:00
|
|
|
this->LocalGenerator->ConvertToFullPath(this->TargetBuildDirectory);
|
|
|
|
cmSystemTools::MakeDirectory(this->TargetBuildDirectoryFull.c_str());
|
2006-07-10 15:52:35 +04:00
|
|
|
|
2006-02-14 18:36:04 +03:00
|
|
|
// Construct the rule file name.
|
|
|
|
this->BuildFileName = this->TargetBuildDirectory;
|
|
|
|
this->BuildFileName += "/build.make";
|
|
|
|
this->BuildFileNameFull = this->TargetBuildDirectoryFull;
|
|
|
|
this->BuildFileNameFull += "/build.make";
|
2006-07-10 15:52:35 +04:00
|
|
|
|
2006-07-11 17:55:27 +04:00
|
|
|
// Construct the rule file name.
|
|
|
|
this->ProgressFileName = this->TargetBuildDirectory;
|
|
|
|
this->ProgressFileName += "/progress.make";
|
|
|
|
this->ProgressFileNameFull = this->TargetBuildDirectoryFull;
|
|
|
|
this->ProgressFileNameFull += "/progress.make";
|
|
|
|
|
|
|
|
// reset the progress count
|
|
|
|
this->NumberOfProgressActions = 0;
|
|
|
|
|
2006-02-14 18:36:04 +03:00
|
|
|
// Open the rule file. This should be copy-if-different because the
|
|
|
|
// rules may depend on this file itself.
|
2006-07-10 15:52:35 +04:00
|
|
|
this->BuildFileStream =
|
2006-02-14 18:36:04 +03:00
|
|
|
new cmGeneratedFileStream(this->BuildFileNameFull.c_str());
|
|
|
|
this->BuildFileStream->SetCopyIfDifferent(true);
|
|
|
|
if(!this->BuildFileStream)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this->LocalGenerator->WriteDisclaimer(*this->BuildFileStream);
|
|
|
|
this->LocalGenerator->WriteSpecialTargetsTop(*this->BuildFileStream);
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
2006-06-01 19:45:51 +04:00
|
|
|
void cmMakefileTargetGenerator::WriteTargetBuildRules()
|
2006-02-14 18:36:04 +03:00
|
|
|
{
|
|
|
|
// write the custom commands for this target
|
|
|
|
// Look for files registered for cleaning in this directory.
|
|
|
|
if(const char* additional_clean_files =
|
|
|
|
this->Makefile->GetProperty
|
|
|
|
("ADDITIONAL_MAKE_CLEAN_FILES"))
|
|
|
|
{
|
2006-07-10 15:52:35 +04:00
|
|
|
cmSystemTools::ExpandListArgument(additional_clean_files,
|
2006-02-14 18:36:04 +03:00
|
|
|
this->CleanFiles);
|
2006-07-10 15:52:35 +04:00
|
|
|
}
|
2006-06-01 19:45:51 +04:00
|
|
|
|
|
|
|
// add custom commands to the clean rules?
|
2006-07-10 15:52:35 +04:00
|
|
|
const char* clean_no_custom =
|
2006-06-01 19:45:51 +04:00
|
|
|
this->Makefile->GetProperty("CLEAN_NO_CUSTOM");
|
|
|
|
bool clean = cmSystemTools::IsOff(clean_no_custom);
|
2006-07-10 15:52:35 +04:00
|
|
|
|
2006-06-01 19:45:51 +04:00
|
|
|
// First generate the object rule files. Save a list of all object
|
|
|
|
// files for this target.
|
|
|
|
const std::vector<cmSourceFile*>& sources = this->Target->GetSourceFiles();
|
|
|
|
for(std::vector<cmSourceFile*>::const_iterator source = sources.begin();
|
|
|
|
source != sources.end(); ++source)
|
|
|
|
{
|
|
|
|
if(cmCustomCommand* cc = (*source)->GetCustomCommand())
|
|
|
|
{
|
|
|
|
this->GenerateCustomRuleFile(*cc);
|
|
|
|
if (clean)
|
|
|
|
{
|
|
|
|
const std::vector<std::string>& outputs = cc->GetOutputs();
|
|
|
|
for(std::vector<std::string>::const_iterator o = outputs.begin();
|
|
|
|
o != outputs.end(); ++o)
|
|
|
|
{
|
|
|
|
this->CleanFiles.push_back
|
|
|
|
(this->Convert(o->c_str(),
|
|
|
|
cmLocalGenerator::START_OUTPUT,
|
|
|
|
cmLocalGenerator::UNCHANGED));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(!(*source)->GetPropertyAsBool("HEADER_FILE_ONLY"))
|
|
|
|
{
|
|
|
|
if(!this->GlobalGenerator->IgnoreFile
|
2007-06-18 19:59:23 +04:00
|
|
|
((*source)->GetExtension().c_str()))
|
2006-06-01 19:45:51 +04:00
|
|
|
{
|
|
|
|
// Generate this object file's rule file.
|
|
|
|
this->WriteObjectRuleFiles(*(*source));
|
|
|
|
}
|
|
|
|
else if((*source)->GetPropertyAsBool("EXTERNAL_OBJECT"))
|
|
|
|
{
|
|
|
|
// This is an external object file. Just add it.
|
|
|
|
this->ExternalObjects.push_back((*source)->GetFullPath());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// We only get here if a source file is not an external object
|
|
|
|
// and has an extension that is listed as an ignored file type
|
|
|
|
// for this language. No message or diagnosis should be
|
|
|
|
// given.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2006-02-14 18:36:04 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
void cmMakefileTargetGenerator::WriteCommonCodeRules()
|
|
|
|
{
|
|
|
|
// Include the dependencies for the target.
|
|
|
|
std::string dependFileNameFull = this->TargetBuildDirectoryFull;
|
|
|
|
dependFileNameFull += "/depend.make";
|
|
|
|
*this->BuildFileStream
|
|
|
|
<< "# Include any dependencies generated for this target.\n"
|
2006-03-15 19:02:08 +03:00
|
|
|
<< this->LocalGenerator->IncludeDirective << " "
|
2006-02-14 18:36:04 +03:00
|
|
|
<< this->Convert(dependFileNameFull.c_str(),
|
2006-07-11 17:55:27 +04:00
|
|
|
cmLocalGenerator::HOME_OUTPUT,
|
|
|
|
cmLocalGenerator::MAKEFILE)
|
|
|
|
<< "\n\n";
|
|
|
|
|
|
|
|
// Include the progress variables for the target.
|
|
|
|
*this->BuildFileStream
|
|
|
|
<< "# Include the progress variables for this target.\n"
|
|
|
|
<< this->LocalGenerator->IncludeDirective << " "
|
|
|
|
<< this->Convert(this->ProgressFileNameFull.c_str(),
|
|
|
|
cmLocalGenerator::HOME_OUTPUT,
|
|
|
|
cmLocalGenerator::MAKEFILE)
|
2006-02-14 18:36:04 +03:00
|
|
|
<< "\n\n";
|
2006-07-10 15:52:35 +04:00
|
|
|
|
2006-02-14 18:36:04 +03:00
|
|
|
// make sure the depend file exists
|
|
|
|
if (!cmSystemTools::FileExists(dependFileNameFull.c_str()))
|
|
|
|
{
|
|
|
|
// Write an empty dependency file.
|
|
|
|
cmGeneratedFileStream depFileStream(dependFileNameFull.c_str());
|
|
|
|
depFileStream
|
|
|
|
<< "# Empty dependencies file for " << this->Target->GetName() << ".\n"
|
|
|
|
<< "# This may be replaced when dependencies are built." << std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Open the flags file. This should be copy-if-different because the
|
|
|
|
// rules may depend on this file itself.
|
|
|
|
this->FlagFileNameFull = this->TargetBuildDirectoryFull;
|
|
|
|
this->FlagFileNameFull += "/flags.make";
|
2006-07-10 15:52:35 +04:00
|
|
|
this->FlagFileStream =
|
2006-02-14 18:36:04 +03:00
|
|
|
new cmGeneratedFileStream(this->FlagFileNameFull.c_str());
|
|
|
|
this->FlagFileStream->SetCopyIfDifferent(true);
|
|
|
|
if(!this->FlagFileStream)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this->LocalGenerator->WriteDisclaimer(*this->FlagFileStream);
|
2006-07-10 15:52:35 +04:00
|
|
|
|
2006-02-14 18:36:04 +03:00
|
|
|
// Include the flags for the target.
|
|
|
|
*this->BuildFileStream
|
|
|
|
<< "# Include the compile flags for this target's objects.\n"
|
2006-03-15 19:02:08 +03:00
|
|
|
<< this->LocalGenerator->IncludeDirective << " "
|
2006-07-10 15:52:35 +04:00
|
|
|
<< this->Convert(this->FlagFileNameFull.c_str(),
|
|
|
|
cmLocalGenerator::HOME_OUTPUT,
|
2006-02-14 18:36:04 +03:00
|
|
|
cmLocalGenerator::MAKEFILE)
|
|
|
|
<< "\n\n";
|
2006-06-01 19:45:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
void cmMakefileTargetGenerator::WriteTargetLanguageFlags()
|
|
|
|
{
|
2006-02-14 18:36:04 +03:00
|
|
|
// write language flags for target
|
2007-08-02 21:38:39 +04:00
|
|
|
std::set<cmStdString> languages;
|
|
|
|
this->Target->GetLanguages(languages);
|
2007-12-13 23:54:29 +03:00
|
|
|
// put the compiler in the rules.make file so that if it changes
|
|
|
|
// things rebuild
|
|
|
|
for(std::set<cmStdString>::const_iterator l = languages.begin();
|
|
|
|
l != languages.end(); ++l)
|
|
|
|
{
|
|
|
|
cmStdString compiler = "CMAKE_";
|
|
|
|
compiler += *l;
|
|
|
|
compiler += "_COMPILER";
|
|
|
|
*this->FlagFileStream << "# compile " << l->c_str() << " with " <<
|
|
|
|
this->Makefile->GetSafeDefinition(compiler.c_str()) << "\n";
|
|
|
|
}
|
|
|
|
|
2007-08-02 21:38:39 +04:00
|
|
|
for(std::set<cmStdString>::const_iterator l = languages.begin();
|
|
|
|
l != languages.end(); ++l)
|
2006-02-14 18:36:04 +03:00
|
|
|
{
|
2007-08-02 21:38:39 +04:00
|
|
|
const char *lang = l->c_str();
|
2006-02-14 18:36:04 +03:00
|
|
|
std::string flags;
|
2008-01-14 17:20:58 +03:00
|
|
|
std::string defines;
|
2006-02-14 18:36:04 +03:00
|
|
|
bool shared = ((this->Target->GetType() == cmTarget::SHARED_LIBRARY) ||
|
|
|
|
(this->Target->GetType() == cmTarget::MODULE_LIBRARY));
|
2007-03-28 07:13:25 +04:00
|
|
|
|
|
|
|
// Add the export symbol definition for shared library objects.
|
|
|
|
if(const char* exportMacro = this->Target->GetExportMacro())
|
2006-02-14 18:36:04 +03:00
|
|
|
{
|
|
|
|
flags += "-D";
|
2007-03-28 07:13:25 +04:00
|
|
|
flags += exportMacro;
|
2006-02-14 18:36:04 +03:00
|
|
|
}
|
2006-07-10 15:52:35 +04:00
|
|
|
|
2008-01-14 17:20:58 +03:00
|
|
|
// Add preprocessor definitions for this target and configuration.
|
|
|
|
this->LocalGenerator->AppendDefines
|
|
|
|
(defines, this->Target->GetProperty("COMPILE_DEFINITIONS"));
|
2008-01-16 05:02:00 +03:00
|
|
|
std::string defPropName = "COMPILE_DEFINITIONS_";
|
|
|
|
defPropName +=
|
2008-01-14 17:20:58 +03:00
|
|
|
cmSystemTools::UpperCase(this->LocalGenerator->ConfigurationName);
|
|
|
|
this->LocalGenerator->AppendDefines
|
|
|
|
(defines, this->Target->GetProperty(defPropName.c_str()));
|
|
|
|
|
2006-02-14 18:36:04 +03:00
|
|
|
// Add language-specific flags.
|
2006-02-24 19:13:31 +03:00
|
|
|
this->LocalGenerator
|
|
|
|
->AddLanguageFlags(flags, lang,
|
2006-03-15 19:02:08 +03:00
|
|
|
this->LocalGenerator->ConfigurationName.c_str());
|
2006-07-10 15:52:35 +04:00
|
|
|
|
2007-12-31 00:11:38 +03:00
|
|
|
// Fortran-specific flags computed for this target.
|
|
|
|
if(*l == "Fortran")
|
|
|
|
{
|
|
|
|
this->AddFortranFlags(flags);
|
|
|
|
}
|
|
|
|
|
2006-02-14 18:36:04 +03:00
|
|
|
// Add shared-library flags if needed.
|
|
|
|
this->LocalGenerator->AddSharedFlags(flags, lang, shared);
|
2006-07-10 15:52:35 +04:00
|
|
|
|
2006-02-14 18:36:04 +03:00
|
|
|
// Add include directory flags.
|
|
|
|
this->LocalGenerator->
|
|
|
|
AppendFlags(flags, this->LocalGenerator->GetIncludeFlags(lang));
|
|
|
|
// Add include directory flags.
|
|
|
|
this->LocalGenerator->
|
|
|
|
AppendFlags(flags,this->GetFrameworkFlags().c_str());
|
|
|
|
|
|
|
|
*this->FlagFileStream << lang << "_FLAGS = " << flags << "\n\n";
|
2008-01-14 17:20:58 +03:00
|
|
|
*this->FlagFileStream << lang << "_DEFINES = " << defines << "\n\n";
|
2006-02-14 18:36:04 +03:00
|
|
|
}
|
2007-02-01 19:33:30 +03:00
|
|
|
|
|
|
|
// Add target-specific flags.
|
|
|
|
if(this->Target->GetProperty("COMPILE_FLAGS"))
|
|
|
|
{
|
|
|
|
std::string flags;
|
|
|
|
this->LocalGenerator->AppendFlags
|
|
|
|
(flags, this->Target->GetProperty("COMPILE_FLAGS"));
|
|
|
|
*this->FlagFileStream << "# TARGET_FLAGS = " << flags << "\n\n";
|
|
|
|
}
|
2006-02-14 18:36:04 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
void cmMakefileTargetGenerator::WriteObjectRuleFiles(cmSourceFile& source)
|
|
|
|
{
|
|
|
|
// Identify the language of the source file.
|
|
|
|
const char* lang = this->LocalGenerator->GetSourceFileLanguage(source);
|
|
|
|
if(!lang)
|
|
|
|
{
|
2006-04-21 05:54:35 +04:00
|
|
|
// don't know anything about this file so skip it
|
2006-02-14 18:36:04 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the full path name of the object file.
|
2008-01-08 00:12:37 +03:00
|
|
|
bool hasSourceExtension;
|
2006-02-14 18:36:04 +03:00
|
|
|
std::string objNoTargetDir;
|
2006-07-10 15:52:35 +04:00
|
|
|
std::string obj =
|
|
|
|
this->LocalGenerator->GetObjectFileName(*this->Target, source,
|
2008-01-08 00:12:37 +03:00
|
|
|
&objNoTargetDir,
|
|
|
|
&hasSourceExtension);
|
2006-02-14 18:36:04 +03:00
|
|
|
|
|
|
|
// Avoid generating duplicate rules.
|
2006-03-15 19:02:08 +03:00
|
|
|
if(this->ObjectFiles.find(obj) == this->ObjectFiles.end())
|
2006-02-14 18:36:04 +03:00
|
|
|
{
|
2006-03-15 19:02:08 +03:00
|
|
|
this->ObjectFiles.insert(obj);
|
2006-02-14 18:36:04 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cmOStringStream err;
|
|
|
|
err << "Warning: Source file \""
|
2007-06-18 19:59:23 +04:00
|
|
|
<< source.GetFullPath()
|
2006-07-10 15:52:35 +04:00
|
|
|
<< "\" is listed multiple times for target \""
|
2006-02-14 18:36:04 +03:00
|
|
|
<< this->Target->GetName()
|
|
|
|
<< "\".";
|
|
|
|
cmSystemTools::Message(err.str().c_str(), "Warning");
|
|
|
|
return;
|
|
|
|
}
|
2006-07-10 15:52:35 +04:00
|
|
|
|
2006-02-14 18:36:04 +03:00
|
|
|
// Create the directory containing the object file. This may be a
|
|
|
|
// subdirectory under the target's directory.
|
|
|
|
std::string dir = cmSystemTools::GetFilenamePath(obj.c_str());
|
|
|
|
cmSystemTools::MakeDirectory
|
|
|
|
(this->LocalGenerator->ConvertToFullPath(dir).c_str());
|
2006-07-10 15:52:35 +04:00
|
|
|
|
2006-02-14 18:36:04 +03:00
|
|
|
// Save this in the target's list of object files.
|
2006-03-28 17:54:01 +04:00
|
|
|
if ( source.GetPropertyAsBool("EXTRA_CONTENT") )
|
|
|
|
{
|
|
|
|
this->ExtraContent.insert(obj);
|
|
|
|
}
|
2006-02-14 18:36:04 +03:00
|
|
|
this->Objects.push_back(obj);
|
2007-08-02 17:37:10 +04:00
|
|
|
this->CleanFiles.push_back(obj);
|
2006-07-07 00:04:49 +04:00
|
|
|
|
|
|
|
// TODO: Remove
|
2006-07-10 15:52:35 +04:00
|
|
|
//std::string relativeObj
|
|
|
|
//= this->LocalGenerator->GetHomeRelativeOutputPath();
|
2006-07-07 00:04:49 +04:00
|
|
|
//relativeObj += obj;
|
|
|
|
|
2006-02-14 18:36:04 +03:00
|
|
|
// we compute some depends when writing the depend.make that we will also
|
|
|
|
// use in the build.make, same with depMakeFile
|
|
|
|
std::vector<std::string> depends;
|
|
|
|
std::string depMakeFile;
|
2006-07-10 15:52:35 +04:00
|
|
|
|
2006-02-14 18:36:04 +03:00
|
|
|
// generate the build rule file
|
|
|
|
this->WriteObjectBuildFile(obj, lang, source, depends);
|
2006-07-10 15:52:35 +04:00
|
|
|
|
2006-02-14 18:36:04 +03:00
|
|
|
// The object file should be checked for dependency integrity.
|
2007-08-07 21:57:13 +04:00
|
|
|
std::string objFullPath = this->Makefile->GetCurrentOutputDirectory();
|
|
|
|
objFullPath += "/";
|
|
|
|
objFullPath += obj;
|
|
|
|
objFullPath =
|
|
|
|
this->Convert(objFullPath.c_str(), cmLocalGenerator::FULL);
|
|
|
|
std::string srcFullPath =
|
|
|
|
this->Convert(source.GetFullPath().c_str(), cmLocalGenerator::FULL);
|
2006-05-12 20:29:09 +04:00
|
|
|
this->LocalGenerator->
|
2007-08-07 21:57:13 +04:00
|
|
|
AddImplicitDepends(*this->Target, lang,
|
|
|
|
objFullPath.c_str(),
|
|
|
|
srcFullPath.c_str());
|
|
|
|
|
2006-02-14 18:36:04 +03:00
|
|
|
// add this to the list of objects for this local generator
|
|
|
|
if(cmSystemTools::FileIsFullPath(objNoTargetDir.c_str()))
|
|
|
|
{
|
|
|
|
objNoTargetDir = cmSystemTools::GetFilenameName(objNoTargetDir);
|
|
|
|
}
|
2008-01-08 00:12:37 +03:00
|
|
|
cmLocalUnixMakefileGenerator3::LocalObjectInfo& info =
|
|
|
|
this->LocalGenerator->LocalObjectFiles[objNoTargetDir];
|
|
|
|
info.HasSourceExtension = hasSourceExtension;
|
|
|
|
info.push_back(
|
|
|
|
cmLocalUnixMakefileGenerator3::LocalObjectEntry(this->Target, lang)
|
|
|
|
);
|
2006-02-14 18:36:04 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
void
|
|
|
|
cmMakefileTargetGenerator
|
|
|
|
::WriteObjectBuildFile(std::string &obj,
|
2006-07-10 15:52:35 +04:00
|
|
|
const char *lang,
|
2006-02-14 18:36:04 +03:00
|
|
|
cmSourceFile& source,
|
|
|
|
std::vector<std::string>& depends)
|
|
|
|
{
|
2006-07-10 15:52:35 +04:00
|
|
|
this->LocalGenerator->AppendRuleDepend(depends,
|
2006-05-12 20:29:09 +04:00
|
|
|
this->FlagFileNameFull.c_str());
|
2006-02-14 18:36:04 +03:00
|
|
|
|
|
|
|
// generate the depend scanning rule
|
|
|
|
this->WriteObjectDependRules(source, depends);
|
|
|
|
|
|
|
|
std::string relativeObj = this->LocalGenerator->GetHomeRelativeOutputPath();
|
2006-07-07 00:04:49 +04:00
|
|
|
if ( source.GetPropertyAsBool("MACOSX_CONTENT") )
|
|
|
|
{
|
|
|
|
relativeObj = "";
|
|
|
|
}
|
2006-02-14 18:36:04 +03:00
|
|
|
relativeObj += obj;
|
|
|
|
// Write the build rule.
|
2006-02-20 20:48:56 +03:00
|
|
|
|
2006-02-14 18:36:04 +03:00
|
|
|
// Build the set of compiler flags.
|
|
|
|
std::string flags;
|
2006-02-20 20:48:56 +03:00
|
|
|
|
|
|
|
// Add language-specific flags.
|
|
|
|
std::string langFlags = "$(";
|
|
|
|
langFlags += lang;
|
|
|
|
langFlags += "_FLAGS)";
|
|
|
|
this->LocalGenerator->AppendFlags(flags, langFlags.c_str());
|
|
|
|
|
|
|
|
// Add target-specific flags.
|
2006-02-14 18:36:04 +03:00
|
|
|
if(this->Target->GetProperty("COMPILE_FLAGS"))
|
|
|
|
{
|
2006-05-12 20:29:09 +04:00
|
|
|
this->LocalGenerator->AppendFlags
|
|
|
|
(flags, this->Target->GetProperty("COMPILE_FLAGS"));
|
2006-02-14 18:36:04 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Add flags from source file properties.
|
|
|
|
if (source.GetProperty("COMPILE_FLAGS"))
|
|
|
|
{
|
2006-05-12 20:29:09 +04:00
|
|
|
this->LocalGenerator->AppendFlags
|
|
|
|
(flags, source.GetProperty("COMPILE_FLAGS"));
|
2006-02-14 18:36:04 +03:00
|
|
|
*this->FlagFileStream << "# Custom flags: "
|
|
|
|
<< relativeObj << "_FLAGS = "
|
|
|
|
<< source.GetProperty("COMPILE_FLAGS")
|
|
|
|
<< "\n"
|
|
|
|
<< "\n";
|
|
|
|
}
|
2006-07-10 15:52:35 +04:00
|
|
|
|
2008-01-14 17:20:58 +03:00
|
|
|
// Add language-specific defines.
|
|
|
|
std::string defines = "$(";
|
|
|
|
defines += lang;
|
|
|
|
defines += "_DEFINES)";
|
|
|
|
|
|
|
|
// Add source-sepcific preprocessor definitions.
|
|
|
|
if(const char* compile_defs = source.GetProperty("COMPILE_DEFINITIONS"))
|
|
|
|
{
|
|
|
|
this->LocalGenerator->AppendDefines(defines, compile_defs);
|
|
|
|
*this->FlagFileStream << "# Custom defines: "
|
|
|
|
<< relativeObj << "_DEFINES = "
|
|
|
|
<< compile_defs << "\n"
|
|
|
|
<< "\n";
|
|
|
|
}
|
|
|
|
std::string configUpper =
|
|
|
|
cmSystemTools::UpperCase(this->LocalGenerator->ConfigurationName);
|
2008-01-16 05:02:00 +03:00
|
|
|
std::string defPropName = "COMPILE_DEFINITIONS_";
|
|
|
|
defPropName += configUpper;
|
2008-01-14 17:20:58 +03:00
|
|
|
if(const char* config_compile_defs =
|
|
|
|
source.GetProperty(defPropName.c_str()))
|
|
|
|
{
|
|
|
|
this->LocalGenerator->AppendDefines(defines, config_compile_defs);
|
|
|
|
*this->FlagFileStream
|
|
|
|
<< "# Custom defines: "
|
|
|
|
<< relativeObj << "_DEFINES_" << configUpper
|
|
|
|
<< " = " << config_compile_defs << "\n"
|
|
|
|
<< "\n";
|
|
|
|
}
|
|
|
|
|
2006-02-14 18:36:04 +03:00
|
|
|
// Get the output paths for source and object files.
|
|
|
|
std::string sourceFile = source.GetFullPath();
|
2006-03-15 19:02:08 +03:00
|
|
|
if(this->LocalGenerator->UseRelativePaths)
|
2006-02-14 18:36:04 +03:00
|
|
|
{
|
|
|
|
sourceFile = this->Convert(sourceFile.c_str(),
|
2006-05-12 20:29:09 +04:00
|
|
|
cmLocalGenerator::HOME_OUTPUT);
|
2006-02-14 18:36:04 +03:00
|
|
|
}
|
|
|
|
sourceFile = this->Convert(sourceFile.c_str(),
|
2006-05-12 20:29:09 +04:00
|
|
|
cmLocalGenerator::NONE,
|
|
|
|
cmLocalGenerator::SHELL);
|
|
|
|
std::string objectFile = this->Convert(obj.c_str(),
|
|
|
|
cmLocalGenerator::START_OUTPUT,
|
|
|
|
cmLocalGenerator::SHELL);
|
2006-07-10 15:52:35 +04:00
|
|
|
|
2006-02-14 18:36:04 +03:00
|
|
|
// Construct the build message.
|
|
|
|
std::vector<std::string> no_commands;
|
|
|
|
std::vector<std::string> commands;
|
2006-07-10 15:52:35 +04:00
|
|
|
|
2006-05-23 17:11:46 +04:00
|
|
|
// add in a progress call if needed
|
2006-06-12 19:40:31 +04:00
|
|
|
std::string progressDir = this->Makefile->GetHomeOutputDirectory();
|
2006-06-14 20:28:32 +04:00
|
|
|
progressDir += cmake::GetCMakeFilesDirectory();
|
2006-06-12 19:40:31 +04:00
|
|
|
cmOStringStream progCmd;
|
|
|
|
progCmd << "$(CMAKE_COMMAND) -E cmake_progress_report ";
|
|
|
|
progCmd << this->LocalGenerator->Convert(progressDir.c_str(),
|
|
|
|
cmLocalGenerator::FULL,
|
|
|
|
cmLocalGenerator::SHELL);
|
2006-07-11 17:55:27 +04:00
|
|
|
this->NumberOfProgressActions++;
|
|
|
|
progCmd << " $(CMAKE_PROGRESS_"
|
|
|
|
<< this->NumberOfProgressActions
|
|
|
|
<< ")";
|
2006-06-12 19:40:31 +04:00
|
|
|
commands.push_back(progCmd.str());
|
2006-07-10 15:52:35 +04:00
|
|
|
|
2006-06-12 20:18:59 +04:00
|
|
|
std::string buildEcho = "Building ";
|
|
|
|
buildEcho += lang;
|
|
|
|
buildEcho += " object ";
|
|
|
|
buildEcho += relativeObj;
|
|
|
|
this->LocalGenerator->AppendEcho(commands, buildEcho.c_str(),
|
|
|
|
cmLocalUnixMakefileGenerator3::EchoBuild);
|
|
|
|
|
2006-02-14 18:36:04 +03:00
|
|
|
// Construct the compile rules.
|
|
|
|
std::string compileRuleVar = "CMAKE_";
|
|
|
|
compileRuleVar += lang;
|
|
|
|
compileRuleVar += "_COMPILE_OBJECT";
|
|
|
|
std::string compileRule =
|
|
|
|
this->Makefile->GetRequiredDefinition(compileRuleVar.c_str());
|
2007-11-21 21:37:14 +03:00
|
|
|
std::vector<std::string> compileCommands;
|
|
|
|
cmSystemTools::ExpandListArgument(compileRule, compileCommands);
|
|
|
|
|
|
|
|
// Change the command working directory to the local build tree.
|
|
|
|
this->LocalGenerator->CreateCDCommand
|
|
|
|
(compileCommands,
|
|
|
|
this->Makefile->GetStartOutputDirectory(),
|
|
|
|
this->Makefile->GetHomeOutputDirectory());
|
2007-11-23 22:53:06 +03:00
|
|
|
commands.insert(commands.end(),
|
|
|
|
compileCommands.begin(), compileCommands.end());
|
2006-04-20 00:36:14 +04:00
|
|
|
|
2007-02-02 00:56:36 +03:00
|
|
|
std::string targetOutPathPDB;
|
|
|
|
{
|
|
|
|
std::string targetFullPathPDB;
|
|
|
|
const char* configName = this->LocalGenerator->ConfigurationName.c_str();
|
2007-03-08 22:57:28 +03:00
|
|
|
if(this->Target->GetType() == cmTarget::EXECUTABLE ||
|
|
|
|
this->Target->GetType() == cmTarget::STATIC_LIBRARY ||
|
|
|
|
this->Target->GetType() == cmTarget::SHARED_LIBRARY ||
|
|
|
|
this->Target->GetType() == cmTarget::MODULE_LIBRARY)
|
2007-02-02 00:56:36 +03:00
|
|
|
{
|
2007-03-08 23:33:19 +03:00
|
|
|
targetFullPathPDB = this->Target->GetDirectory();
|
2007-03-08 22:57:28 +03:00
|
|
|
targetFullPathPDB += "/";
|
2007-02-02 00:56:36 +03:00
|
|
|
targetFullPathPDB += this->Target->GetPDBName(configName);
|
|
|
|
}
|
|
|
|
targetOutPathPDB =
|
|
|
|
this->Convert(targetFullPathPDB.c_str(),cmLocalGenerator::FULL,
|
2007-03-08 18:31:03 +03:00
|
|
|
cmLocalGenerator::SHELL);
|
2007-02-02 00:56:36 +03:00
|
|
|
}
|
2006-02-20 21:42:18 +03:00
|
|
|
cmLocalGenerator::RuleVariables vars;
|
|
|
|
vars.Language = lang;
|
2007-02-02 00:56:36 +03:00
|
|
|
vars.TargetPDB = targetOutPathPDB.c_str();
|
2006-02-20 21:42:18 +03:00
|
|
|
vars.Source = sourceFile.c_str();
|
2007-11-21 21:37:14 +03:00
|
|
|
std::string shellObj =
|
|
|
|
this->Convert(obj.c_str(),
|
|
|
|
cmLocalGenerator::NONE,
|
2007-02-19 22:25:45 +03:00
|
|
|
cmLocalGenerator::SHELL).c_str();
|
2007-11-21 21:37:14 +03:00
|
|
|
vars.Object = shellObj.c_str();
|
2006-04-17 22:01:22 +04:00
|
|
|
std::string objectDir = cmSystemTools::GetFilenamePath(obj);
|
|
|
|
vars.ObjectDir = objectDir.c_str();
|
2006-02-20 21:42:18 +03:00
|
|
|
vars.Flags = flags.c_str();
|
2008-01-14 17:20:58 +03:00
|
|
|
vars.Defines = defines.c_str();
|
2006-07-10 15:52:35 +04:00
|
|
|
|
2006-02-14 18:36:04 +03:00
|
|
|
// Expand placeholders in the commands.
|
|
|
|
for(std::vector<std::string>::iterator i = commands.begin();
|
|
|
|
i != commands.end(); ++i)
|
|
|
|
{
|
2006-02-20 21:42:18 +03:00
|
|
|
this->LocalGenerator->ExpandRuleVariables(*i, vars);
|
2006-02-14 18:36:04 +03:00
|
|
|
}
|
|
|
|
|
2006-07-10 15:52:35 +04:00
|
|
|
|
2006-02-14 18:36:04 +03:00
|
|
|
// Write the rule.
|
|
|
|
this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, 0,
|
2006-02-16 00:35:16 +03:00
|
|
|
relativeObj.c_str(),
|
|
|
|
depends, commands, false);
|
2006-02-14 18:36:04 +03:00
|
|
|
|
2007-09-13 21:37:45 +04:00
|
|
|
// Check for extra outputs created by the compilation.
|
|
|
|
if(const char* extra_outputs_str =
|
|
|
|
source.GetProperty("OBJECT_OUTPUTS"))
|
|
|
|
{
|
|
|
|
std::vector<std::string> extra_outputs;
|
|
|
|
cmSystemTools::ExpandListArgument(extra_outputs_str, extra_outputs);
|
|
|
|
for(std::vector<std::string>::const_iterator eoi = extra_outputs.begin();
|
|
|
|
eoi != extra_outputs.end(); ++eoi)
|
|
|
|
{
|
|
|
|
// Register this as an extra output for the object file rule.
|
|
|
|
// This will cause the object file to be rebuilt if the extra
|
|
|
|
// output is missing.
|
|
|
|
this->GenerateExtraOutput(eoi->c_str(), relativeObj.c_str(), false);
|
|
|
|
|
|
|
|
// Register this as an extra file to clean.
|
|
|
|
this->CleanFiles.push_back(eoi->c_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-08-15 20:00:27 +04:00
|
|
|
bool lang_is_c_or_cxx = ((strcmp(lang, "C") == 0) ||
|
|
|
|
(strcmp(lang, "CXX") == 0));
|
|
|
|
bool do_preprocess_rules = lang_is_c_or_cxx &&
|
2006-08-08 07:25:21 +04:00
|
|
|
this->LocalGenerator->GetCreatePreprocessedSourceRules();
|
2006-08-15 20:00:27 +04:00
|
|
|
bool do_assembly_rules = lang_is_c_or_cxx &&
|
2006-08-08 07:25:21 +04:00
|
|
|
this->LocalGenerator->GetCreateAssemblySourceRules();
|
|
|
|
if(do_preprocess_rules || do_assembly_rules)
|
|
|
|
{
|
|
|
|
std::vector<std::string> force_depends;
|
|
|
|
force_depends.push_back("cmake_force");
|
|
|
|
std::string::size_type dot_pos = relativeObj.rfind(".");
|
|
|
|
std::string relativeObjBase = relativeObj.substr(0, dot_pos);
|
2007-11-21 21:37:14 +03:00
|
|
|
dot_pos = obj.rfind(".");
|
|
|
|
std::string objBase = obj.substr(0, dot_pos);
|
2006-08-08 07:25:21 +04:00
|
|
|
|
|
|
|
if(do_preprocess_rules)
|
|
|
|
{
|
|
|
|
commands.clear();
|
2006-08-09 19:43:35 +04:00
|
|
|
std::string relativeObjI = relativeObjBase + ".i";
|
2007-11-21 21:37:14 +03:00
|
|
|
std::string objI = objBase + ".i";
|
2006-08-08 07:25:21 +04:00
|
|
|
|
|
|
|
std::string preprocessEcho = "Preprocessing ";
|
|
|
|
preprocessEcho += lang;
|
|
|
|
preprocessEcho += " source to ";
|
2007-11-21 21:37:14 +03:00
|
|
|
preprocessEcho += objI;
|
2006-08-08 07:25:21 +04:00
|
|
|
this->LocalGenerator->AppendEcho(
|
|
|
|
commands, preprocessEcho.c_str(),
|
|
|
|
cmLocalUnixMakefileGenerator3::EchoBuild
|
|
|
|
);
|
|
|
|
|
|
|
|
std::string preprocessRuleVar = "CMAKE_";
|
|
|
|
preprocessRuleVar += lang;
|
|
|
|
preprocessRuleVar += "_CREATE_PREPROCESSED_SOURCE";
|
|
|
|
if(const char* preprocessRule =
|
|
|
|
this->Makefile->GetDefinition(preprocessRuleVar.c_str()))
|
|
|
|
{
|
2007-11-21 21:37:14 +03:00
|
|
|
std::vector<std::string> preprocessCommands;
|
|
|
|
cmSystemTools::ExpandListArgument(preprocessRule, preprocessCommands);
|
|
|
|
this->LocalGenerator->CreateCDCommand
|
|
|
|
(preprocessCommands,
|
|
|
|
this->Makefile->GetStartOutputDirectory(),
|
|
|
|
this->Makefile->GetHomeOutputDirectory());
|
|
|
|
commands.insert(commands.end(),
|
|
|
|
preprocessCommands.begin(),
|
|
|
|
preprocessCommands.end());
|
|
|
|
|
2008-01-14 17:20:58 +03:00
|
|
|
std::string shellObjI =
|
|
|
|
this->Convert(objI.c_str(),
|
|
|
|
cmLocalGenerator::NONE,
|
|
|
|
cmLocalGenerator::SHELL).c_str();
|
|
|
|
vars.PreprocessedSource = shellObjI.c_str();
|
2006-08-08 07:25:21 +04:00
|
|
|
|
|
|
|
// Expand placeholders in the commands.
|
|
|
|
for(std::vector<std::string>::iterator i = commands.begin();
|
|
|
|
i != commands.end(); ++i)
|
|
|
|
{
|
|
|
|
this->LocalGenerator->ExpandRuleVariables(*i, vars);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
std::string cmd = "$(CMAKE_COMMAND) -E cmake_unimplemented_variable ";
|
|
|
|
cmd += preprocessRuleVar;
|
|
|
|
commands.push_back(cmd);
|
|
|
|
}
|
|
|
|
|
|
|
|
this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, 0,
|
2006-08-09 19:43:35 +04:00
|
|
|
relativeObjI.c_str(),
|
2006-08-08 07:25:21 +04:00
|
|
|
force_depends, commands, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(do_assembly_rules)
|
|
|
|
{
|
|
|
|
commands.clear();
|
2006-08-09 19:43:35 +04:00
|
|
|
std::string relativeObjS = relativeObjBase + ".s";
|
2007-11-21 21:37:14 +03:00
|
|
|
std::string objS = objBase + ".s";
|
2006-08-08 07:25:21 +04:00
|
|
|
|
|
|
|
std::string assemblyEcho = "Compiling ";
|
|
|
|
assemblyEcho += lang;
|
|
|
|
assemblyEcho += " source to assembly ";
|
2007-11-21 21:37:14 +03:00
|
|
|
assemblyEcho += objS;
|
2006-08-08 07:25:21 +04:00
|
|
|
this->LocalGenerator->AppendEcho(
|
|
|
|
commands, assemblyEcho.c_str(),
|
|
|
|
cmLocalUnixMakefileGenerator3::EchoBuild
|
|
|
|
);
|
|
|
|
|
|
|
|
std::string assemblyRuleVar = "CMAKE_";
|
|
|
|
assemblyRuleVar += lang;
|
|
|
|
assemblyRuleVar += "_CREATE_ASSEMBLY_SOURCE";
|
|
|
|
if(const char* assemblyRule =
|
|
|
|
this->Makefile->GetDefinition(assemblyRuleVar.c_str()))
|
|
|
|
{
|
2007-11-21 21:37:14 +03:00
|
|
|
std::vector<std::string> assemblyCommands;
|
|
|
|
cmSystemTools::ExpandListArgument(assemblyRule, assemblyCommands);
|
|
|
|
this->LocalGenerator->CreateCDCommand
|
|
|
|
(assemblyCommands,
|
|
|
|
this->Makefile->GetStartOutputDirectory(),
|
|
|
|
this->Makefile->GetHomeOutputDirectory());
|
|
|
|
commands.insert(commands.end(),
|
|
|
|
assemblyCommands.begin(),
|
|
|
|
assemblyCommands.end());
|
|
|
|
|
2008-01-14 17:20:58 +03:00
|
|
|
std::string shellObjS =
|
|
|
|
this->Convert(objS.c_str(),
|
|
|
|
cmLocalGenerator::NONE,
|
|
|
|
cmLocalGenerator::SHELL).c_str();
|
|
|
|
vars.AssemblySource = shellObjS.c_str();
|
2006-08-08 07:25:21 +04:00
|
|
|
|
|
|
|
// Expand placeholders in the commands.
|
|
|
|
for(std::vector<std::string>::iterator i = commands.begin();
|
|
|
|
i != commands.end(); ++i)
|
|
|
|
{
|
|
|
|
this->LocalGenerator->ExpandRuleVariables(*i, vars);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
std::string cmd = "$(CMAKE_COMMAND) -E cmake_unimplemented_variable ";
|
|
|
|
cmd += assemblyRuleVar;
|
|
|
|
commands.push_back(cmd);
|
|
|
|
}
|
|
|
|
|
|
|
|
this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, 0,
|
|
|
|
relativeObjS.c_str(),
|
|
|
|
force_depends, commands, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-02-14 18:36:04 +03:00
|
|
|
// If the language needs provides-requires mode, create the
|
|
|
|
// corresponding targets.
|
|
|
|
std::string objectRequires = relativeObj;
|
|
|
|
objectRequires += ".requires";
|
|
|
|
std::vector<std::string> p_depends;
|
|
|
|
// always provide an empty requires target
|
|
|
|
this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, 0,
|
2006-07-10 15:52:35 +04:00
|
|
|
objectRequires.c_str(), p_depends,
|
2006-02-16 00:35:16 +03:00
|
|
|
no_commands, true);
|
2006-02-14 18:36:04 +03:00
|
|
|
|
|
|
|
// write a build rule to recursively build what this obj provides
|
|
|
|
std::string objectProvides = relativeObj;
|
|
|
|
objectProvides += ".provides";
|
|
|
|
std::string temp = relativeObj;
|
|
|
|
temp += ".provides.build";
|
|
|
|
std::vector<std::string> r_commands;
|
2006-07-10 15:52:35 +04:00
|
|
|
std::string tgtMakefileName =
|
2006-02-14 18:36:04 +03:00
|
|
|
this->LocalGenerator->GetRelativeTargetDirectory(*this->Target);
|
|
|
|
tgtMakefileName += "/build.make";
|
|
|
|
r_commands.push_back
|
2006-05-12 20:29:09 +04:00
|
|
|
(this->LocalGenerator->GetRecursiveMakeCall(tgtMakefileName.c_str(),
|
|
|
|
temp.c_str()));
|
|
|
|
|
2006-02-14 18:36:04 +03:00
|
|
|
p_depends.clear();
|
|
|
|
p_depends.push_back(objectRequires);
|
|
|
|
this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, 0,
|
2006-07-10 15:52:35 +04:00
|
|
|
objectProvides.c_str(), p_depends,
|
2006-02-16 00:35:16 +03:00
|
|
|
r_commands, true);
|
2006-07-10 15:52:35 +04:00
|
|
|
|
2006-02-14 18:36:04 +03:00
|
|
|
// write the provides.build rule dependency on the obj file
|
|
|
|
p_depends.clear();
|
|
|
|
p_depends.push_back(relativeObj);
|
|
|
|
this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, 0,
|
2006-02-16 00:35:16 +03:00
|
|
|
temp.c_str(), p_depends, no_commands,
|
|
|
|
true);
|
2006-02-14 18:36:04 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
void cmMakefileTargetGenerator::WriteTargetRequiresRules()
|
|
|
|
{
|
|
|
|
std::vector<std::string> depends;
|
|
|
|
std::vector<std::string> no_commands;
|
|
|
|
|
|
|
|
// Construct the name of the dependency generation target.
|
2006-07-10 15:52:35 +04:00
|
|
|
std::string depTarget =
|
2006-02-14 18:36:04 +03:00
|
|
|
this->LocalGenerator->GetRelativeTargetDirectory(*this->Target);
|
|
|
|
depTarget += "/requires";
|
|
|
|
|
|
|
|
// This target drives dependency generation for all object files.
|
|
|
|
std::string relPath = this->LocalGenerator->GetHomeRelativeOutputPath();
|
|
|
|
std::string objTarget;
|
|
|
|
for(std::vector<std::string>::const_iterator obj = this->Objects.begin();
|
|
|
|
obj != this->Objects.end(); ++obj)
|
|
|
|
{
|
|
|
|
objTarget = relPath;
|
|
|
|
objTarget += *obj;
|
|
|
|
objTarget += ".requires";
|
|
|
|
depends.push_back(objTarget);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Write the rule.
|
|
|
|
this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, 0,
|
2006-02-16 00:35:16 +03:00
|
|
|
depTarget.c_str(),
|
|
|
|
depends, no_commands, true);
|
2006-02-14 18:36:04 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
void cmMakefileTargetGenerator::WriteTargetCleanRules()
|
|
|
|
{
|
|
|
|
std::vector<std::string> depends;
|
|
|
|
std::vector<std::string> commands;
|
|
|
|
|
|
|
|
// Construct the clean target name.
|
2006-07-10 15:52:35 +04:00
|
|
|
std::string cleanTarget =
|
2006-02-14 18:36:04 +03:00
|
|
|
this->LocalGenerator->GetRelativeTargetDirectory(*this->Target);
|
|
|
|
cleanTarget += "/clean";
|
2006-07-10 15:52:35 +04:00
|
|
|
|
2006-02-14 18:36:04 +03:00
|
|
|
// Construct the clean command.
|
2006-03-09 22:30:35 +03:00
|
|
|
this->LocalGenerator->AppendCleanCommand(commands, this->CleanFiles,
|
|
|
|
*this->Target);
|
2006-05-12 20:29:09 +04:00
|
|
|
this->LocalGenerator->CreateCDCommand
|
|
|
|
(commands,
|
|
|
|
this->Makefile->GetStartOutputDirectory(),
|
|
|
|
this->Makefile->GetHomeOutputDirectory());
|
2006-07-10 15:52:35 +04:00
|
|
|
|
2006-02-14 18:36:04 +03:00
|
|
|
// Write the rule.
|
|
|
|
this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, 0,
|
2006-02-16 00:35:16 +03:00
|
|
|
cleanTarget.c_str(),
|
|
|
|
depends, commands, true);
|
2006-02-14 18:36:04 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
void cmMakefileTargetGenerator::WriteTargetDependRules()
|
|
|
|
{
|
|
|
|
// must write the targets depend info file
|
|
|
|
std::string dir = this->LocalGenerator->GetTargetDirectory(*this->Target);
|
|
|
|
this->InfoFileNameFull = dir;
|
|
|
|
this->InfoFileNameFull += "/DependInfo.cmake";
|
2006-07-10 15:52:35 +04:00
|
|
|
this->InfoFileNameFull =
|
2006-02-14 18:36:04 +03:00
|
|
|
this->LocalGenerator->ConvertToFullPath(this->InfoFileNameFull);
|
2006-07-10 15:52:35 +04:00
|
|
|
this->InfoFileStream =
|
2006-02-14 18:36:04 +03:00
|
|
|
new cmGeneratedFileStream(this->InfoFileNameFull.c_str());
|
|
|
|
this->InfoFileStream->SetCopyIfDifferent(true);
|
|
|
|
if(!*this->InfoFileStream)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this->LocalGenerator->
|
|
|
|
WriteDependLanguageInfo(*this->InfoFileStream,*this->Target);
|
2006-07-10 15:52:35 +04:00
|
|
|
|
2007-12-21 20:22:12 +03:00
|
|
|
// Store multiple output pairs in the depend info file.
|
|
|
|
if(!this->MultipleOutputPairs.empty())
|
|
|
|
{
|
|
|
|
*this->InfoFileStream
|
|
|
|
<< "\n"
|
|
|
|
<< "# Pairs of files generated by the same build rule.\n"
|
|
|
|
<< "SET(CMAKE_MULTIPLE_OUTPUT_PAIRS\n";
|
|
|
|
for(MultipleOutputPairsType::const_iterator pi =
|
|
|
|
this->MultipleOutputPairs.begin();
|
|
|
|
pi != this->MultipleOutputPairs.end(); ++pi)
|
|
|
|
{
|
|
|
|
*this->InfoFileStream << " \"" << pi->first << "\" \""
|
|
|
|
<< pi->second << "\"\n";
|
|
|
|
}
|
|
|
|
*this->InfoFileStream << " )\n\n";
|
|
|
|
}
|
|
|
|
|
2007-12-28 19:49:46 +03:00
|
|
|
// Store list of targets linked directly or transitively.
|
|
|
|
{
|
|
|
|
*this->InfoFileStream
|
|
|
|
<< "\n"
|
|
|
|
<< "# Targets to which this target links.\n"
|
|
|
|
<< "SET(CMAKE_TARGET_LINKED_INFO_FILES\n";
|
|
|
|
cmGlobalGenerator* gg = this->GlobalGenerator;
|
|
|
|
std::set<cmTarget const*> emitted;
|
|
|
|
cmTarget::LinkLibraryVectorType const& libs =
|
|
|
|
this->Target->GetLinkLibraries();
|
|
|
|
for(cmTarget::LinkLibraryVectorType::const_iterator j = libs.begin();
|
|
|
|
j != libs.end(); ++j)
|
|
|
|
{
|
|
|
|
if(cmTarget const* linkee = gg->FindTarget(0, j->first.c_str(), false))
|
|
|
|
{
|
|
|
|
if(emitted.insert(linkee).second)
|
|
|
|
{
|
|
|
|
cmMakefile* mf = linkee->GetMakefile();
|
|
|
|
cmLocalGenerator* lg = mf->GetLocalGenerator();
|
|
|
|
std::string di = mf->GetStartOutputDirectory();
|
|
|
|
di += "/";
|
|
|
|
di += lg->GetTargetDirectory(*linkee);
|
|
|
|
di += "/DependInfo.cmake";
|
|
|
|
*this->InfoFileStream << " \"" << di << "\"\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*this->InfoFileStream
|
|
|
|
<< " )\n";
|
|
|
|
}
|
|
|
|
|
2007-12-31 00:11:38 +03:00
|
|
|
// Check for a target-specific module output directory.
|
|
|
|
if(const char* mdir = this->GetFortranModuleDirectory())
|
|
|
|
{
|
|
|
|
*this->InfoFileStream
|
|
|
|
<< "\n"
|
|
|
|
<< "# Fortran module output directory.\n"
|
|
|
|
<< "SET(CMAKE_Fortran_TARGET_MODULE_DIR \"" << mdir << "\")\n";
|
|
|
|
}
|
|
|
|
|
2006-02-14 18:36:04 +03:00
|
|
|
// and now write the rule to use it
|
|
|
|
std::vector<std::string> depends;
|
|
|
|
std::vector<std::string> commands;
|
|
|
|
|
|
|
|
// Construct the name of the dependency generation target.
|
2006-07-10 15:52:35 +04:00
|
|
|
std::string depTarget =
|
2006-02-14 18:36:04 +03:00
|
|
|
this->LocalGenerator->GetRelativeTargetDirectory(*this->Target);
|
|
|
|
depTarget += "/depend";
|
2006-07-10 15:52:35 +04:00
|
|
|
|
2006-02-14 18:36:04 +03:00
|
|
|
// Add a command to call CMake to scan dependencies. CMake will
|
|
|
|
// touch the corresponding depends file after scanning dependencies.
|
|
|
|
cmOStringStream depCmd;
|
|
|
|
// TODO: Account for source file properties and directory-level
|
|
|
|
// definitions when scanning for dependencies.
|
2006-04-27 18:41:37 +04:00
|
|
|
#if !defined(_WIN32) || defined(__CYGWIN__)
|
|
|
|
// This platform supports symlinks, so cmSystemTools will translate
|
|
|
|
// paths. Make sure PWD is set to the original name of the home
|
|
|
|
// output directory to help cmSystemTools to create the same
|
|
|
|
// translation table for the dependency scanning process.
|
|
|
|
depCmd << "cd "
|
|
|
|
<< (this->LocalGenerator->Convert(
|
|
|
|
this->Makefile->GetHomeOutputDirectory(),
|
|
|
|
cmLocalGenerator::FULL, cmLocalGenerator::SHELL))
|
|
|
|
<< " && ";
|
|
|
|
#endif
|
2006-05-25 17:47:30 +04:00
|
|
|
// Generate a call this signature:
|
|
|
|
//
|
|
|
|
// cmake -E cmake_depends <generator>
|
|
|
|
// <home-src-dir> <start-src-dir>
|
|
|
|
// <home-out-dir> <start-out-dir>
|
2007-12-20 01:15:41 +03:00
|
|
|
// <dep-info> --color=$(COLOR)
|
2006-05-25 17:47:30 +04:00
|
|
|
//
|
|
|
|
// This gives the dependency scanner enough information to recreate
|
|
|
|
// the state of our local generator sufficiently for its needs.
|
|
|
|
depCmd << "$(CMAKE_COMMAND) -E cmake_depends \""
|
2006-02-14 18:36:04 +03:00
|
|
|
<< this->GlobalGenerator->GetName() << "\" "
|
2006-05-25 17:47:30 +04:00
|
|
|
<< this->Convert(this->Makefile->GetHomeDirectory(),
|
|
|
|
cmLocalGenerator::FULL, cmLocalGenerator::SHELL)
|
2006-02-14 18:36:04 +03:00
|
|
|
<< " "
|
2006-05-25 17:47:30 +04:00
|
|
|
<< this->Convert(this->Makefile->GetStartDirectory(),
|
|
|
|
cmLocalGenerator::FULL, cmLocalGenerator::SHELL)
|
|
|
|
<< " "
|
|
|
|
<< this->Convert(this->Makefile->GetHomeOutputDirectory(),
|
|
|
|
cmLocalGenerator::FULL, cmLocalGenerator::SHELL)
|
|
|
|
<< " "
|
|
|
|
<< this->Convert(this->Makefile->GetStartOutputDirectory(),
|
|
|
|
cmLocalGenerator::FULL, cmLocalGenerator::SHELL)
|
2006-02-14 18:36:04 +03:00
|
|
|
<< " "
|
|
|
|
<< this->Convert(this->InfoFileNameFull.c_str(),
|
2007-12-20 01:15:41 +03:00
|
|
|
cmLocalGenerator::FULL, cmLocalGenerator::SHELL)
|
|
|
|
<< " --color=$(COLOR)";
|
2006-02-14 18:36:04 +03:00
|
|
|
commands.push_back(depCmd.str());
|
2006-07-10 15:52:35 +04:00
|
|
|
|
2006-08-31 22:09:56 +04:00
|
|
|
// Make sure all custom command outputs in this target are built.
|
2007-05-01 21:51:25 +04:00
|
|
|
if(this->CustomCommandDriver == OnDepends)
|
2006-09-29 00:40:35 +04:00
|
|
|
{
|
|
|
|
this->DriveCustomCommands(depends);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Write the rule.
|
|
|
|
this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, 0,
|
2007-12-20 00:36:30 +03:00
|
|
|
depTarget.c_str(),
|
2007-12-21 19:00:03 +03:00
|
|
|
depends, commands, true);
|
2006-09-29 00:40:35 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
void
|
|
|
|
cmMakefileTargetGenerator
|
|
|
|
::DriveCustomCommands(std::vector<std::string>& depends)
|
|
|
|
{
|
|
|
|
// Depend on all custom command outputs.
|
2006-08-31 22:09:56 +04:00
|
|
|
const std::vector<cmSourceFile*>& sources =
|
|
|
|
this->Target->GetSourceFiles();
|
|
|
|
for(std::vector<cmSourceFile*>::const_iterator source = sources.begin();
|
|
|
|
source != sources.end(); ++source)
|
|
|
|
{
|
|
|
|
if(cmCustomCommand* cc = (*source)->GetCustomCommand())
|
|
|
|
{
|
|
|
|
const std::vector<std::string>& outputs = cc->GetOutputs();
|
|
|
|
for(std::vector<std::string>::const_iterator o = outputs.begin();
|
|
|
|
o != outputs.end(); ++o)
|
|
|
|
{
|
|
|
|
depends.push_back(*o);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2006-02-14 18:36:04 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
void cmMakefileTargetGenerator
|
|
|
|
::WriteObjectDependRules(cmSourceFile& source,
|
|
|
|
std::vector<std::string>& depends)
|
|
|
|
{
|
|
|
|
// Create the list of dependencies known at cmake time. These are
|
|
|
|
// shared between the object file and dependency scanning rule.
|
|
|
|
depends.push_back(source.GetFullPath());
|
|
|
|
if(const char* objectDeps = source.GetProperty("OBJECT_DEPENDS"))
|
|
|
|
{
|
|
|
|
std::vector<std::string> deps;
|
|
|
|
cmSystemTools::ExpandListArgument(objectDeps, deps);
|
|
|
|
for(std::vector<std::string>::iterator i = deps.begin();
|
|
|
|
i != deps.end(); ++i)
|
|
|
|
{
|
|
|
|
depends.push_back(i->c_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
void cmMakefileTargetGenerator
|
|
|
|
::GenerateCustomRuleFile(const cmCustomCommand& cc)
|
|
|
|
{
|
|
|
|
// Collect the commands.
|
|
|
|
std::vector<std::string> commands;
|
2006-04-11 19:06:19 +04:00
|
|
|
std::string comment = this->LocalGenerator->ConstructComment(cc);
|
|
|
|
if(!comment.empty())
|
|
|
|
{
|
2006-07-13 22:03:56 +04:00
|
|
|
// add in a progress call if needed
|
|
|
|
std::string progressDir = this->Makefile->GetHomeOutputDirectory();
|
|
|
|
progressDir += cmake::GetCMakeFilesDirectory();
|
|
|
|
cmOStringStream progCmd;
|
|
|
|
progCmd << "$(CMAKE_COMMAND) -E cmake_progress_report ";
|
|
|
|
progCmd << this->LocalGenerator->Convert(progressDir.c_str(),
|
|
|
|
cmLocalGenerator::FULL,
|
|
|
|
cmLocalGenerator::SHELL);
|
|
|
|
this->NumberOfProgressActions++;
|
|
|
|
progCmd << " $(CMAKE_PROGRESS_"
|
|
|
|
<< this->NumberOfProgressActions
|
|
|
|
<< ")";
|
|
|
|
commands.push_back(progCmd.str());
|
2006-04-11 19:06:19 +04:00
|
|
|
this->LocalGenerator
|
|
|
|
->AppendEcho(commands, comment.c_str(),
|
|
|
|
cmLocalUnixMakefileGenerator3::EchoGenerate);
|
|
|
|
}
|
2006-02-14 18:36:04 +03:00
|
|
|
this->LocalGenerator->AppendCustomCommand(commands, cc);
|
2006-07-10 15:52:35 +04:00
|
|
|
|
2006-02-14 18:36:04 +03:00
|
|
|
// Collect the dependencies.
|
|
|
|
std::vector<std::string> depends;
|
|
|
|
this->LocalGenerator->AppendCustomDepend(depends, cc);
|
|
|
|
|
2007-05-01 21:51:25 +04:00
|
|
|
// Add a dependency on the rule file itself.
|
|
|
|
this->LocalGenerator->AppendRuleDepend(depends,
|
|
|
|
this->BuildFileNameFull.c_str());
|
|
|
|
|
2006-10-02 18:20:53 +04:00
|
|
|
// Check whether we need to bother checking for a symbolic output.
|
|
|
|
bool need_symbolic = this->GlobalGenerator->GetNeedSymbolicMark();
|
|
|
|
|
2006-02-14 18:36:04 +03:00
|
|
|
// Write the rule.
|
2006-04-11 19:06:19 +04:00
|
|
|
const std::vector<std::string>& outputs = cc.GetOutputs();
|
|
|
|
std::vector<std::string>::const_iterator o = outputs.begin();
|
2006-10-02 18:20:53 +04:00
|
|
|
{
|
|
|
|
bool symbolic = false;
|
|
|
|
if(need_symbolic)
|
|
|
|
{
|
|
|
|
if(cmSourceFile* sf = this->Makefile->GetSource(o->c_str()))
|
|
|
|
{
|
|
|
|
symbolic = sf->GetPropertyAsBool("SYMBOLIC");
|
|
|
|
}
|
|
|
|
}
|
2006-04-11 19:06:19 +04:00
|
|
|
this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, 0,
|
|
|
|
o->c_str(), depends, commands,
|
2006-10-02 18:20:53 +04:00
|
|
|
symbolic);
|
|
|
|
}
|
2006-04-11 19:06:19 +04:00
|
|
|
|
2007-03-09 19:29:15 +03:00
|
|
|
// Write rules to drive building any outputs beyond the first.
|
|
|
|
const char* in = o->c_str();
|
2006-04-11 19:06:19 +04:00
|
|
|
for(++o; o != outputs.end(); ++o)
|
2006-02-14 18:36:04 +03:00
|
|
|
{
|
2006-10-02 18:20:53 +04:00
|
|
|
bool symbolic = false;
|
|
|
|
if(need_symbolic)
|
|
|
|
{
|
|
|
|
if(cmSourceFile* sf = this->Makefile->GetSource(o->c_str()))
|
|
|
|
{
|
|
|
|
symbolic = sf->GetPropertyAsBool("SYMBOLIC");
|
|
|
|
}
|
|
|
|
}
|
2007-03-09 19:29:15 +03:00
|
|
|
this->GenerateExtraOutput(o->c_str(), in, symbolic);
|
|
|
|
}
|
2007-09-17 18:50:46 +04:00
|
|
|
|
|
|
|
// Setup implicit dependency scanning.
|
|
|
|
for(cmCustomCommand::ImplicitDependsList::const_iterator
|
|
|
|
idi = cc.GetImplicitDepends().begin();
|
|
|
|
idi != cc.GetImplicitDepends().end(); ++idi)
|
|
|
|
{
|
|
|
|
std::string objFullPath =
|
|
|
|
this->Convert(outputs[0].c_str(), cmLocalGenerator::FULL);
|
|
|
|
std::string srcFullPath =
|
|
|
|
this->Convert(idi->second.c_str(), cmLocalGenerator::FULL);
|
|
|
|
this->LocalGenerator->
|
|
|
|
AddImplicitDepends(*this->Target, idi->first.c_str(),
|
|
|
|
objFullPath.c_str(),
|
|
|
|
srcFullPath.c_str());
|
|
|
|
}
|
2007-03-09 19:29:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
void
|
|
|
|
cmMakefileTargetGenerator
|
|
|
|
::GenerateExtraOutput(const char* out, const char* in, bool symbolic)
|
|
|
|
{
|
|
|
|
// Add a rule to build the primary output if the extra output needs
|
|
|
|
// to be created.
|
|
|
|
std::vector<std::string> commands;
|
|
|
|
std::vector<std::string> depends;
|
2007-05-16 21:24:17 +04:00
|
|
|
std::string emptyCommand = this->GlobalGenerator->GetEmptyRuleHackCommand();
|
2007-03-09 19:29:15 +03:00
|
|
|
if(!emptyCommand.empty())
|
|
|
|
{
|
|
|
|
commands.push_back(emptyCommand);
|
2006-02-14 18:36:04 +03:00
|
|
|
}
|
2007-03-09 19:29:15 +03:00
|
|
|
depends.push_back(in);
|
|
|
|
this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, 0,
|
|
|
|
out, depends, commands,
|
|
|
|
symbolic);
|
|
|
|
|
|
|
|
// Register the extra output as paired with the first output so that
|
|
|
|
// the check-build-system step will remove the primary output if any
|
|
|
|
// extra outputs are missing. This forces the rule to regenerate
|
|
|
|
// all outputs.
|
2007-12-21 20:22:12 +03:00
|
|
|
this->AddMultipleOutputPair(out, in);
|
2006-02-14 18:36:04 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
void
|
|
|
|
cmMakefileTargetGenerator
|
|
|
|
::WriteObjectsVariable(std::string& variableName,
|
|
|
|
std::string& variableNameExternal)
|
|
|
|
{
|
|
|
|
// Write a make variable assignment that lists all objects for the
|
|
|
|
// target.
|
2006-07-10 15:52:35 +04:00
|
|
|
variableName =
|
|
|
|
this->LocalGenerator->CreateMakeVariable(this->Target->GetName(),
|
2006-05-12 20:29:09 +04:00
|
|
|
"_OBJECTS");
|
2006-02-14 18:36:04 +03:00
|
|
|
*this->BuildFileStream
|
|
|
|
<< "# Object files for target " << this->Target->GetName() << "\n"
|
|
|
|
<< variableName.c_str() << " =";
|
|
|
|
std::string object;
|
2006-07-10 15:52:35 +04:00
|
|
|
const char* objName =
|
2006-02-14 18:36:04 +03:00
|
|
|
this->Makefile->GetDefinition("CMAKE_NO_QUOTED_OBJECTS");
|
2006-07-10 15:52:35 +04:00
|
|
|
const char* lineContinue =
|
2006-02-14 18:36:04 +03:00
|
|
|
this->Makefile->GetDefinition("CMAKE_MAKE_LINE_CONTINUE");
|
|
|
|
if(!lineContinue)
|
|
|
|
{
|
|
|
|
lineContinue = "\\";
|
|
|
|
}
|
|
|
|
for(std::vector<std::string>::const_iterator i = this->Objects.begin();
|
|
|
|
i != this->Objects.end(); ++i)
|
|
|
|
{
|
2006-03-28 17:54:01 +04:00
|
|
|
if ( this->ExtraContent.find(i->c_str()) != this->ExtraContent.end() )
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2006-02-14 18:36:04 +03:00
|
|
|
*this->BuildFileStream << " " << lineContinue << "\n";
|
|
|
|
if(objName)
|
|
|
|
{
|
2006-07-10 15:52:35 +04:00
|
|
|
*this->BuildFileStream <<
|
|
|
|
this->Convert(i->c_str(), cmLocalGenerator::START_OUTPUT,
|
2006-02-14 18:36:04 +03:00
|
|
|
cmLocalGenerator::MAKEFILE);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-07-10 15:52:35 +04:00
|
|
|
*this->BuildFileStream <<
|
2006-02-14 18:36:04 +03:00
|
|
|
this->LocalGenerator->ConvertToQuotedOutputPath(i->c_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*this->BuildFileStream << "\n";
|
|
|
|
|
|
|
|
// Write a make variable assignment that lists all external objects
|
|
|
|
// for the target.
|
2006-07-10 15:52:35 +04:00
|
|
|
variableNameExternal =
|
2006-05-12 20:29:09 +04:00
|
|
|
this->LocalGenerator->CreateMakeVariable(this->Target->GetName(),
|
|
|
|
"_EXTERNAL_OBJECTS");
|
2006-02-14 18:36:04 +03:00
|
|
|
*this->BuildFileStream
|
|
|
|
<< "\n"
|
2006-07-10 15:52:35 +04:00
|
|
|
<< "# External object files for target "
|
2006-05-12 20:29:09 +04:00
|
|
|
<< this->Target->GetName() << "\n"
|
2006-02-14 18:36:04 +03:00
|
|
|
<< variableNameExternal.c_str() << " =";
|
2006-07-10 15:52:35 +04:00
|
|
|
for(std::vector<std::string>::const_iterator i =
|
2006-02-14 18:36:04 +03:00
|
|
|
this->ExternalObjects.begin();
|
|
|
|
i != this->ExternalObjects.end(); ++i)
|
|
|
|
{
|
|
|
|
object = this->Convert(i->c_str(),cmLocalGenerator::START_OUTPUT);
|
|
|
|
*this->BuildFileStream
|
|
|
|
<< " " << lineContinue << "\n"
|
|
|
|
<< this->Makefile->GetSafeDefinition("CMAKE_OBJECT_NAME");
|
|
|
|
if(objName)
|
|
|
|
{
|
2006-07-10 15:52:35 +04:00
|
|
|
*this->BuildFileStream <<
|
|
|
|
this->Convert(i->c_str(), cmLocalGenerator::START_OUTPUT,
|
2006-05-12 20:29:09 +04:00
|
|
|
cmLocalGenerator::MAKEFILE);
|
2006-02-14 18:36:04 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-07-10 15:52:35 +04:00
|
|
|
*this->BuildFileStream <<
|
2006-02-14 18:36:04 +03:00
|
|
|
this->LocalGenerator->ConvertToQuotedOutputPath(i->c_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*this->BuildFileStream << "\n" << "\n";
|
|
|
|
}
|
|
|
|
|
2006-06-16 00:17:11 +04:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
void
|
|
|
|
cmMakefileTargetGenerator
|
|
|
|
::WriteObjectsString(std::string& buildObjs)
|
|
|
|
{
|
|
|
|
std::string object;
|
|
|
|
const char* no_quoted =
|
|
|
|
this->Makefile->GetDefinition("CMAKE_NO_QUOTED_OBJECTS");
|
|
|
|
const char* space = "";
|
|
|
|
for(std::vector<std::string>::const_iterator i = this->Objects.begin();
|
|
|
|
i != this->Objects.end(); ++i)
|
|
|
|
{
|
|
|
|
if ( this->ExtraContent.find(i->c_str()) != this->ExtraContent.end() )
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
buildObjs += space;
|
|
|
|
space = " ";
|
|
|
|
if(no_quoted)
|
|
|
|
{
|
|
|
|
buildObjs +=
|
|
|
|
this->Convert(i->c_str(), cmLocalGenerator::START_OUTPUT,
|
|
|
|
cmLocalGenerator::SHELL);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
buildObjs +=
|
|
|
|
this->LocalGenerator->ConvertToQuotedOutputPath(i->c_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for(std::vector<std::string>::const_iterator i =
|
|
|
|
this->ExternalObjects.begin();
|
|
|
|
i != this->ExternalObjects.end(); ++i)
|
|
|
|
{
|
|
|
|
buildObjs += space;
|
|
|
|
space = " ";
|
|
|
|
if(no_quoted)
|
|
|
|
{
|
|
|
|
buildObjs +=
|
|
|
|
this->Convert(i->c_str(), cmLocalGenerator::START_OUTPUT,
|
|
|
|
cmLocalGenerator::SHELL);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
buildObjs +=
|
|
|
|
this->LocalGenerator->ConvertToQuotedOutputPath(i->c_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-06-01 19:45:51 +04:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
void cmMakefileTargetGenerator::WriteTargetDriverRule(const char* main_output,
|
|
|
|
bool relink)
|
|
|
|
{
|
|
|
|
// Compute the name of the driver target.
|
2006-10-10 05:25:58 +04:00
|
|
|
std::string dir =
|
|
|
|
this->LocalGenerator->GetRelativeTargetDirectory(*this->Target);
|
2006-06-01 19:45:51 +04:00
|
|
|
std::string buildTargetRuleName = dir;
|
|
|
|
buildTargetRuleName += relink?"/preinstall":"/build";
|
|
|
|
buildTargetRuleName = this->Convert(buildTargetRuleName.c_str(),
|
|
|
|
cmLocalGenerator::HOME_OUTPUT,
|
2007-02-19 20:26:32 +03:00
|
|
|
cmLocalGenerator::UNCHANGED);
|
2006-06-01 19:45:51 +04:00
|
|
|
|
|
|
|
// Build the list of target outputs to drive.
|
|
|
|
std::vector<std::string> depends;
|
|
|
|
if(main_output)
|
|
|
|
{
|
|
|
|
depends.push_back(main_output);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* comment = 0;
|
|
|
|
if(relink)
|
|
|
|
{
|
|
|
|
// Setup the comment for the preinstall driver.
|
|
|
|
comment = "Rule to relink during preinstall.";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Setup the comment for the main build driver.
|
|
|
|
comment = "Rule to build all files generated by this target.";
|
2006-09-29 00:40:35 +04:00
|
|
|
|
|
|
|
// Make sure all custom command outputs in this target are built.
|
2007-05-01 21:51:25 +04:00
|
|
|
if(this->CustomCommandDriver == OnBuild)
|
2006-09-29 00:40:35 +04:00
|
|
|
{
|
|
|
|
this->DriveCustomCommands(depends);
|
|
|
|
}
|
2006-06-01 19:45:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Write the driver rule.
|
|
|
|
std::vector<std::string> no_commands;
|
|
|
|
this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, comment,
|
|
|
|
buildTargetRuleName.c_str(),
|
|
|
|
depends, no_commands, true);
|
|
|
|
}
|
2006-02-14 18:36:04 +03:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
std::string cmMakefileTargetGenerator::GetFrameworkFlags()
|
|
|
|
{
|
|
|
|
#ifndef __APPLE__
|
|
|
|
return std::string();
|
|
|
|
#else
|
|
|
|
std::set<cmStdString> emitted;
|
2007-03-30 18:53:02 +04:00
|
|
|
emitted.insert("/System/Library/Frameworks");
|
2006-02-14 18:36:04 +03:00
|
|
|
std::vector<std::string> includes;
|
2006-02-15 20:30:01 +03:00
|
|
|
this->LocalGenerator->GetIncludeDirectories(includes);
|
2006-02-14 18:36:04 +03:00
|
|
|
std::vector<std::string>::iterator i;
|
|
|
|
// check all include directories for frameworks as this
|
|
|
|
// will already have added a -F for the framework
|
|
|
|
for(i = includes.begin(); i != includes.end(); ++i)
|
|
|
|
{
|
2007-10-10 19:06:15 +04:00
|
|
|
if(this->Target->NameResolvesToFramework(i->c_str()))
|
2006-02-14 18:36:04 +03:00
|
|
|
{
|
|
|
|
std::string frameworkDir = *i;
|
|
|
|
frameworkDir += "/../";
|
|
|
|
frameworkDir = cmSystemTools::CollapseFullPath(frameworkDir.c_str());
|
|
|
|
emitted.insert(frameworkDir);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string flags;
|
|
|
|
std::vector<std::string>& frameworks = this->Target->GetFrameworks();
|
|
|
|
for(i = frameworks.begin();
|
|
|
|
i != frameworks.end(); ++i)
|
|
|
|
{
|
|
|
|
if(emitted.insert(*i).second)
|
|
|
|
{
|
|
|
|
flags += "-F";
|
|
|
|
flags += this->LocalGenerator->ConvertToOutputForExisting(i->c_str());
|
|
|
|
flags += " ";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return flags;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
void cmMakefileTargetGenerator
|
|
|
|
::AppendTargetDepends(std::vector<std::string>& depends)
|
|
|
|
{
|
|
|
|
// Static libraries never depend on anything for linking.
|
|
|
|
if(this->Target->GetType() == cmTarget::STATIC_LIBRARY)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2006-11-28 00:13:41 +03:00
|
|
|
// Compute which library configuration to link.
|
|
|
|
cmTarget::LinkLibraryType linkType = cmTarget::OPTIMIZED;
|
|
|
|
if(cmSystemTools::UpperCase(
|
|
|
|
this->LocalGenerator->ConfigurationName.c_str()) == "DEBUG")
|
|
|
|
{
|
|
|
|
linkType = cmTarget::DEBUG;
|
|
|
|
}
|
2006-02-14 18:36:04 +03:00
|
|
|
// Keep track of dependencies already listed.
|
|
|
|
std::set<cmStdString> emitted;
|
|
|
|
|
|
|
|
// A target should not depend on itself.
|
|
|
|
emitted.insert(this->Target->GetName());
|
|
|
|
|
|
|
|
// Loop over all library dependencies.
|
2006-07-10 15:52:35 +04:00
|
|
|
const cmTarget::LinkLibraryVectorType& tlibs =
|
2006-03-15 19:02:08 +03:00
|
|
|
this->Target->GetLinkLibraries();
|
|
|
|
for(cmTarget::LinkLibraryVectorType::const_iterator lib = tlibs.begin();
|
2006-02-14 18:36:04 +03:00
|
|
|
lib != tlibs.end(); ++lib)
|
|
|
|
{
|
2006-11-28 00:13:41 +03:00
|
|
|
// skip the library if it is not general and the link type
|
|
|
|
// does not match the current target
|
|
|
|
if(lib->second != cmTarget::GENERAL &&
|
|
|
|
lib->second != linkType)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2006-02-14 18:36:04 +03:00
|
|
|
// Don't emit the same library twice for this target.
|
|
|
|
if(emitted.insert(lib->first).second)
|
|
|
|
{
|
2006-09-12 18:03:57 +04:00
|
|
|
// Depend on other CMake targets.
|
2006-07-10 15:52:35 +04:00
|
|
|
if(cmTarget* tgt =
|
2007-05-22 18:24:59 +04:00
|
|
|
this->GlobalGenerator->FindTarget(0, lib->first.c_str(), false))
|
2006-02-14 18:36:04 +03:00
|
|
|
{
|
|
|
|
if(const char* location =
|
2006-03-15 19:02:08 +03:00
|
|
|
tgt->GetLocation(this->LocalGenerator->ConfigurationName.c_str()))
|
2006-02-14 18:36:04 +03:00
|
|
|
{
|
|
|
|
depends.push_back(location);
|
|
|
|
}
|
|
|
|
}
|
2006-09-12 18:21:47 +04:00
|
|
|
// depend on full path libs as well
|
|
|
|
else if(cmSystemTools::FileIsFullPath(lib->first.c_str()))
|
|
|
|
{
|
|
|
|
depends.push_back(lib->first.c_str());
|
|
|
|
}
|
2006-09-12 18:03:57 +04:00
|
|
|
}
|
2006-02-14 18:36:04 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
void cmMakefileTargetGenerator
|
|
|
|
::CloseFileStreams()
|
|
|
|
{
|
|
|
|
delete this->BuildFileStream;
|
|
|
|
delete this->InfoFileStream;
|
|
|
|
delete this->FlagFileStream;
|
|
|
|
}
|
2006-03-14 22:03:16 +03:00
|
|
|
|
|
|
|
void cmMakefileTargetGenerator::RemoveForbiddenFlags(const char* flagVar,
|
2006-07-10 15:52:35 +04:00
|
|
|
const char* linkLang,
|
2006-03-14 22:03:16 +03:00
|
|
|
std::string& linkFlags)
|
|
|
|
{
|
|
|
|
// check for language flags that are not allowed at link time, and
|
|
|
|
// remove them, -w on darwin for gcc -w -dynamiclib sends -w to libtool
|
|
|
|
// which fails, there may be more]
|
2006-07-10 15:52:35 +04:00
|
|
|
|
2006-03-14 22:03:16 +03:00
|
|
|
std::string removeFlags = "CMAKE_";
|
|
|
|
removeFlags += linkLang;
|
|
|
|
removeFlags += flagVar;
|
2006-07-10 15:52:35 +04:00
|
|
|
std::string removeflags =
|
2006-03-14 22:03:16 +03:00
|
|
|
this->Makefile->GetSafeDefinition(removeFlags.c_str());
|
|
|
|
std::vector<std::string> removeList;
|
|
|
|
cmSystemTools::ExpandListArgument(removeflags, removeList);
|
|
|
|
for(std::vector<std::string>::iterator i = removeList.begin();
|
|
|
|
i != removeList.end(); ++i)
|
|
|
|
{
|
|
|
|
cmSystemTools::ReplaceString(linkFlags, i->c_str(), "");
|
|
|
|
}
|
|
|
|
}
|
2006-07-11 17:55:27 +04:00
|
|
|
|
|
|
|
void cmMakefileTargetGenerator::WriteProgressVariables(unsigned long total,
|
|
|
|
unsigned long ¤t)
|
|
|
|
{
|
2006-07-12 22:15:06 +04:00
|
|
|
cmGeneratedFileStream *progressFileStream =
|
|
|
|
new cmGeneratedFileStream(this->ProgressFileNameFull.c_str());
|
|
|
|
if(!progressFileStream)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-07-11 17:55:27 +04:00
|
|
|
unsigned long num;
|
|
|
|
unsigned long i;
|
|
|
|
for (i = 1; i <= this->NumberOfProgressActions; ++i)
|
|
|
|
{
|
2006-07-12 22:15:06 +04:00
|
|
|
*progressFileStream
|
2006-07-11 17:55:27 +04:00
|
|
|
<< "CMAKE_PROGRESS_" << i << " = ";
|
|
|
|
if (total <= 100)
|
|
|
|
{
|
|
|
|
num = i + current;
|
2006-07-12 22:15:06 +04:00
|
|
|
*progressFileStream << num;
|
2006-07-11 17:55:27 +04:00
|
|
|
this->LocalGenerator->ProgressFiles[this->Target->GetName()]
|
|
|
|
.push_back(num);
|
|
|
|
}
|
|
|
|
else if (((i+current)*100)/total > ((i-1+current)*100)/total)
|
|
|
|
{
|
|
|
|
num = ((i+current)*100)/total;
|
2006-07-12 22:15:06 +04:00
|
|
|
*progressFileStream << num;
|
2006-07-11 17:55:27 +04:00
|
|
|
this->LocalGenerator->ProgressFiles[this->Target->GetName()]
|
|
|
|
.push_back(num);
|
|
|
|
}
|
2006-07-12 22:15:06 +04:00
|
|
|
*progressFileStream << "\n";
|
2006-07-11 17:55:27 +04:00
|
|
|
}
|
2006-08-14 18:51:08 +04:00
|
|
|
*progressFileStream << "\n";
|
2006-07-11 17:55:27 +04:00
|
|
|
current += this->NumberOfProgressActions;
|
2006-07-12 22:15:06 +04:00
|
|
|
delete progressFileStream;
|
2006-07-11 17:55:27 +04:00
|
|
|
}
|
2007-12-21 20:22:12 +03:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
void
|
|
|
|
cmMakefileTargetGenerator
|
|
|
|
::AddMultipleOutputPair(const char* depender, const char* dependee)
|
|
|
|
{
|
|
|
|
MultipleOutputPairsType::value_type p(depender, dependee);
|
|
|
|
this->MultipleOutputPairs.insert(p);
|
|
|
|
}
|
2007-12-28 22:59:06 +03:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
void
|
|
|
|
cmMakefileTargetGenerator
|
|
|
|
::CreateLinkScript(const char* name,
|
|
|
|
std::vector<std::string> const& link_commands,
|
|
|
|
std::vector<std::string>& makefile_commands)
|
|
|
|
{
|
|
|
|
// Create the link script file.
|
|
|
|
std::string linkScriptName = this->TargetBuildDirectoryFull;
|
|
|
|
linkScriptName += "/";
|
|
|
|
linkScriptName += name;
|
|
|
|
cmGeneratedFileStream linkScriptStream(linkScriptName.c_str());
|
|
|
|
for(std::vector<std::string>::const_iterator cmd = link_commands.begin();
|
|
|
|
cmd != link_commands.end(); ++cmd)
|
|
|
|
{
|
|
|
|
// Do not write out empty commands or commands beginning in the
|
|
|
|
// shell no-op ":".
|
|
|
|
if(!cmd->empty() && (*cmd)[0] != ':')
|
|
|
|
{
|
|
|
|
linkScriptStream << *cmd << "\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create the makefile command to invoke the link script.
|
|
|
|
std::string link_command = "$(CMAKE_COMMAND) -E cmake_link_script ";
|
|
|
|
link_command += this->Convert(linkScriptName.c_str(),
|
|
|
|
cmLocalGenerator::START_OUTPUT,
|
|
|
|
cmLocalGenerator::SHELL);
|
|
|
|
link_command += " --verbose=$(VERBOSE)";
|
|
|
|
makefile_commands.push_back(link_command);
|
|
|
|
}
|
2007-12-31 00:11:38 +03:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
const char* cmMakefileTargetGenerator::GetFortranModuleDirectory()
|
|
|
|
{
|
|
|
|
// Compute the module directory.
|
|
|
|
if(!this->FortranModuleDirectoryComputed)
|
|
|
|
{
|
|
|
|
const char* target_mod_dir =
|
|
|
|
this->Target->GetProperty("Fortran_MODULE_DIRECTORY");
|
|
|
|
const char* moddir_flag =
|
|
|
|
this->Makefile->GetDefinition("CMAKE_Fortran_MODDIR_FLAG");
|
|
|
|
if(target_mod_dir && moddir_flag)
|
|
|
|
{
|
|
|
|
// Compute the full path to the module directory.
|
|
|
|
if(cmSystemTools::FileIsFullPath(target_mod_dir))
|
|
|
|
{
|
|
|
|
// Already a full path.
|
|
|
|
this->FortranModuleDirectory = target_mod_dir;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Interpret relative to the current output directory.
|
|
|
|
this->FortranModuleDirectory =
|
|
|
|
this->Makefile->GetCurrentOutputDirectory();
|
|
|
|
this->FortranModuleDirectory += "/";
|
|
|
|
this->FortranModuleDirectory += target_mod_dir;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make sure the module output directory exists.
|
|
|
|
cmSystemTools::MakeDirectory(this->FortranModuleDirectory.c_str());
|
|
|
|
}
|
|
|
|
this->FortranModuleDirectoryComputed = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return the computed directory.
|
|
|
|
if(this->FortranModuleDirectory.empty())
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return this->FortranModuleDirectory.c_str();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
void cmMakefileTargetGenerator::AddFortranFlags(std::string& flags)
|
|
|
|
{
|
|
|
|
// Add a module output directory flag if necessary.
|
|
|
|
if(const char* mod_dir = this->GetFortranModuleDirectory())
|
|
|
|
{
|
|
|
|
const char* moddir_flag =
|
|
|
|
this->Makefile->GetRequiredDefinition("CMAKE_Fortran_MODDIR_FLAG");
|
|
|
|
std::string modflag = moddir_flag;
|
|
|
|
modflag += this->Convert(mod_dir,
|
|
|
|
cmLocalGenerator::START_OUTPUT,
|
|
|
|
cmLocalGenerator::SHELL);
|
|
|
|
this->LocalGenerator->AppendFlags(flags, modflag.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
// If there is a separate module path flag then duplicate the
|
|
|
|
// include path with it. This compiler does not search the include
|
|
|
|
// path for modules.
|
|
|
|
if(const char* modpath_flag =
|
|
|
|
this->Makefile->GetDefinition("CMAKE_Fortran_MODPATH_FLAG"))
|
|
|
|
{
|
|
|
|
std::vector<std::string> includes;
|
|
|
|
this->LocalGenerator->GetIncludeDirectories(includes);
|
|
|
|
for(std::vector<std::string>::const_iterator idi = includes.begin();
|
|
|
|
idi != includes.end(); ++idi)
|
|
|
|
{
|
|
|
|
std::string flg = modpath_flag;
|
|
|
|
flg += this->Convert(idi->c_str(),
|
|
|
|
cmLocalGenerator::NONE,
|
|
|
|
cmLocalGenerator::SHELL);
|
|
|
|
this->LocalGenerator->AppendFlags(flags, flg.c_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|