From af1c48871cedc29eb0dc773556c606c670df55ee Mon Sep 17 00:00:00 2001 From: Alex Turbov Date: Sun, 29 Apr 2018 17:09:40 +0300 Subject: CPack: Use project version as default for `CPACK_PACKAGE_VERSION` * Introduce `CMAKE_PROJECT_VERSION` and the corresponsing components: `CMAKE_PROJECT_VERSION_MAJOR`, `CMAKE_PROJECT_VERSION_MINOR`, `CMAKE_PROJECT_VERSION_PATCH` and `CMAKE_PROJECT_VERSION_TWEAK`. * `CPack` module use `CMAKE_PROJECT_VERSION_MAJOR`, `CMAKE_PROJECT_VERSION_MINOR` and `CMAKE_PROJECT_VERSION_PATCH` to initialize corresponsing CPack variables. --- Source/cmProjectCommand.cxx | 54 +++++++++++++++++++++++++-------------------- 1 file changed, 30 insertions(+), 24 deletions(-) (limited to 'Source/cmProjectCommand.cxx') diff --git a/Source/cmProjectCommand.cxx b/Source/cmProjectCommand.cxx index 6ddb0b8927..a25bd6b381 100644 --- a/Source/cmProjectCommand.cxx +++ b/Source/cmProjectCommand.cxx @@ -249,6 +249,12 @@ bool cmProjectCommand::InitialPass(std::vector const& args, vv = projectName + "_VERSION_TWEAK"; this->Makefile->AddDefinition("PROJECT_VERSION_TWEAK", vb[3]); this->Makefile->AddDefinition(vv, vb[3]); + // Also, try set top level variables + TopLevelCMakeVarCondSet("CMAKE_PROJECT_VERSION", vs.c_str()); + TopLevelCMakeVarCondSet("CMAKE_PROJECT_VERSION_MAJOR", vb[0]); + TopLevelCMakeVarCondSet("CMAKE_PROJECT_VERSION_MINOR", vb[1]); + TopLevelCMakeVarCondSet("CMAKE_PROJECT_VERSION_PATCH", vb[2]); + TopLevelCMakeVarCondSet("CMAKE_PROJECT_VERSION_TWEAK", vb[3]); } else if (cmp0048 != cmPolicies::OLD) { // Set project VERSION variables to empty std::vector vv; @@ -262,6 +268,13 @@ bool cmProjectCommand::InitialPass(std::vector const& args, vv.push_back(projectName + "_VERSION_MINOR"); vv.push_back(projectName + "_VERSION_PATCH"); vv.push_back(projectName + "_VERSION_TWEAK"); + if (this->Makefile->IsRootMakefile()) { + vv.push_back("CMAKE_PROJECT_VERSION"); + vv.push_back("CMAKE_PROJECT_VERSION_MAJOR"); + vv.push_back("CMAKE_PROJECT_VERSION_MINOR"); + vv.push_back("CMAKE_PROJECT_VERSION_PATCH"); + vv.push_back("CMAKE_PROJECT_VERSION_TWEAK"); + } std::string vw; for (std::string const& i : vv) { const char* v = this->Makefile->GetDefinition(i); @@ -286,36 +299,14 @@ bool cmProjectCommand::InitialPass(std::vector const& args, this->Makefile->AddDefinition("PROJECT_DESCRIPTION", description.c_str()); this->Makefile->AddDefinition(projectName + "_DESCRIPTION", description.c_str()); - // Set the CMAKE_PROJECT_DESCRIPTION variable to be the highest-level - // project name in the tree. If there are two project commands - // in the same CMakeLists.txt file, and it is the top level - // CMakeLists.txt file, then go with the last one. - if (!this->Makefile->GetDefinition("CMAKE_PROJECT_DESCRIPTION") || - (this->Makefile->IsRootMakefile())) { - this->Makefile->AddDefinition("CMAKE_PROJECT_DESCRIPTION", - description.c_str()); - this->Makefile->AddCacheDefinition( - "CMAKE_PROJECT_DESCRIPTION", description.c_str(), - "Value Computed by CMake", cmStateEnums::STATIC); - } + TopLevelCMakeVarCondSet("CMAKE_PROJECT_DESCRIPTION", description.c_str()); } if (haveHomepage) { this->Makefile->AddDefinition("PROJECT_HOMEPAGE_URL", homepage.c_str()); this->Makefile->AddDefinition(projectName + "_HOMEPAGE_URL", homepage.c_str()); - // Set the CMAKE_PROJECT_HOMEPAGE_URL variable to be the highest-level - // project name in the tree. If there are two project commands - // in the same CMakeLists.txt file, and it is the top level - // CMakeLists.txt file, then go with the last one. - if (!this->Makefile->GetDefinition("CMAKE_PROJECT_HOMEPAGE_URL") || - (this->Makefile->IsRootMakefile())) { - this->Makefile->AddDefinition("CMAKE_PROJECT_HOMEPAGE_URL", - homepage.c_str()); - this->Makefile->AddCacheDefinition( - "CMAKE_PROJECT_HOMEPAGE_URL", homepage.c_str(), - "Value Computed by CMake", cmStateEnums::STATIC); - } + TopLevelCMakeVarCondSet("CMAKE_PROJECT_HOMEPAGE_URL", homepage.c_str()); } if (languages.empty()) { @@ -338,3 +329,18 @@ bool cmProjectCommand::InitialPass(std::vector const& args, } return true; } + +void cmProjectCommand::TopLevelCMakeVarCondSet(const char* const name, + const char* const value) +{ + // Set the CMAKE_PROJECT_XXX variable to be the highest-level + // project name in the tree. If there are two project commands + // in the same CMakeLists.txt file, and it is the top level + // CMakeLists.txt file, then go with the last one. + if (!this->Makefile->GetDefinition(name) || + (this->Makefile->IsRootMakefile())) { + this->Makefile->AddDefinition(name, value); + this->Makefile->AddCacheDefinition(name, value, "Value Computed by CMake", + cmStateEnums::STATIC); + } +} -- cgit v1.2.1