project: Add optional LANGUAGES keyword
Teach the project() command to recognize an optional "LANGUAGES" keyword after the project name and prior to the list of languages. Do not allow multiple copies of the keyword. If the keyword is specified and no languages are listed, imply NONE.
This commit is contained in:
parent
00007dcc36
commit
16d040c958
|
@ -5,7 +5,7 @@ Set a name and enable languages for the entire project.
|
|||
|
||||
.. code-block:: cmake
|
||||
|
||||
project(<PROJECT-NAME> [<language-name>...])
|
||||
project(<PROJECT-NAME> [LANGUAGES] [<language-name>...])
|
||||
|
||||
Sets the name of the project and stores the name in the
|
||||
:variable:`PROJECT_NAME` variable. Additionally this sets variables
|
||||
|
@ -18,7 +18,8 @@ Sets the name of the project and stores the name in the
|
|||
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
|
||||
given. Specify language ``NONE`` to skip enabling any languages.
|
||||
given. Specify language ``NONE``, or use the ``LANGUAGES`` keyword
|
||||
and list no languages, to skip enabling any languages.
|
||||
|
||||
If a variable exists called :variable:`CMAKE_PROJECT_<PROJECT-NAME>_INCLUDE`,
|
||||
the file pointed to by that variable will be included as the last step of the
|
||||
|
|
|
@ -62,15 +62,33 @@ bool cmProjectCommand
|
|||
"Value Computed by CMake", cmCacheManager::STATIC);
|
||||
}
|
||||
|
||||
bool haveLanguages = false;
|
||||
std::vector<std::string> languages;
|
||||
if(args.size() > 1)
|
||||
for(size_t i = 1; i < args.size(); ++i)
|
||||
{
|
||||
for(size_t i =1; i < args.size(); ++i)
|
||||
if(args[i] == "LANGUAGES")
|
||||
{
|
||||
if(haveLanguages)
|
||||
{
|
||||
this->Makefile->IssueMessage
|
||||
(cmake::FATAL_ERROR, "LANGUAGES may be specified at most once.");
|
||||
cmSystemTools::SetFatalErrorOccured();
|
||||
return true;
|
||||
}
|
||||
haveLanguages = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
languages.push_back(args[i]);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
if (haveLanguages && languages.empty())
|
||||
{
|
||||
languages.push_back("NONE");
|
||||
}
|
||||
|
||||
if (languages.empty())
|
||||
{
|
||||
// if no language is specified do c and c++
|
||||
languages.push_back("C");
|
||||
|
|
|
@ -82,6 +82,7 @@ add_RunCMake_test(include)
|
|||
add_RunCMake_test(include_directories)
|
||||
add_RunCMake_test(list)
|
||||
add_RunCMake_test(message)
|
||||
add_RunCMake_test(project)
|
||||
add_RunCMake_test(string)
|
||||
add_RunCMake_test(try_compile)
|
||||
add_RunCMake_test(set)
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
cmake_minimum_required(VERSION 2.8.4)
|
||||
project(${RunCMake_TEST} NONE)
|
||||
include(${RunCMake_TEST}.cmake)
|
|
@ -0,0 +1 @@
|
|||
ENABLED_LANGUAGES='NONE'
|
|
@ -0,0 +1,3 @@
|
|||
project(ProjectA LANGUAGES)
|
||||
get_property(langs GLOBAL PROPERTY ENABLED_LANGUAGES)
|
||||
message(STATUS "ENABLED_LANGUAGES='${langs}'")
|
|
@ -0,0 +1 @@
|
|||
ENABLED_LANGUAGES='NONE'
|
|
@ -0,0 +1,3 @@
|
|||
project(ProjectA NONE)
|
||||
get_property(langs GLOBAL PROPERTY ENABLED_LANGUAGES)
|
||||
message(STATUS "ENABLED_LANGUAGES='${langs}'")
|
|
@ -0,0 +1 @@
|
|||
ENABLED_LANGUAGES='NONE'
|
|
@ -0,0 +1,3 @@
|
|||
project(ProjectA LANGUAGES NONE)
|
||||
get_property(langs GLOBAL PROPERTY ENABLED_LANGUAGES)
|
||||
message(STATUS "ENABLED_LANGUAGES='${langs}'")
|
|
@ -0,0 +1 @@
|
|||
1
|
|
@ -0,0 +1,4 @@
|
|||
CMake Error at LanguagesTwice.cmake:1 \(project\):
|
||||
LANGUAGES may be specified at most once.
|
||||
Call Stack \(most recent call first\):
|
||||
CMakeLists.txt:3 \(include\)$
|
|
@ -0,0 +1,2 @@
|
|||
project(ProjectA LANGUAGES NONE LANGUAGES)
|
||||
message("This line not reached.")
|
|
@ -0,0 +1,6 @@
|
|||
include(RunCMake)
|
||||
|
||||
run_cmake(LanguagesImplicit)
|
||||
run_cmake(LanguagesEmpty)
|
||||
run_cmake(LanguagesNONE)
|
||||
run_cmake(LanguagesTwice)
|
Loading…
Reference in New Issue