From 1c489923d54592dfdd0a9421f585bb45ccf9aa44 Mon Sep 17 00:00:00 2001 From: Brad King Date: Wed, 28 Mar 2012 08:41:48 -0400 Subject: [PATCH 1/3] Always compile sources with known language Refactoring by commit 11d9b211 (Add cmGeneratorTarget to represent a target during generation, 2012-03-07) and commit 45c2f932 (Simplify cmMakefileTargetGenerator using cmGeneratorTarget, 2012-03-07) preserved behavior introduced by commit 7740ccd1 (some cleanup of the makefile generator, 2006-02-14) that favored the IgnoreFile extension test over the availability of a known compilation language associated with a source file. If a source is not marked as HEADER_FILE_ONLY and has a known language extension or an explicit LANGUAGE property it should be treated as that language. The LANGUAGE source file property documentation says so. --- Source/cmGeneratorTarget.cxx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index 797992890..3f43465b2 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -58,6 +58,10 @@ void cmGeneratorTarget::ClassifySources() this->ExternalObjects.push_back(sf); if(isObjLib) { badObjLib.push_back(sf); } } + else if(sf->GetLanguage()) + { + this->ObjectSources.push_back(sf); + } else if(ext == "def") { this->ModuleDefinitionFile = sf->GetFullPath(); @@ -75,10 +79,6 @@ void cmGeneratorTarget::ClassifySources() // No message or diagnosis should be given. this->ExtraSources.push_back(sf); } - else if(sf->GetLanguage()) - { - this->ObjectSources.push_back(sf); - } else { this->ExtraSources.push_back(sf); From 9a2c60eb836ae26a2cd47f3c21a810047b695db9 Mon Sep 17 00:00:00 2001 From: Brad King Date: Wed, 28 Mar 2012 08:51:14 -0400 Subject: [PATCH 2/3] Classify known header file extensions as headers Commit 328c0f65 (Simplify cmVisualStudio10TargetGenerator source classification, 2012-03-19) introduced the first use of source classification from cmGeneratorTarget (which originated as Makefile generator logic) in a Visual Studio generator for handling of header files. Fix classification of header files to match known header extensions instead of only the HEADER_FILE_ONLY property. Make it consistent with the "Header Files" source group. --- Source/cmGeneratorTarget.cxx | 5 +++++ Source/cmMakefile.cxx | 3 +-- Source/cmSourceFile.h | 3 +++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index 3f43465b2..42dd42819 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -30,6 +30,7 @@ cmGeneratorTarget::cmGeneratorTarget(cmTarget* t): Target(t) //---------------------------------------------------------------------------- void cmGeneratorTarget::ClassifySources() { + cmsys::RegularExpression header(CM_HEADER_REGEX); bool isObjLib = this->Target->GetType() == cmTarget::OBJECT_LIBRARY; std::vector badObjLib; std::vector const& sources = this->Target->GetSourceFiles(); @@ -72,6 +73,10 @@ void cmGeneratorTarget::ClassifySources() this->IDLSources.push_back(sf); if(isObjLib) { badObjLib.push_back(sf); } } + else if(header.find(sf->GetFullPath().c_str())) + { + this->HeaderSources.push_back(sf); + } else if(this->GlobalGenerator->IgnoreFile(sf->GetExtension().c_str())) { // We only get here if a source file is not an external object diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 56e330507..e7e5edaa3 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -778,8 +778,7 @@ void cmMakefile::SetLocalGenerator(cmLocalGenerator* lg) ("Source Files", "\\.(C|M|c|c\\+\\+|cc|cpp|cxx|f|f90|for|fpp" "|ftn|m|mm|rc|def|r|odl|idl|hpj|bat)$"); - this->AddSourceGroup("Header Files", - "\\.(h|hh|h\\+\\+|hm|hpp|hxx|in|txx|inl)$"); + this->AddSourceGroup("Header Files", CM_HEADER_REGEX); this->AddSourceGroup("CMake Rules", "\\.rule$"); this->AddSourceGroup("Resources", "\\.plist$"); this->AddSourceGroup("Object Files", "\\.(lo|o|obj)$"); diff --git a/Source/cmSourceFile.h b/Source/cmSourceFile.h index 55147e192..ae012747d 100644 --- a/Source/cmSourceFile.h +++ b/Source/cmSourceFile.h @@ -116,4 +116,7 @@ private: std::vector Depends; }; +// TODO: Factor out into platform information modules. +#define CM_HEADER_REGEX "\\.(h|hh|h\\+\\+|hm|hpp|hxx|in|txx|inl)$" + #endif From 01e979acef392776bd1ea1fb38126957746954e7 Mon Sep 17 00:00:00 2001 From: Brad King Date: Wed, 28 Mar 2012 13:49:01 -0400 Subject: [PATCH 3/3] VS: Add CMakeLists.txt re-run rules at start of generation Since commit 328c0f65 (Simplify cmVisualStudio10TargetGenerator source classification, 2012-03-19) the VS 10 generator uses the cmGeneratorTarget source classification instead of directly getting the list of source files from the target. This accidentally dropped the CMakeLists.txt files from generated projects because they are added too late for cmGeneratorTarget. All generator-specific source files must be added to targets prior to cmGeneratorTarget construction. Refactor addition of the CMakeLists.txt files with CMake re-run custom commands to take place before normal generation begins, and therefore early enough to be included in the cmGeneratorTarget classification. --- Source/cmGlobalVisualStudioGenerator.cxx | 10 ++++++ Source/cmLocalVisualStudio10Generator.cxx | 18 ---------- Source/cmLocalVisualStudio6Generator.cxx | 29 +++++++++------- Source/cmLocalVisualStudio6Generator.h | 1 + Source/cmLocalVisualStudio7Generator.cxx | 40 +++++++++++++---------- Source/cmLocalVisualStudio7Generator.h | 1 + Source/cmLocalVisualStudioGenerator.h | 2 ++ 7 files changed, 53 insertions(+), 48 deletions(-) diff --git a/Source/cmGlobalVisualStudioGenerator.cxx b/Source/cmGlobalVisualStudioGenerator.cxx index 7da4f8687..2a918c925 100644 --- a/Source/cmGlobalVisualStudioGenerator.cxx +++ b/Source/cmGlobalVisualStudioGenerator.cxx @@ -95,6 +95,16 @@ void cmGlobalVisualStudioGenerator::Generate() // of Visual Studio. this->ConfigureCMakeVisualStudioMacros(); + // Add CMakeLists.txt with custom command to rerun CMake. + for(std::vector::const_iterator + lgi = this->LocalGenerators.begin(); + lgi != this->LocalGenerators.end(); ++lgi) + { + cmLocalVisualStudioGenerator* lg = + static_cast(*lgi); + lg->AddCMakeListsRules(); + } + // Run all the local generators. this->cmGlobalGenerator::Generate(); } diff --git a/Source/cmLocalVisualStudio10Generator.cxx b/Source/cmLocalVisualStudio10Generator.cxx index 8b22705b3..bf0e99709 100644 --- a/Source/cmLocalVisualStudio10Generator.cxx +++ b/Source/cmLocalVisualStudio10Generator.cxx @@ -74,24 +74,6 @@ void cmLocalVisualStudio10Generator::Generate() { cmTargets &tgts = this->Makefile->GetTargets(); - // 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. - for(cmTargets::iterator l = tgts.begin(); l != tgts.end(); ++l) - { - if(l->first != CMAKE_CHECK_BUILD_SYSTEM_TARGET) - { - l->second.AddSourceFile(sf); - } - } - } - } - for(cmTargets::iterator l = tgts.begin(); l != tgts.end(); ++l) { if(static_cast(this->GlobalGenerator) diff --git a/Source/cmLocalVisualStudio6Generator.cxx b/Source/cmLocalVisualStudio6Generator.cxx index 5b99dfd88..99a4c95fc 100644 --- a/Source/cmLocalVisualStudio6Generator.cxx +++ b/Source/cmLocalVisualStudio6Generator.cxx @@ -85,6 +85,23 @@ void cmLocalVisualStudio6Generator::AddHelperCommands() this->CreateCustomTargetsAndCommands(lang); } +void cmLocalVisualStudio6Generator::AddCMakeListsRules() +{ + cmTargets &tgts = this->Makefile->GetTargets(); + for(cmTargets::iterator l = tgts.begin(); + l != tgts.end(); l++) + { + // Add a rule to regenerate the build system when the target + // specification source changes. + const char* suppRegenRule = + this->Makefile->GetDefinition("CMAKE_SUPPRESS_REGENERATION"); + if (!cmSystemTools::IsOn(suppRegenRule)) + { + this->AddDSPBuildRule(l->second); + } + } +} + void cmLocalVisualStudio6Generator::Generate() { this->OutputDSPFile(); @@ -107,18 +124,6 @@ void cmLocalVisualStudio6Generator::OutputDSPFile() // Create the DSP or set of DSP's for libraries and executables cmTargets &tgts = this->Makefile->GetTargets(); - for(cmTargets::iterator l = tgts.begin(); - l != tgts.end(); l++) - { - // Add a rule to regenerate the build system when the target - // specification source changes. - const char* suppRegenRule = - this->Makefile->GetDefinition("CMAKE_SUPPRESS_REGENERATION"); - if (!cmSystemTools::IsOn(suppRegenRule)) - { - this->AddDSPBuildRule(l->second); - } - } // build any targets for(cmTargets::iterator l = tgts.begin(); diff --git a/Source/cmLocalVisualStudio6Generator.h b/Source/cmLocalVisualStudio6Generator.h index a680633c3..1decc3531 100644 --- a/Source/cmLocalVisualStudio6Generator.h +++ b/Source/cmLocalVisualStudio6Generator.h @@ -34,6 +34,7 @@ public: virtual ~cmLocalVisualStudio6Generator(); virtual void AddHelperCommands(); + virtual void AddCMakeListsRules(); /** * Generate the makefile for this directory. diff --git a/Source/cmLocalVisualStudio7Generator.cxx b/Source/cmLocalVisualStudio7Generator.cxx index 363d3702b..9faf46ddf 100644 --- a/Source/cmLocalVisualStudio7Generator.cxx +++ b/Source/cmLocalVisualStudio7Generator.cxx @@ -100,6 +100,28 @@ void cmLocalVisualStudio7Generator::Generate() this->WriteStampFiles(); } +void cmLocalVisualStudio7Generator::AddCMakeListsRules() +{ + cmTargets &tgts = this->Makefile->GetTargets(); + // 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. + for(cmTargets::iterator l = tgts.begin(); l != tgts.end(); ++l) + { + if(l->first != CMAKE_CHECK_BUILD_SYSTEM_TARGET) + { + l->second.AddSourceFile(sf); + } + } + } + } +} + void cmLocalVisualStudio7Generator::FixGlobalTargets() { // Visual Studio .NET 2003 Service Pack 1 will not run post-build @@ -156,24 +178,6 @@ void cmLocalVisualStudio7Generator::WriteProjectFiles() // Get the set of targets in this directory. cmTargets &tgts = this->Makefile->GetTargets(); - // 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. - for(cmTargets::iterator l = tgts.begin(); l != tgts.end(); ++l) - { - if(l->first != CMAKE_CHECK_BUILD_SYSTEM_TARGET) - { - l->second.AddSourceFile(sf); - } - } - } - } - // Create the project file for each target. for(cmTargets::iterator l = tgts.begin(); l != tgts.end(); l++) diff --git a/Source/cmLocalVisualStudio7Generator.h b/Source/cmLocalVisualStudio7Generator.h index 9d3a9f29c..9aa408eda 100644 --- a/Source/cmLocalVisualStudio7Generator.h +++ b/Source/cmLocalVisualStudio7Generator.h @@ -64,6 +64,7 @@ public: virtual void ReadAndStoreExternalGUID(const char* name, const char* path); + virtual void AddCMakeListsRules(); protected: void CreateSingleVCProj(const char *lname, cmTarget &tgt); private: diff --git a/Source/cmLocalVisualStudioGenerator.h b/Source/cmLocalVisualStudioGenerator.h index 410cc9a52..9968592d1 100644 --- a/Source/cmLocalVisualStudioGenerator.h +++ b/Source/cmLocalVisualStudioGenerator.h @@ -58,6 +58,8 @@ public: virtual std::string ComputeLongestObjectDirectory(cmTarget&) const = 0; + virtual void AddCMakeListsRules() = 0; + protected: virtual const char* ReportErrorLabel() const; virtual bool CustomCommandUseLocal() const { return false; }