CMAKE-LANGUAGE(7) CMake CMAKE-LANGUAGE(7)
NAME
cmake-language - CMake Language Reference
ORGANIZATION
CMake input files are written in the CMake Language in source files
named CMakeLists.txt or ending in a .cmake file name extension.
CMake Language source files in a project are organized into:
o Directories (CMakeLists.txt),
o Scripts (<script>.cmake), and
o Modules (<module>.cmake).
Directories
When CMake processes a project source tree, the entry point is a source
file called CMakeLists.txt in the top-level source directory. This
file may contain the entire build specification or use the add_subdi-
rectory() command to add subdirectories to the build. Each subdirec-
tory added by the command must also contain a CMakeLists.txt file as
the entry point to that directory. For each source directory whose
CMakeLists.txt file is processed CMake generates a corresponding direc-
tory in the build tree to act as the default working and output direc-
tory.
Scripts
An individual <script>.cmake source file may be processed in script
mode by using the cmake(1) command-line tool with the -P option.
Script mode simply runs the commands in the given CMake Language source
file and does not generate a build system. It does not allow CMake
commands that define build targets or actions.
Modules
CMake Language code in either Directories or Scripts may use the in-
clude() command to load a <module>.cmake source file in the scope of
the including context. See the cmake-modules(7) manual page for docu-
mentation of modules included with the CMake distribution. Project
source trees may also provide their own modules and specify their loca-
tion(s) in the CMAKE_MODULE_PATH variable.
SYNTAX
Encoding
A CMake Language source file may be written in 7-bit ASCII text for
maximum portability across all supported platforms. Newlines may be
encoded as either \n or \r\n but will be converted to \n as input files
are read.
Note that the implementation is 8-bit clean so source files may be en-
coded as UTF-8 on platforms with system APIs supporting this encoding.
In addition, CMake 3.2 and above support source files encoded in UTF-8
on Windows (using UTF-16 to call system APIs). Furthermore, CMake 3.0
and above allow a leading UTF-8 Byte-Order Mark in source files.
Source Files
A CMake Language source file consists of zero or more Command Invoca-
tions separated by newlines and optionally spaces and Comments:
file ::= file_element*
file_element ::= command_invocation line_ending |
(bracket_comment|space)* line_ending
line_ending ::= line_comment? newline
space ::= <match '[ \t]+'>
newline ::= <match '\n'>
Note that any source file line not inside Command Arguments or a
Bracket Comment can end in a Line Comment.
Command Invocations
A command invocation is a name followed by paren-enclosed arguments
separated by whitespace:
command_invocation ::= space* identifier space* '(' arguments ')'
identifier ::= <match '[A-Za-z_][A-Za-z0-9_]*'>
arguments ::= argument? separated_arguments*
separated_arguments ::= separation+ argument? |
separation* '(' arguments ')'
separation ::= space | line_ending
For example:
add_executable(hello world.c)
Command names are case-insensitive. Nested unquoted parentheses in the
arguments must balance. Each ( or ) is given to the command invocation
as a literal Unquoted Argument. This may be used in calls to the if()
command to enclose conditions. For example:
if(FALSE AND (FALSE OR TRUE)) # evaluates to FALSE
NOTE:
CMake versions prior to 3.0 require command name identifiers to be
at least 2 characters.
CMake versions prior to 2.8.12 silently accept an Unquoted Argument
or a Quoted Argument immediately following a Quoted Argument and not
separated by any whitespace. For compatibility, CMake 2.8.12 and
higher accept such code but produce a warning.
Command Arguments
There are three types of arguments within Command Invocations:
argument ::= bracket_argument | quoted_argument | unquoted_argument
Bracket Argument
A bracket argument, inspired by Lua long bracket syntax, encloses con-
tent between opening and closing brackets of the same length:
bracket_argument ::= bracket_open bracket_content bracket_close
bracket_open ::= '[' '='* '['
bracket_content ::= <any text not containing a bracket_close with
the same number of '=' as the bracket_open>
bracket_close ::= ']' '='* ']'
An opening bracket is written [ followed by zero or more = followed by
[. The corresponding closing bracket is written ] followed by the same
number of = followed by ]. Brackets do not nest. A unique length may
always be chosen for the opening and closing brackets to contain clos-
ing brackets of other lengths.
Bracket argument content consists of all text between the opening and
closing brackets, except that one newline immediately following the
opening bracket, if any, is ignored. No evaluation of the enclosed
content, such as Escape Sequences or Variable References, is performed.
A bracket argument is always given to the command invocation as exactly
one argument.
For example:
message([=[
This is the first line in a bracket argument with bracket length 1.
No \-escape sequences or ${variable} references are evaluated.
This is always one argument even though it contains a ; character.
The text does not end on a closing bracket of length 0 like ]].
It does end in a closing bracket of length 1.
]=])
NOTE:
CMake versions prior to 3.0 do not support bracket arguments. They
interpret the opening bracket as the start of an Unquoted Argument.
Quoted Argument
A quoted argument encloses content between opening and closing dou-
ble-quote characters:
quoted_argument ::= '"' quoted_element* '"'
quoted_element ::= <any character except '\' or '"'> |
escape_sequence |
quoted_continuation
quoted_continuation ::= '\' newline
Quoted argument content consists of all text between opening.
CMAKE-LANGUAGE(7) CMake CMAKE-LANGUAGE(7)
NAME
cmake-language - CMake Language Reference
ORGANIZATION
CMake input files are written in the CMake Language in source files
named CMakeLists.txt or ending in a .cmake file name extension.
CMake Language source files in a project are organized into:
o Directories (CMakeLists.txt),
o Scripts (<script>.cmake), and
o Modules (<module>.cmake).
Directories
When CMake processes a project source tree, the entry point is a source
file called CMakeLists.txt in the top-level source directory. This
file may contain the entire build specification or use the add_subdi-
rectory() command to add subdirectories to the build. Each subdirec-
tory added by the command must also contain a CMakeLists.txt file as
the entry point to that directory. For each source directory whose
CMakeLists.txt file is processed CMake generates a corresponding direc-
tory in the build tree to act as the default working and output direc-
tory.
Scripts
An individual <script>.cmake source file may be processed in script
mode by using the cmake(1) command-line tool with the -P option.
Script mode simply runs the commands in the given CMake Language source
file and does not generate a build system. It does not allow CMake
commands that define build targets or actions.
Modules
CMake Language code in either Directories or Scripts may use the in-
clude() command to load a <module>.cmake source file in the scope of
the including context. See the cmake-modules(7) manual page for docu-
mentation of modules included with the CMake distribution. Project
source trees may also provide their own modules and specify their loca-
tion(s) in the CMAKE_MODULE_PATH variable.
SYNTAX
Encoding
A CMake Language source file may be written in 7-bit ASCII text for
maximum portability across all supported platforms. Newlines may be
encoded as either \n or \r\n but will be converted to \n as input files
are read.
Note that the implementation is 8-bit clean so source files may be en-
coded as UTF-8 on platforms with system APIs supporting this encoding.
In addition, CMake 3.2 and above support source files encoded in UTF-8
on Windows (using UTF-16 to call system APIs). Furthermore, CMake 3.0
and above allow a leading UTF-8 Byte-Order Mark in source files.
Source Files
A CMake Language source file consists of zero or more Command Invoca-
tions separated by newlines and optionally spaces and Comments:
file ::= file_element*
file_element ::= command_invocation line_ending |
(bracket_comment|space)* line_ending
line_ending ::= line_comment? newline
space ::= <match '[ \t]+'>
newline ::= <match '\n'>
Note that any source file line not inside Command Arguments or a
Bracket Comment can end in a Line Comment.
Command Invocations
A command invocation is a name followed by paren-enclosed arguments
separated by whitespace:
command_invocation ::= space* identifier space* '(' arguments ')'
identifier ::= <match '[A-Za-z_][A-Za-z0-9_]*'>
arguments ::= argument? separated_arguments*
separated_arguments ::= separation+ argument? |
separation* '(' arguments ')'
separation ::= space | line_ending
For example:
add_executable(hello world.c)
Command names are case-insensitive. Nested unquoted parentheses in the
arguments must balance. Each ( or ) is given to the command invocation
as a literal Unquoted Argument. This may be used in calls to the if()
command to enclose conditions. For example:
if(FALSE AND (FALSE OR TRUE)) # evaluates to FALSE
NOTE:
CMake versions prior to 3.0 require command name identifiers to be
at least 2 characters.
CMake versions prior to 2.8.12 silently accept an Unquoted Argument
or a Quoted Argument immediately following a Quoted Argument and not
separated by any whitespace. For compatibility, CMake 2.8.12 and
higher accept such code but produce a warning.
Command Arguments
There are three types of arguments within Command Invocations:
argument ::= bracket_argument | quoted_argument | unquoted_argument
Bracket Argument
A bracket argument, inspired by Lua long bracket syntax, encloses con-
tent between opening and closing brackets of the same length:
bracket_argument ::= bracket_open bracket_content bracket_close
bracket_open ::= '[' '='* '['
bracket_content ::= <any text not containing a bracket_close with
the same number of '=' as the bracket_open>
bracket_close ::= ']' '='* ']'
An opening bracket is written [ followed by zero or more = followed by
[. The corresponding closing bracket is written ] followed by the same
number of = followed by ]. Brackets do not nest. A unique length may
always be chosen for the opening and closing brackets to contain clos-
ing brackets of other lengths.
Bracket argument content consists of all text between the opening and
closing brackets, except that one newline immediately following the
opening bracket, if any, is ignored. No evaluation of the enclosed
content, such as Escape Sequences or Variable References, is performed.
A bracket argument is always given to the command invocation as exactly
one argument.
For example:
message([=[
This is the first line in a bracket argument with bracket length 1.
No \-escape sequences or ${variable} references are evaluated.
This is always one argument even though it contains a ; character.
The text does not end on a closing bracket of length 0 like ]].
It does end in a closing bracket of length 1.
]=])
NOTE:
CMake versions prior to 3.0 do not support bracket arguments. They
interpret the opening bracket as the start of an Unquoted Argument.
Quoted Argument
A quoted argument encloses content between opening and closing dou-
ble-quote characters:
quoted_argument ::= '"' quoted_element* '"'
quoted_element ::= <any character except '\' or '"'> |
escape_sequence |
quoted_continuation
quoted_continuation ::= '\' newline
Quoted argument content consists of all text between opening.
CMAKE-LANGUAGE(7) CMake CMAKE-LANGUAGE(7)
NAME
cmake-language - CMake Language Reference
ORGANIZATION
CMake input files are written in the CMake Language in source files
named CMakeLists.txt or ending in a .cmake file name extension.
CMake Language source files in a project are organized into:
o Directories (CMakeLists.txt),
o Scripts (<script>.cmake), and
o Modules (<module>.cmake).
Directories
When CMake processes a project source tree, the entry point is a source
file called CMakeLists.txt in the top-level source directory. This
file may contain the entire build specification or use the add_subdi-
rectory() command to add subdirectories to the build. Each subdirec-
tory added by the command must also contain a CMakeLists.txt file as
the entry point to that directory. For each source directory whose
CMakeLists.txt file is processed CMake generates a corresponding direc-
tory in the build tree to act as the default working and output direc-
tory.
Scripts
An individual <script>.cmake source file may be processed in script
mode by using the cmake(1) command-line tool with the -P option.
Script mode simply runs the commands in the given CMake Language source
file and does not generate a build system. It does not allow CMake
commands that define build targets or actions.
Modules
CMake Language code in either Directories or Scripts may use the in-
clude() command to load a <module>.cmake source file in the scope of
the including context. See the cmake-modules(7) manual page for docu-
mentation of modules included with the CMake distribution. Project
source trees may also provide their own modules and specify their loca-
tion(s) in the CMAKE_MODULE_PATH variable.
SYNTAX
Encoding
A CMake Language source file may be written in 7-bit ASCII text for
maximum portability across all supported platforms. Newlines may be
encoded as either \n or \r\n but will be converted to \n as input files
are read.
Note that the implementation is 8-bit clean so source files may be en-
coded as UTF-8 on platforms with system APIs supporting this encoding.
In addition, CMake 3.2 and above support source files encoded in UTF-8
on Windows (using UTF-16 to call system APIs). Furthermore, CMake 3.0
and above allow a leading UTF-8 Byte-Order Mark in source files.
Source Files
A CMake Language source file consists of zero or more Command Invoca-
tions separated by newlines and optionally spaces and Comments:
file ::= file_element*
file_element ::= command_invocation line_ending |
(bracket_comment|space)* line_ending
line_ending ::= line_comment? newline
space ::= <match '[ \t]+'>
newline ::= <match '\n'>
Note that any source file line not inside Command Arguments or a
Bracket Comment can end in a Line Comment.
Command Invocations
A command invocation is a name followed by paren-enclosed arguments
separated by whitespace:
command_invocation ::= space* identifier space* '(' arguments ')'
identifier ::= <match '[A-Za-z_][A-Za-z0-9_]*'>
arguments ::= argument? separated_arguments*
separated_arguments ::= separation+ argument? |
separation* '(' arguments ')'
separation ::= space | line_ending
For example:
add_executable(hello world.c)
Command names are case-insensitive. Nested unquoted parentheses in the
arguments must balance. Each ( or ) is given to the command invocation
as a lit
3.18.4 September 13, 2021 CMAKE-LANGUAGE(7)
Czas wygenerowania: 0.00032 sek.
Created with the man page lookup class by Andrew Collington.
Based on a C man page viewer by Vadim Pavlov
Unicode soft-hyphen fix (as used by RedHat) by Dan Edwards
Some optimisations by Eli Argon
Caching idea and code contribution by James Richardson
Copyright © 2003-2025 Linux.pl
Hosted by Hosting Linux.pl