diff options
author | David Cole <david.cole@kitware.com> | 2012-03-20 13:34:35 (GMT) |
---|---|---|
committer | CMake Topic Stage <kwrobot@kitware.com> | 2012-03-20 13:34:35 (GMT) |
commit | 31c0bc021940420fcf383bde390c59beb2cd9b9c (patch) | |
tree | 6b8507775944f1deca58394332891d8ff276610e /Source/cmNinjaTargetGenerator.cxx | |
parent | b06f7c077b15de1a2bf354b64092565d0e49d719 (diff) | |
parent | 93d5509b5b1c208f3ed28daf35f9384ab6918441 (diff) | |
download | CMake-31c0bc021940420fcf383bde390c59beb2cd9b9c.zip CMake-31c0bc021940420fcf383bde390c59beb2cd9b9c.tar.gz CMake-31c0bc021940420fcf383bde390c59beb2cd9b9c.tar.bz2 |
Merge topic 'object-library'
93d5509 Merge branch 'ninja-object-library' into object-library
821037c Merge branch 'xcode-object-library' into object-library
eb24c99 Merge branch 'object-library' into xcode-object-library
63d1be8 Xcode: Honor $<TARGET_OBJECTS:...> source expressions
020ba38 Merge branch 'object-library' into xcode-object-library
e8ea615 Build object library targets in Xcode
8045e17 Pre-compute object file names before Xcode generation
247a132 Allow txt files as ExtraSources in object library targets
b063599 Add a default source group for object files.
be01f3b Xcode: Re-factor some existing methods into "FromPath" variants
2693dbe Merge branch 'object-library' into ninja-object-library
51997cb Ninja: Honor $<TARGET_OBJECTS:...> source expressions
23ec258 Merge branch 'object-library' into ninja-object-library
61124de Build object library targets in Ninja
f5b06cd Pre-compute object file names before Ninja generation
a2514f1 Simplify cmNinjaTargetGenerator using cmGeneratorTarget
...
Diffstat (limited to 'Source/cmNinjaTargetGenerator.cxx')
-rw-r--r-- | Source/cmNinjaTargetGenerator.cxx | 96 |
1 files changed, 54 insertions, 42 deletions
diff --git a/Source/cmNinjaTargetGenerator.cxx b/Source/cmNinjaTargetGenerator.cxx index 9acbc67..4c4a53f 100644 --- a/Source/cmNinjaTargetGenerator.cxx +++ b/Source/cmNinjaTargetGenerator.cxx @@ -14,6 +14,7 @@ #include "cmGlobalNinjaGenerator.h" #include "cmLocalNinjaGenerator.h" #include "cmGeneratedFileStream.h" +#include "cmGeneratorTarget.h" #include "cmNinjaNormalTargetGenerator.h" #include "cmNinjaUtilityTargetGenerator.h" #include "cmSystemTools.h" @@ -33,6 +34,7 @@ cmNinjaTargetGenerator::New(cmTarget* target) case cmTarget::SHARED_LIBRARY: case cmTarget::STATIC_LIBRARY: case cmTarget::MODULE_LIBRARY: + case cmTarget::OBJECT_LIBRARY: return new cmNinjaNormalTargetGenerator(target); case cmTarget::UTILITY: @@ -60,6 +62,8 @@ cmNinjaTargetGenerator::cmNinjaTargetGenerator(cmTarget* target) static_cast<cmLocalNinjaGenerator*>(Makefile->GetLocalGenerator())), Objects() { + this->GeneratorTarget = + this->GetGlobalGenerator()->GetGeneratorTarget(target); } cmNinjaTargetGenerator::~cmNinjaTargetGenerator() @@ -218,7 +222,8 @@ ComputeDefines(cmSourceFile *source, const std::string& language) cmNinjaDeps cmNinjaTargetGenerator::ComputeLinkDeps() const { // Static libraries never depend on other targets for linking. - if (this->Target->GetType() == cmTarget::STATIC_LIBRARY) + if (this->Target->GetType() == cmTarget::STATIC_LIBRARY || + this->Target->GetType() == cmTarget::OBJECT_LIBRARY) return cmNinjaDeps(); cmComputeLinkInformation* cli = @@ -231,9 +236,9 @@ cmNinjaDeps cmNinjaTargetGenerator::ComputeLinkDeps() const std::transform(deps.begin(), deps.end(), result.begin(), MapToNinjaPath()); // Add a dependency on the link definitions file, if any. - if(!this->ModuleDefinitionFile.empty()) + if(!this->GeneratorTarget->ModuleDefinitionFile.empty()) { - result.push_back(this->ModuleDefinitionFile); + result.push_back(this->GeneratorTarget->ModuleDefinitionFile); } return result; @@ -253,7 +258,10 @@ cmNinjaTargetGenerator std::string path = this->LocalGenerator->GetHomeRelativeOutputPath(); if(!path.empty()) path += "/"; - path += this->LocalGenerator->GetObjectFileName(*this->Target, *source); + std::string const& objectName = this->GeneratorTarget->Objects[source]; + path += this->LocalGenerator->GetTargetDirectory(*this->Target); + path += "/"; + path += objectName; return path; } @@ -377,12 +385,37 @@ cmNinjaTargetGenerator << this->GetTargetName() << "\n\n"; - // For each source files of this target. - for(std::vector<cmSourceFile*>::const_iterator i = - this->GetTarget()->GetSourceFiles().begin(); - i != this->GetTarget()->GetSourceFiles().end(); - ++i) - this->WriteObjectBuildStatement(*i); + for(std::vector<cmSourceFile*>::const_iterator + si = this->GeneratorTarget->CustomCommands.begin(); + si != this->GeneratorTarget->CustomCommands.end(); ++si) + { + cmCustomCommand const* cc = (*si)->GetCustomCommand(); + this->GetLocalGenerator()->AddCustomCommandTarget(cc, this->GetTarget()); + } + // TODO: this->GeneratorTarget->OSXContent + for(std::vector<cmSourceFile*>::const_iterator + si = this->GeneratorTarget->ExternalObjects.begin(); + si != this->GeneratorTarget->ExternalObjects.end(); ++si) + { + this->Objects.push_back(this->GetSourceFilePath(*si)); + } + for(std::vector<cmSourceFile*>::const_iterator + si = this->GeneratorTarget->ObjectSources.begin(); + si != this->GeneratorTarget->ObjectSources.end(); ++si) + { + this->WriteObjectBuildStatement(*si); + } + + { + // Add object library contents as external objects. + std::vector<std::string> objs; + this->GeneratorTarget->UseObjectLibraries(objs); + for(std::vector<std::string>::iterator oi = objs.begin(); + oi != objs.end(); ++oi) + { + this->Objects.push_back(ConvertToNinjaPath(oi->c_str())); + } + } this->GetBuildFileStream() << "\n"; } @@ -391,26 +424,10 @@ void cmNinjaTargetGenerator ::WriteObjectBuildStatement(cmSourceFile* source) { - if (cmCustomCommand *cc = source->GetCustomCommand()) - this->GetLocalGenerator()->AddCustomCommandTarget(cc, this->GetTarget()); - cmNinjaDeps emptyDeps; std::string comment; const char* language = source->GetLanguage(); - // If we cannot get the language this is probably a non-source file provided - // in the list (typically an header file). - if (!language) { - if (source->GetPropertyAsBool("EXTERNAL_OBJECT")) - this->Objects.push_back(this->GetSourceFilePath(source)); - if(cmSystemTools::UpperCase(source->GetExtension()) == "DEF") - this->ModuleDefinitionFile = GetSourceFilePath(source); - return; - } - - if (source->GetPropertyAsBool("HEADER_FILE_ONLY")) - return; - std::string rule = this->LanguageCompilerRule(language); cmNinjaDeps outputs; @@ -435,21 +452,16 @@ cmNinjaTargetGenerator std::back_inserter(orderOnlyDeps), MapToNinjaPath()); } - // Add order-only dependency on any header file with a custom command. - { - const std::vector<cmSourceFile*>& sources = - this->GetTarget()->GetSourceFiles(); - for(std::vector<cmSourceFile*>::const_iterator si = sources.begin(); - si != sources.end(); ++si) { - if (!(*si)->GetLanguage()) { - if (cmCustomCommand* cc = (*si)->GetCustomCommand()) { - const std::vector<std::string>& ccoutputs = cc->GetOutputs(); - std::transform(ccoutputs.begin(), ccoutputs.end(), - std::back_inserter(orderOnlyDeps), MapToNinjaPath()); - } - } + // Add order-only dependencies on custom command outputs. + for(std::vector<cmSourceFile*>::const_iterator + si = this->GeneratorTarget->CustomCommands.begin(); + si != this->GeneratorTarget->CustomCommands.end(); ++si) + { + cmCustomCommand const* cc = (*si)->GetCustomCommand(); + const std::vector<std::string>& ccoutputs = cc->GetOutputs(); + std::transform(ccoutputs.begin(), ccoutputs.end(), + std::back_inserter(orderOnlyDeps), MapToNinjaPath()); } - } // If the source file is GENERATED and does not have a custom command // (either attached to this source file or another one), assume that one of @@ -493,7 +505,7 @@ void cmNinjaTargetGenerator ::AddModuleDefinitionFlag(std::string& flags) { - if(this->ModuleDefinitionFile.empty()) + if(this->GeneratorTarget->ModuleDefinitionFile.empty()) { return; } @@ -510,6 +522,6 @@ cmNinjaTargetGenerator // vs6's "cl -link" pass it to the linker. std::string flag = defFileFlag; flag += (this->LocalGenerator->ConvertToLinkReference( - this->ModuleDefinitionFile.c_str())); + this->GeneratorTarget->ModuleDefinitionFile.c_str())); this->LocalGenerator->AppendFlags(flags, flag.c_str()); } |