mirror of
https://github.com/Kitware/CMake.git
synced 2025-10-17 15:32:10 +08:00
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`.
This commit is contained in:
@@ -8,6 +8,7 @@ Set a name, version, and enable languages for the entire project.
|
|||||||
project(<PROJECT-NAME> [LANGUAGES] [<language-name>...])
|
project(<PROJECT-NAME> [LANGUAGES] [<language-name>...])
|
||||||
project(<PROJECT-NAME>
|
project(<PROJECT-NAME>
|
||||||
[VERSION <major>[.<minor>[.<patch>[.<tweak>]]]]
|
[VERSION <major>[.<minor>[.<patch>[.<tweak>]]]]
|
||||||
|
[DESCRIPTION <project-description-string>]
|
||||||
[LANGUAGES <language-name>...])
|
[LANGUAGES <language-name>...])
|
||||||
|
|
||||||
Sets the name of the project and stores the name in the
|
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
|
Variables corresponding to unspecified versions are set to the empty string
|
||||||
(if policy :policy:`CMP0048` is set to ``NEW``).
|
(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.
|
Optionally you can specify which languages your project supports.
|
||||||
Example languages are ``C``, ``CXX`` (i.e. C++), ``Fortran``, etc.
|
Example languages are ``C``, ``CXX`` (i.e. C++), ``Fortran``, etc.
|
||||||
By default ``C`` and ``CXX`` are enabled if no language options are
|
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_MINOR_VERSION
|
||||||
/variable/CMAKE_PARENT_LIST_FILE
|
/variable/CMAKE_PARENT_LIST_FILE
|
||||||
/variable/CMAKE_PATCH_VERSION
|
/variable/CMAKE_PATCH_VERSION
|
||||||
|
/variable/CMAKE_PROJECT_DESCRIPTION
|
||||||
/variable/CMAKE_PROJECT_NAME
|
/variable/CMAKE_PROJECT_NAME
|
||||||
/variable/CMAKE_RANLIB
|
/variable/CMAKE_RANLIB
|
||||||
/variable/CMAKE_ROOT
|
/variable/CMAKE_ROOT
|
||||||
@@ -97,6 +98,7 @@ Variables that Provide Information
|
|||||||
/variable/PROJECT-NAME_VERSION_PATCH
|
/variable/PROJECT-NAME_VERSION_PATCH
|
||||||
/variable/PROJECT-NAME_VERSION_TWEAK
|
/variable/PROJECT-NAME_VERSION_TWEAK
|
||||||
/variable/PROJECT_BINARY_DIR
|
/variable/PROJECT_BINARY_DIR
|
||||||
|
/variable/PROJECT_DESCRIPTION
|
||||||
/variable/PROJECT_NAME
|
/variable/PROJECT_NAME
|
||||||
/variable/PROJECT_SOURCE_DIR
|
/variable/PROJECT_SOURCE_DIR
|
||||||
/variable/PROJECT_VERSION
|
/variable/PROJECT_VERSION
|
||||||
|
5
Help/release/dev/project_description.rst
Normal file
5
Help/release/dev/project_description.rst
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
project-description
|
||||||
|
-------------------
|
||||||
|
|
||||||
|
* The :command:`project` command learned an optional ``DESCRIPTION`` parameter.
|
||||||
|
See :command:`project` command and :variable:`PROJECT_DESCRIPTION` variable.
|
7
Help/variable/CMAKE_PROJECT_DESCRIPTION.rst
Normal file
7
Help/variable/CMAKE_PROJECT_DESCRIPTION.rst
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
CMAKE_PROJECT_DESCRIPTION
|
||||||
|
-------------------------
|
||||||
|
|
||||||
|
The description of the current project.
|
||||||
|
|
||||||
|
This specifies description of the current project from the closest inherited
|
||||||
|
:command:`project` command.
|
6
Help/variable/PROJECT_DESCRIPTION.rst
Normal file
6
Help/variable/PROJECT_DESCRIPTION.rst
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
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
|
# .. 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
|
# .. variable:: CPACK_PACKAGE_FILE_NAME
|
||||||
#
|
#
|
||||||
@@ -360,8 +365,13 @@ _cpack_set_default(CPACK_PACKAGE_VERSION_PATCH "1")
|
|||||||
_cpack_set_default(CPACK_PACKAGE_VERSION
|
_cpack_set_default(CPACK_PACKAGE_VERSION
|
||||||
"${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}")
|
"${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}")
|
||||||
_cpack_set_default(CPACK_PACKAGE_VENDOR "Humanity")
|
_cpack_set_default(CPACK_PACKAGE_VENDOR "Humanity")
|
||||||
_cpack_set_default(CPACK_PACKAGE_DESCRIPTION_SUMMARY
|
if(CMAKE_PROJECT_DESCRIPTION)
|
||||||
"${CMAKE_PROJECT_NAME} built using CMake")
|
_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
|
_cpack_set_default(CPACK_PACKAGE_DESCRIPTION_FILE
|
||||||
"${CMAKE_ROOT}/Templates/CPack.GenericDescription.txt")
|
"${CMAKE_ROOT}/Templates/CPack.GenericDescription.txt")
|
||||||
|
@@ -62,10 +62,13 @@ bool cmProjectCommand::InitialPass(std::vector<std::string> const& args,
|
|||||||
|
|
||||||
bool haveVersion = false;
|
bool haveVersion = false;
|
||||||
bool haveLanguages = false;
|
bool haveLanguages = false;
|
||||||
|
bool haveDescription = false;
|
||||||
std::string version;
|
std::string version;
|
||||||
|
std::string description;
|
||||||
std::vector<std::string> languages;
|
std::vector<std::string> languages;
|
||||||
enum Doing
|
enum Doing
|
||||||
{
|
{
|
||||||
|
DoingDescription,
|
||||||
DoingLanguages,
|
DoingLanguages,
|
||||||
DoingVersion
|
DoingVersion
|
||||||
};
|
};
|
||||||
@@ -89,9 +92,21 @@ bool cmProjectCommand::InitialPass(std::vector<std::string> const& args,
|
|||||||
}
|
}
|
||||||
haveVersion = true;
|
haveVersion = true;
|
||||||
doing = DoingVersion;
|
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) {
|
} else if (doing == DoingVersion) {
|
||||||
doing = DoingLanguages;
|
doing = DoingLanguages;
|
||||||
version = args[i];
|
version = args[i];
|
||||||
|
} else if (doing == DoingDescription) {
|
||||||
|
doing = DoingLanguages;
|
||||||
|
description = args[i];
|
||||||
} else // doing == DoingLanguages
|
} else // doing == DoingLanguages
|
||||||
{
|
{
|
||||||
languages.push_back(args[i]);
|
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 (languages.empty()) {
|
||||||
// if no language is specified do c and c++
|
// if no language is specified do c and c++
|
||||||
languages.push_back("C");
|
languages.push_back("C");
|
||||||
|
1
Tests/RunCMake/project/ProjectDescription-stdout.txt
Normal file
1
Tests/RunCMake/project/ProjectDescription-stdout.txt
Normal file
@@ -0,0 +1 @@
|
|||||||
|
PROJECT_DESCRIPTION=Test Project
|
6
Tests/RunCMake/project/ProjectDescription.cmake
Normal file
6
Tests/RunCMake/project/ProjectDescription.cmake
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
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}")
|
1
Tests/RunCMake/project/ProjectDescription2-result.txt
Normal file
1
Tests/RunCMake/project/ProjectDescription2-result.txt
Normal file
@@ -0,0 +1 @@
|
|||||||
|
1
|
1
Tests/RunCMake/project/ProjectDescription2-stderr.txt
Normal file
1
Tests/RunCMake/project/ProjectDescription2-stderr.txt
Normal file
@@ -0,0 +1 @@
|
|||||||
|
DESCRITPION may be specified at most once.
|
2
Tests/RunCMake/project/ProjectDescription2.cmake
Normal file
2
Tests/RunCMake/project/ProjectDescription2.cmake
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
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(LanguagesEmpty)
|
||||||
run_cmake(LanguagesNONE)
|
run_cmake(LanguagesNONE)
|
||||||
run_cmake(LanguagesTwice)
|
run_cmake(LanguagesTwice)
|
||||||
|
run_cmake(ProjectDescription)
|
||||||
|
run_cmake(ProjectDescription2)
|
||||||
run_cmake(VersionAndLanguagesEmpty)
|
run_cmake(VersionAndLanguagesEmpty)
|
||||||
run_cmake(VersionEmpty)
|
run_cmake(VersionEmpty)
|
||||||
run_cmake(VersionInvalid)
|
run_cmake(VersionInvalid)
|
||||||
|
Reference in New Issue
Block a user