From KitwarePublic
cmake version 2.6-patch 0
------------------------------------------------------------------------------
Name
cmake - Cross-Platform Makefile Generator.
------------------------------------------------------------------------------
Usage
cmake [options] <path-to-source>
cmake [options] <path-to-existing-build>
------------------------------------------------------------------------------
Description
The "cmake" executable is the CMake command-line interface. It may be used
to configure projects in scripts. Project configuration settings may be
specified on the command line with the -D option. The -i option will cause
cmake to interactively prompt for such settings.
CMake is a cross-platform build system generator. Projects specify their
build process with platform-independent CMake listfiles included in each
directory of a source tree with the name CMakeLists.txt. Users build a
project by using CMake to generate a build system for a native tool on their
platform.
------------------------------------------------------------------------------
Options
-C <initial-cache>
Pre-load a script to populate the cache.
When cmake is first run in an empty build tree, it creates a
CMakeCache.txt file and populates it with customizable settings for
the project. This option may be used to specify a file from which to
load cache entries before the first pass through the project's cmake
listfiles. The loaded entries take priority over the project's
default values. The given file should be a CMake script containing
SET commands that use the CACHE option, not a cache-format file.
-D <var>:<type>=<value>
Create a cmake cache entry.
When cmake is first run in an empty build tree, it creates a
CMakeCache.txt file and populates it with customizable settings for
the project. This option may be used to specify a setting that takes
priority over the project's default value. The option may be repeated
for as many cache entries as desired.
-U <globbing_expr>
Remove matching entries from CMake cache.
This option may be used to remove one or more variables from the
CMakeCache.txt file, globbing expressions using * and ? are supported.
The option may be repeated for as many cache entries as desired.
Use with care, you can make your CMakeCache.txt non-working.
-G <generator-name>
Specify a makefile generator.
CMake may support multiple native build systems on certain platforms.
A makefile generator is responsible for generating a particular build
system. Possible generator names are specified in the Generators
section.
-Wno-dev
Suppress developer warnings.
Suppress warnings that are meant for the author of the CMakeLists.txt
files.
-Wdev
Enable developer warnings.
Enable warnings that are meant for the author of the CMakeLists.txt
files.
-E
CMake command mode.
For true platform independence, CMake provides a list of commands that
can be used on all systems. Run with -E help for the usage
information.
-i
Run in wizard mode.
Wizard mode runs cmake interactively without a GUI. The user is
prompted to answer questions about the project configuration. The
answers are used to set cmake cache values.
-L[A][H]
List non-advanced cached variables.
List cache variables will run CMake and list all the variables from
the CMake cache that are not marked as INTERNAL or ADVANCED. This
will effectively display current CMake settings, which can be then
changed with -D option. Changing some of the variable may result in
more variables being created. If A is specified, then it will display
also advanced variables. If H is specified, it will also display help
for each variable.
-N
View mode only.
Only load the cache. Do not actually run configure and generate
steps.
-P <file>
Process script mode.
Process the given cmake file as a script written in the CMake
language. No configure or generate step is performed and the cache is
not modified. If variables are defined using -D, this must be done
before the -P argument.
--graphviz=[file]
Generate graphviz of dependencies.
Generate a graphviz input file that will contain all the library and
executable dependencies in the project.
--system-information [file]
Dump information about this system.
Dump a wide range of information about the current system. If run
from the top of a binary tree for a CMake project it will dump
additional information such as the cache, log files etc.
--debug-trycompile
Do not delete the try compile directories..
Do not delete the files and directories created for try_compile calls.
This is useful in debugging failed try_compiles.
--debug-output
Put cmake in a debug mode.
Print extra stuff during the cmake run like stack traces with
message(send_error ) calls.
--help-command cmd [file]
Print help for a single command and exit.
Full documentation specific to the given command is displayed. If a
file is specified, the documentation is written into and the output
format is determined depending on the filename suffix. Supported are
man page, HTML, DocBook and plain text.
--help-command-list [file]
List available listfile commands and exit.
The list contains all commands for which help may be obtained by using
the --help-command argument followed by a command name. If a file is
specified, the documentation is written into and the output format is
determined depending on the filename suffix. Supported are man page,
HTML, DocBook and plain text.
--help-commands [file]
Print help for all commands and exit.
Full documentation specific for all current command is displayed.If a
file is specified, the documentation is written into and the output
format is determined depending on the filename suffix. Supported are
man page, HTML, DocBook and plain text.
--help-compatcommands [file]
Print help for compatibility commands.
Full documentation specific for all compatibility commands is
displayed.If a file is specified, the documentation is written into
and the output format is determined depending on the filename suffix.
Supported are man page, HTML, DocBook and plain text.
--help-module module [file]
Print help for a single module and exit.
Full documentation specific to the given module is displayed.If a file
is specified, the documentation is written into and the output format
is determined depending on the filename suffix. Supported are man
page, HTML, DocBook and plain text.
--help-module-list [file]
List available modules and exit.
The list contains all modules for which help may be obtained by using
the --help-module argument followed by a module name. If a file is
specified, the documentation is written into and the output format is
determined depending on the filename suffix. Supported are man page,
HTML, DocBook and plain text.
--help-modules [file]
Print help for all modules and exit.
Full documentation for all modules is displayed. If a file is
specified, the documentation is written into and the output format is
determined depending on the filename suffix. Supported are man page,
HTML, DocBook and plain text.
--help-custom-modules [file]
Print help for all custom modules and exit.
Full documentation for all custom modules is displayed. If a file is
specified, the documentation is written into and the output format is
determined depending on the filename suffix. Supported are man page,
HTML, DocBook and plain text.
--help-property prop [file]
Print help for a single property and exit.
Full documentation specific to the given property is displayed.If a
file is specified, the documentation is written into and the output
format is determined depending on the filename suffix. Supported are
man page, HTML, DocBook and plain text.
--help-property-list [file]
List available properties and exit.
The list contains all properties for which help may be obtained by
using the --help-property argument followed by a property name. If a
file is specified, the help is written into it.If a file is specified,
the documentation is written into and the output format is determined
depending on the filename suffix. Supported are man page, HTML,
DocBook and plain text.
--help-properties [file]
Print help for all properties and exit.
Full documentation for all properties is displayed.If a file is
specified, the documentation is written into and the output format is
determined depending on the filename suffix. Supported are man page,
HTML, DocBook and plain text.
--help-variable var [file]
Print help for a single variable and exit.
Full documentation specific to the given variable is displayed.If a
file is specified, the documentation is written into and the output
format is determined depending on the filename suffix. Supported are
man page, HTML, DocBook and plain text.
--help-variable-list [file]
List documented variables and exit.
The list contains all variables for which help may be obtained by
using the --help-variable argument followed by a variable name. If a
file is specified, the help is written into it.If a file is specified,
the documentation is written into and the output format is determined
depending on the filename suffix. Supported are man page, HTML,
DocBook and plain text.
--help-variables [file]
Print help for all variables and exit.
Full documentation for all variables is displayed.If a file is
specified, the documentation is written into and the output format is
determined depending on the filename suffix. Supported are man page,
HTML, DocBook and plain text.
--copyright [file]
Print the CMake copyright and exit.
If a file is specified, the copyright is written into it.
--help
Print usage information and exit.
Usage describes the basic command line interface and its options.
--help-full [file]
Print full help and exit.
Full help displays most of the documentation provided by the UNIX man
page. It is provided for use on non-UNIX platforms, but is also
convenient if the man page is not installed. If a file is specified,
the help is written into it.
--help-html [file]
Print full help in HTML format.
This option is used by CMake authors to help produce web pages. If a
file is specified, the help is written into it.
--help-man [file]
Print full help as a UNIX man page and exit.
This option is used by the cmake build to generate the UNIX man page.
If a file is specified, the help is written into it.
--version [file]
Show program name/version banner and exit.
If a file is specified, the version is written into it.
------------------------------------------------------------------------------
Generators
The following generators are available on this platform:
Unix Makefiles
Generates standard UNIX makefiles.
A hierarchy of UNIX makefiles is generated into the build tree. Any
standard UNIX-style make program can build the project through the
default make target. A "make install" target is also provided.
CodeBlocks - Unix Makefiles
Generates CodeBlocks project files.
Project files for CodeBlocks will be created in the top directory and
in every subdirectory which features a CMakeLists.txt file containing
a PROJECT() call. Additionally a hierarchy of makefiles is generated
into the build tree. The appropriate make program can build the
project through the default make target. A "make install" target is
also provided.
Eclipse CDT4 - Unix Makefiles
Generates Eclipse CDT 4.0 project files.
Project files for Eclipse will be created in the top directory and
will have a linked resource to every subdirectory which features a
CMakeLists.txt file containing a PROJECT() call.Additionally a
hierarchy of makefiles is generated into the build tree. The
appropriate make program can build the project through the default
make target. A "make install" target is also provided.
KDevelop3
Generates KDevelop 3 project files.
Project files for KDevelop 3 will be created in the top directory and
in every subdirectory which features a CMakeLists.txt file containing
a PROJECT() call. If you change the settings using KDevelop cmake
will try its best to keep your changes when regenerating the project
files. Additionally a hierarchy of UNIX makefiles is generated into
the build tree. Any standard UNIX-style make program can build the
project through the default make target. A "make install" target is
also provided.
KDevelop3 - Unix Makefiles
Generates KDevelop 3 project files.
Project files for KDevelop 3 will be created in the top directory and
in every subdirectory which features a CMakeLists.txt file containing
a PROJECT() call. If you change the settings using KDevelop cmake
will try its best to keep your changes when regenerating the project
files. Additionally a hierarchy of UNIX makefiles is generated into
the build tree. Any standard UNIX-style make program can build the
project through the default make target. A "make install" target is
also provided.
------------------------------------------------------------------------------
Commands
add_custom_command
Add a custom build rule to the generated build system.
There are two main signatures for add_custom_command The first
signature is for adding a custom command to produce an output.
add_custom_command(OUTPUT output1 [output2 ...]
COMMAND command1 [ARGS] [args1...]
[COMMAND command2 [ARGS] [args2...] ...]
[MAIN_DEPENDENCY depend]
[DEPENDS [depends...]]
[IMPLICIT_DEPENDS <lang1> depend1 ...]
[WORKING_DIRECTORY dir]
[COMMENT comment] [VERBATIM] [APPEND])
This defines a new command that can be executed during the build
process. The outputs named should be listed as source files in the
target for which they are to be generated. If an output name is a
relative path it will be interpreted relative to the build tree
directory corresponding to the current source directory. Note that
MAIN_DEPENDENCY is completely optional and is used as a suggestion to
visual studio about where to hang the custom command. In makefile
terms this creates a new target in the following form:
OUTPUT: MAIN_DEPENDENCY DEPENDS
COMMAND
If more than one command is specified they will be executed in order.
The optional ARGS argument is for backward compatibility and will be
ignored.
The second signature adds a custom command to a target such as a
library or executable. This is useful for performing an operation
before or after building the target. The command becomes part of the
target and will only execute when the target itself is built. If the
target is already built, the command will not execute.
add_custom_command(TARGET target
PRE_BUILD | PRE_LINK | POST_BUILD
COMMAND command1 [ARGS] [args1...]
[COMMAND command2 [ARGS] [args2...] ...]
[WORKING_DIRECTORY dir]
[COMMENT comment] [VERBATIM])
This defines a new command that will be associated with building the
specified target. When the command will happen is determined by which
of the following is specified:
PRE_BUILD - run before all other dependencies
PRE_LINK - run after other dependencies
POST_BUILD - run after the target has been built
Note that the PRE_BUILD option is only supported on Visual Studio 7 or
later. For all other generators PRE_BUILD will be treated as
PRE_LINK.
If WORKING_DIRECTORY is specified the command will be executed in the
directory given. If COMMENT is set, the value will be displayed as a
message before the commands are executed at build time. If APPEND is
specified the COMMAND and DEPENDS option values are appended to the
custom command for the first output specified. There must have
already been a previous call to this command with the same output.
The COMMENT, WORKING_DIRECTORY, and MAIN_DEPENDENCY options are
currently ignored when APPEND is given, but may be used in the future.
If VERBATIM is given then all the arguments to the commands will be
passed exactly as specified no matter the build tool used. Note that
one level of escapes is still used by the CMake language processor
before ADD_CUSTOM_TARGET even sees the arguments. Use of VERBATIM is
recommended as it enables correct behavior. When VERBATIM is not
given the behavior is platform specific. In the future VERBATIM may
be enabled by default. The only reason it is an option is to preserve
compatibility with older CMake code.
If the output of the custom command is not actually created as a file
on disk it should be marked as SYMBOLIC with
SET_SOURCE_FILES_PROPERTIES.
The IMPLICIT_DEPENDS option requests scanning of implicit dependencies
of an input file. The language given specifies the programming
language whose corresponding dependency scanner should be used.
Currently only C and CXX language scanners are supported.
Dependencies discovered from the scanning are added to those of the
custom command at build time. Note that the IMPLICIT_DEPENDS option
is currently supported only for Makefile generators and will be
ignored by other generators.
If COMMAND specifies an executable target (created by ADD_EXECUTABLE)
it will automatically be replaced by the location of the executable
created at build time. Additionally a target-level dependency will be
added so that the executable target will be built before any target
using this custom command. However this does NOT add a file-level
dependency that would cause the custom command to re-run whenever the
executable is recompiled.
If DEPENDS specifies any target (created by an ADD_* command) a
target-level dependency is created to make sure the target is built
before any target using this custom command. Additionally, if the
target is an executable or library a file-level dependency is created
to cause the custom command to re-run whenever the target is
recompiled.
add_custom_target
Add a target with no output so it will always be built.
add_custom_target(Name [ALL] [command1 [args1...]]
[COMMAND command2 [args2...] ...]
[DEPENDS depend depend depend ... ]
[WORKING_DIRECTORY dir]
[COMMENT comment] [VERBATIM])
Adds a target with the given name that executes the given commands.
The target has no output file and is ALWAYS CONSIDERED OUT OF DATE
even if the commands try to create a file with the name of the target.
Use ADD_CUSTOM_COMMAND to generate a file with dependencies. By
default nothing depends on the custom target. Use ADD_DEPENDENCIES to
add dependencies to or from other targets. If the ALL option is
specified it indicates that this target should be added to the default
build target so that it will be run every time (the command cannot be
called ALL). The command and arguments are optional and if not
specified an empty target will be created. If WORKING_DIRECTORY is
set, then the command will be run in that directory. If COMMENT is
set, the value will be displayed as a message before the commands are
executed at build time. Dependencies listed with the DEPENDS argument
may reference files and outputs of custom commands created with
ADD_CUSTOM_COMMAND.
If VERBATIM is given then all the arguments to the commands will be
passed exactly as specified no matter the build tool used. Note that
one level of escapes is still used by the CMake language processor
before add_custom_target even sees the arguments. Use of VERBATIM is
recommended as it enables correct behavior. When VERBATIM is not
given the behavior is platform specific. In the future VERBATIM may
be enabled by default. The only reason it is an option is to preserve
compatibility with older CMake code.
add_definitions
Adds -D define flags to the compilation of source files.
add_definitions(-DFOO -DBAR ...)
Adds flags to the compiler command line for sources in the current
directory and below. This command can be used to add any flags, but
it was originally intended to add preprocessor definitions. Flags
beginning in -D or /D that look like preprocessor definitions are
automatically added to the COMPILE_DEFINITIONS property for the
current directory. Definitions with non-trival values may be left in
the set of flags instead of being converted for reasons of backwards
compatibility. See documentation of the directory, target, and source
file COMPILE_DEFINITIONS properties for details on adding preprocessor
definitions to specific scopes and configurations.
add_dependencies
Add a dependency between top-level targets.
add_dependencies(target-name depend-target1
depend-target2 ...)
Make a top-level target depend on other top-level targets. A
top-level target is one created by ADD_EXECUTABLE, ADD_LIBRARY, or
ADD_CUSTOM_TARGET. Adding dependencies with this command can be used
to make sure one target is built before another target. See the
DEPENDS option of ADD_CUSTOM_TARGET and ADD_CUSTOM_COMMAND for adding
file-level dependencies in custom rules. See the OBJECT_DEPENDS
option in SET_SOURCE_FILES_PROPERTIES to add file-level dependencies
to object files.
add_executable
Add an executable to the project using the specified source files.
add_executable(<name> [WIN32] [MACOSX_BUNDLE] [EXCLUDE_FROM_ALL]
source1 source2 ... sourceN)
Adds an executable target called <name> to be built from the source
files listed in the command invocation. The <name> corresponds to the
logical target name and must be globally unique within a project. The
actual file name of the executable built is constructed based on
conventions of the native platform (such as <name>.exe or just
<name>).
By default the executable file will be created in the build tree
directory corresponding to the source tree directory in which the
command was invoked. See documentation of the
RUNTIME_OUTPUT_DIRECTORY target property to change this location. See
documentation of the OUTPUT_NAME target property to change the <name>
part of the final file name.
If WIN32 is given the property WIN32_EXECUTABLE will be set on the
target created. See documentation of that target property for
details.
If MACOSX_BUNDLE is given the corresponding property will be set on
the created target. See documentation of the MACOSX_BUNDLE target
property for details.
If EXCLUDE_FROM_ALL is given the corresponding property will be set on
the created target. See documentation of the EXCLUDE_FROM_ALL target
property for details.
The add_executable command can also create IMPORTED executable targets
using this signature:
add_executable(<name> IMPORTED)
An IMPORTED executable target references an executable file located
outside the project. No rules are generated to build it. The target
name has scope in the directory in which it is created and below. It
may be referenced like any target built within the project. IMPORTED
executables are useful for convenient reference from commands like
add_custom_command. Details about the imported executable are
specified by setting properties whose names begin in "IMPORTED_". The
most important such property is IMPORTED_LOCATION (and its
per-configuration version IMPORTED_LOCATION_<CONFIG>) which specifies
the location of the main executable file on disk. See documentation
of the IMPORTED_* properties for more information.
add_library
Add a library to the project using the specified source files.
add_library(<name> [STATIC | SHARED | MODULE] [EXCLUDE_FROM_ALL]
source1 source2 ... sourceN)
Adds a library target called <name> to be built from the source files
listed in the command invocation. The <name> corresponds to the
logical target name and must be globally unique within a project. The
actual file name of the library built is constructed based on
conventions of the native platform (such as lib<name>.a or
<name>.lib).
STATIC, SHARED, or MODULE may be given to specify the type of library
to be created. STATIC libraries are archives of object files for use
when linking other targets. SHARED libraries are linked dynamically
and loaded at runtime. MODULE libraries are plugins that are not
linked into other targets but may be loaded dynamically at runtime
using dlopen-like functionality. If no type is given explicitly the
type is STATIC or SHARED based on whether the current value of the
variable BUILD_SHARED_LIBS is true.
By default the library file will be created in the build tree
directory corresponding to the source tree directory in which the
command was invoked. See documentation of the
ARCHIVE_OUTPUT_DIRECTORY, LIBRARY_OUTPUT_DIRECTORY, and
RUNTIME_OUTPUT_DIRECTORY target properties to change this location.
See documentation of the OUTPUT_NAME target property to change the
<name> part of the final file name.
If EXCLUDE_FROM_ALL is given the corresponding property will be set on
the created target. See documentation of the EXCLUDE_FROM_ALL target
property for details.
The add_library command can also create IMPORTED library targets using
this signature:
add_library(<name> <SHARED|STATIC|MODULE> IMPORTED)
An IMPORTED library target references a library file located outside
the project. No rules are generated to build it. The target name has
scope in the directory in which it is created and below. It may be
referenced like any target built within the project. IMPORTED
libraries are useful for convenient reference from commands like
target_link_libraries. Details about the imported library are
specified by setting properties whose names begin in "IMPORTED_". The
most important such property is IMPORTED_LOCATION (and its
per-configuration version IMPORTED_LOCATION_<CONFIG>) which specifies
the location of the main library file on disk. See documentation of
the IMPORTED_* properties for more information.
add_subdirectory
Add a subdirectory to the build.
add_subdirectory(source_dir [binary_dir]
[EXCLUDE_FROM_ALL])
Add a subdirectory to the build. The source_dir specifies the
directory in which the source CmakeLists.txt and code files are
located. If it is a relative path it will be evaluated with respect
to the current directory (the typical usage), but it may also be an
absolute path. The binary_dir specifies the directory in which to
place the output files. If it is a relative path it will be evaluated
with respect to the current output directory, but it may also be an
absolute path. If binary_dir is not specified, the value of
source_dir, before expanding any relative path, will be used (the
typical usage). The CMakeLists.txt file in the specified source
directory will be processed immediately by CMake before processing in
the current input file continues beyond this command.
If the EXCLUDE_FROM_ALL argument is provided then this subdirectory
will not be included in build by default. Users will have to
explicitly start a build in the generated output directory. This is
useful for having cmake create a build system for a set of examples in
a project. One would want cmake to generate a single build system for
all the examples, but one may not want the targets to show up in the
main build system.
add_test
Add a test to the project with the specified arguments.
add_test(testname Exename arg1 arg2 ...)
If the ENABLE_TESTING command has been run, this command adds a test
target to the current directory. If ENABLE_TESTING has not been run,
this command does nothing. The tests are run by the testing subsystem
by executing Exename with the specified arguments. Exename can be
either an executable built by this project or an arbitrary executable
on the system (like tclsh). The test will be run with the current
working directory set to the CMakeList.txt files corresponding
directory in the binary tree.
aux_source_directory
Find all source files in a directory.
aux_source_directory(<dir> <variable>)
Collects the names of all the source files in the specified directory
and stores the list in the <variable> provided. This command is
intended to be used by projects that use explicit template
instantiation. Template instantiation files can be stored in a
"Templates" subdirectory and collected automatically using this
command to avoid manually listing all instantiations.
It is tempting to use this command to avoid writing the list of source
files for a library or executable target. While this seems to work,
there is no way for CMake to generate a build system that knows when a
new source file has been added. Normally the generated build system
knows when it needs to rerun CMake because the CMakeLists.txt file is
modified to add a new source. When the source is just added to the
directory without modifying this file, one would have to manually
rerun CMake to generate a build system incorporating the new file.
break
Break from an enclosing foreach or while loop.
break()
Breaks from an enclosing foreach loop or while loop
build_command
Get the command line that will build this project.
build_command(<variable> <makecommand>)
Sets the given <variable> to a string containing the command that will
build this project from the root of the build tree using the build
tool given by <makecommand>. <makecommand> should be msdev, nmake,
make or one of the end user build tools. This is useful for
configuring testing systems.
cmake_minimum_required
Set the minimum required version of cmake for a project.
cmake_minimum_required(VERSION major[.minor[.patch]]
[FATAL_ERROR])
If the current version of CMake is lower than that required it will
stop processing the project and report an error. When a version
higher than 2.4 is specified the command implicitly invokes
cmake_policy(VERSION major[.minor[.patch]])
which sets the cmake policy version level to the version specified.
When version 2.4 or lower is given the command implicitly invokes
cmake_policy(VERSION 2.4)
which enables compatibility features for CMake 2.4 and lower.
The FATAL_ERROR option is accepted but ignored. It is left from CMake
versions 2.4 and lower in which failure to meet the minimum version
was a warning by default.
cmake_policy
Manage CMake Policy settings.
As CMake evolves it is sometimes necessary to change existing behavior
in order to fix bugs or improve implementations of existing features.
The CMake Policy mechanism is designed to help keep existing projects
building as new versions of CMake introduce changes in behavior. Each
new policy (behavioral change) is given an identifier of the form
"CMP<NNNN>" where "<NNNN>" is an integer index. Documentation
associated with each policy describes the OLD and NEW behavior and the
reason the policy was introduced. Projects may set each policy to
select the desired behavior. When CMake needs to know which behavior
to use it checks for a setting specified by the project. If no
setting is available the OLD behavior is assumed and a warning is
produced requesting that the policy be set.
The cmake_policy command is used to set policies to OLD or NEW
behavior. While setting policies individually is supported, we
encourage projects to set policies based on CMake versions.
cmake_policy(VERSION major.minor[.patch])
Specify that the current CMake list file is written for the given
version of CMake. All policies introduced in the specified version or
earlier will be set to use NEW behavior. All policies introduced
after the specified version will be reset to use OLD behavior with a
warning. This effectively requests behavior preferred as of a given
CMake version and tells newer CMake versions to warn about their new
policies. The policy version specified must be at least 2.4 or the
command will report an error. In order to get compatibility features
supporting versions earlier than 2.4 see documentation of policy
CMP0001.
cmake_policy(SET CMP<NNNN> NEW)
cmake_policy(SET CMP<NNNN> OLD)
Tell CMake to use the OLD or NEW behavior for a given policy.
Projects depending on the old behavior of a given policy may silence a
policy warning by setting the policy state to OLD. Alternatively one
may fix the project to work with the new behavior and set the policy
state to NEW.
cmake_policy(PUSH)
cmake_policy(POP)
Push and pop the current policy setting state on a stack. Each PUSH
must have a matching POP. This is useful when mixing multiple
projects, subprojects, and files included from external projects that
may each have been written for a different version of CMake. Each
subdirectory entered by the project automatically pushes a new level
on the stack to isolate the subdirectories from their parents.
configure_file
Copy a file to another location and modify its contents.
configure_file(InputFile OutputFile
[COPYONLY] [ESCAPE_QUOTES] [@ONLY])
The Input and Output files have to have full paths. This command
replaces any variables in the input file referenced as ${VAR} or @VAR@
with their values as determined by CMake. If a variable is not
defined, it will be replaced with nothing. If COPYONLY is specified,
then no variable expansion will take place. If ESCAPE_QUOTES is
specified then any substituted quotes will be C-style escaped. The
file will be configured with the current values of CMake variables.
If @ONLY is specified, only variables of the form @VAR@ will be
replaces and ${VAR} will be ignored. This is useful for configuring
scripts that use ${VAR}. Any occurrences of #cmakedefine VAR will be
replaced with either #define VAR or /* #undef VAR */ depending on the
setting of VAR in CMake
create_test_sourcelist
Create a test driver and source list for building test programs.
create_test_sourcelist(sourceListName driverName
test1 test2 test3
EXTRA_INCLUDE include.h
FUNCTION function)
A test driver is a program that links together many small tests into a
single executable. This is useful when building static executables
with large libraries to shrink the total required size. The list of
source files needed to build the test driver will be in
sourceListName. DriverName is the name of the test driver program.
The rest of the arguments consist of a list of test source files, can
be semicolon separated. Each test source file should have a function
in it that is the same name as the file with no extension (foo.cxx
should have int foo(int, char*[]);) DriverName will be able to call
each of the tests by name on the command line. If EXTRA_INCLUDE is
specified, then the next argument is included into the generated file.
If FUNCTION is specified, then the next argument is taken as a
function name that is passed a pointer to ac and av. This can be used
to add extra command line processing to each test. The cmake variable
CMAKE_TESTDRIVER_BEFORE_TESTMAIN can be set to have code that will be
placed directly before calling the test main function.
CMAKE_TESTDRIVER_AFTER_TESTMAIN can be set to have code that will be
placed directly after the call to the test main function.
define_property
Define and document custom properties.
define_property(<GLOBAL | DIRECTORY | TARGET | SOURCE |
TEST | VARIABLE | CACHED_VARIABLE>
PROPERTY <name> [INHERITED]
BRIEF_DOCS <brief-doc>
FULL_DOCS <full-doc>)
Define one property in a scope for use with the set_property and
get_property commands. This is primarily useful to associate
documentation with property names that may be retrieved with the
get_property command. The first argument determines the kind of scope
in which the property should be used. It must be one of the
following:
GLOBAL = associated with the global namespace
DIRECTORY = associated with one directory
TARGET = associated with one target
SOURCE = associated with one source file
TEST = associated with a test named with add_test command
VARIABLE = documents a CMake language variable
CACHED_VARIABLE = documents a CMake cache variable
Note that unlike set_property and get_property no actual scope needs
to be given; only the kind of scope is important.
The required PROPERTY option is immediately followed by the name of
the property being defined.
If the INHERITED option then the get_property command will chain up to
the next higher scope when the requested property is not set in the
scope given to the command. DIRECTORY scope chains to GLOBAL.
TARGET, SOURCE, and TEST chain to DIRECTORY.
The BRIEF_DOCS and FULL_DOCS options are followed by strings to be
associated with the property as its brief and full documentation.
Corresponding options to the get_property command will retrieve the
documentation.
else
Starts the else portion of an if block.
else(expression)
See the if command.
elseif
Starts the elseif portion of an if block.
elseif(expression)
See the if command.
enable_language
Enable a language (CXX/C/Fortran/etc)
enable_language(languageName [OPTIONAL] )
This command enables support for the named language in CMake. This is
the same as the project command but does not create any of the extra
variables that are created by the project command. Example languages
are CXX, C, Fortran.
If OPTIONAL is used, use the CMAKE_<languageName>_COMPILER_WORKS
variable to check whether the language has been enabled successfully.
enable_testing
Enable testing for current directory and below.
enable_testing()
Enables testing for this directory and below. See also the add_test
command. Note that ctest expects to find a test file in the build
directory root. Therefore, this command should be in the source
directory root.
endforeach
Ends a list of commands in a FOREACH block.
endforeach(expression)
See the FOREACH command.
endfunction
Ends a list of commands in a function block.
endfunction(expression)
See the function command.
endif
Ends a list of commands in an if block.
endif(expression)
See the if command.
endmacro
Ends a list of commands in a macro block.
endmacro(expression)
See the macro command.
endwhile
Ends a list of commands in a while block.
endwhile(expression)
See the while command.
execute_process
Execute one or more child processes.
execute_process(COMMAND <cmd1> [args1...]]
[COMMAND <cmd2> [args2...] [...]]
[WORKING_DIRECTORY <directory>]
[TIMEOUT <seconds>]
[RESULT_VARIABLE <variable>]
[OUTPUT_VARIABLE <variable>]
[ERROR_VARIABLE <variable>]
[INPUT_FILE <file>]
[OUTPUT_FILE <file>]
[ERROR_FILE <file>]
[OUTPUT_QUIET]
[ERROR_QUIET]
[OUTPUT_STRIP_TRAILING_WHITESPACE]
[ERROR_STRIP_TRAILING_WHITESPACE])
Runs the given sequence of one or more commands with the standard
output of each process piped to the standard input of the next. A
single standard error pipe is used for all processes. If
WORKING_DIRECTORY is given the named directory will be set as the
current working directory of the child processes. If TIMEOUT is given
the child processes will be terminated if they do not finish in the
specified number of seconds (fractions are allowed). If
RESULT_VARIABLE is given the variable will be set to contain the
result of running the processes. This will be an integer return code
from the last child or a string describing an error condition. If
OUTPUT_VARIABLE or ERROR_VARIABLE are given the variable named will be
set with the contents of the standard output and standard error pipes
respectively. If the same variable is named for both pipes their
output will be merged in the order produced. If INPUT_FILE,
OUTPUT_FILE, or ERROR_FILE is given the file named will be attached to
the standard input of the first process, standard output of the last
process, or standard error of all processes respectively. If
OUTPUT_QUIET or ERROR_QUIET is given then the standard output or
standard error results will be quietly ignored. If more than one
OUTPUT_* or ERROR_* option is given for the same pipe the precedence
is not specified. If no OUTPUT_* or ERROR_* options are given the
output will be shared with the corresponding pipes of the CMake
process itself.
The execute_process command is a newer more powerful version of
exec_program, but the old command has been kept for compatibility.
export
Export targets from the build tree for use by outside projects.
export(TARGETS [target1 [target2 [...]]] [NAMESPACE <namespace>]
[APPEND] FILE <filename>)
Create a file <filename> that may be included by outside projects to
import targets from the current project's build tree. This is useful
during cross-compiling to build utility executables that can run on
the host platform in one project and then import them into another
project being compiled for the target platform. If the NAMESPACE
option is given the <namespace> string will be prepended to all target
names written to the file. If the APPEND option is given the
generated code will be appended to the file instead of overwriting it.
If a library target is included in the export but a target to which it
links is not included the behavior is unspecified.
The file created by this command is specific to the build tree and
should never be installed. See the install(EXPORT) command to export
targets from an installation tree.
file
File manipulation command.
file(WRITE filename "message to write"... )
file(APPEND filename "message to write"... )
file(READ filename variable [LIMIT numBytes] [OFFSET offset] [HEX])
file(STRINGS filename variable [LIMIT_COUNT num]
[LIMIT_INPUT numBytes] [LIMIT_OUTPUT numBytes]
[LENGTH_MINIMUM numBytes] [LENGTH_MAXIMUM numBytes]
[NEWLINE_CONSUME] [REGEX regex]
[NO_HEX_CONVERSION])
file(GLOB variable [RELATIVE path] [globbing expressions]...)
file(GLOB_RECURSE variable [RELATIVE path]
[globbing expressions]...)
file(REMOVE [file1 ...])
file(REMOVE_RECURSE [file1 ...])
file(MAKE_DIRECTORY [directory1 directory2 ...])
file(RELATIVE_PATH variable directory file)
file(TO_CMAKE_PATH path result)
file(TO_NATIVE_PATH path result)
file(DOWNLOAD url file [TIMEOUT timeout] [STATUS status] [LOG log])
WRITE will write a message into a file called 'filename'. It
overwrites the file if it already exists, and creates the file if it
does not exist.
APPEND will write a message into a file same as WRITE, except it will
append it to the end of the file
READ will read the content of a file and store it into the variable.
It will start at the given offset and read up to numBytes. If the
argument HEX is given, the binary data will be converted to
hexadecimal representation and this will be stored in the variable.
STRINGS will parse a list of ASCII strings from a file and store it in
a variable. Binary data in the file are ignored. Carriage return
(CR) characters are ignored. It works also for Intel Hex and Motorola
S-record files, which are automatically converted to binary format
when reading them. Disable this using NO_HEX_CONVERSION.
LIMIT_COUNT sets the maximum number of strings to return. LIMIT_INPUT
sets the maximum number of bytes to read from the input file.
LIMIT_OUTPUT sets the maximum number of bytes to store in the output
variable. LENGTH_MINIMUM sets the minimum length of a string to
return. Shorter strings are ignored. LENGTH_MAXIMUM sets the maximum
length of a string to return. Longer strings are split into strings
no longer than the maximum length. NEWLINE_CONSUME allows newlines to
be included in strings instead of terminating them.
REGEX specifies a regular expression that a string must match to be
returned. Typical usage
file(STRINGS myfile.txt myfile)
stores a list in the variable "myfile" in which each item is a line
from the input file.
GLOB will generate a list of all files that match the globbing
expressions and store it into the variable. Globbing expressions are
similar to regular expressions, but much simpler. If RELATIVE flag is
specified for an expression, the results will be returned as a
relative path to the given path.
Examples of globbing expressions include:
*.cxx - match all files with extension cxx
*.vt? - match all files with extension vta,...,vtz
f[3-5].txt - match files f3.txt, f4.txt, f5.txt
GLOB_RECURSE will generate similar list as the regular GLOB, except it
will traverse all the subdirectories of the matched directory and
match the files.
Examples of recursive globbing include:
/dir/*.py - match all python files in /dir and subdirectories
MAKE_DIRECTORY will create the given directories, also if their parent
directories don't exist yet
REMOVE will remove the given files, also in subdirectories
REMOVE_RECURSE will remove the given files and directories, also
non-empty directories
RELATIVE_PATH will determine relative path from directory to the given
file.
TO_CMAKE_PATH will convert path into a cmake style path with unix /.
The input can be a single path or a system path like "$ENV{PATH}".
Note the double quotes around the ENV call TO_CMAKE_PATH only takes
one argument.
TO_NATIVE_PATH works just like TO_CMAKE_PATH, but will convert from a
cmake style path into the native path style \ for windows and / for
UNIX.
DOWNLOAD will download the givin URL to the given file. If LOG var is
specified a log of the download will be put in var. If STATUS var is
specified the status of the operation will be put in var. The status
is returned in a list of length 2. The first element is the numeric
return value for the operation, and the second element is a string
value for the error. A 0 numeric error means no error in the
operation. If TIMEOUT time is specified, the operation will timeout
after time seconds, time can be specified as a float.
find_file
Find the full path to a file.
find_path(<VAR> name1 [path1 path2 ...])
This is the short-hand signature for the command that is sufficient in
many cases. It is the same as find_path(<VAR> name1 [PATHS path1
path2 ...])
find_path(
<VAR>
name | NAMES name1 [name2 ...]
[PATHS path1 [path2 ... ENV var]]
[PATH_SUFFIXES suffix1 [suffix2 ...]]
[DOC "cache documentation string"]
[NO_DEFAULT_PATH]
[NO_CMAKE_ENVIRONMENT_PATH]
[NO_CMAKE_PATH]
[NO_SYSTEM_ENVIRONMENT_PATH]
[NO_CMAKE_SYSTEM_PATH]
[CMAKE_FIND_ROOT_PATH_BOTH |
ONLY_CMAKE_FIND_ROOT_PATH |
NO_CMAKE_FIND_ROOT_PATH]
)
This command is used to find a full path to named file. A cache entry
named by <VAR> is created to store the result of this command. If the
full path to a file is found the result is stored in the variable and
the search will not be repeated unless the variable is cleared. If
nothing is found, the result will be <VAR>-NOTFOUND, and the search
will be attempted again the next time find_path is invoked with the
same variable. The name of the full path to a file that is searched
for is specified by the names listed after the NAMES argument.
Additional search locations can be specified after the PATHS argument.
If ENV var is found in the PATHS section the environment variable var
will be read and converted from a system environment variable to a
cmake style list of paths. For example ENV PATH would be a way to
list the system path variable. The argument after DOC will be used
for the documentation string in the cache. PATH_SUFFIXES can be used
to give sub directories that will be appended to the search paths.
If NO_DEFAULT_PATH is specified, then no additional paths are added to
the search. If NO_DEFAULT_PATH is not specified, the search process
is as follows:
1. Search cmake specific environment variables. This can be skipped
if NO_CMAKE_ENVIRONMENT_PATH is passed.
<prefix>/include for each <prefix> in CMAKE_PREFIX_PATH
CMAKE_INCLUDE_PATH
CMAKE_FRAMEWORK_PATH
2. Search cmake variables with the same names as the cmake specific
environment variables. These are intended to be used on the command
line with a -DVAR=value. This can be skipped if NO_CMAKE_PATH is
passed.
<prefix>/include for each <prefix> in CMAKE_PREFIX_PATH
CMAKE_INCLUDE_PATH
CMAKE_FRAMEWORK_PATH
3. Search the standard system environment variables. This can be
skipped if NO_SYSTEM_ENVIRONMENT_PATH is an argument.
PATH
INCLUDE
4. Search cmake variables defined in the Platform files for the
current system. This can be skipped if NO_CMAKE_SYSTEM_PATH is
passed.
<prefix>/include for each <prefix> in CMAKE_SYSTEM_PREFIX_PATH
CMAKE_SYSTEM_INCLUDE_PATH
CMAKE_SYSTEM_FRAMEWORK_PATH
5. Search the paths specified after PATHS or in the short-hand
version of the command.
On Darwin or systems supporting OS X Frameworks, the cmake variable
CMAKE_FIND_FRAMEWORK can be set to empty or one of the following:
"FIRST" - Try to find frameworks before standard
libraries or headers. This is the default on Darwin.
"LAST" - Try to find frameworks after standard
libraries or headers.
"ONLY" - Only try to find frameworks.
"NEVER". - Never try to find frameworks.
On Darwin or systems supporting OS X Application Bundles, the cmake
variable CMAKE_FIND_APPBUNDLE can be set to empty or one of the
following:
"FIRST" - Try to find application bundles before standard
programs. This is the default on Darwin.
"LAST" - Try to find application bundles after standard
programs.
"ONLY" - Only try to find application bundles.
"NEVER". - Never try to find application bundles.
The CMake variable CMAKE_FIND_ROOT_PATH specifies one or more
directories to be prepended to all other search directories. This
effectively "re-roots" the entire search under given locations. By
default it is empty. It is especially useful when cross-compiling to
point to the root directory of the target environment and CMake will
search there too. By default at first the directories listed in
CMAKE_FIND_ROOT_PATH and then the non-rooted directories will be
searched. The default behavior can be adjusted by setting
CMAKE_FIND_ROOT_PATH_MODE_INCLUDE. This behavior can be manually
overridden on a per-call basis. By using CMAKE_FIND_ROOT_PATH_BOTH
the search order will be as described above. If
NO_CMAKE_FIND_ROOT_PATH is used then CMAKE_FIND_ROOT_PATH will not be
used. If ONLY_CMAKE_FIND_ROOT_PATH is used then only the re-rooted
directories will be searched.
The reason the paths listed in the call to the command are searched
last is that most users of CMake would expect things to be found first
in the locations specified by their environment. Projects may
override this behavior by simply calling the command twice:
find_path(<VAR> NAMES name PATHS paths... NO_DEFAULT_PATH)
find_path(<VAR> NAMES name)
Once one of these calls succeeds the result variable will be set and
stored in the cache so that neither call will search again.
find_library
Find a library.
find_library(<VAR> name1 [path1 path2 ...])
This is the short-hand signature for the command that is sufficient in
many cases. It is the same as find_library(<VAR> name1 [PATHS path1
path2 ...])
find_library(
<VAR>
name | NAMES name1 [name2 ...]
[PATHS path1 [path2 ... ENV var]]
[PATH_SUFFIXES suffix1 [suffix2 ...]]
[DOC "cache documentation string"]
[NO_DEFAULT_PATH]
[NO_CMAKE_ENVIRONMENT_PATH]
[NO_CMAKE_PATH]
[NO_SYSTEM_ENVIRONMENT_PATH]
[NO_CMAKE_SYSTEM_PATH]
[CMAKE_FIND_ROOT_PATH_BOTH |
ONLY_CMAKE_FIND_ROOT_PATH |
NO_CMAKE_FIND_ROOT_PATH]
)
This command is used to find a library. A cache entry named by <VAR>
is created to store the result of this command. If the library is
found the result is stored in the variable and the search will not be
repeated unless the variable is cleared. If nothing is found, the
result will be <VAR>-NOTFOUND, and the search will be attempted again
the next time find_library is invoked with the same variable. The
name of the library that is searched for is specified by the names
listed after the NAMES argument. Additional search locations can be
specified after the PATHS argument. If ENV var is found in the PATHS
section the environment variable var will be read and converted from a
system environment variable to a cmake style list of paths. For
example ENV PATH would be a way to list the system path variable. The
argument after DOC will be used for the documentation string in the
cache. PATH_SUFFIXES can be used to give sub directories that will be
appended to the search paths.
If NO_DEFAULT_PATH is specified, then no additional paths are added to
the search. If NO_DEFAULT_PATH is not specified, the search process
is as follows:
1. Search cmake specific environment variables. This can be skipped
if NO_CMAKE_ENVIRONMENT_PATH is passed.
<prefix>/lib for each <prefix> in CMAKE_PREFIX_PATH
CMAKE_LIBRARY_PATH
CMAKE_FRAMEWORK_PATH
2. Search cmake variables with the same names as the cmake specific
environment variables. These are intended to be used on the command
line with a -DVAR=value. This can be skipped if NO_CMAKE_PATH is
passed.
<prefix>/lib for each <prefix> in CMAKE_PREFIX_PATH
CMAKE_LIBRARY_PATH
CMAKE_FRAMEWORK_PATH
3. Search the standard system environment variables. This can be
skipped if NO_SYSTEM_ENVIRONMENT_PATH is an argument.
PATH
LIB
4. Search cmake variables defined in the Platform files for the
current system. This can be skipped if NO_CMAKE_SYSTEM_PATH is
passed.
<prefix>/lib for each <prefix> in CMAKE_SYSTEM_PREFIX_PATH
CMAKE_SYSTEM_LIBRARY_PATH
CMAKE_SYSTEM_FRAMEWORK_PATH
5. Search the paths specified after PATHS or in the short-hand
version of the command.
On Darwin or systems supporting OS X Frameworks, the cmake variable
CMAKE_FIND_FRAMEWORK can be set to empty or one of the following:
"FIRST" - Try to find frameworks before standard
libraries or headers. This is the default on Darwin.
"LAST" - Try to find frameworks after standard
libraries or headers.
"ONLY" - Only try to find frameworks.
"NEVER". - Never try to find frameworks.
On Darwin or systems supporting OS X Application Bundles, the cmake
variable CMAKE_FIND_APPBUNDLE can be set to empty or one of the
following:
"FIRST" - Try to find application bundles before standard
programs. This is the default on Darwin.
"LAST" - Try to find application bundles after standard
programs.
"ONLY" - Only try to find application bundles.
"NEVER". - Never try to find application bundles.
The CMake variable CMAKE_FIND_ROOT_PATH specifies one or more
directories to be prepended to all other search directories. This
effectively "re-roots" the entire search under given locations. By
default it is empty. It is especially useful when cross-compiling to
point to the root directory of the target environment and CMake will
search there too. By default at first the directories listed in
CMAKE_FIND_ROOT_PATH and then the non-rooted directories will be
searched. The default behavior can be adjusted by setting
CMAKE_FIND_ROOT_PATH_MODE_LIBRARY. This behavior can be manually
overridden on a per-call basis. By using CMAKE_FIND_ROOT_PATH_BOTH
the search order will be as described above. If
NO_CMAKE_FIND_ROOT_PATH is used then CMAKE_FIND_ROOT_PATH will not be
used. If ONLY_CMAKE_FIND_ROOT_PATH is used then only the re-rooted
directories will be searched.
The reason the paths listed in the call to the command are searched
last is that most users of CMake would expect things to be found first
in the locations specified by their environment. Projects may
override this behavior by simply calling the command twice:
find_library(<VAR> NAMES name PATHS paths... NO_DEFAULT_PATH)
find_library(<VAR> NAMES name)
Once one of these calls succeeds the result variable will be set and
stored in the cache so that neither call will search again.
If the library found is a framework, then VAR will be set to the full
path to the framework <fullPath>/A.framework. When a full path to a
framework is used as a library, CMake will use a -framework A, and a
-F<fullPath> to link the framework to the target.
find_package
Load settings for an external project.
find_package(<package> [major[.minor[.patch]]] [EXACT] [QUIET]
[[REQUIRED|COMPONENTS] [components...]])
Finds and loads settings from an external project. <package>_FOUND
will be set to indicate whether the package was found. When the
package is found package-specific information is provided through
variables documented by the package itself. The QUIET option disables
messages if the package cannot be found. The REQUIRED option stops
processing with an error message if the package cannot be found. A
package-specific list of components may be listed after the REQUIRED
option or after the COMPONENTS option if no REQUIRED option is given.
The "[major[.minor[.patch]]]" version argument specifies a desired
version with which the package found should be compatible. The EXACT
option requests that the version be matched exactly. Version support
is currently provided only on a package-by-package basis (details
below).
User code should generally look for packages using the above simple
signature. The remainder of this command documentation specifies the
full command signature and details of the search process. Project
maintainers wishing to provide a package to be found by this command
are encouraged to read on.
The command has two modes by which it searches for packages: "Module"
mode and "Config" mode. Module mode is available when the command is
invoked with the above reduced signature. CMake searches for a file
called "Find<package>.cmake" in the CMAKE_MODULE_PATH followed by the
CMake installation. If the file is found, it is read and processed by
CMake. It is responsible for finding the package, checking the
version, and producing any needed messages. Many find-modules provide
limited or no support for versioning; check the module documentation.
If no module is found the command proceeds to Config mode.
The complete Config mode command signature is:
find_package(<package> [major[.minor[.patch]]] [EXACT] [QUIET]
[[REQUIRED|COMPONENTS] [components...]] [NO_MODULE]
[NAMES name1 [name2 ...]]
[CONFIGS config1 [config2 ...]]
[PATHS path1 [path2 ... ]]
[PATH_SUFFIXES suffix1 [suffix2 ...]]
[NO_DEFAULT_PATH]
[NO_CMAKE_ENVIRONMENT_PATH]
[NO_CMAKE_PATH]
[NO_SYSTEM_ENVIRONMENT_PATH]
[NO_CMAKE_BUILDS_PATH]
[NO_CMAKE_SYSTEM_PATH]
[CMAKE_FIND_ROOT_PATH_BOTH |
ONLY_CMAKE_FIND_ROOT_PATH |
NO_CMAKE_FIND_ROOT_PATH])
The NO_MODULE option may be used to skip Module mode explicitly. It
is also implied by use of options not specified in the reduced
signature.
Config mode attempts to locate a configuration file provided by the
package to be found. A cache entry called <package>_DIR is created to
hold the directory containing the file. By default the command
searches for a package with the name <package>. If the NAMES option
is given the names following it are used instead of <package>. The
command searches for a file called "<name>Config.cmake" or
"<lower-case-name>-config.cmake" for each name specified. A
replacement set of possible configuration file names may be given
using the CONFIGS option. The search procedure is specified below.
Once found, the configuration file is read and processed by CMake.
Since the file is provided by the package it already knows the
location of package contents. The full path to the configuration file
is stored in the cmake variable <package>_CONFIG.
If the package configuration file cannot be found CMake will generate
an error describing the problem unless the QUIET argument is
specified. If REQUIRED is specified and the package is not found a
fatal error is generated and the configure step stops executing. If
<package>_DIR has been set to a directory not containing a
configuration file a fatal error is always generated because user
intervention is required.
When the "[major[.minor[.patch]]]" version argument is specified
Config mode will only find a version of the package that claims
compatibility with the requested version. If the EXACT option is
given only a version of the package claiming an exact match of the
requested version may be found. CMake does not establish any
convention for the meaning of version numbers. Package version
numbers are checked by "version" files provided by the packages
themselves. For a candidate package confguration file
"<config-file>.cmake" the corresponding version file is located next
to it and named either "<config-file>-version.cmake" or
"<config-file>Version.cmake". If no such version file is available
then the configuration file is assumed to not be compatible with any
requested version. When a version file is found it is loaded to check
the requested version number. The version file is loaded in a nested
scope in which the following variables have been defined:
PACKAGE_FIND_NAME = the <package> name
PACKAGE_FIND_VERSION = full requested version string
PACKAGE_FIND_VERSION_MAJOR = requested major version, if any
PACKAGE_FIND_VERSION_MINOR = requested minor version, if any
PACKAGE_FIND_VERSION_PATCH = requested patch version, if any
The version file checks whether it satisfies the requested version and
sets these variables:
PACKAGE_VERSION = package version (major[.minor[.patch]])
PACKAGE_VERSION_EXACT = true if version is exact match
PACKAGE_VERSION_COMPATIBLE = true if version is compatible
These variables are checked by the find_package command to determine
whether the configuration file provides an acceptable version. They
are not available after the find_package call returns. If the version
is acceptable the following variables are set:
<package>_VERSION = package version (major[.minor[.patch]])
<package>_VERSION_MAJOR = major from major[.minor[.patch]], if any
<package>_VERSION_MINOR = minor from major[.minor[.patch]], if any
<package>_VERSION_PATCH = patch from major[.minor[.patch]], if any
and the corresponding package configuration file is loaded. When
multiple package configuration files are available whose version files
claim compatibility with the version requested it is unspecified which
one is chosen. No attempt is made to choose a highest or closest
version number.
Config mode provides an elaborate interface and search procedure.
Much of the interface is provided for completeness and for use
internally by find-modules loaded by Module mode. Most user code
should simply call
find_package(<package> [major[.minor]] [EXACT] [REQUIRED|QUIET])
in order to find a package. Package maintainers providing CMake
package configuration files are encouraged to name and install them
such that the procedure outlined below will find them without
requiring use of additional options.
CMake constructs a set of possible installation prefixes for the
package. Under each prefix several directories are searched for a
configuration file. The tables below show the directories searched.
Each entry is meant for installation trees following Windows (W), UNIX
(U), or Apple (A) conventions.
<prefix>/ (W)
<prefix>/(cmake|CMake)/ (W)
<prefix>/(share|lib)/<name>*/ (U)
<prefix>/(share|lib)/<name>*/(cmake|CMake)/ (U)
On systems supporting OS X Frameworks and Application Bundles the
following directories are searched for frameworks or bundles
containing a configuration file:
<prefix>/<name>.framework/Resources/ (A)
<prefix>/<name>.framework/Resources/CMake/ (A)
<prefix>/<name>.framework/Versions/*/Resources/ (A)
<prefix>/<name>.framework/Versions/*/Resources/CMake/ (A)
<prefix>/<name>.app/Contents/Resources/ (A)
<prefix>/<name>.app/Contents/Resources/CMake/ (A)
In all cases the <name> is treated as case-insensitive and corresponds
to any of the names specified (<package> or names given by NAMES). If
PATH_SUFFIXES is specified the suffixes are appended to each (W) or
(U) directory entry one-by-one.
This set of directories is intended to work in cooperation with
projects that provide configuration files in their installation trees.
Directories above marked with (W) are intended for installations on
Windows where the prefix may point at the top of an application's
installation directory. Those marked with (U) are intended for
installations on UNIX platforms where the prefix is shared by multiple
packages. This is merely a convention, so all (W) and (U) directories
are still searched on all platforms. Directories marked with (A) are
intended for installations on Apple platforms. The cmake variables
CMAKE_FIND_FRAMEWORK and CMAKE_FIND_APPBUNDLE determine the order of
preference as specified below.
The set of installation prefixes is constructed using the following
steps. If NO_DEFAULT_PATH is specified steps 1-5 are skipped.
1. Search cmake specific environment variables. This can be skipped
if NO_CMAKE_ENVIRONMENT_PATH is passed.
CMAKE_PREFIX_PATH
CMAKE_FRAMEWORK_PATH
CMAKE_APPBUNDLE_PATH
2. Search cmake variables with the same names as the cmake specific
environment variables. These are intended to be used on the command
line with a -DVAR=value. This can be skipped if NO_CMAKE_PATH is
passed.
CMAKE_PREFIX_PATH
CMAKE_FRAMEWORK_PATH
CMAKE_APPBUNDLE_PATH
3. Search the standard system environment variables. This can be
skipped if NO_SYSTEM_ENVIRONMENT_PATH is passed. Path entries ending
in "/bin" or "/sbin" are automatically converted to their parent
directories.
PATH
4. Search project build trees recently configured in a CMake GUI.
This can be skipped if NO_CMAKE_BUILDS_PATH is passed. It is intended
for the case when a user is building multiple dependent projects one
after another.
5. Search cmake variables defined in the Platform files for the
current system. This can be skipped if NO_CMAKE_SYSTEM_PATH is
passed.
CMAKE_SYSTEM_PREFIX_PATH
CMAKE_SYSTEM_FRAMEWORK_PATH
CMAKE_SYSTEM_APPBUNDLE_PATH
6. Search paths specified by the PATHS option.
On Darwin or systems supporting OS X Frameworks, the cmake variable
CMAKE_FIND_FRAMEWORK can be set to empty or one of the following:
"FIRST" - Try to find frameworks before standard
libraries or headers. This is the default on Darwin.
"LAST" - Try to find frameworks after standard
libraries or headers.
"ONLY" - Only try to find frameworks.
"NEVER". - Never try to find frameworks.
On Darwin or systems supporting OS X Application Bundles, the cmake
variable CMAKE_FIND_APPBUNDLE can be set to empty or one of the
following:
"FIRST" - Try to find application bundles before standard
programs. This is the default on Darwin.
"LAST" - Try to find application bundles after standard
programs.
"ONLY" - Only try to find application bundles.
"NEVER". - Never try to find application bundles.
The CMake variable CMAKE_FIND_ROOT_PATH specifies one or more
directories to be prepended to all other search directories. This
effectively "re-roots" the entire search under given locations. By
default it is empty. It is especially useful when cross-compiling to
point to the root directory of the target environment and CMake will
search there too. By default at first the directories listed in
CMAKE_FIND_ROOT_PATH and then the non-rooted directories will be
searched. The default behavior can be adjusted by setting
CMAKE_FIND_ROOT_PATH_MODE_PACKAGE. This behavior can be manually
overridden on a per-call basis. By using CMAKE_FIND_ROOT_PATH_BOTH
the search order will be as described above. If
NO_CMAKE_FIND_ROOT_PATH is used then CMAKE_FIND_ROOT_PATH will not be
used. If ONLY_CMAKE_FIND_ROOT_PATH is used then only the re-rooted
directories will be searched.
The reason the paths listed in the call to the command are searched
last is that most users of CMake would expect things to be found first
in the locations specified by their environment. Projects may
override this behavior by simply calling the command twice:
find_package(<package> PATHS paths... NO_DEFAULT_PATH)
find_package(<package>)
Once one of these calls succeeds the result variable will be set and
stored in the cache so that neither call will search again.
find_path
Find the directory containing a file.
find_path(<VAR> name1 [path1 path2 ...])
This is the short-hand signature for the command that is sufficient in
many cases. It is the same as find_path(<VAR> name1 [PATHS path1
path2 ...])
find_path(
<VAR>
name | NAMES name1 [name2 ...]
[PATHS path1 [path2 ... ENV var]]
[PATH_SUFFIXES suffix1 [suffix2 ...]]
[DOC "cache documentation string"]
[NO_DEFAULT_PATH]
[NO_CMAKE_ENVIRONMENT_PATH]
[NO_CMAKE_PATH]
[NO_SYSTEM_ENVIRONMENT_PATH]
[NO_CMAKE_SYSTEM_PATH]
[CMAKE_FIND_ROOT_PATH_BOTH |
ONLY_CMAKE_FIND_ROOT_PATH |
NO_CMAKE_FIND_ROOT_PATH]
)
This command is used to find a directory containing the named file. A
cache entry named by <VAR> is created to store the result of this
command. If the file in a directory is found the result is stored in
the variable and the search will not be repeated unless the variable
is cleared. If nothing is found, the result will be <VAR>-NOTFOUND,
and the search will be attempted again the next time find_path is
invoked with the same variable. The name of the file in a directory
that is searched for is specified by the names listed after the NAMES
argument. Additional search locations can be specified after the
PATHS argument. If ENV var is found in the PATHS section the
environment variable var will be read and converted from a system
environment variable to a cmake style list of paths. For example ENV
PATH would be a way to list the system path variable. The argument
after DOC will be used for the documentation string in the cache.
PATH_SUFFIXES can be used to give sub directories that will be
appended to the search paths.
If NO_DEFAULT_PATH is specified, then no additional paths are added to
the search. If NO_DEFAULT_PATH is not specified, the search process
is as follows:
1. Search cmake specific environment variables. This can be skipped
if NO_CMAKE_ENVIRONMENT_PATH is passed.
<prefix>/include for each <prefix> in CMAKE_PREFIX_PATH
CMAKE_INCLUDE_PATH
CMAKE_FRAMEWORK_PATH
2. Search cmake variables with the same names as the cmake specific
environment variables. These are intended to be used on the command
line with a -DVAR=value. This can be skipped if NO_CMAKE_PATH is
passed.
<prefix>/include for each <prefix> in CMAKE_PREFIX_PATH
CMAKE_INCLUDE_PATH
CMAKE_FRAMEWORK_PATH
3. Search the standard system environment variables. This can be
skipped if NO_SYSTEM_ENVIRONMENT_PATH is an argument.
PATH
INCLUDE
4. Search cmake variables defined in the Platform files for the
current system. This can be skipped if NO_CMAKE_SYSTEM_PATH is
passed.
<prefix>/include for each <prefix> in CMAKE_SYSTEM_PREFIX_PATH
CMAKE_SYSTEM_INCLUDE_PATH
CMAKE_SYSTEM_FRAMEWORK_PATH
5. Search the paths specified after PATHS or in the short-hand
version of the command.
On Darwin or systems supporting OS X Frameworks, the cmake variable
CMAKE_FIND_FRAMEWORK can be set to empty or one of the following:
"FIRST" - Try to find frameworks before standard
libraries or headers. This is the default on Darwin.
"LAST" - Try to find frameworks after standard
libraries or headers.
"ONLY" - Only try to find frameworks.
"NEVER". - Never try to find frameworks.
On Darwin or systems supporting OS X Application Bundles, the cmake
variable CMAKE_FIND_APPBUNDLE can be set to empty or one of the
following:
"FIRST" - Try to find application bundles before standard
programs. This is the default on Darwin.
"LAST" - Try to find application bundles after standard
programs.
"ONLY" - Only try to find application bundles.
"NEVER". - Never try to find application bundles.
The CMake variable CMAKE_FIND_ROOT_PATH specifies one or more
directories to be prepended to all other search directories. This
effectively "re-roots" the entire search under given locations. By
default it is empty. It is especially useful when cross-compiling to
point to the root directory of the target environment and CMake will
search there too. By default at first the directories listed in
CMAKE_FIND_ROOT_PATH and then the non-rooted directories will be
searched. The default behavior can be adjusted by setting
CMAKE_FIND_ROOT_PATH_MODE_INCLUDE. This behavior can be manually
overridden on a per-call basis. By using CMAKE_FIND_ROOT_PATH_BOTH
the search order will be as described above. If
NO_CMAKE_FIND_ROOT_PATH is used then CMAKE_FIND_ROOT_PATH will not be
used. If ONLY_CMAKE_FIND_ROOT_PATH is used then only the re-rooted
directories will be searched.
The reason the paths listed in the call to the command are searched
last is that most users of CMake would expect things to be found first
in the locations specified by their environment. Projects may
override this behavior by simply calling the command twice:
find_path(<VAR> NAMES name PATHS paths... NO_DEFAULT_PATH)
find_path(<VAR> NAMES name)
Once one of these calls succeeds the result variable will be set and
stored in the cache so that neither call will search again.
When searching for frameworks, if the file is specified as A/b.h, then
the framework search will look for A.framework/Headers/b.h. If that
is found the path will be set to the path to the framework. CMake
will convert this to the correct -F option to include the file.
find_program
Find an executable program.
find_program(<VAR> name1 [path1 path2 ...])
This is the short-hand signature for the command that is sufficient in
many cases. It is the same as find_program(<VAR> name1 [PATHS path1
path2 ...])
find_program(
<VAR>
name | NAMES name1 [name2 ...]
[PATHS path1 [path2 ... ENV var]]
[PATH_SUFFIXES suffix1 [suffix2 ...]]
[DOC "cache documentation string"]
[NO_DEFAULT_PATH]
[NO_CMAKE_ENVIRONMENT_PATH]
[NO_CMAKE_PATH]
[NO_SYSTEM_ENVIRONMENT_PATH]
[NO_CMAKE_SYSTEM_PATH]
[CMAKE_FIND_ROOT_PATH_BOTH |
ONLY_CMAKE_FIND_ROOT_PATH |
NO_CMAKE_FIND_ROOT_PATH]
)
This command is used to find a program. A cache entry named by <VAR>
is created to store the result of this command. If the program is
found the result is stored in the variable and the search will not be
repeated unless the variable is cleared. If nothing is found, the
result will be <VAR>-NOTFOUND, and the search will be attempted again
the next time find_program is invoked with the same variable. The
name of the program that is searched for is specified by the names
listed after the NAMES argument. Additional search locations can be
specified after the PATHS argument. If ENV var is found in the PATHS
section the environment variable var will be read and converted from a
system environment variable to a cmake style list of paths. For
example ENV PATH would be a way to list the system path variable. The
argument after DOC will be used for the documentation string in the
cache. PATH_SUFFIXES can be used to give sub directories that will be
appended to the search paths.
If NO_DEFAULT_PATH is specified, then no additional paths are added to
the search. If NO_DEFAULT_PATH is not specified, the search process
is as follows:
1. Search cmake specific environment variables. This can be skipped
if NO_CMAKE_ENVIRONMENT_PATH is passed.
<prefix>/[s]bin for each <prefix> in CMAKE_PREFIX_PATH
CMAKE_PROGRAM_PATH
CMAKE_APPBUNDLE_PATH
2. Search cmake variables with the same names as the cmake specific
environment variables. These are intended to be used on the command
line with a -DVAR=value. This can be skipped if NO_CMAKE_PATH is
passed.
<prefix>/[s]bin for each <prefix> in CMAKE_PREFIX_PATH
CMAKE_PROGRAM_PATH
CMAKE_APPBUNDLE_PATH
3. Search the standard system environment variables. This can be
skipped if NO_SYSTEM_ENVIRONMENT_PATH is an argument.
PATH
4. Search cmake variables defined in the Platform files for the
current system. This can be skipped if NO_CMAKE_SYSTEM_PATH is
passed.
<prefix>/[s]bin for each <prefix> in CMAKE_SYSTEM_PREFIX_PATH
CMAKE_SYSTEM_PROGRAM_PATH
CMAKE_SYSTEM_APPBUNDLE_PATH
5. Search the paths specified after PATHS or in the short-hand
version of the command.
On Darwin or systems supporting OS X Frameworks, the cmake variable
CMAKE_FIND_FRAMEWORK can be set to empty or one of the following:
"FIRST" - Try to find frameworks before standard
libraries or headers. This is the default on Darwin.
"LAST" - Try to find frameworks after standard
libraries or headers.
"ONLY" - Only try to find frameworks.
"NEVER". - Never try to find frameworks.
On Darwin or systems supporting OS X Application Bundles, the cmake
variable CMAKE_FIND_APPBUNDLE can be set to empty or one of the
following:
"FIRST" - Try to find application bundles before standard
programs. This is the default on Darwin.
"LAST" - Try to find application bundles after standard
programs.
"ONLY" - Only try to find application bundles.
"NEVER". - Never try to find application bundles.
The CMake variable CMAKE_FIND_ROOT_PATH specifies one or more
directories to be prepended to all other search directories. This
effectively "re-roots" the entire search under given locations. By
default it is empty. It is especially useful when cross-compiling to
point to the root directory of the target environment and CMake will
search there too. By default at first the directories listed in
CMAKE_FIND_ROOT_PATH and then the non-rooted directories will be
searched. The default behavior can be adjusted by setting
CMAKE_FIND_ROOT_PATH_MODE_PROGRAM. This behavior can be manually
overridden on a per-call basis. By using CMAKE_FIND_ROOT_PATH_BOTH
the search order will be as described above. If
NO_CMAKE_FIND_ROOT_PATH is used then CMAKE_FIND_ROOT_PATH will not be
used. If ONLY_CMAKE_FIND_ROOT_PATH is used then only the re-rooted
directories will be searched.
The reason the paths listed in the call to the command are searched
last is that most users of CMake would expect things to be found first
in the locations specified by their environment. Projects may
override this behavior by simply calling the command twice:
find_program(<VAR> NAMES name PATHS paths... NO_DEFAULT_PATH)
find_program(<VAR> NAMES name)
Once one of these calls succeeds the result variable will be set and
stored in the cache so that neither call will search again.
fltk_wrap_ui
Create FLTK user interfaces Wrappers.
fltk_wrap_ui(resultingLibraryName source1
source2 ... sourceN )
Produce .h and .cxx files for all the .fl and .fld files listed. The
resulting .h and .cxx files will be added to a variable named
resultingLibraryName_FLTK_UI_SRCS which should be added to your
library.
foreach
Evaluate a group of commands for each value in a list.
foreach(loop_var arg1 arg2 ...)
COMMAND1(ARGS ...)
COMMAND2(ARGS ...)
...
endforeach(loop_var)
foreach(loop_var RANGE total)
foreach(loop_var RANGE start stop [step])
All commands between foreach and the matching endforeach are recorded
without being invoked. Once the endforeach is evaluated, the recorded
list of commands is invoked once for each argument listed in the
original foreach command. Before each iteration of the loop
"${loop_var}" will be set as a variable with the current value in the
list.
Foreach can also iterate over a generated range of numbers. There are
three types of this iteration:
* When specifying single number, the range will have elements 0 to
"total".
* When specifying two numbers, the range will have elements from the
first number to the second number.
* The third optional number is the increment used to iterate from the
first number to the second number.
function
Start recording a function for later invocation as a command.
function(<name> [arg1 [arg2 [arg3 ...]]])
COMMAND1(ARGS ...)
COMMAND2(ARGS ...)
...
endfunction(<name>)
Define a function named <name> that takes arguments named arg1 arg2
arg3 (...). Commands listed after function, but before the matching
endfunction, are not invoked until the function is invoked. When it
is invoked, the commands recorded in the function are first modified
by replacing formal parameters (${arg1}) with the arguments passed,
and then invoked as normal commands. In addition to referencing the
formal parameters you can reference the variable ARGC which will be
set to the number of arguments passed into the function as well as
ARGV0 ARGV1 ARGV2 ... which will have the actual values of the
arguments passed in. This facilitates creating functions with
optional arguments. Additionally ARGV holds the list of all arguments
given to the function and ARGN holds the list of argument pass the
last expected argument.
get_cmake_property
Get a property of the CMake instance.
get_cmake_property(VAR property)
Get a property from the CMake instance. The value of the property is
stored in the variable VAR. If the property is not found, CMake will
report an error. Some supported properties include: VARIABLES,
CACHE_VARIABLES, COMMANDS, and MACROS.
get_directory_property
Get a property of the directory.
get_directory_property(VAR [DIRECTORY dir] property)
Get a property from the Directory. The value of the property is
stored in the variable VAR. If the property is not found, CMake will
report an error. The properties include: VARIABLES, CACHE_VARIABLES,
COMMANDS, MACROS, INCLUDE_DIRECTORIES, LINK_DIRECTORIES, DEFINITIONS,
INCLUDE_REGULAR_EXPRESSION, LISTFILE_STACK, PARENT_DIRECTORY, and
DEFINITION varname. If the DIRECTORY argument is provided then the
property of the provided directory will be retrieved instead of the
current directory. You can only get properties of a directory during
or after it has been traversed by cmake.
get_filename_component
Get a specific component of a full filename.
get_filename_component(VarName FileName
PATH|ABSOLUTE|NAME|EXT|NAME_WE
[CACHE])
Set VarName to be the path (PATH), file name (NAME), file extension
(EXT), file name without extension (NAME_WE) of FileName, or the full
absolute (ABSOLUTE) file name without symlinks. Note that the path is
converted to Unix slashes format and has no trailing slashes. The
longest file extension is always considered. If the optional CACHE
argument is specified, the result variable is added to the cache.
get_filename_component(VarName FileName
PROGRAM [PROGRAM_ARGS ArgVar]
[CACHE])
The program in FileName will be found in the system search path or
left as a full path. If PROGRAM_ARGS is present with PROGRAM, then
any command-line arguments present in the FileName string are split
from the program name and stored in ArgVar. This is used to separate
a program name from its arguments in a command line string.
get_property
Get a property.
get_property(<variable>
<GLOBAL |
DIRECTORY [dir] |
TARGET <target> |
SOURCE <source> |
TEST <test> |
VARIABLE>
PROPERTY <name>
[SET | DEFINED | BRIEF_DOCS | FULL_DOCS])
Get one property from one object in a scope. The first argument
specifies the variable in which to store the result. The second
argument determines the scope from which to get the property. It must
be one of the following:
GLOBAL scope is unique and does not accept a name.
DIRECTORY scope defaults to the current directory but another
directory (already processed by CMake) may be named by full or
relative path.
TARGET scope must name one existing target.
SOURCE scope must name one source file.
TEST scope must name one existing test.
VARIABLE scope is unique and does not accept a name.
The required PROPERTY option is immediately followed by the name of
the property to get. If the property is not set an empty value is
returned. If the SET option is given the variable is set to a boolean
value indicating whether the property has been set.If the DEFINED
option is given the variable is set to a boolean value indicating
whether the property has been defined such as with define_property.
If BRIEF_DOCS or FULL_DOCS is given then the variable is set to a
string containing documentation for the requested property. If
documentation is requested for a property that has not been defined
NOTFOUND is returned.
get_source_file_property
Get a property for a source file.
get_source_file_property(VAR file property)
Get a property from a source file. The value of the property is
stored in the variable VAR. If the property is not found, VAR will be
set to "NOTFOUND". Use set_source_files_properties to set property
values. Source file properties usually control how the file is built.
One property that is always there is LOCATION
get_target_property
Get a property from a target.
get_target_property(VAR target property)
Get a property from a target. The value of the property is stored in
the variable VAR. If the property is not found, VAR will be set to
"NOTFOUND". Use set_target_properties to set property values.
Properties are usually used to control how a target is built.
The read-only property "<CONFIG>_LOCATION" provides the full path to
the file on disk that will be created for the target when building
under configuration <CONFIG> (in upper-case, such as
"DEBUG_LOCATION"). The read-only property "LOCATION" specifies the
full path to the file on disk that will be created for the target.
The path may contain a build-system-specific portion that is replaced
at build time with the configuration getting built (such as
"$(ConfigurationName)" in VS). This is very useful for executable
targets to get the path to the executable file for use in a custom
command.
The read-only property "TYPE" returns which type the specified target
has (EXECUTABLE, STATIC_LIBRARY, SHARED_LIBRARY, MODULE_LIBRARY,
UTILITY, INSTALL_FILES or INSTALL_PROGRAMS). This command can get
properties for any target so far created. The targets do not need to
be in the current CMakeLists.txt file.
get_test_property
Get a property of the test.
get_test_property(test VAR property)
Get a property from the Test. The value of the property is stored in
the variable VAR. If the property is not found, CMake will report an
error. For a list of standard properties you can type cmake
--help-property-list
if
Conditionally execute a group of commands.
if(expression)
# then section.
COMMAND1(ARGS ...)
COMMAND2(ARGS ...)
...
elseif(expression2)
# elseif section.
COMMAND1(ARGS ...)
COMMAND2(ARGS ...)
...
else(expression)
# else section.
COMMAND1(ARGS ...)
COMMAND2(ARGS ...)
...
endif(expression)
Evaluates the given expression. If the result is true, the commands
in the THEN section are invoked. Otherwise, the commands in the else
section are invoked. The elseif and else sections are optional. You
may have multiple elseif clauses. Note that the same expression must
be given to if, and endif. Long expressions can be used and the order
or precedence is that the EXISTS, COMMAND, and DEFINED operators will
be evaluated first. Then any EQUAL, LESS, GREATER, STRLESS,
STRGREATER, STREQUAL, MATCHES will be evaluated. Then NOT operators
and finally AND, OR operators will be evaluated. Possible expressions
are:
if(variable)
True if the variable's value is not empty, 0, N, NO, OFF, FALSE,
NOTFOUND, or <variable>-NOTFOUND.
if(NOT variable)
True if the variable's value is empty, 0, N, NO, OFF, FALSE, NOTFOUND,
or <variable>-NOTFOUND.
if(variable1 AND variable2)
True if both variables would be considered true individually.
if(variable1 OR variable2)
True if either variable would be considered true individually.
if(COMMAND command-name)
True if the given name is a command, macro or function that can be
invoked.
if(POLICY policy-id)
True if the given name is an existing policy (of the form CMP<NNNN>).
if(EXISTS file-name)
if(EXISTS directory-name)
True if the named file or directory exists. Behavior is well-defined
only for full paths.
if(file1 IS_NEWER_THAN file2)
True if file1 is newer than file2 or if one of the two files doesn't
exist. Behavior is well-defined only for full paths.
if(IS_DIRECTORY directory-name)
True if the given name is a directory. Behavior is well-defined only
for full paths.
if(IS_ABSOLUTE path)
True if the given path is an absolute path.
if(variable MATCHES regex)
if(string MATCHES regex)
True if the given string or variable's value matches the given regular
expression.
if(variable LESS number)
if(string LESS number)
if(variable GREATER number)
if(string GREATER number)
if(variable EQUAL number)
if(string EQUAL number)
True if the given string or variable's value is a valid number and the
inequality or equality is true.
if(variable STRLESS string)
if(string STRLESS string)
if(variable STRGREATER string)
if(string STRGREATER string)
if(variable STREQUAL string)
if(string STREQUAL string)
True if the given string or variable's value is lexicographically less
(or greater, or equal) than the string on the right.
if(DEFINED variable)
True if the given variable is defined. It does not matter if the
variable is true or false just if it has been set.
include
Read CMake listfile code from the given file.
include(file1 [OPTIONAL] [RESULT_VARIABLE <VAR>])
include(module [OPTIONAL] [RESULT_VARIABLE <VAR>])
Reads CMake listfile code from the given file. Commands in the file
are processed immediately as if they were written in place of the
include command. If OPTIONAL is present, then no error is raised if
the file does not exist. If RESULT_VARIABLE is given the variable
will be set to the full filename which has been included or NOTFOUND
if it failed.
If a module is specified instead of a file, the file with name
<modulename>.cmake is searched in the CMAKE_MODULE_PATH.
include_directories
Add include directories to the build.
include_directories([AFTER|BEFORE] [SYSTEM] dir1 dir2 ...)
Add the given directories to those searched by the compiler for
include files. By default the directories are appended onto the
current list of directories. This default behavior can be changed by
setting CMAKE_include_directories_BEFORE to ON. By using BEFORE or
AFTER you can select between appending and prepending, independent
from the default. If the SYSTEM option is given the compiler will be
told that the directories are meant as system include directories on
some platforms.
include_external_msproject
Include an external Microsoft project file in a workspace.
include_external_msproject(projectname location
dep1 dep2 ...)
Includes an external Microsoft project in the generated workspace
file. Currently does nothing on UNIX.
include_regular_expression
Set the regular expression used for dependency checking.
include_regular_expression(regex_match [regex_complain])
Set the regular expressions used in dependency checking. Only files
matching regex_match will be traced as dependencies. Only files
matching regex_complain will generate warnings if they cannot be found
(standard header paths are not searched). The defaults are:
regex_match = "^.*$" (match everything)
regex_complain = "^$" (match empty string only)
install
Specify rules to run at install time.
This command generates installation rules for a project. Rules
specified by calls to this command within a source directory are
executed in order during installation. The order across directories
is not defined.
There are multiple signatures for this command. Some of them define
installation properties for files and targets. Properties common to
multiple signatures are covered here but they are valid only for
signatures that specify them.
DESTINATION arguments specify the directory on disk to which a file
will be installed. If a full path (with a leading slash or drive
letter) is given it is used directly. If a relative path is given it
is interpreted relative to the value of CMAKE_INSTALL_PREFIX.
PERMISSIONS arguments specify permissions for installed files. Valid
permissions are OWNER_READ, OWNER_WRITE, OWNER_EXECUTE, GROUP_READ,
GROUP_WRITE, GROUP_EXECUTE, WORLD_READ, WORLD_WRITE, WORLD_EXECUTE,
SETUID, and SETGID. Permissions that do not make sense on certain
platforms are ignored on those platforms.
The CONFIGURATIONS argument specifies a list of build configurations
for which the install rule applies (Debug, Release, etc.).
The COMPONENT argument specifies an installation component name with
which the install rule is associated, such as "runtime" or
"development". During component-specific installation only install
rules associated with the given component name will be executed.
During a full installation all components are installed.
The RENAME argument specifies a name for an installed file that may be
different from the original file. Renaming is allowed only when a
single file is installed by the command.
The OPTIONAL argument specifies that it is not an error if the file to
be installed does not exist.
The TARGETS signature:
install(TARGETS targets... [EXPORT <export-name>]
[[ARCHIVE|LIBRARY|RUNTIME|FRAMEWORK|BUNDLE|
PRIVATE_HEADER|PUBLIC_HEADER|RESOURCE]
[DESTINATION <dir>]
[PERMISSIONS permissions...]
[CONFIGURATIONS [Debug|Release|...]]
[COMPONENT <component>]
[OPTIONAL] [NAMELINK_ONLY|NAMELINK_SKIP]
] [...])
The TARGETS form specifies rules for installing targets from a
project. There are five kinds of target files that may be installed:
ARCHIVE, LIBRARY, RUNTIME, FRAMEWORK, and BUNDLE. Executables are
treated as RUNTIME targets, except that those marked with the
MACOSX_BUNDLE property are treated as BUNDLE targets on OS X. Static
libraries are always treated as ARCHIVE targets. Module libraries are
always treated as LIBRARY targets. For non-DLL platforms shared
libraries are treated as LIBRARY targets, except that those marked
with the FRAMEWORK property are treated as FRAMEWORK targets on OS X.
For DLL platforms the DLL part of a shared library is treated as a
RUNTIME target and the corresponding import library is treated as an
ARCHIVE target. All Windows-based systems including Cygwin are DLL
platforms. The ARCHIVE, LIBRARY, RUNTIME, and FRAMEWORK arguments
change the type of target to which the subsequent properties apply.
If none is given the installation properties apply to all target
types. If only one is given then only targets of that type will be
installed (which can be used to install just a DLL or just an import
library).
The PRIVATE_HEADER, PUBLIC_HEADER, and RESOURCE arguments cause
subsequent properties to be applied to installing a FRAMEWORK shared
library target's associated files on non-Apple platforms. Rules
defined by these arguments are ignored on Apple platforms because the
associated files are installed into the appropriate locations inside
the framework folder. See documentation of the PRIVATE_HEADER,
PUBLIC_HEADER, and RESOURCE target properties for details.
Either NAMELINK_ONLY or NAMELINK_SKIP may be specified as a LIBRARY
option. On some platforms a versioned shared library has a symbolic
link such as
lib<name>.so -> lib<name>.so.1
where "lib<name>.so.1" is the soname of the library and "lib<name>.so"
is a "namelink" allowing linkers to find the library when given
"-l<name>". The NAMELINK_ONLY option causes installation of only the
namelink when a library target is installed. The NAMELINK_SKIP option
causes installation of library files other than the namelink when a
library target is installed. When neither option is given both
portions are installed. On platforms where versioned shared libraries
do not have namelinks or when a library is not versioned the
NAMELINK_SKIP option installs the library and the NAMELINK_ONLY option
installs nothing. See the VERSION and SOVERSION target properties for
details on creating versioned shared libraries.
One or more groups of properties may be specified in a single call to
the TARGETS form of this command. A target may be installed more than
once to different locations. Consider hypothetical targets "myExe",
"mySharedLib", and "myStaticLib". The code
install(TARGETS myExe mySharedLib myStaticLib
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib/static)
install(TARGETS mySharedLib DESTINATION /some/full/path)
will install myExe to <prefix>/bin and myStaticLib to
<prefix>/lib/static. On non-DLL platforms mySharedLib will be
installed to <prefix>/lib and /some/full/path. On DLL platforms the
mySharedLib DLL will be installed to <prefix>/bin and /some/full/path
and its import library will be installed to <prefix>/lib/static and
/some/full/path. On non-DLL platforms mySharedLib will be installed
to <prefix>/lib and /some/full/path.
The EXPORT option associates the installed target files with an export
called <export-name>. It must appear before any RUNTIME, LIBRARY, or
ARCHIVE options. See documentation of the install(EXPORT ...)
signature below for details.
Installing a target with EXCLUDE_FROM_ALL set to true has undefined
behavior.
The FILES signature:
install(FILES files... DESTINATION <dir>
[PERMISSIONS permissions...]
[CONFIGURATIONS [Debug|Release|...]]
[COMPONENT <component>]
[RENAME <name>] [OPTIONAL])
The FILES form specifies rules for installing files for a project.
File names given as relative paths are interpreted with respect to the
current source directory. Files installed by this form are by default
given permissions OWNER_WRITE, OWNER_READ, GROUP_READ, and WORLD_READ
if no PERMISSIONS argument is given.
The PROGRAMS signature:
install(PROGRAMS files... DESTINATION <dir>
[PERMISSIONS permissions...]
[CONFIGURATIONS [Debug|Release|...]]
[COMPONENT <component>]
[RENAME <name>] [OPTIONAL])
The PROGRAMS form is identical to the FILES form except that the
default permissions for the installed file also include OWNER_EXECUTE,
GROUP_EXECUTE, and WORLD_EXECUTE. This form is intended to install
programs that are not targets, such as shell scripts. Use the TARGETS
form to install targets built within the project.
The DIRECTORY signature:
install(DIRECTORY dirs... DESTINATION <dir>
[FILE_PERMISSIONS permissions...]
[DIRECTORY_PERMISSIONS permissions...]
[USE_SOURCE_PERMISSIONS]
[CONFIGURATIONS [Debug|Release|...]]
[COMPONENT <component>] [FILES_MATCHING]
[[PATTERN <pattern> | REGEX <regex>]
[EXCLUDE] [PERMISSIONS permissions...]] [...])
The DIRECTORY form installs contents of one or more directories to a
given destination. The directory structure is copied verbatim to the
destination. The last component of each directory name is appended to
the destination directory but a trailing slash may be used to avoid
this because it leaves the last component empty. Directory names
given as relative paths are interpreted with respect to the current
source directory. If no input directory names are given the
destination directory will be created but nothing will be installed
into it. The FILE_PERMISSIONS and DIRECTORY_PERMISSIONS options
specify permissions given to files and directories in the destination.
If USE_SOURCE_PERMISSIONS is specified and FILE_PERMISSIONS is not,
file permissions will be copied from the source directory structure.
If no permissions are specified files will be given the default
permissions specified in the FILES form of the command, and the
directories will be given the default permissions specified in the
PROGRAMS form of the command.
Installation of directories may be controlled with fine granularity
using the PATTERN or REGEX options. These "match" options specify a
globbing pattern or regular expression to match directories or files
encountered within input directories. They may be used to apply
certain options (see below) to a subset of the files and directories
encountered. The full path to each input file or directory (with
forward slashes) is matched against the expression. A PATTERN will
match only complete file names: the portion of the full path matching
the pattern must occur at the end of the file name and be preceded by
a slash. A REGEX will match any portion of the full path but it may
use '/' and '$' to simulate the PATTERN behavior. By default all
files and directories are installed whether or not they are matched.
The FILES_MATCHING option may be given before the first match option
to disable installation of files (but not directories) not matched by
any expression. For example, the code
install(DIRECTORY src/ DESTINATION include/myproj
FILES_MATCHING PATTERN "*.h")
will extract and install header files from a source tree.
Some options may follow a PATTERN or REGEX expression and are applied
only to files or directories matching them. The EXCLUDE option will
skip the matched file or directory. The PERMISSIONS option overrides
the permissions setting for the matched file or directory. For
example the code
install(DIRECTORY icons scripts/ DESTINATION share/myproj
PATTERN "CVS" EXCLUDE
PATTERN "scripts/*"
PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ
GROUP_EXECUTE GROUP_READ)
will install the icons directory to share/myproj/icons and the scripts
directory to share/myproj. The icons will get default file
permissions, the scripts will be given specific permissions, and any
CVS directories will be excluded.
The SCRIPT and CODE signature:
install([[SCRIPT <file>] [CODE <code>]] [...])
The SCRIPT form will invoke the given CMake script files during
installation. If the script file name is a relative path it will be
interpreted with respect to the current source directory. The CODE
form will invoke the given CMake code during installation. Code is
specified as a single argument inside a double-quoted string. For
example, the code
install(CODE "MESSAGE(\"Sample install message.\")")
will print a message during installation.
The EXPORT signature:
install(EXPORT <export-name> DESTINATION <dir>
[NAMESPACE <namespace>] [FILE <name>.cmake]
[PERMISSIONS permissions...]
[CONFIGURATIONS [Debug|Release|...]]
[COMPONENT <component>])
The EXPORT form generates and installs a CMake file containing code to
import targets from the installation tree into another project.
Target installations are associated with the export <export-name>
using the EXPORT option of the install(TARGETS ...) signature
documented above. The NAMESPACE option will prepend <namespace> to
the target names as they are written to the import file. By default
the generated file will be called <export-name>.cmake but the FILE
option may be used to specify a different name. The value given to
the FILE option must be a file name with the ".cmake" extension. If a
CONFIGURATIONS option is given then the file will only be installed
when one of the named configurations is installed. Additionally, the
generated import file will reference only the matching target
configurations. If a COMPONENT option is specified that does not
match that given to the targets associated with <export-name> the
behavior is undefined. If a library target is included in the export
but a target to which it links is not included the behavior is
unspecified.
The EXPORT form is useful to help outside projects use targets built
and installed by the current project. For example, the code
install(TARGETS myexe EXPORT myproj DESTINATION bin)
install(EXPORT myproj NAMESPACE mp_ DESTINATION lib/myproj)
will install the executable myexe to <prefix>/bin and code to import
it in the file "<prefix>/lib/myproj/myproj.cmake". An outside project
may load this file with the include command and reference the myexe
executable from the installation tree using the imported target name
mp_myexe as if the target were built in its own tree.
NOTE: This command supercedes the INSTALL_TARGETS command and the
target properties PRE_INSTALL_SCRIPT and POST_INSTALL_SCRIPT. It also
replaces the FILES forms of the INSTALL_FILES and INSTALL_PROGRAMS
commands. The processing order of these install rules relative to
those generated by INSTALL_TARGETS, INSTALL_FILES, and
INSTALL_PROGRAMS commands is not defined.
link_directories
Specify directories in which the linker will look for libraries.
link_directories(directory1 directory2 ...)
Specify the paths in which the linker should search for libraries.
The command will apply only to targets created after it is called.
list
List operations.
list(LENGTH <list> <output variable>)
list(GET <list> <element index> [<element index> ...] <output variable>)
list(APPEND <list> <element> [<element> ...])
list(FIND <list> <value> <output variable>)
list(INSERT <list> <element_index> <element> [<element> ...])
list(REMOVE_ITEM <list> <value> [<value> ...])
list(REMOVE_AT <list> <index> [<index> ...])
list(REMOVE_DUPLICATES <list>)
list(REVERSE <list>)
list(SORT <list>)
LENGTH will return a given list's length.
GET will return list of elements specified by indices from the list.
APPEND will append elements to the list.
FIND will return the index of the element specified in the list or -1
if it wasn't found.
INSERT will insert elements to the list to the specified location.
REMOVE_AT and REMOVE_ITEM will remove items from the list. The
difference is that REMOVE_ITEM will remove the given items, while
REMOVE_AT will remove the items at the given indices.
REMOVE_DUPLICATES will remove duplicated items in the list.
REVERSE reverses the contents of the list in-place.
SORT sorts the list in-place alphabetically.
NOTES: A list in cmake is a ; separated group of strings. To create a
list the set command can be used. For example, set(var a b c d e)
creates a list with a;b;c;d;e, and set(var "a b c d e") creates a
string or a list with one item in it.
When specifying index values, if <element index> is 0 or greater, it
is indexed from the beginning of the list, with 0 representing the
first list element. If <element index> is -1 or lesser, it is indexed
from the end of the list, with -1 representing the last list element.
Be careful when counting with negative indices: they do not start from
0. -0 is equivalent to 0, the first list element.
load_cache
Load in the values from another project's CMake cache.
load_cache(pathToCacheFile READ_WITH_PREFIX
prefix entry1...)
Read the cache and store the requested entries in variables with their
name prefixed with the given prefix. This only reads the values, and
does not create entries in the local project's cache.
load_cache(pathToCacheFile [EXCLUDE entry1...]
[INCLUDE_INTERNALS entry1...])
Load in the values from another cache and store them in the local
project's cache as internal entries. This is useful for a project
that depends on another project built in a different tree. EXCLUDE
option can be used to provide a list of entries to be excluded.
INCLUDE_INTERNALS can be used to provide a list of internal entries to
be included. Normally, no internal entries are brought in. Use of
this form of the command is strongly discouraged, but it is provided
for backward compatibility.
load_command
Load a command into a running CMake.
load_command(COMMAND_NAME <loc1> [loc2 ...])
The given locations are searched for a library whose name is
cmCOMMAND_NAME. If found, it is loaded as a module and the command is
added to the set of available CMake commands. Usually, TRY_COMPILE is
used before this command to compile the module. If the command is
successfully loaded a variable named
CMAKE_LOADED_COMMAND_<COMMAND_NAME>
will be set to the full path of the module that was loaded. Otherwise
the variable will not be set.
macro
Start recording a macro for later invocation as a command.
macro(<name> [arg1 [arg2 [arg3 ...]]])
COMMAND1(ARGS ...)
COMMAND2(ARGS ...)
...
endmacro(<name>)
Define a macro named <name> that takes arguments named arg1 arg2 arg3
(...). Commands listed after macro, but before the matching endmacro,
are not invoked until the macro is invoked. When it is invoked, the
commands recorded in the macro are first modified by replacing formal
parameters (${arg1}) with the arguments passed, and then invoked as
normal commands. In addition to referencing the formal parameters you
can reference the values ${ARGC} which will be set to the number of
arguments passed into the function as well as ${ARGV0} ${ARGV1}
${ARGV2} ... which will have the actual values of the arguments