diff options
-rw-r--r-- | Source/cmAddCustomTargetCommand.cxx | 57 | ||||
-rw-r--r-- | Source/cmCMakeMinimumRequired.h | 7 | ||||
-rw-r--r-- | Source/cmCMakePolicyCommand.h | 6 | ||||
-rw-r--r-- | Source/cmConfigureFileCommand.cxx | 21 | ||||
-rw-r--r-- | Source/cmFindBase.cxx | 14 | ||||
-rw-r--r-- | Source/cmListFileCache.cxx | 3 | ||||
-rw-r--r-- | Source/cmLocalGenerator.cxx | 32 | ||||
-rw-r--r-- | Source/cmMakefile.cxx | 43 | ||||
-rw-r--r-- | Source/cmPolicies.cxx | 86 | ||||
-rw-r--r-- | Source/cmPolicies.h | 12 | ||||
-rw-r--r-- | Source/cmake.cxx | 27 | ||||
-rw-r--r-- | Tests/MakeClean/ToClean/CMakeLists.txt | 1 | ||||
-rw-r--r-- | Tests/Preprocess/CMakeLists.txt | 1 |
13 files changed, 128 insertions, 182 deletions
diff --git a/Source/cmAddCustomTargetCommand.cxx b/Source/cmAddCustomTargetCommand.cxx index 07f00ea..9a3b4b3 100644 --- a/Source/cmAddCustomTargetCommand.cxx +++ b/Source/cmAddCustomTargetCommand.cxx @@ -21,18 +21,6 @@ bool cmAddCustomTargetCommand ::InitialPass(std::vector<std::string> const& args, cmExecutionStatus& status) { - // This enum must be before an enum is used in a switch statment. - // If not there is an ICE on the itanium version of gcc we are running - // on dash8 - - // Keep track of parser state. - enum tdoing { - doing_command, - doing_depends, - doing_working_directory, - doing_comment, - doing_verbatim - }; if(args.size() < 1 ) { this->SetError("called with incorrect number of arguments"); @@ -41,34 +29,20 @@ bool cmAddCustomTargetCommand // Check the target name. if(args[0].find_first_of("/\\") != args[0].npos) - { - // slashes are not allowed anymore in taret names CMP_0001 - switch (this->Makefile->GetPolicyStatus(cmPolicies::CMP_0001)) { - case cmPolicies::WARN: - this->Makefile->IssueWarning( - this->Makefile->GetPolicies()->GetPolicyWarning - (cmPolicies::CMP_0001)); - case cmPolicies::OLD: -// if (this->Makefile->IsBWCompatibilityLessThan(2,2)) -// { -// break; -// } - case cmPolicies::NEW: - this->SetError("You included a / or \\ in your target name and " - "this is not allowed according to policy CMP_0001. Run " - "cmake --help-policy CMP_0001 for more information."); - return false; - case cmPolicies::REQUIRED_IF_USED: - case cmPolicies::REQUIRED_ALWAYS: - this->Makefile->IssueError( - this->Makefile->GetPolicies()->GetRequiredPolicyError - (cmPolicies::CMP_0001).c_str() - ); - return false; + if(!this->Makefile->NeedBackwardsCompatibility(2,2)) + { + cmOStringStream e; + e << "called with invalid target name \"" << args[0] + << "\". Target names may not contain a slash. " + << "Use ADD_CUSTOM_COMMAND to generate files. " + << "Set CMAKE_BACKWARDS_COMPATIBILITY to 2.2 " + << "or lower to skip this check."; + this->SetError(e.str().c_str()); + return false; + } } - } - + // Accumulate one command line at a time. cmCustomCommandLine currentLine; @@ -83,6 +57,13 @@ bool cmAddCustomTargetCommand const char* comment = 0; // Keep track of parser state. + enum tdoing { + doing_command, + doing_depends, + doing_working_directory, + doing_comment, + doing_verbatim + }; tdoing doing = doing_command; // Look for the ALL option. diff --git a/Source/cmCMakeMinimumRequired.h b/Source/cmCMakeMinimumRequired.h index d7a1b7e..25e77f3 100644 --- a/Source/cmCMakeMinimumRequired.h +++ b/Source/cmCMakeMinimumRequired.h @@ -70,6 +70,13 @@ public: " [FATAL_ERROR])\n" "If the current version of CMake is lower than that required " "it will stop processing the project and report an error.\n" + "When a version higher than 2.4 is specified the command implicitly " + "invokes\n" + " cmake_policy(VERSION major[.minor[.patch]])\n" + "which sets the cmake policy version level to the version specified.\n" + "When version 2.4 or lower is given the command implicitly invokes\n" + " cmake_policy(VERSION 2.4)\n" + "which enables compatibility features for CMake 2.4 and lower.\n" "The FATAL_ERROR option is accepted but ignored. It is left from " "CMake versions 2.4 and lower in which failure to meet the minimum " "version was a warning by default."; diff --git a/Source/cmCMakePolicyCommand.h b/Source/cmCMakePolicyCommand.h index fcc207e..61f9dd4 100644 --- a/Source/cmCMakePolicyCommand.h +++ b/Source/cmCMakePolicyCommand.h @@ -76,7 +76,11 @@ public: "to WARN, which is like OLD but also produces a warning. " "This effectively requests behavior preferred as of a given CMake " "version and tells newer CMake versions to warn about their new " - "policies." + "policies. " + "The policy version specified must be at least 2.4 or the command " + "will report an error. " + "In order to get compatibility features supporting versions earlier " + "than 2.4 see documentation of policy CMP_0001." "\n" " cmake_policy(SET <CMP_NNNN> NEW)\n" " cmake_policy(SET <CMP_NNNN> OLD)\n" diff --git a/Source/cmConfigureFileCommand.cxx b/Source/cmConfigureFileCommand.cxx index d768886..cac2552 100644 --- a/Source/cmConfigureFileCommand.cxx +++ b/Source/cmConfigureFileCommand.cxx @@ -40,29 +40,10 @@ bool cmConfigureFileCommand this->CopyOnly = false; this->EscapeQuotes = false; - // for CMake 2.0 and earlier CONFIGURE_FILE defaults to the FinalPass, // after 2.0 it only does InitialPass - this->Immediate = false; - const char* versionValue - = this->Makefile->GetDefinition("CMAKE_BACKWARDS_COMPATIBILITY"); - if (versionValue && atof(versionValue) > 2.0) - { - this->Immediate = true; - } + this->Immediate = !this->Makefile->NeedBackwardsCompatibility(2,0); - switch (this->Makefile->GetPolicyStatus(cmPolicies::CMP_0003)) - { - case cmPolicies::WARN: - case cmPolicies::OLD: - break; - case cmPolicies::NEW: - case cmPolicies::REQUIRED_IF_USED: - case cmPolicies::REQUIRED_ALWAYS: - this->Immediate = true; - } - - this->AtOnly = false; for(unsigned int i=2;i < args.size();++i) { diff --git a/Source/cmFindBase.cxx b/Source/cmFindBase.cxx index 14987ac..f5f1430 100644 --- a/Source/cmFindBase.cxx +++ b/Source/cmFindBase.cxx @@ -109,19 +109,7 @@ bool cmFindBase::ParseArguments(std::vector<std::string> const& argsIn) // CMake versions below 2.3 did not search all these extra // locations. Preserve compatibility unless a modern argument is // passed. - bool compatibility = false; - const char* versionValue = - this->Makefile->GetDefinition("CMAKE_BACKWARDS_COMPATIBILITY"); - int major = 0; - int minor = 0; - if(versionValue && sscanf(versionValue, "%d.%d", &major, &minor) != 2) - { - versionValue = 0; - } - if(versionValue && (major < 2 || major == 2 && minor < 3)) - { - compatibility = true; - } + bool compatibility = this->Makefile->NeedBackwardsCompatibility(2,3); // copy argsIn into args so it can be modified, // in the process extract the DOC "documentation" diff --git a/Source/cmListFileCache.cxx b/Source/cmListFileCache.cxx index 234c8e5..55604a6 100644 --- a/Source/cmListFileCache.cxx +++ b/Source/cmListFileCache.cxx @@ -149,6 +149,9 @@ bool cmListFile::ParseFile(const char* filename, mf->IssueWarning( mf->GetPolicies()->GetPolicyWarning(cmPolicies::CMP_0000) ); + + // Implicitly set the version for the user. + mf->SetPolicyVersion("2.4"); case cmPolicies::OLD: break; default: diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index f96704f..76b843a 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -1195,15 +1195,7 @@ void cmLocalGenerator::GetIncludeDirectories(std::vector<std::string>& dirs, // CMake versions below 2.0 would add the source tree to the -I path // automatically. Preserve compatibility. - const char* versionValue = - this->Makefile->GetDefinition("CMAKE_BACKWARDS_COMPATIBILITY"); - int major = 0; - int minor = 0; - if(versionValue && sscanf(versionValue, "%d.%d", &major, &minor) != 2) - { - versionValue = 0; - } - if(versionValue && major < 2) + if(this->NeedBackwardsCompatibility(1,9)) { includeSourceDir = true; } @@ -2679,6 +2671,28 @@ bool cmLocalGenerator::NeedBackwardsCompatibility(unsigned int major, unsigned int minor, unsigned int patch) { + // Check the policy to decide whether to pay attention to this + // variable. + switch(this->Makefile->GetPolicyStatus(cmPolicies::CMP_0001)) + { + case cmPolicies::WARN: + // WARN is just OLD without warning because user code does not + // always affect whether this check is done. + case cmPolicies::OLD: + // Old behavior is to check the variable. + break; + case cmPolicies::NEW: + // New behavior is to ignore the variable. + return false; + case cmPolicies::REQUIRED_IF_USED: + case cmPolicies::REQUIRED_ALWAYS: + // This will never be the case because the only way to require + // the setting is to require the user to specify version policy + // 2.6 or higher. Once we add that requirement then this whole + // method can be removed anyway. + return false; + } + // Compatibility is needed if CMAKE_BACKWARDS_COMPATIBILITY is set // equal to or lower than the given version. unsigned int actual_compat = this->GetBackwardsCompatibility(); diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 1f3bda8..aaea0de 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -1143,13 +1143,8 @@ void cmMakefile::AddLinkLibraryForTarget(const char *target, this->GetCMakeInstance()->GetGlobalGenerator()->FindTarget(0,lib); if(tgt) { - bool allowModules = true; - const char* versionValue - = this->GetDefinition("CMAKE_BACKWARDS_COMPATIBILITY"); - if (versionValue && (atof(versionValue) >= 2.4) ) - { - allowModules = false; - } + // CMake versions below 2.4 allowed linking to modules. + bool allowModules = this->NeedBackwardsCompatibility(2,3); // if it is not a static or shared library then you can not link to it if(!((tgt->GetType() == cmTarget::STATIC_LIBRARY) || (tgt->GetType() == cmTarget::SHARED_LIBRARY) || @@ -2092,15 +2087,7 @@ const char *cmMakefile::ExpandVariablesInString(std::string& source, << ":" << line << ":\n" << parser.GetError() << ", when parsing string \"" << source.c_str() << "\""; - const char* versionValue - = this->GetDefinition("CMAKE_BACKWARDS_COMPATIBILITY"); - int major = 0; - int minor = 0; - if ( versionValue ) - { - sscanf(versionValue, "%d.%d", &major, &minor); - } - if ( major < 2 || major == 2 && minor < 1 ) + if(this->NeedBackwardsCompatibility(2,0)) { cmSystemTools::Error(error.str().c_str()); cmSystemTools::SetFatalErrorOccured(); @@ -3333,9 +3320,7 @@ bool cmMakefile::EnforceUniqueName(std::string const& name, std::string& msg, "\n" "If you are building an older project it is possible that " "it violated this rule but was working accidentally because " - "CMake did not previously diagnose this problem. " - "Set CMAKE_BACKWARDS_COMPATIBILITY to 2.4 or lower to disable " - "this error.\n"; + "CMake did not previously diagnose this problem.\n"; if(isCustom && existing->GetType() == cmTarget::UTILITY) { e << @@ -3422,6 +3407,26 @@ bool cmMakefile::SetPolicy(cmPolicies::PolicyID id, IsValidPolicyStatus(id,status)) { this->PolicyStack.back()[id] = status; + + // Special hook for presenting compatibility variable as soon as + // the user requests it. + if(id == cmPolicies::CMP_0001 && + (status == cmPolicies::WARN || status == cmPolicies::OLD)) + { + if(!(this->GetCacheManager() + ->GetCacheValue("CMAKE_BACKWARDS_COMPATIBILITY"))) + { + // Set it to 2.4 because that is the last version where the + // variable had meaning. + this->AddCacheDefinition + ("CMAKE_BACKWARDS_COMPATIBILITY", "2.4", + "For backwards compatibility, what version of CMake " + "commands and " + "syntax should this version of CMake try to support.", + cmCacheManager::STRING); + } + } + return true; } return false; diff --git a/Source/cmPolicies.cxx b/Source/cmPolicies.cxx index 79fecc3..bc123b1 100644 --- a/Source/cmPolicies.cxx +++ b/Source/cmPolicies.cxx @@ -84,7 +84,8 @@ public: cmPolicies::cmPolicies() { // define all the policies - this->DefinePolicy(CMP_0000, "CMP_0000", + this->DefinePolicy( + CMP_0000, "CMP_0000", "Missing a CMake version specification. You must have a cmake_policy " "call.", "CMake requires that projects specify what version of CMake they have " @@ -94,36 +95,32 @@ cmPolicies::cmPolicies() "2.6 in that example with the verison of CMake you are writing to. " "This policy is being put in place because it aids us in detecting " "and maintaining backwards compatibility.", - 2,6,0, cmPolicies::WARN); -// this->PolicyStringMap["CMP_POLICY_SPECIFICATION"] = CMP_0000; - - this->DefinePolicy(CMP_0001, "CMP_0001", - "CMake does not allow target names to include slash characters.", - "CMake requires that target names not include any / or \\ characters " - "please change the name of any targets to not use such characters." - , - 2,4,0, cmPolicies::REQUIRED_IF_USED); -// this->PolicyStringMap["CMP_TARGET_NAMES_WITH_SLASHES"] = CMP_0001; - - this->DefinePolicy(CMP_0002, "CMP_0002", - "CMake requires that target names be globaly unique.", - "CMake requires that target names not include any / or \\ characters " - "please change the name of any targets to not use such characters." - , - 2,6,0, cmPolicies::WARN); -// this->PolicyStringMap["CMP_REQUIRE_UNIQUE_TARGET_NAMES"] = CMP_0002; + 2,6,0, cmPolicies::WARN + ); - this->DefinePolicy(CMP_0003, "CMP_0003", - "CMake configures file immediately after 2.0.", - "In CMake 2.0 and earlier the configure_file command would not " - "configure the file until after processing all CMakeLists files. " - "In CMake 2.2 and later the default behavior is that it will " - "configure the file right when the command is invoked." - , - 2,6,0, cmPolicies::NEW); -// this->PolicyStringMap["CMP_CONFIGURE_FILE_IMMEDIATE"] = CMP_0003; + this->DefinePolicy( + CMP_0001, "CMP_0001", + "CMAKE_BACKWARDS_COMPATIBILITY should no longer be used.", + "The OLD behavior is to check CMAKE_BACKWARDS_COMPATIBILITY and present " + "it to the user. " + "The NEW behavior is to ignore CMAKE_BACKWARDS_COMPATIBILITY " + "completely.\n" + "In CMake 2.4 and below the variable CMAKE_BACKWARDS_COMPATIBILITY was " + "used to request compatibility with earlier versions of CMake. " + "In CMake 2.6 and above all compatibility issues are handled by policies " + "and the cmake_policy command. " + "However, CMake must still check CMAKE_BACKWARDS_COMPATIBILITY for " + "projects written for CMake 2.4 and below.", + 2,6,0, cmPolicies::WARN + ); - } + this->DefinePolicy( + CMP_0002, "CMP_0002", + "CMake requires that target names be globaly unique.", + "....", + 2,6,0, cmPolicies::WARN + ); +} cmPolicies::~cmPolicies() { @@ -187,27 +184,18 @@ bool cmPolicies::ApplyPolicyVersion(cmMakefile *mf, // it is an error if the policy version is less than 2.4 if (majorVer < 2 || majorVer == 2 && minorVer < 4) { - mf->IssueError("An attempt was made to set the policy version of " - "CMake to something earlier than 2.4, this is an error!"); + mf->IssueError( + "An attempt was made to set the policy version of CMake to something " + "earlier than \"2.4\". " + "In CMake 2.4 and below backwards compatibility was handled with the " + "CMAKE_BACKWARDS_COMPATIBILITY variable. " + "In order to get compatibility features supporting versions earlier " + "than 2.4 set policy CMP_0001 to OLD to tell CMake to check the " + "CMAKE_BACKWARDS_COMPATIBILITY variable. " + "One way to so this is to set the policy version to 2.4 exactly." + ); } - - // if the version is 2.4 then make sure the backwards compatibility variable is visible - if (majorVer == 2 && minorVer == 4) - { - // set the default BACKWARDS compatibility to be visible - mf->GetCacheManager()->GetCacheIterator( - "CMAKE_BACKWARDS_COMPATIBILITY").SetType - (cmCacheManager::STRING); - // const char *cbcValue = - // mf->GetCacheManager()-> - // GetCacheValue("CMAKE_BACKWARDS_COMPATIBILITY"); - // mf->AddCacheDefinition - // ("CMAKE_BACKWARDS_COMPATIBILITY",cbcValue, - // "For backwards compatibility, what version of CMake commands and " - // "syntax should this version of CMake allow.", - // cmCacheManager::STRING); - } - + // now loop over all the policies and set them as appropriate std::map<cmPolicies::PolicyID,cmPolicy *>::iterator i = this->Policies.begin(); diff --git a/Source/cmPolicies.h b/Source/cmPolicies.h index 68745da..7e976d6 100644 --- a/Source/cmPolicies.h +++ b/Source/cmPolicies.h @@ -38,12 +38,12 @@ public: enum PolicyStatus { OLD, WARN, NEW, REQUIRED_IF_USED, REQUIRED_ALWAYS }; static const char* PolicyStatusNames[]; - enum PolicyID {CMP_0000, CMP_POLICY_SPECIFICATION = CMP_0000, - CMP_0001, CMP_TARGET_NAMES_WITH_SLASHES = CMP_0001, - CMP_0002, CMP_REQUIRE_UNIQUE_TARGET_NAMES = CMP_0002, - CMP_0003, CMP_CONFIGURE_FILE_IMMEDIATE = CMP_0003 - }; - + enum PolicyID + { + CMP_0000, // Policy version specification + CMP_0001, // Ignore old compatibility variable + CMP_0002 + }; ///! convert a string policy ID into a number bool GetPolicyID(const char *id, /* out */ cmPolicies::PolicyID &pid); diff --git a/Source/cmake.cxx b/Source/cmake.cxx index e9d92b3..356772a 100644 --- a/Source/cmake.cxx +++ b/Source/cmake.cxx @@ -1899,19 +1899,6 @@ int cmake::ActualConfigure() cmCacheManager::INTERNAL); } - // set the default BACKWARDS compatibility to the current version - if(!this->CacheManager->GetCacheValue("CMAKE_BACKWARDS_COMPATIBILITY")) - { - char ver[256]; - sprintf(ver,"%i.%i",cmVersion::GetMajorVersion(), - cmVersion::GetMinorVersion()); - this->CacheManager->AddCacheEntry - ("CMAKE_BACKWARDS_COMPATIBILITY",ver, - "For backwards compatibility, what version of CMake commands and " - "syntax should this version of CMake allow.", - cmCacheManager::INTERNAL); - } - // no generator specified on the command line if(!this->GlobalGenerator) { @@ -2392,20 +2379,6 @@ int cmake::LoadCache() { return -3; } - - // set the default BACKWARDS compatibility to the current version - if(!this->CacheManager->GetCacheValue("CMAKE_BACKWARDS_COMPATIBILITY")) - { - char ver[256]; - sprintf(ver,"%i.%i",cmVersion::GetMajorVersion(), - cmVersion::GetMinorVersion()); - this->CacheManager->AddCacheEntry - ("CMAKE_BACKWARDS_COMPATIBILITY",ver, - "For backwards compatibility, what version of CMake commands and " - "syntax should this version of CMake allow.", - cmCacheManager::INTERNAL); - } - return 0; } diff --git a/Tests/MakeClean/ToClean/CMakeLists.txt b/Tests/MakeClean/ToClean/CMakeLists.txt index bc51876..47542e8 100644 --- a/Tests/MakeClean/ToClean/CMakeLists.txt +++ b/Tests/MakeClean/ToClean/CMakeLists.txt @@ -1,3 +1,4 @@ +cmake_policy(VERSION 2.6) PROJECT(ToClean) # Build a simple project. diff --git a/Tests/Preprocess/CMakeLists.txt b/Tests/Preprocess/CMakeLists.txt index fdda65f..b1f95f4 100644 --- a/Tests/Preprocess/CMakeLists.txt +++ b/Tests/Preprocess/CMakeLists.txt @@ -1,3 +1,4 @@ +cmake_policy(VERSION 2.6) project(Preprocess) # This test is meant both as a test and as a reference for supported |