Commit 16d040c9 authored by Brad King's avatar Brad King
Browse files

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.
parent 00007dcc
......@@ -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)
......
cmake_minimum_required(VERSION 2.8.4)
project(${RunCMake_TEST} NONE)
include(${RunCMake_TEST}.cmake)
project(ProjectA LANGUAGES)
get_property(langs GLOBAL PROPERTY ENABLED_LANGUAGES)
message(STATUS "ENABLED_LANGUAGES='${langs}'")
project(ProjectA NONE)
get_property(langs GLOBAL PROPERTY ENABLED_LANGUAGES)
message(STATUS "ENABLED_LANGUAGES='${langs}'")
project(ProjectA LANGUAGES NONE)
get_property(langs GLOBAL PROPERTY ENABLED_LANGUAGES)
message(STATUS "ENABLED_LANGUAGES='${langs}'")
CMake Error at LanguagesTwice.cmake:1 \(project\):
LANGUAGES may be specified at most once.
Call Stack \(most recent call first\):
CMakeLists.txt:3 \(include\)$
project(ProjectA LANGUAGES NONE LANGUAGES)
message("This line not reached.")
include(RunCMake)
run_cmake(LanguagesImplicit)
run_cmake(LanguagesEmpty)
run_cmake(LanguagesNONE)
run_cmake(LanguagesTwice)
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