VS10: Port to cmGeneratorTarget.

This commit is contained in:
Stephen Kelly 2015-10-22 18:27:57 +02:00
parent 7f8bb857b8
commit 459c891088
5 changed files with 37 additions and 34 deletions

View File

@ -331,7 +331,7 @@ void cmGlobalVisualStudio10Generator::Generate()
this->cmGlobalVisualStudio8Generator::Generate(); this->cmGlobalVisualStudio8Generator::Generate();
if(this->LongestSource.Length > 0) if(this->LongestSource.Length > 0)
{ {
cmMakefile* mf = this->LongestSource.Target->GetMakefile(); cmLocalGenerator* lg = this->LongestSource.Target->GetLocalGenerator();
std::ostringstream e; std::ostringstream e;
e << e <<
"The binary and/or source directory paths may be too long to generate " "The binary and/or source directory paths may be too long to generate "
@ -346,13 +346,13 @@ void cmGlobalVisualStudio10Generator::Generate()
" " << this->LongestSource.SourceFile->GetFullPath() << "\n" " " << this->LongestSource.SourceFile->GetFullPath() << "\n"
"This is because some Visual Studio tools would append the relative " "This is because some Visual Studio tools would append the relative "
"path to the end of the referencing directory path, as in:\n" "path to the end of the referencing directory path, as in:\n"
" " << mf->GetCurrentBinaryDirectory() << "/" " " << lg->GetCurrentBinaryDirectory() << "/"
<< this->LongestSource.SourceRel << "\n" << this->LongestSource.SourceRel << "\n"
"and then incorrectly complain that the file does not exist because " "and then incorrectly complain that the file does not exist because "
"the path length is too long for some internal buffer or API. " "the path length is too long for some internal buffer or API. "
"To avoid this problem CMake must use a full path for this file " "To avoid this problem CMake must use a full path for this file "
"which then triggers the VS 10 property dialog bug."; "which then triggers the VS 10 property dialog bug.";
mf->IssueMessage(cmake::WARNING, e.str().c_str()); lg->IssueMessage(cmake::WARNING, e.str().c_str());
} }
} }
@ -591,9 +591,11 @@ cmGlobalVisualStudio10Generator
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
void cmGlobalVisualStudio10Generator::PathTooLong( void cmGlobalVisualStudio10Generator::PathTooLong(
cmTarget* target, cmSourceFile const* sf, std::string const& sfRel) cmGeneratorTarget *target, cmSourceFile const* sf,
std::string const& sfRel)
{ {
size_t len = (strlen(target->GetMakefile()->GetCurrentBinaryDirectory()) + size_t len =
(strlen(target->GetLocalGenerator()->GetCurrentBinaryDirectory()) +
1 + sfRel.length()); 1 + sfRel.length());
if(len > this->LongestSource.Length) if(len > this->LongestSource.Length)
{ {

View File

@ -95,7 +95,7 @@ public:
/** Generate an <output>.rule file path for a given command output. */ /** Generate an <output>.rule file path for a given command output. */
virtual std::string GenerateRuleFile(std::string const& output) const; virtual std::string GenerateRuleFile(std::string const& output) const;
void PathTooLong(cmTarget* target, cmSourceFile const* sf, void PathTooLong(cmGeneratorTarget* target, cmSourceFile const* sf,
std::string const& sfRel); std::string const& sfRel);
virtual const char* GetToolsVersion() { return "4.0"; } virtual const char* GetToolsVersion() { return "4.0"; }
@ -139,7 +139,7 @@ private:
{ {
LongestSourcePath(): Length(0), Target(0), SourceFile(0) {} LongestSourcePath(): Length(0), Target(0), SourceFile(0) {}
size_t Length; size_t Length;
cmTarget* Target; cmGeneratorTarget* Target;
cmSourceFile const* SourceFile; cmSourceFile const* SourceFile;
std::string SourceRel; std::string SourceRel;
}; };

View File

@ -90,7 +90,7 @@ void cmLocalVisualStudio10Generator::Generate()
else else
{ {
cmVisualStudio10TargetGenerator tg( cmVisualStudio10TargetGenerator tg(
(*l)->Target, static_cast<cmGlobalVisualStudio10Generator*>( *l, static_cast<cmGlobalVisualStudio10Generator*>(
this->GetGlobalGenerator())); this->GetGlobalGenerator()));
tg.Generate(); tg.Generate();
} }

View File

@ -13,7 +13,6 @@
#include "cmVisualStudio10TargetGenerator.h" #include "cmVisualStudio10TargetGenerator.h"
#include "cmGlobalVisualStudio10Generator.h" #include "cmGlobalVisualStudio10Generator.h"
#include "cmGeneratorTarget.h" #include "cmGeneratorTarget.h"
#include "cmTarget.h"
#include "cmComputeLinkInformation.h" #include "cmComputeLinkInformation.h"
#include "cmGeneratedFileStream.h" #include "cmGeneratedFileStream.h"
#include "cmMakefile.h" #include "cmMakefile.h"
@ -167,13 +166,12 @@ static std::string cmVS10EscapeComment(std::string comment)
} }
cmVisualStudio10TargetGenerator:: cmVisualStudio10TargetGenerator::
cmVisualStudio10TargetGenerator(cmTarget* target, cmVisualStudio10TargetGenerator(cmGeneratorTarget* target,
cmGlobalVisualStudio10Generator* gg) cmGlobalVisualStudio10Generator* gg)
{ {
this->GlobalGenerator = gg; this->GlobalGenerator = gg;
this->Target = target; this->GeneratorTarget = target;
this->GeneratorTarget = gg->GetGeneratorTarget(target); this->Makefile = target->Target->GetMakefile();
this->Makefile = target->GetMakefile();
this->Makefile->GetConfigurations(this->Configurations); this->Makefile->GetConfigurations(this->Configurations);
this->LocalGenerator = this->LocalGenerator =
(cmLocalVisualStudio7Generator*) (cmLocalVisualStudio7Generator*)
@ -275,8 +273,9 @@ void cmVisualStudio10TargetGenerator::Generate()
return; return;
} }
// Tell the global generator the name of the project file // Tell the global generator the name of the project file
this->Target->SetProperty("GENERATOR_FILE_NAME",this->Name.c_str()); this->GeneratorTarget->Target
this->Target->SetProperty("GENERATOR_FILE_NAME_EXT", ->SetProperty("GENERATOR_FILE_NAME",this->Name.c_str());
this->GeneratorTarget->Target->SetProperty("GENERATOR_FILE_NAME_EXT",
".vcxproj"); ".vcxproj");
if(this->GeneratorTarget->GetType() <= cmState::OBJECT_LIBRARY) if(this->GeneratorTarget->GetType() <= cmState::OBJECT_LIBRARY)
{ {
@ -732,7 +731,8 @@ void cmVisualStudio10TargetGenerator
cmGlobalVisualStudio10Generator* gg = cmGlobalVisualStudio10Generator* gg =
static_cast<cmGlobalVisualStudio10Generator*>(this->GlobalGenerator); static_cast<cmGlobalVisualStudio10Generator*>(this->GlobalGenerator);
const char* mfcFlag = const char* mfcFlag =
this->Target->GetMakefile()->GetDefinition("CMAKE_MFC_FLAG"); this->GeneratorTarget->
Target->GetMakefile()->GetDefinition("CMAKE_MFC_FLAG");
std::string mfcFlagValue = mfcFlag ? mfcFlag : "0"; std::string mfcFlagValue = mfcFlag ? mfcFlag : "0";
std::string useOfMfcValue = "false"; std::string useOfMfcValue = "false";
@ -1462,7 +1462,8 @@ void cmVisualStudio10TargetGenerator::WriteSource(
} }
else else
{ {
this->GlobalGenerator->PathTooLong(this->Target, sf, sourceRel); this->GlobalGenerator->PathTooLong(this->GeneratorTarget,
sf, sourceRel);
} }
} }
this->ConvertToWindowsSlash(sourceFile); this->ConvertToWindowsSlash(sourceFile);
@ -1915,12 +1916,12 @@ bool cmVisualStudio10TargetGenerator::ComputeClOptions(
std::string baseFlagVar = "CMAKE_"; std::string baseFlagVar = "CMAKE_";
baseFlagVar += linkLanguage; baseFlagVar += linkLanguage;
baseFlagVar += "_FLAGS"; baseFlagVar += "_FLAGS";
flags = this-> flags = this->GeneratorTarget->
Target->GetMakefile()->GetRequiredDefinition(baseFlagVar.c_str()); Target->GetMakefile()->GetRequiredDefinition(baseFlagVar.c_str());
std::string flagVar = baseFlagVar + std::string("_") + std::string flagVar = baseFlagVar + std::string("_") +
cmSystemTools::UpperCase(configName); cmSystemTools::UpperCase(configName);
flags += " "; flags += " ";
flags += this-> flags += this->GeneratorTarget->
Target->GetMakefile()->GetRequiredDefinition(flagVar.c_str()); Target->GetMakefile()->GetRequiredDefinition(flagVar.c_str());
} }
// set the correct language // set the correct language
@ -1936,7 +1937,8 @@ bool cmVisualStudio10TargetGenerator::ComputeClOptions(
linkLanguage, configName.c_str()); linkLanguage, configName.c_str());
// Get preprocessor definitions for this directory. // Get preprocessor definitions for this directory.
std::string defineFlags = this->Target->GetMakefile()->GetDefineFlags(); std::string defineFlags =
this->GeneratorTarget->Target->GetMakefile()->GetDefineFlags();
if(this->MSTools) if(this->MSTools)
{ {
clOptions.FixExceptionHandlingDefault(); clOptions.FixExceptionHandlingDefault();
@ -2440,11 +2442,11 @@ cmVisualStudio10TargetGenerator::ComputeLinkOptions(std::string const& config)
linkFlagVarBase += linkType; linkFlagVarBase += linkType;
linkFlagVarBase += "_LINKER_FLAGS"; linkFlagVarBase += "_LINKER_FLAGS";
flags += " "; flags += " ";
flags += this-> flags += this->GeneratorTarget->
Target->GetMakefile()->GetRequiredDefinition(linkFlagVarBase.c_str()); Target->GetMakefile()->GetRequiredDefinition(linkFlagVarBase.c_str());
std::string linkFlagVar = linkFlagVarBase + "_" + CONFIG; std::string linkFlagVar = linkFlagVarBase + "_" + CONFIG;
flags += " "; flags += " ";
flags += this-> flags += this->GeneratorTarget->
Target->GetMakefile()->GetRequiredDefinition(linkFlagVar.c_str()); Target->GetMakefile()->GetRequiredDefinition(linkFlagVar.c_str());
const char* targetLinkFlags = const char* targetLinkFlags =
this->GeneratorTarget->GetProperty("LINK_FLAGS"); this->GeneratorTarget->GetProperty("LINK_FLAGS");
@ -2674,7 +2676,8 @@ cmVisualStudio10TargetGenerator::WriteLinkOptions(std::string const& config)
linkOptions.OutputFlagMap(*this->BuildFileStream, " "); linkOptions.OutputFlagMap(*this->BuildFileStream, " ");
this->WriteString("</Link>\n", 2); this->WriteString("</Link>\n", 2);
if(!this->GlobalGenerator->NeedLinkLibraryDependencies(*this->Target)) if(!this->GlobalGenerator->NeedLinkLibraryDependencies(
*this->GeneratorTarget->Target))
{ {
this->WriteString("<ProjectReference>\n", 2); this->WriteString("<ProjectReference>\n", 2);
this->WriteString( this->WriteString(
@ -2811,7 +2814,7 @@ cmVisualStudio10TargetGenerator::WriteEvents(std::string const& configName)
{ {
addedPrelink = true; addedPrelink = true;
std::vector<cmCustomCommand> commands = std::vector<cmCustomCommand> commands =
this->Target->GetPreLinkCommands(); this->GeneratorTarget->Target->GetPreLinkCommands();
this->GlobalGenerator->AddSymbolExportCommand( this->GlobalGenerator->AddSymbolExportCommand(
this->GeneratorTarget, commands, configName); this->GeneratorTarget, commands, configName);
this->WriteEvent("PreLinkEvent", commands, configName); this->WriteEvent("PreLinkEvent", commands, configName);
@ -2820,12 +2823,12 @@ cmVisualStudio10TargetGenerator::WriteEvents(std::string const& configName)
if (!addedPrelink) if (!addedPrelink)
{ {
this->WriteEvent("PreLinkEvent", this->WriteEvent("PreLinkEvent",
this->Target->GetPreLinkCommands(), configName); this->GeneratorTarget->Target->GetPreLinkCommands(), configName);
} }
this->WriteEvent("PreBuildEvent", this->WriteEvent("PreBuildEvent",
this->Target->GetPreBuildCommands(), configName); this->GeneratorTarget->Target->GetPreBuildCommands(), configName);
this->WriteEvent("PostBuildEvent", this->WriteEvent("PostBuildEvent",
this->Target->GetPostBuildCommands(), configName); this->GeneratorTarget->Target->GetPostBuildCommands(), configName);
} }
void cmVisualStudio10TargetGenerator::WriteEvent( void cmVisualStudio10TargetGenerator::WriteEvent(
@ -2875,7 +2878,7 @@ void cmVisualStudio10TargetGenerator::WriteProjectReferences()
for( OrderedTargetDependSet::const_iterator i = depends.begin(); for( OrderedTargetDependSet::const_iterator i = depends.begin();
i != depends.end(); ++i) i != depends.end(); ++i)
{ {
cmTarget const* dt = (*i)->Target; cmGeneratorTarget const* dt = *i;
if(dt->GetType() == cmState::INTERFACE_LIBRARY) if(dt->GetType() == cmState::INTERFACE_LIBRARY)
{ {
continue; continue;
@ -2883,12 +2886,12 @@ void cmVisualStudio10TargetGenerator::WriteProjectReferences()
// skip fortran targets as they can not be processed by MSBuild // skip fortran targets as they can not be processed by MSBuild
// the only reference will be in the .sln file // the only reference will be in the .sln file
if(static_cast<cmGlobalVisualStudioGenerator*>(this->GlobalGenerator) if(static_cast<cmGlobalVisualStudioGenerator*>(this->GlobalGenerator)
->TargetIsFortranOnly(*dt)) ->TargetIsFortranOnly(*dt->Target))
{ {
continue; continue;
} }
this->WriteString("<ProjectReference Include=\"", 2); this->WriteString("<ProjectReference Include=\"", 2);
cmMakefile* mf = dt->GetMakefile(); cmLocalGenerator* lg = dt->GetLocalGenerator();
std::string name = dt->GetName(); std::string name = dt->GetName();
std::string path; std::string path;
const char* p = dt->GetProperty("EXTERNAL_MSPROJECT"); const char* p = dt->GetProperty("EXTERNAL_MSPROJECT");
@ -2898,7 +2901,7 @@ void cmVisualStudio10TargetGenerator::WriteProjectReferences()
} }
else else
{ {
path = mf->GetCurrentBinaryDirectory(); path = lg->GetCurrentBinaryDirectory();
path += "/"; path += "/";
path += dt->GetName(); path += dt->GetName();
path += ".vcxproj"; path += ".vcxproj";

View File

@ -13,7 +13,6 @@
#define cmVisualStudioTargetGenerator_h #define cmVisualStudioTargetGenerator_h
#include "cmStandardIncludes.h" #include "cmStandardIncludes.h"
class cmTarget;
class cmMakefile; class cmMakefile;
class cmGeneratorTarget; class cmGeneratorTarget;
class cmGeneratedFileStream; class cmGeneratedFileStream;
@ -29,7 +28,7 @@ struct cmIDEFlagTable;
class cmVisualStudio10TargetGenerator class cmVisualStudio10TargetGenerator
{ {
public: public:
cmVisualStudio10TargetGenerator(cmTarget* target, cmVisualStudio10TargetGenerator(cmGeneratorTarget* target,
cmGlobalVisualStudio10Generator* gg); cmGlobalVisualStudio10Generator* gg);
~cmVisualStudio10TargetGenerator(); ~cmVisualStudio10TargetGenerator();
void Generate(); void Generate();
@ -148,7 +147,6 @@ private:
OptionsMap LinkOptions; OptionsMap LinkOptions;
std::string PathToVcxproj; std::string PathToVcxproj;
std::vector<std::string> Configurations; std::vector<std::string> Configurations;
cmTarget* Target;
cmGeneratorTarget* GeneratorTarget; cmGeneratorTarget* GeneratorTarget;
cmMakefile* Makefile; cmMakefile* Makefile;
std::string Platform; std::string Platform;