diff options
author | Brad King <brad.king@kitware.com> | 2017-10-18 17:30:09 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2017-10-18 18:24:07 (GMT) |
commit | 344d149ae45251125f3dad038d9f10e531eb6fd1 (patch) | |
tree | fc945d8bc8a6b4239b2125bf55ae3b9b193f87ef /Source/cmLocalVisualStudio7Generator.cxx | |
parent | 6dec363028ad969fb1a7b160e42ab815ccbb60ca (diff) | |
download | CMake-344d149ae45251125f3dad038d9f10e531eb6fd1.zip CMake-344d149ae45251125f3dad038d9f10e531eb6fd1.tar.gz CMake-344d149ae45251125f3dad038d9f10e531eb6fd1.tar.bz2 |
VS,Xcode: Add CMakeLists.txt sources without mutating targets
Rather than injecting `CMakeLists.txt` files into each target's
`SOURCES`, teach the generators to add them during generation using
dedicated code. This avoids mutating the original targets, and avoids
polluting `$<TARGET_PROPERTY:foo,SOURCES>` with generator-specific
content.
This also avoids listing the `CMakeLists.txt` sources in the results of
`CMAKE_DEBUG_TARGET_PROPERTIES==SOURCES` so the `RunCMake.TargetSources`
test no longer needs a separate case for IDEs.
Diffstat (limited to 'Source/cmLocalVisualStudio7Generator.cxx')
-rw-r--r-- | Source/cmLocalVisualStudio7Generator.cxx | 100 |
1 files changed, 54 insertions, 46 deletions
diff --git a/Source/cmLocalVisualStudio7Generator.cxx b/Source/cmLocalVisualStudio7Generator.cxx index d8030b7..beb80f2 100644 --- a/Source/cmLocalVisualStudio7Generator.cxx +++ b/Source/cmLocalVisualStudio7Generator.cxx @@ -36,6 +36,13 @@ private: cmLocalVisualStudio7Generator* LocalGenerator; }; +class cmLocalVisualStudio7Generator::AllConfigSources +{ +public: + std::vector<cmGeneratorTarget::AllConfigSource> Sources; + std::map<cmSourceFile const*, size_t> Index; +}; + extern cmVS7FlagTable cmLocalVisualStudio7GeneratorFlagTable[]; static void cmConvertToWindowsSlash(std::string& s) @@ -83,29 +90,6 @@ void cmLocalVisualStudio7Generator::Generate() this->WriteStampFiles(); } -void cmLocalVisualStudio7Generator::AddCMakeListsRules() -{ - // Create the regeneration custom rule. - if (!this->Makefile->IsOn("CMAKE_SUPPRESS_REGENERATION")) { - // Create a rule to regenerate the build system when the target - // specification source changes. - if (cmSourceFile* sf = this->CreateVCProjBuildRule()) { - // Add the rule to targets that need it. - const std::vector<cmGeneratorTarget*>& tgts = - this->GetGeneratorTargets(); - for (std::vector<cmGeneratorTarget*>::const_iterator l = tgts.begin(); - l != tgts.end(); ++l) { - if ((*l)->GetType() == cmStateEnums::GLOBAL_TARGET) { - continue; - } - if ((*l)->GetName() != CMAKE_CHECK_BUILD_SYSTEM_TARGET) { - (*l)->AddSource(sf->GetFullPath()); - } - } - } - } -} - void cmLocalVisualStudio7Generator::FixGlobalTargets() { // Visual Studio .NET 2003 Service Pack 1 will not run post-build @@ -239,19 +223,29 @@ void cmLocalVisualStudio7Generator::CreateSingleVCProj( cmSourceFile* cmLocalVisualStudio7Generator::CreateVCProjBuildRule() { + if (this->Makefile->IsOn("CMAKE_SUPPRESS_REGENERATION")) { + return nullptr; + } + + std::string makefileIn = this->GetCurrentSourceDirectory(); + makefileIn += "/"; + makefileIn += "CMakeLists.txt"; + makefileIn = cmSystemTools::CollapseFullPath(makefileIn); + if (cmSourceFile* file = this->Makefile->GetSource(makefileIn)) { + if (file->GetCustomCommand()) { + return file; + } + } + if (!cmSystemTools::FileExists(makefileIn)) { + return nullptr; + } + std::string stampName = this->GetCurrentBinaryDirectory(); stampName += "/"; stampName += cmake::GetCMakeFilesDirectoryPostSlash(); stampName += "generate.stamp"; cmCustomCommandLine commandLine; commandLine.push_back(cmSystemTools::GetCMakeCommand()); - std::string makefileIn = this->GetCurrentSourceDirectory(); - makefileIn += "/"; - makefileIn += "CMakeLists.txt"; - makefileIn = cmSystemTools::CollapseFullPath(makefileIn.c_str()); - if (!cmSystemTools::FileExists(makefileIn.c_str())) { - return 0; - } std::string comment = "Building Custom Rule "; comment += makefileIn; std::string args; @@ -275,10 +269,13 @@ cmSourceFile* cmLocalVisualStudio7Generator::CreateVCProjBuildRule() fullpathStampName.c_str(), listFiles, makefileIn.c_str(), commandLines, comment.c_str(), no_working_directory, true, false); if (cmSourceFile* file = this->Makefile->GetSource(makefileIn.c_str())) { + // Finalize the source file path now since we're adding this after + // the generator validated all project-named sources. + file->GetFullPath(); return file; } else { cmSystemTools::Error("Error adding rule for ", makefileIn.c_str()); - return 0; + return nullptr; } } @@ -1368,13 +1365,26 @@ void cmLocalVisualStudio7Generator::WriteVCProjFile(std::ostream& fout, // We may be modifying the source groups temporarily, so make a copy. std::vector<cmSourceGroup> sourceGroups = this->Makefile->GetSourceGroups(); - std::vector<cmGeneratorTarget::AllConfigSource> const& sources = - target->GetAllConfigSources(); - std::map<cmSourceFile const*, size_t> sourcesIndex; + AllConfigSources sources; + sources.Sources = target->GetAllConfigSources(); + + // Add CMakeLists.txt file with rule to re-run CMake for user convenience. + if (target->GetType() != cmStateEnums::GLOBAL_TARGET && + target->GetName() != CMAKE_CHECK_BUILD_SYSTEM_TARGET) { + if (cmSourceFile const* sf = this->CreateVCProjBuildRule()) { + cmGeneratorTarget::AllConfigSource acs; + acs.Source = sf; + acs.Kind = cmGeneratorTarget::SourceKindCustomCommand; + for (size_t ci = 0; ci < configs.size(); ++ci) { + acs.Configs.push_back(ci); + } + sources.Sources.emplace_back(std::move(acs)); + } + } - for (size_t si = 0; si < sources.size(); ++si) { - cmSourceFile const* sf = sources[si].Source; - sourcesIndex[sf] = si; + for (size_t si = 0; si < sources.Sources.size(); ++si) { + cmSourceFile const* sf = sources.Sources[si].Source; + sources.Index[sf] = si; if (!sf->GetObjectLibrary().empty()) { if (this->FortranProject) { // Intel Fortran does not support per-config source locations @@ -1400,7 +1410,7 @@ void cmLocalVisualStudio7Generator::WriteVCProjFile(std::ostream& fout, // Loop through every source group. for (unsigned int i = 0; i < sourceGroups.size(); ++i) { cmSourceGroup sg = sourceGroups[i]; - this->WriteGroup(&sg, target, fout, libName, configs, sourcesIndex); + this->WriteGroup(&sg, target, fout, libName, configs, sources); } fout << "\t</Files>\n"; @@ -1567,7 +1577,7 @@ std::string cmLocalVisualStudio7Generator::ComputeLongestObjectDirectory( bool cmLocalVisualStudio7Generator::WriteGroup( const cmSourceGroup* sg, cmGeneratorTarget* target, std::ostream& fout, const std::string& libName, std::vector<std::string> const& configs, - std::map<cmSourceFile const*, size_t> const& sourcesIndex) + AllConfigSources const& sources) { cmGlobalVisualStudio7Generator* gg = static_cast<cmGlobalVisualStudio7Generator*>(this->GlobalGenerator); @@ -1579,7 +1589,7 @@ bool cmLocalVisualStudio7Generator::WriteGroup( std::ostringstream tmpOut; for (unsigned int i = 0; i < children.size(); ++i) { if (this->WriteGroup(&children[i], target, tmpOut, libName, configs, - sourcesIndex)) { + sources)) { hasChildrenWithSources = true; } } @@ -1595,9 +1605,6 @@ bool cmLocalVisualStudio7Generator::WriteGroup( this->WriteVCProjBeginGroup(fout, name.c_str(), ""); } - std::vector<cmGeneratorTarget::AllConfigSource> const& sources = - target->GetAllConfigSources(); - // Loop through each source in the source group. for (std::vector<const cmSourceFile*>::const_iterator sf = sourceFiles.begin(); @@ -1608,10 +1615,11 @@ bool cmLocalVisualStudio7Generator::WriteGroup( target->GetType() == cmStateEnums::GLOBAL_TARGET) { // Look up the source kind and configs. std::map<cmSourceFile const*, size_t>::const_iterator map_it = - sourcesIndex.find(*sf); + sources.Index.find(*sf); // The map entry must exist because we populated it earlier. - assert(map_it != sourcesIndex.end()); - cmGeneratorTarget::AllConfigSource const& acs = sources[map_it->second]; + assert(map_it != sources.Index.end()); + cmGeneratorTarget::AllConfigSource const& acs = + sources.Sources[map_it->second]; FCInfo fcinfo(this, target, acs, configs); |