Commit 3b484871 authored by Alex Turbov's avatar Alex Turbov Committed by Brad King

project: Add `DESCRIPTION` parameter

It is quite often the project description has used in a real world software.
Examples include:

* part of a help screen of the application
* builtin resources (`*.rc` files, data for "About" dialog of a GUI app, & etc)
* most generators for CPack can use it
* it could be used by documentary software (Doxygen, Sphinx) which is usually
  integrated to CMake based projects via `add_custom_target()`

Now `project()` call learned an optional `DESCRIPTION` parameter with a
short string describing a project. Being specified, it would set the
`PROJECT_DESCRIPTION` variable which could be used in `configure_file()`
or whatever user wants.  Also `PROJECT_DESCRIPTION` is a default value
for `CPACK_PACKAGE_DESCRIPTION_SUMMARY`.
parent c791fb12
......@@ -8,6 +8,7 @@ Set a name, version, and enable languages for the entire project.
project(<PROJECT-NAME> [LANGUAGES] [<language-name>...])
project(<PROJECT-NAME>
[VERSION <major>[.<minor>[.<patch>[.<tweak>]]]]
[DESCRIPTION <project-description-string>]
[LANGUAGES <language-name>...])
Sets the name of the project and stores the name in the
......@@ -40,6 +41,10 @@ in variables
Variables corresponding to unspecified versions are set to the empty string
(if policy :policy:`CMP0048` is set to ``NEW``).
If optional ``DESCRIPTION`` is given, then additional :variable:`PROJECT_DESCRIPTION`
variable will be set to its argument. The argument must be a string with short
description of the project (only a few words).
Optionally you can specify which languages your project supports.
Example languages are ``C``, ``CXX`` (i.e. C++), ``Fortran``, etc.
By default ``C`` and ``CXX`` are enabled if no language options are
......
......@@ -60,6 +60,7 @@ Variables that Provide Information
/variable/CMAKE_MINOR_VERSION
/variable/CMAKE_PARENT_LIST_FILE
/variable/CMAKE_PATCH_VERSION
/variable/CMAKE_PROJECT_DESCRIPTION
/variable/CMAKE_PROJECT_NAME
/variable/CMAKE_RANLIB
/variable/CMAKE_ROOT
......@@ -97,6 +98,7 @@ Variables that Provide Information
/variable/PROJECT-NAME_VERSION_PATCH
/variable/PROJECT-NAME_VERSION_TWEAK
/variable/PROJECT_BINARY_DIR
/variable/PROJECT_DESCRIPTION
/variable/PROJECT_NAME
/variable/PROJECT_SOURCE_DIR
/variable/PROJECT_VERSION
......
project-description
-------------------
* The :command:`project` command learned an optional ``DESCRIPTION`` parameter.
See :command:`project` command and :variable:`PROJECT_DESCRIPTION` variable.
CMAKE_PROJECT_DESCRIPTION
-------------------------
The description of the current project.
This specifies description of the current project from the closest inherited
:command:`project` command.
PROJECT_DESCRIPTION
-------------------
Short project description given to the project command.
This is the description given to the most recent :command:`project` command.
......@@ -98,7 +98,12 @@
#
# .. variable:: CPACK_PACKAGE_DESCRIPTION_SUMMARY
#
# Short description of the project (only a few words).
# Short description of the project (only a few words). Default value is::
#
# ${PROJECT_DESCRIPTION}
#
# if DESCRIPTION has given to the project() call or
# CMake generated string with PROJECT_NAME otherwise.
#
# .. variable:: CPACK_PACKAGE_FILE_NAME
#
......@@ -360,8 +365,13 @@ _cpack_set_default(CPACK_PACKAGE_VERSION_PATCH "1")
_cpack_set_default(CPACK_PACKAGE_VERSION
"${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}")
_cpack_set_default(CPACK_PACKAGE_VENDOR "Humanity")
_cpack_set_default(CPACK_PACKAGE_DESCRIPTION_SUMMARY
"${CMAKE_PROJECT_NAME} built using CMake")
if(CMAKE_PROJECT_DESCRIPTION)
_cpack_set_default(CPACK_PACKAGE_DESCRIPTION_SUMMARY
"${CMAKE_PROJECT_DESCRIPTION}")
else()
_cpack_set_default(CPACK_PACKAGE_DESCRIPTION_SUMMARY
"${CMAKE_PROJECT_NAME} built using CMake")
endif()
_cpack_set_default(CPACK_PACKAGE_DESCRIPTION_FILE
"${CMAKE_ROOT}/Templates/CPack.GenericDescription.txt")
......
......@@ -62,10 +62,13 @@ bool cmProjectCommand::InitialPass(std::vector<std::string> const& args,
bool haveVersion = false;
bool haveLanguages = false;
bool haveDescription = false;
std::string version;
std::string description;
std::vector<std::string> languages;
enum Doing
{
DoingDescription,
DoingLanguages,
DoingVersion
};
......@@ -89,9 +92,21 @@ bool cmProjectCommand::InitialPass(std::vector<std::string> const& args,
}
haveVersion = true;
doing = DoingVersion;
} else if (args[i] == "DESCRIPTION") {
if (haveDescription) {
this->Makefile->IssueMessage(
cmake::FATAL_ERROR, "DESCRITPION may be specified at most once.");
cmSystemTools::SetFatalErrorOccured();
return true;
}
haveDescription = true;
doing = DoingDescription;
} else if (doing == DoingVersion) {
doing = DoingLanguages;
version = args[i];
} else if (doing == DoingDescription) {
doing = DoingLanguages;
description = args[i];
} else // doing == DoingLanguages
{
languages.push_back(args[i]);
......@@ -197,6 +212,22 @@ bool cmProjectCommand::InitialPass(std::vector<std::string> const& args,
}
}
if (haveDescription) {
this->Makefile->AddDefinition("PROJECT_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);
}
}
if (languages.empty()) {
// if no language is specified do c and c++
languages.push_back("C");
......
cmake_policy(SET CMP0048 NEW)
project(ProjectDescriptionTest VERSION 1.0.0 DESCRIPTION "Test Project" LANGUAGES)
if(NOT PROJECT_DESCRIPTION)
message(FATAL_ERROR "PROJECT_DESCRIPTION expected to be set")
endif()
message(STATUS "PROJECT_DESCRIPTION=${PROJECT_DESCRIPTION}")
DESCRITPION may be specified at most once.
cmake_policy(SET CMP0048 NEW)
project(ProjectDescriptionTest VERSION 1.0.0 DESCRIPTION "Test Project" DESCRIPTION "Only once allowed" LANGUAGES)
......@@ -7,6 +7,8 @@ run_cmake(LanguagesImplicit)
run_cmake(LanguagesEmpty)
run_cmake(LanguagesNONE)
run_cmake(LanguagesTwice)
run_cmake(ProjectDescription)
run_cmake(ProjectDescription2)
run_cmake(VersionAndLanguagesEmpty)
run_cmake(VersionEmpty)
run_cmake(VersionInvalid)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment