code:
<!DOCTYPE html>

    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.19: https://docutils.sourceforge.io/" />

  <title>qt_wrap_ui — CMake 3.29.0-rc3 Documentation</title>

    <link rel="stylesheet" type="text/css" href="../_static/pygments.css" />
    <link rel="stylesheet" type="text/css" href="../_static/cmake.css" />

    <link rel="icon" href="../_static/cmake-favicon.ico"/>
    <link rel="index" title="Index" href="../genindex.html" />
    <link rel="search" title="Search" href="../search.html" />
    <link rel="next" title="remove" href="remove.html" />
    <link rel="prev" title="qt_wrap_cpp" href="qt_wrap_cpp.html" />

Navigation

          index

          next |

          previous |

    CMake »

    3.29.0-rc3 Documentation »

cmake-commands(7) »

qt_wrap_ui

qt_wrap_ui¶

Deprecated since version 3.14: This command was originally added to support Qt 3 before the
add_custom_command() command was sufficiently mature.  The
FindQt4 module provides the qt4_wrap_ui() macro, which
should be used instead for Qt 4 projects.  For projects using Qt 5 or
later, use the equivalent macro provided by Qt itself (e.g. Qt 5 provides
qt5_wrap_ui()).

Manually create Qt user interfaces Wrappers.

qt_wrap_ui(resultingLibraryName HeadersDestName
           SourcesDestName SourceLists ...)

Produces .h and .cxx files for all the .ui files listed in the
SourceLists.  The .h files will be added to the library using the
HeadersDestNamesource list.  The .cxx files will be added to the
library using the SourcesDestNamesource list.

Consider updating the project to use the AUTOUIC target property
instead for a more automated way of invoking the uic tool.

Previous topic

qt_wrap_cpp

Next topic

remove

This Page

Show Source

Quick search

    <form class="search" action="../search.html" method="get">
      <input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/>
      <input type="submit" value="Go" />
    </form>

Navigation

          index

          next |

          previous |

    CMake »

    3.29.0-rc3 Documentation »

cmake-commands(7) »

qt_wrap_ui

        © Copyright 2000-2024 Kitware, Inc. and Contributors.
      Created using Sphinx 6.2.1.


code:
<!DOCTYPE html>

    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.19: https://docutils.sourceforge.io/" />

  <title>remove — CMake 3.29.0-rc3 Documentation</title>

    <link rel="stylesheet" type="text/css" href="../_static/pygments.css" />
    <link rel="stylesheet" type="text/css" href="../_static/cmake.css" />

    <link rel="icon" href="../_static/cmake-favicon.ico"/>
    <link rel="index" title="Index" href="../genindex.html" />
    <link rel="search" title="Search" href="../search.html" />
    <link rel="next" title="subdir_depends" href="subdir_depends.html" />
    <link rel="prev" title="qt_wrap_ui" href="qt_wrap_ui.html" />

Navigation

          index

          next |

          previous |

    CMake »

    3.29.0-rc3 Documentation »

cmake-commands(7) »

remove

remove¶

Deprecated since version 3.0: Use the list(REMOVE_ITEM) command instead.

remove(VAR VALUE VALUE ...)

Removes VALUE from the variable VAR.  This is typically used to
remove entries from a vector (e.g.  semicolon separated list).  VALUE
is expanded.

Previous topic

qt_wrap_ui

Next topic

subdir_depends

This Page

Show Source

Quick search

    <form class="search" action="../search.html" method="get">
      <input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/>
      <input type="submit" value="Go" />
    </form>

Navigation

          index

          next |

          previous |

    CMake »

    3.29.0-rc3 Documentation »

cmake-commands(7) »

remove

        © Copyright 2000-2024 Kitware, Inc. and Contributors.
      Created using Sphinx 6.2.1.

repo_name: lazytadpole/codenamesilverfish

license: mit


code:
<!DOCTYPE html>

    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.19: https://docutils.sourceforge.io/" />

  <title>remove_definitions — CMake 3.29.0-rc3 Documentation</title>

    <link rel="stylesheet" type="text/css" href="../_static/pygments.css" />
    <link rel="stylesheet" type="text/css" href="../_static/cmake.css" />

    <link rel="icon" href="../_static/cmake-favicon.ico"/>
    <link rel="index" title="Index" href="../genindex.html" />
    <link rel="search" title="Search" href="../search.html" />
    <link rel="next" title="set_source_files_properties" href="set_source_files_properties.html" />
    <link rel="prev" title="project" href="project.html" />

Navigation

          index

          next |

          previous |

    CMake »

    3.29.0-rc3 Documentation »

cmake-commands(7) »

remove_definitions

remove_definitions¶

Remove -D define flags added by add_definitions().

remove_definitions(-DFOO -DBAR ...)

Removes flags (added by add_definitions()) from the compiler
command line for sources in the current directory and below.

Previous topic

project

Next topic

set_source_files_properties

This Page

Show Source

Quick search

    <form class="search" action="../search.html" method="get">
      <input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/>
      <input type="submit" value="Go" />
    </form>

Navigation

          index

          next |

          previous |

    CMake »

    3.29.0-rc3 Documentation »

cmake-commands(7) »

remove_definitions

        © Copyright 2000-2024 Kitware, Inc. and Contributors.
      Created using Sphinx 6.2.1.


code:
<!DOCTYPE html>

    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.19: https://docutils.sourceforge.io/" />

  <title>return — CMake 3.29.0-rc3 Documentation</title>

    <link rel="stylesheet" type="text/css" href="../_static/pygments.css" />
    <link rel="stylesheet" type="text/css" href="../_static/cmake.css" />

    <link rel="icon" href="../_static/cmake-favicon.ico"/>
    <link rel="index" title="Index" href="../genindex.html" />
    <link rel="search" title="Search" href="../search.html" />
    <link rel="next" title="separate_arguments" href="separate_arguments.html" />
    <link rel="prev" title="option" href="option.html" />

Navigation

          index

          next |

          previous |

    CMake »

    3.29.0-rc3 Documentation »

cmake-commands(7) »

return

return¶

Return from a file, directory or function.

return([PROPAGATE <var-name>...])

When this command is encountered in an included file (via include() or
find_package()), it causes processing of the current file to stop
and control is returned to the including file.  If it is encountered in a
file which is not included by another file, e.g. a CMakeLists.txt,
deferred calls scheduled by cmake_language(DEFER) are invoked and
control is returned to the parent directory if there is one.

If return() is called in a function, control is returned to the caller
of that function.  Note that a macro(), unlike a function(),
is expanded in place and therefore cannot handle return().

Policy CMP0140 controls the behavior regarding the arguments of the
command.  All arguments are ignored unless that policy is set to NEW.

PROPAGATE

New in version 3.25.

This option sets or unsets the specified variables in the parent directory or
function caller scope. This is equivalent to set(PARENT_SCOPE) or
unset(PARENT_SCOPE) commands, except for the way it interacts
with the block() command, as described below.

The PROPAGATE option can be very useful in conjunction with the
block() command.  A return will propagate the
specified variables through any enclosing block scopes created by the
block() commands.  Inside a function, this ensures the variables
are propagated to the function's caller, regardless of any blocks within
the function.  If not inside a function, it ensures the variables are
propagated to the parent file or directory scope. For example:

CMakeLists.txt¶

cmake_minimum_required(VERSION 3.25)
project(example)

set(var1 "top-value")

block(SCOPE_FOR VARIABLES)
  add_subdirectory(subDir)
  # var1 has the value "block-nested"
endblock()

# var1 has the value "top-value"

subDir/CMakeLists.txt¶

function(multi_scopes result_var1 result_var2)
  block(SCOPE_FOR VARIABLES)
    # This would only propagate out of the immediate block, not to
    # the caller of the function.
    #set(${result_var1} "new-value" PARENT_SCOPE)
    #unset(${result_var2} PARENT_SCOPE)

    # This propagates the variables through the enclosing block and
    # out to the caller of the function.
    set(${result_var1} "new-value")
    unset(${result_var2})
    return(PROPAGATE ${result_var1} ${result_var2})
  endblock()
endfunction()

set(var1 "some-value")
set(var2 "another-value")

multi_scopes(var1 var2)
# Now var1 will hold "new-value" and var2 will be unset

block(SCOPE_FOR VARIABLES)
  # This return() will set var1 in the directory scope that included us
  # via add_subdirectory(). The surrounding block() here does not limit
  # propagation to the current file, but the block() in the parent
  # directory scope does prevent propagation going any further.
  set(var1 "block-nested")
  return(PROPAGATE var1)
endblock()

See Also¶

block()

function()

Table of Contents

return

See Also

Previous topic

option

Next topic

separate_arguments

This Page

Show Source

Quick search

    <form class="search" action="../search.html" method="get">
      <input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/>
      <input type="submit" value="Go" />
    </form>

Navigation

          index

          next |

          previous |

    CMake »

    3.29.0-rc3 Documentation »

cmake-commands(7) »

return

        © Copyright 2000-2024 Kitware, Inc. and Contributors.
      Created using Sphinx 6.2.1.


code:
<!DOCTYPE html>

    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.19: https://docutils.sourceforge.io/" />

  <title>separate_arguments — CMake 3.29.0-rc3 Documentation</title>

    <link rel="stylesheet" type="text/css" href="../_static/pygments.css" />
    <link rel="stylesheet" type="text/css" href="../_static/cmake.css" />

    <link rel="icon" href="../_static/cmake-favicon.ico"/>
    <link rel="index" title="Index" href="../genindex.html" />
    <link rel="search" title="Search" href="../search.html" />
    <link rel="next" title="set" href="set.html" />
    <link rel="prev" title="return" href="return.html" />

Navigation

          index

          next |

          previous |

    CMake »

    3.29.0-rc3 Documentation »

cmake-commands(7) »

separate_arguments

separate_arguments¶

Parse command-line arguments into a semicolon-separated list.

separate_arguments(<variable> <mode> [PROGRAM [SEPARATE_ARGS]] <args>)

Parses a space-separated string <args> into a list of items,
and stores this list in semicolon-separated standard form in <variable>.

This function is intended for parsing command-line arguments.
The entire command line must be passed as one string in the
argument <args>.

The exact parsing rules depend on the operating system.
They are specified by the <mode> argument which must
be one of the following keywords:

UNIX_COMMAND

Arguments are separated by unquoted whitespace.
Both single-quote and double-quote pairs are respected.
A backslash escapes the next literal character (\" is ");
there are no special escapes (\n is just n).

WINDOWS_COMMAND

A Windows command-line is parsed using the same
syntax the runtime library uses to construct argv at startup.  It
separates arguments by whitespace that is not double-quoted.
Backslashes are literal unless they precede double-quotes.  See the
MSDN article Parsing C Command-Line Arguments for details.

NATIVE_COMMAND

New in version 3.9.

Proceeds as in WINDOWS_COMMAND mode if the host system is Windows.
Otherwise proceeds as in UNIX_COMMAND mode.

PROGRAM

New in version 3.19.

The first item in <args> is assumed to be an executable and will be
searched in the system search path or left as a full path. If not found,
<variable> will be empty. Otherwise, <variable> is a list of 2
elements:

Absolute path of the program

Any command-line arguments present in <args> as a string

For example:

separate_arguments (out UNIX_COMMAND PROGRAM "cc -c main.c")

First element of the list: /path/to/cc

Second element of the list: " -c main.c"

SEPARATE_ARGS

When this sub-option of PROGRAM option is specified, command-line
arguments will be split as well and stored in <variable>.

For example:

separate_arguments (out UNIX_COMMAND PROGRAM SEPARATE_ARGS "cc -c main.c")

The contents of out will be: /path/to/cc;-c;main.c

separate_arguments(<var>)

Convert the value of <var> to a semi-colon separated list.  All
spaces are replaced with ';'.  This helps with generating command
lines.

Previous topic

return

Next topic

set

This Page

Show Source

Quick search

    <form class="search" action="../search.html" method="get">
      <input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/>
      <input type="submit" value="Go" />
    </form>

Navigation

          index

          next |

          previous |

    CMake »

    3.29.0-rc3 Documentation »

cmake-commands(7) »

separate_arguments

        © Copyright 2000-2024 Kitware, Inc. and Contributors.
      Created using Sphinx 6.2.1.


code:
<!DOCTYPE html>

    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.19: https://docutils.sourceforge.io/" />

  <title>set — CMake 3.29.0-rc3 Documentation</title>

    <link rel="stylesheet" type="text/css" href="../_static/pygments.css" />
    <link rel="stylesheet" type="text/css" href="../_static/cmake.css" />

    <link rel="icon" href="../_static/cmake-favicon.ico"/>
    <link rel="index" title="Index" href="../genindex.html" />
    <link rel="search" title="Search" href="../search.html" />
    <link rel="next" title="set_directory_properties" href="set_directory_properties.html" />
    <link rel="prev" title="separate_arguments" href="separate_arguments.html" />

Navigation

          index

          next |

          previous |

    CMake »

    3.29.0-rc3 Documentation »

cmake-commands(7) »

set

set¶

Set a normal, cache, or environment variable to a given value.
See the cmake-language(7) variables
documentation for the scopes and interaction of normal variables
and cache entries.

Signatures of this command that specify a <value>... placeholder
expect zero or more arguments.  Multiple arguments will be joined as
a semicolon-separated list to form the
actual variable value to be set.

Set Normal Variable¶

set(<variable> <value>... [PARENT_SCOPE])¶

Set or unset <variable> in the current function or directory scope:

If at least one <value>... is given, set the variable to that value.

If no value is given, unset the variable.  This is equivalent to
unset(<variable>).

If the PARENT_SCOPE option is given the variable will be set in
the scope above the current scope.  Each new directory or function()
command creates a new scope.  A scope can also be created with the
block() command. set(PARENT_SCOPE) will set the value
of a variable into the parent directory, calling function, or
encompassing scope (whichever is applicable to the case at hand).
The previous state of the variable's value stays the same in the
current scope (e.g., if it was undefined before, it is still undefined
and if it had a value, it is still that value).

The block(PROPAGATE) and return(PROPAGATE) commands
can be used as an alternate method to the set(PARENT_SCOPE)
and unset(PARENT_SCOPE) commands to update the parent scope.

Note

When evaluating Variable References of the form ${VAR}, CMake
first searches for a normal variable with that name.  If no such normal
variable exists, CMake will then search for a cache entry with that name.
Because of this, unsetting a normal variable can expose a cache variable
that was previously hidden.  To force a variable reference of the form
${VAR} to return an empty string, use set(<variable> ""), which
clears the normal variable but leaves it defined.

Set Cache Entry¶

set(<variable> <value>... CACHE <type> <docstring> [FORCE])¶

Sets the given cache <variable> (cache entry).  Since cache entries
are meant to provide user-settable values this does not overwrite
existing cache entries by default.  Use the FORCE option to
overwrite existing entries.

The <type> must be specified as one of:

BOOL

Boolean ON/OFF value.
cmake-gui(1) offers a checkbox.

FILEPATH

Path to a file on disk.
cmake-gui(1) offers a file dialog.

PATH

Path to a directory on disk.
cmake-gui(1) offers a file dialog.

STRING

A line of text.
cmake-gui(1) offers a text field or a drop-down selection
if the STRINGS cache entry property is set.

INTERNAL

A line of text.
cmake-gui(1) does not show internal entries.
They may be used to store variables persistently across runs.
Use of this type implies FORCE.

The <docstring> must be specified as a line of text
providing a quick summary of the option
for presentation to cmake-gui(1) users.

If the cache entry does not exist prior to the call or the FORCE
option is given then the cache entry will be set to the given value.

Note

The content of the cache variable will not be directly accessible
if a normal variable of the same name already exists
(see rules of variable evaluation).
If policy CMP0126 is set to OLD, any normal variable
binding in the current scope will be removed.

It is possible for the cache entry to exist prior to the call but
have no type set if it was created on the cmake(1) command
line by a user through the -D<var>=<value> option
without specifying a type.  In this case the set command will add the
type.  Furthermore, if the <type> is PATH or FILEPATH
and the <value> provided on the command line is a relative path,
then the set command will treat the path as relative to the
current working directory and convert it to an absolute path.

Set Environment Variable¶

set(ENV{<variable>} [<value>])¶

Sets an Environment Variable
to the given value.
Subsequent calls of $ENV{<variable>} will return this new value.

This command affects only the current CMake process, not the process
from which CMake was called, nor the system environment at large,
nor the environment of subsequent build or test processes.

If no argument is given after ENV{<variable>} or if <value> is
an empty string, then this command will clear any existing value of the
environment variable.

Arguments after <value> are ignored. If extra arguments are found,
then an author warning is issued.

See Also¶

unset()

Table of Contents

set

Set Normal Variable

Set Cache Entry

Set Environment Variable

See Also

Previous topic

separate_arguments

Next topic

set_directory_properties

This Page

Show Source

Quick search

    <form class="search" action="../search.html" method="get">
      <input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/>
      <input type="submit" value="Go" />
    </form>

Navigation

          index

          next |

          previous |

    CMake »

    3.29.0-rc3 Documentation »

cmake-commands(7) »

set

        © Copyright 2000-2024 Kitware, Inc. and Contributors.
      Created using Sphinx 6.2.1.


code:
<!DOCTYPE html>

    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.19: https://docutils.sourceforge.io/" />

  <title>set_directory_properties — CMake 3.29.0-rc3 Documentation</title>

    <link rel="stylesheet" type="text/css" href="../_static/pygments.css" />
    <link rel="stylesheet" type="text/css" href="../_static/cmake.css" />

    <link rel="icon" href="../_static/cmake-favicon.ico"/>
    <link rel="index" title="Index" href="../genindex.html" />
    <link rel="search" title="Search" href="../search.html" />
    <link rel="next" title="set_property" href="set_property.html" />
    <link rel="prev" title="set" href="set.html" />

Navigation

          index

          next |

          previous |

    CMake »

    3.29.0-rc3 Documentation »

cmake-commands(7) »

set_directory_properties

set_directory_properties¶

Set properties of the current directory and subdirectories.

set_directory_properties(PROPERTIES <prop1> <value1> [<prop2> <value2>] ...)

Sets properties of the current directory and its subdirectories in key-value
pairs.

See also the set_property(DIRECTORY) command.

See Properties on Directories for the list of properties known to CMake
and their individual documentation for the behavior of each property.

See Also¶

define_property()

get_directory_property()

the more general set_property() command

Table of Contents

set_directory_properties

See Also

Previous topic

set

Next topic

set_property

This Page

Show Source

Quick search

    <form class="search" action="../search.html" method="get">
      <input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/>
      <input type="submit" value="Go" />
    </form>

Navigation

          index

          next |

          previous |

    CMake »

    3.29.0-rc3 Documentation »

cmake-commands(7) »

set_directory_properties

        © Copyright 2000-2024 Kitware, Inc. and Contributors.
      Created using Sphinx 6.2.1.


code:
<!DOCTYPE html>

    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.19: https://docutils.sourceforge.io/" />

  <title>set_property — CMake 3.29.0-rc3 Documentation</title>

    <link rel="stylesheet" type="text/css" href="../_static/pygments.css" />
    <link rel="stylesheet" type="text/css" href="../_static/cmake.css" />

    <link rel="icon" href="../_static/cmake-favicon.ico"/>
    <link rel="index" title="Index" href="../genindex.html" />
    <link rel="search" title="Search" href="../search.html" />
    <link rel="next" title="site_name" href="site_name.html" />
    <link rel="prev" title="set_directory_properties" href="set_directory_properties.html" />

Navigation

          index

          next |

          previous |

    CMake »

    3.29.0-rc3 Documentation »

cmake-commands(7) »

set_property

set_property¶

Set a named property in a given scope.

set_property(<GLOBAL                      |
              DIRECTORY [<dir>]           |
              TARGET    [<target1> ...]   |
              SOURCE    [<src1> ...]
                        [DIRECTORY <dirs> ...]
                        [TARGET_DIRECTORY <targets> ...] |
              INSTALL   [<file1> ...]     |
              TEST      [<test1> ...]
                        [DIRECTORY <dir>] |
              CACHE     [<entry1> ...]    >
             [APPEND] [APPEND_STRING]
             PROPERTY <name> [<value1> ...])

Sets one property on zero or more objects of a scope.

The first argument determines the scope in which the property is set.
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 other directories
(already processed by CMake) may be named by full or relative path.
Relative paths are treated as relative to the current source directory.
See also the set_directory_properties() command.

New in version 3.19: <dir> may reference a binary directory.

TARGET

Scope may name zero or more existing targets.
See also the set_target_properties() command.

Alias Targets do not support setting target properties.

SOURCE

Scope may name zero or more source files.  By default, source file properties
are only visible to targets added in the same directory (CMakeLists.txt).

New in version 3.18: Visibility can be set in other directory scopes using one or both of the
following sub-options:

DIRECTORY <dirs>...

The source file property will be set in each of the <dirs>
directories' scopes.  CMake must already know about
each of these directories, either by having added them through a call to
add_subdirectory() or it being the top level source directory.
Relative paths are treated as relative to the current source directory.

New in version 3.19: <dirs> may reference a binary directory.

TARGET_DIRECTORY <targets>...

The source file property will be set in each of the directory scopes
where any of the specified <targets> were created (the <targets>
must therefore already exist).

See also the set_source_files_properties() command.

INSTALL

New in version 3.1.

Scope may name zero or more installed file paths.
These are made available to CPack to influence deployment.

Both the property key and value may use generator expressions.
Specific properties may apply to installed files and/or directories.

Path components have to be separated by forward slashes,
must be normalized and are case sensitive.

To reference the installation prefix itself with a relative path use ..

Currently installed file properties are only defined for
the WIX generator where the given paths are relative
to the installation prefix.

TEST

Scope is limited to the directory the command is called in. It may name zero
or more existing tests. See also command set_tests_properties().

Test property values may be specified using
generator expressions
for tests created by the add_test(NAME) signature.

New in version 3.28: Visibility can be set in other directory scopes using the following sub-option:

DIRECTORY <dir>

The test property will be set in the <dir> directory's scope. CMake must
already know about this directory, either by having added it through a call
to add_subdirectory() or it being the top level source directory.
Relative paths are treated as relative to the current source directory.
<dir> may reference a binary directory.

CACHE

Scope must name zero or more existing cache entries.

The required PROPERTY option is immediately followed by the name of
the property to set.  Remaining arguments are used to compose the
property value in the form of a semicolon-separated list.

If the APPEND option is given the list is appended to any existing
property value (except that empty values are ignored and not appended).
If the APPEND_STRING option is given the string is
appended to any existing property value as string, i.e. it results in a
longer string and not a list of strings.  When using APPEND or
APPEND_STRING with a property defined to support INHERITED
behavior (see define_property()), no inheriting occurs when
finding the initial value to append to.  If the property is not already
directly set in the nominated scope, the command will behave as though
APPEND or APPEND_STRING had not been given.

Note

The GENERATED source file property may be globally visible.
See its documentation for details.

See Also¶

define_property()

get_property()

The cmake-properties(7) manual for a list of properties
in each scope.

Table of Contents

set_property

See Also

Previous topic

set_directory_properties

Next topic

site_name

This Page

Show Source

Quick search

    <form class="search" action="../search.html" method="get">
      <input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/>
      <input type="submit" value="Go" />
    </form>

Navigation

          index

          next |

          previous |

    CMake »

    3.29.0-rc3 Documentation »

cmake-commands(7) »

set_property

        © Copyright 2000-2024 Kitware, Inc. and Contributors.
      Created using Sphinx 6.2.1.


code:
<!DOCTYPE html>

    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.19: https://docutils.sourceforge.io/" />

  <title>set_source_files_properties — CMake 3.29.0-rc3 Documentation</title>

    <link rel="stylesheet" type="text/css" href="../_static/pygments.css" />
    <link rel="stylesheet" type="text/css" href="../_static/cmake.css" />

    <link rel="icon" href="../_static/cmake-favicon.ico"/>
    <link rel="index" title="Index" href="../genindex.html" />
    <link rel="search" title="Search" href="../search.html" />
    <link rel="next" title="set_target_properties" href="set_target_properties.html" />
    <link rel="prev" title="remove_definitions" href="remove_definitions.html" />

Navigation

          index

          next |

          previous |

    CMake »

    3.29.0-rc3 Documentation »

cmake-commands(7) »

set_source_files_properties

set_source_files_properties¶

Source files can have properties that affect how they are built.

set_source_files_properties(<files> ...
                            [DIRECTORY <dirs> ...]
                            [TARGET_DIRECTORY <targets> ...]
                            PROPERTIES <prop1> <value1>
                            [<prop2> <value2>] ...)

Sets properties associated with source files using a key/value paired
list.

New in version 3.18: By default, source file properties are only visible to targets added in the
same directory (CMakeLists.txt).  Visibility can be set in other directory
scopes using one or both of the following options:

DIRECTORY <dirs>...

The source file properties will be set in each of the <dirs>
directories' scopes.  CMake must already know about each of these
source directories, either by having added them through a call to
add_subdirectory() or it being the top level source directory.
Relative paths are treated as relative to the current source directory.

TARGET_DIRECTORY <targets>...

The source file properties will be set in each of the directory scopes
where any of the specified <targets> were created (the <targets>
must therefore already exist).

Use get_source_file_property() to get property values.
See also the set_property(SOURCE) command.

Note

The GENERATED source file property may be globally visible.
See its documentation for details.

See Also¶

define_property()

get_source_file_property()

Properties on Source Files for the list of properties known
to CMake

Table of Contents

set_source_files_properties

See Also

Previous topic

remove_definitions

Next topic

set_target_properties

This Page

Show Source

Quick search

    <form class="search" action="../search.html" method="get">
      <input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/>
      <input type="submit" value="Go" />
    </form>

Navigation

          index

          next |

          previous |

    CMake »

    3.29.0-rc3 Documentation »

cmake-commands(7) »

set_source_files_properties

        © Copyright 2000-2024 Kitware, Inc. and Contributors.
      Created using Sphinx 6.2.1.


code:
<!DOCTYPE html>

    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.19: https://docutils.sourceforge.io/" />

  <title>set_target_properties — CMake 3.29.0-rc3 Documentation</title>

    <link rel="stylesheet" type="text/css" href="../_static/pygments.css" />
    <link rel="stylesheet" type="text/css" href="../_static/cmake.css" />

    <link rel="icon" href="../_static/cmake-favicon.ico"/>
    <link rel="index" title="Index" href="../genindex.html" />
    <link rel="search" title="Search" href="../search.html" />
    <link rel="next" title="set_tests_properties" href="set_tests_properties.html" />
    <link rel="prev" title="set_source_files_properties" href="set_source_files_properties.html" />

Navigation

          index

          next |

          previous |

    CMake »

    3.29.0-rc3 Documentation »

cmake-commands(7) »

set_target_properties

set_target_properties¶

Targets can have properties that affect how they are built.

set_target_properties(<targets> ...
                      PROPERTIES <prop1> <value1>
                      [<prop2> <value2>] ...)

Sets properties on targets.  The syntax for the command is to list all
the targets you want to change, and then provide the values you want to
set next.  You can use any prop value pair you want and extract it
later with the get_property() or get_target_property()
command.

Alias Targets do not support setting target properties.

See Also¶

define_property()

get_target_property()

the more general set_property() command

Properties on Targets for the list of properties known to CMake

Table of Contents

set_target_properties

See Also

Previous topic

set_source_files_properties

Next topic

set_tests_properties

This Page

Show Source

Quick search

    <form class="search" action="../search.html" method="get">
      <input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/>
      <input type="submit" value="Go" />
    </form>

Navigation

          index

          next |

          previous |

    CMake »

    3.29.0-rc3 Documentation »

cmake-commands(7) »

set_target_properties

        © Copyright 2000-2024 Kitware, Inc. and Contributors.
      Created using Sphinx 6.2.1.


code:
<!DOCTYPE html>

    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.19: https://docutils.sourceforge.io/" />

  <title>set_tests_properties — CMake 3.29.0-rc3 Documentation</title>

    <link rel="stylesheet" type="text/css" href="../_static/pygments.css" />
    <link rel="stylesheet" type="text/css" href="../_static/cmake.css" />

    <link rel="icon" href="../_static/cmake-favicon.ico"/>
    <link rel="index" title="Index" href="../genindex.html" />
    <link rel="search" title="Search" href="../search.html" />
    <link rel="next" title="source_group" href="source_group.html" />
    <link rel="prev" title="set_target_properties" href="set_target_properties.html" />

Navigation

          index

          next |

          previous |

    CMake »

    3.29.0-rc3 Documentation »

cmake-commands(7) »

set_tests_properties

set_tests_properties¶

Set a property of the tests.

set_tests_properties(<tests>...
                     [DIRECTORY <dir>]
                     PROPERTIES <prop1> <value1>
                     [<prop2> <value2>]...)

Sets a property for the tests.  If the test is not found, CMake
will report an error.

Test property values may be specified using
generator expressions
for tests created by the add_test(NAME) signature.

New in version 3.28: Visibility can be set in other directory scopes using the following option:

DIRECTORY <dir>

The test properties will be set in the <dir> directory's scope.
CMake must already know about this directory, either by having added it
through a call to add_subdirectory() or it being the top level
source directory. Relative paths are treated as relative to the current
source directory. <dir> may reference a binary directory.

See Also¶

add_test()

define_property()

the more general set_property() command

Properties on Tests for the list of properties known to CMake

Table of Contents

set_tests_properties

See Also

Previous topic

set_target_properties

Next topic

source_group

This Page

Show Source

Quick search

    <form class="search" action="../search.html" method="get">
      <input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/>
      <input type="submit" value="Go" />
    </form>

Navigation

          index

          next |

          previous |

    CMake »

    3.29.0-rc3 Documentation »

cmake-commands(7) »

set_tests_properties

        © Copyright 2000-2024 Kitware, Inc. and Contributors.
      Created using Sphinx 6.2.1.


code:
<!DOCTYPE html>

    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.19: https://docutils.sourceforge.io/" />

  <title>site_name — CMake 3.29.0-rc3 Documentation</title>

    <link rel="stylesheet" type="text/css" href="../_static/pygments.css" />
    <link rel="stylesheet" type="text/css" href="../_static/cmake.css" />

    <link rel="icon" href="../_static/cmake-favicon.ico"/>
    <link rel="index" title="Index" href="../genindex.html" />
    <link rel="search" title="Search" href="../search.html" />
    <link rel="next" title="string" href="string.html" />
    <link rel="prev" title="set_property" href="set_property.html" />

Navigation

          index

          next |

          previous |

    CMake »

    3.29.0-rc3 Documentation »

cmake-commands(7) »

site_name

site_name¶

Set the given variable to the name of the computer.

site_name(variable)

On UNIX-like platforms, if the variable HOSTNAME is set, its value
will be executed as a command expected to print out the host name,
much like the hostname command-line tool.

Previous topic

set_property

Next topic

string

This Page

Show Source

Quick search

    <form class="search" action="../search.html" method="get">
      <input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/>
      <input type="submit" value="Go" />
    </form>

Navigation

          index

          next |

          previous |

    CMake »

    3.29.0-rc3 Documentation »

cmake-commands(7) »

site_name

        © Copyright 2000-2024 Kitware, Inc. and Contributors.
      Created using Sphinx 6.2.1.


code:
<!DOCTYPE html>

    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.19: https://docutils.sourceforge.io/" />

  <title>source_group — CMake 3.29.0-rc3 Documentation</title>

    <link rel="stylesheet" type="text/css" href="../_static/pygments.css" />
    <link rel="stylesheet" type="text/css" href="../_static/cmake.css" />

    <link rel="icon" href="../_static/cmake-favicon.ico"/>
    <link rel="index" title="Index" href="../genindex.html" />
    <link rel="search" title="Search" href="../search.html" />
    <link rel="next" title="target_compile_definitions" href="target_compile_definitions.html" />
    <link rel="prev" title="set_tests_properties" href="set_tests_properties.html" />

Navigation

          index

          next |

          previous |

    CMake »

    3.29.0-rc3 Documentation »

cmake-commands(7) »

source_group

source_group¶

Define a grouping for source files in IDE project generation.
There are two different signatures to create source groups.

source_group(<name> [FILES <src>...] [REGULAR_EXPRESSION <regex>])
source_group(TREE <root> [PREFIX <prefix>] [FILES <src>...])

Defines a group into which sources will be placed in project files.
This is intended to set up file tabs in Visual Studio.
The group is scoped in the directory where the command is called,
and applies to sources in targets created in that directory.

The options are:

TREE

New in version 3.8.

CMake will automatically detect, from <src> files paths, source groups
it needs to create, to keep structure of source groups analogically to the
actual files and directories structure in the project. Paths of <src>
files will be cut to be relative to <root>. The command fails if the
paths within src do not start with root.

PREFIX

New in version 3.8.

Source group and files located directly in <root> path, will be placed
in <prefix> source groups.

FILES

Any source file specified explicitly will be placed in group
<name>.  Relative paths are interpreted with respect to the
current source directory.

REGULAR_EXPRESSION

Any source file whose name matches the regular expression will
be placed in group <name>.

If a source file matches multiple groups, the last group that
explicitly lists the file with FILES will be favored, if any.
If no group explicitly lists the file, the last group whose
regular expression matches the file will be favored.

The <name> of the group and <prefix> argument may contain forward
slashes or backslashes to specify subgroups.  Backslashes need to be escaped
appropriately:

source_group(base/subdir ...)
source_group(outer\\inner ...)
source_group(TREE <root> PREFIX sources\\inc ...)

New in version 3.18: Allow using forward slashes (/) to specify subgroups.

For backwards compatibility, the short-hand signature

source_group(<name> <regex>)

is equivalent to

source_group(<name> REGULAR_EXPRESSION <regex>)

Previous topic

set_tests_properties

Next topic

target_compile_definitions

This Page

Show Source

Quick search

    <form class="search" action="../search.html" method="get">
      <input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/>
      <input type="submit" value="Go" />
    </form>

Navigation

          index

          next |

          previous |

    CMake »

    3.29.0-rc3 Documentation »

cmake-commands(7) »

source_group

        © Copyright 2000-2024 Kitware, Inc. and Contributors.
      Created using Sphinx 6.2.1.


code:
<!DOCTYPE html>

    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.19: https://docutils.sourceforge.io/" />

  <title>subdir_depends — CMake 3.29.0-rc3 Documentation</title>

    <link rel="stylesheet" type="text/css" href="../_static/pygments.css" />
    <link rel="stylesheet" type="text/css" href="../_static/cmake.css" />

    <link rel="icon" href="../_static/cmake-favicon.ico"/>
    <link rel="index" title="Index" href="../genindex.html" />
    <link rel="search" title="Search" href="../search.html" />
    <link rel="next" title="subdirs" href="subdirs.html" />
    <link rel="prev" title="remove" href="remove.html" />

Navigation

          index

          next |

          previous |

    CMake »

    3.29.0-rc3 Documentation »

cmake-commands(7) »

subdir_depends

subdir_depends¶

Disallowed since version 3.0.  See CMake Policy CMP0029.

Does nothing.

subdir_depends(subdir dep1 dep2 ...)

Does not do anything.  This command used to help projects order
parallel builds correctly.  This functionality is now automatic.

Previous topic

remove

Next topic

subdirs

This Page

Show Source

Quick search

    <form class="search" action="../search.html" method="get">
      <input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/>
      <input type="submit" value="Go" />
    </form>

Navigation

          index

          next |

          previous |

    CMake »

    3.29.0-rc3 Documentation »

cmake-commands(7) »

subdir_depends

        © Copyright 2000-2024 Kitware, Inc. and Contributors.
      Created using Sphinx 6.2.1.


code:
<!DOCTYPE html>

    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.19: https://docutils.sourceforge.io/" />

  <title>subdirs — CMake 3.29.0-rc3 Documentation</title>

    <link rel="stylesheet" type="text/css" href="../_static/pygments.css" />
    <link rel="stylesheet" type="text/css" href="../_static/cmake.css" />

    <link rel="icon" href="../_static/cmake-favicon.ico"/>
    <link rel="index" title="Index" href="../genindex.html" />
    <link rel="search" title="Search" href="../search.html" />
    <link rel="next" title="use_mangled_mesa" href="use_mangled_mesa.html" />
    <link rel="prev" title="subdir_depends" href="subdir_depends.html" />

Navigation

          index

          next |

          previous |

    CMake »

    3.29.0-rc3 Documentation »

cmake-commands(7) »

subdirs

subdirs¶

Deprecated since version 3.0: Use the add_subdirectory() command instead.

Add a list of subdirectories to the build.

subdirs(dir1 dir2 ...[EXCLUDE_FROM_ALL exclude_dir1 exclude_dir2 ...]
        [PREORDER] )

Add a list of subdirectories to the build.  The add_subdirectory()
command should be used instead of subdirs although subdirs will still
work.  This will cause any CMakeLists.txt files in the sub directories
to be processed by CMake.  Any directories after the PREORDER flag are
traversed first by makefile builds, the PREORDER flag has no effect on
IDE projects.  Any directories after the EXCLUDE_FROM_ALL marker will
not be included in the top level makefile or project file.  This is
useful for having CMake create makefiles or projects for a set of
examples in a project.  You would want CMake to generate makefiles or
project files for all the examples at the same time, but you would not
want them to show up in the top level project or be built each time
make is run from the top.

Previous topic

subdir_depends

Next topic

use_mangled_mesa

This Page

Show Source

Quick search

    <form class="search" action="../search.html" method="get">
      <input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/>
      <input type="submit" value="Go" />
    </form>

Navigation

          index

          next |

          previous |

    CMake »

    3.29.0-rc3 Documentation »

cmake-commands(7) »

subdirs

        © Copyright 2000-2024 Kitware, Inc. and Contributors.
      Created using Sphinx 6.2.1.


code:
<!DOCTYPE html>

    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.19: https://docutils.sourceforge.io/" />

  <title>target_compile_definitions — CMake 3.29.0-rc3 Documentation</title>

    <link rel="stylesheet" type="text/css" href="../_static/pygments.css" />
    <link rel="stylesheet" type="text/css" href="../_static/cmake.css" />

    <link rel="icon" href="../_static/cmake-favicon.ico"/>
    <link rel="index" title="Index" href="../genindex.html" />
    <link rel="search" title="Search" href="../search.html" />
    <link rel="next" title="target_compile_features" href="target_compile_features.html" />
    <link rel="prev" title="source_group" href="source_group.html" />

Navigation

          index

          next |

          previous |

    CMake »

    3.29.0-rc3 Documentation »

cmake-commands(7) »

target_compile_definitions

target_compile_definitions¶

Add compile definitions to a target.

target_compile_definitions(<target>
  <INTERFACE|PUBLIC|PRIVATE> [items1...]
  [<INTERFACE|PUBLIC|PRIVATE> [items2...] ...])

Specifies compile definitions to use when compiling a given <target>.  The
named <target> must have been created by a command such as
add_executable() or add_library() and must not be an
ALIAS target.

The INTERFACE, PUBLIC and PRIVATE keywords are required to
specify the scope of the following arguments.
PRIVATE and PUBLIC items will populate the COMPILE_DEFINITIONS
property of <target>. PUBLIC and INTERFACE items will populate the
INTERFACE_COMPILE_DEFINITIONS property of <target>.
The following arguments specify compile definitions.  Repeated calls for the
same <target> append items in the order called.

New in version 3.11: Allow setting INTERFACE items on IMPORTED targets.

Arguments to target_compile_definitions may use generator expressions
with the syntax $<...>. See the cmake-generator-expressions(7)
manual for available expressions.  See the cmake-buildsystem(7) manual
for more on defining buildsystem properties.

Any leading -D on an item will be removed.  Empty items are ignored.
For example, the following are all equivalent:

target_compile_definitions(foo PUBLIC FOO)
target_compile_definitions(foo PUBLIC -DFOO)  # -D removed
target_compile_definitions(foo PUBLIC "" FOO) # "" ignored
target_compile_definitions(foo PUBLIC -D FOO) # -D becomes "", then ignored

Definitions may optionally have values:

target_compile_definitions(foo PUBLIC FOO=1)

Note that many compilers treat -DFOO as equivalent to -DFOO=1, but
other tools may not recognize this in all circumstances (e.g. IntelliSense).

See Also¶

add_compile_definitions()

target_compile_features()

target_compile_options()

target_include_directories()

target_link_libraries()

target_link_directories()

target_link_options()

target_precompile_headers()

target_sources()

Table of Contents

target_compile_definitions

See Also

Previous topic

source_group

Next topic

target_compile_features

This Page

Show Source

Quick search

    <form class="search" action="../search.html" method="get">
      <input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/>
      <input type="submit" value="Go" />
    </form>

Navigation

          index

          next |

          previous |

    CMake »

    3.29.0-rc3 Documentation »

cmake-commands(7) »

target_compile_definitions

        © Copyright 2000-2024 Kitware, Inc. and Contributors.
      Created using Sphinx 6.2.1.


code:
<!DOCTYPE html>

    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.19: https://docutils.sourceforge.io/" />

  <title>target_compile_features — CMake 3.29.0-rc3 Documentation</title>

    <link rel="stylesheet" type="text/css" href="../_static/pygments.css" />
    <link rel="stylesheet" type="text/css" href="../_static/cmake.css" />

    <link rel="icon" href="../_static/cmake-favicon.ico"/>
    <link rel="index" title="Index" href="../genindex.html" />
    <link rel="search" title="Search" href="../search.html" />
    <link rel="next" title="target_compile_options" href="target_compile_options.html" />
    <link rel="prev" title="target_compile_definitions" href="target_compile_definitions.html" />

Navigation

          index

          next |

          previous |

    CMake »

    3.29.0-rc3 Documentation »

cmake-commands(7) »

target_compile_features

target_compile_features¶

New in version 3.1.

Add expected compiler features to a target.

target_compile_features(<target> <PRIVATE|PUBLIC|INTERFACE> <feature> [...])

Specifies compiler features required when compiling a given target.  If the
feature is not listed in the CMAKE_C_COMPILE_FEATURES,
CMAKE_CUDA_COMPILE_FEATURES, or CMAKE_CXX_COMPILE_FEATURES
variables, then an error will be reported by CMake.  If the use of the feature requires
an additional compiler flag, such as -std=gnu++11, the flag will be added
automatically.

The INTERFACE, PUBLIC and PRIVATE keywords are required to
specify the scope of the features.  PRIVATE and PUBLIC items will
populate the COMPILE_FEATURES property of <target>.
PUBLIC and INTERFACE items will populate the
INTERFACE_COMPILE_FEATURES property of <target>.
Repeated calls for the same <target> append items.

New in version 3.11: Allow setting INTERFACE items on IMPORTED targets.

The named <target> must have been created by a command such as
add_executable() or add_library() and must not be an
ALIAS target.

for more on defining buildsystem properties.

Arguments to target_compile_features may use generator expressions
with the syntax $<...>. See the cmake-generator-expressions(7)
manual for available expressions.  See the cmake-compile-features(7)
manual for information on compile features and a list of supported compilers.

See Also¶

target_compile_definitions()

target_compile_options()

target_include_directories()

target_link_libraries()

target_link_directories()

target_link_options()

target_precompile_headers()

target_sources()

Table of Contents

target_compile_features

See Also

Previous topic

target_compile_definitions

Next topic

target_compile_options

This Page

Show Source

Quick search

    <form class="search" action="../search.html" method="get">
      <input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/>
      <input type="submit" value="Go" />
    </form>

Navigation

          index

          next |

          previous |

    CMake »

    3.29.0-rc3 Documentation »

cmake-commands(7) »

target_compile_features

        © Copyright 2000-2024 Kitware, Inc. and Contributors.
      Created using Sphinx 6.2.1.


code:
<!DOCTYPE html>

    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.19: https://docutils.sourceforge.io/" />

  <title>target_compile_options — CMake 3.29.0-rc3 Documentation</title>

    <link rel="stylesheet" type="text/css" href="../_static/pygments.css" />
    <link rel="stylesheet" type="text/css" href="../_static/cmake.css" />

    <link rel="icon" href="../_static/cmake-favicon.ico"/>
    <link rel="index" title="Index" href="../genindex.html" />
    <link rel="search" title="Search" href="../search.html" />
    <link rel="next" title="target_include_directories" href="target_include_directories.html" />
    <link rel="prev" title="target_compile_features" href="target_compile_features.html" />

Navigation

          index

          next |

          previous |

    CMake »

    3.29.0-rc3 Documentation »

cmake-commands(7) »

target_compile_options

target_compile_options¶

Add compile options to a target.

target_compile_options(<target> [BEFORE]
  <INTERFACE|PUBLIC|PRIVATE> [items1...]
  [<INTERFACE|PUBLIC|PRIVATE> [items2...] ...])

Adds options to the COMPILE_OPTIONS or
INTERFACE_COMPILE_OPTIONS target properties. These options
are used when compiling the given <target>, which must have been
created by a command such as add_executable() or
add_library() and must not be an ALIAS target.

Note

These options are not used when linking the target.
See the target_link_options() command for that.

Arguments¶

If BEFORE is specified, the content will be prepended to the property
instead of being appended.  See policy CMP0101 which affects
whether BEFORE will be ignored in certain cases.

The INTERFACE, PUBLIC and PRIVATE keywords are required to
specify the scope of the following arguments.
PRIVATE and PUBLIC items will populate the COMPILE_OPTIONS
property of <target>.  PUBLIC and INTERFACE items will populate the
INTERFACE_COMPILE_OPTIONS property of <target>.
The following arguments specify compile options.  Repeated calls for the same
<target> append items in the order called.

New in version 3.11: Allow setting INTERFACE items on IMPORTED targets.

Arguments to target_compile_options may use generator expressions
with the syntax $<...>. See the cmake-generator-expressions(7)
manual for available expressions.  See the cmake-buildsystem(7) manual
for more on defining buildsystem properties.

Option De-duplication¶

The final set of options used for a target is constructed by
accumulating options from the current target and the usage requirements of
its dependencies.  The set of options is de-duplicated to avoid repetition.

New in version 3.12: While beneficial for individual options, the de-duplication step can break
up option groups.  For example, -option A -option B becomes
-option A B.  One may specify a group of options using shell-like
quoting along with a SHELL: prefix.  The SHELL: prefix is dropped,
and the rest of the option string is parsed using the
separate_arguments() UNIX_COMMAND mode. For example,
"SHELL:-option A" "SHELL:-option B" becomes -option A -option B.

See Also¶

This command can be used to add any options. However, for adding
preprocessor definitions and include directories it is recommended
to use the more specific commands target_compile_definitions()
and target_include_directories().

For directory-wide settings, there is the command add_compile_options().

For file-specific settings, there is the source file property COMPILE_OPTIONS.

This command adds compile options for all languages in a target.
Use the COMPILE_LANGUAGE generator expression to specify
per-language compile options.

target_compile_features()

target_link_libraries()

target_link_directories()

target_link_options()

target_precompile_headers()

target_sources()

CMAKE_<LANG>_FLAGS and CMAKE_<LANG>_FLAGS_<CONFIG>
add language-wide flags passed to all invocations of the compiler.
This includes invocations that drive compiling and those that drive linking.

Table of Contents

target_compile_options

Arguments

Option De-duplication

See Also

Previous topic

target_compile_features

Next topic

target_include_directories

This Page

Show Source

Quick search

    <form class="search" action="../search.html" method="get">
      <input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/>
      <input type="submit" value="Go" />
    </form>

Navigation

          index

          next |

          previous |

    CMake »

    3.29.0-rc3 Documentation »

cmake-commands(7) »

target_compile_options

        © Copyright 2000-2024 Kitware, Inc. and Contributors.
      Created using Sphinx 6.2.1.


code:
<!DOCTYPE html>

    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.19: https://docutils.sourceforge.io/" />

  <title>target_include_directories — CMake 3.29.0-rc3 Documentation</title>

    <link rel="stylesheet" type="text/css" href="../_static/pygments.css" />
    <link rel="stylesheet" type="text/css" href="../_static/cmake.css" />

    <link rel="icon" href="../_static/cmake-favicon.ico"/>
    <link rel="index" title="Index" href="../genindex.html" />
    <link rel="search" title="Search" href="../search.html" />
    <link rel="next" title="target_link_directories" href="target_link_directories.html" />
    <link rel="prev" title="target_compile_options" href="target_compile_options.html" />

Navigation

          index

          next |

          previous |

    CMake »

    3.29.0-rc3 Documentation »

cmake-commands(7) »

target_include_directories

target_include_directories¶

Add include directories to a target.

target_include_directories(<target> [SYSTEM] [AFTER|BEFORE]
  <INTERFACE|PUBLIC|PRIVATE> [items1...]
  [<INTERFACE|PUBLIC|PRIVATE> [items2...] ...])

Specifies include directories to use when compiling a given target.
The named <target> must have been created by a command such
as add_executable() or add_library() and must not be an
ALIAS target.

By using AFTER or BEFORE explicitly, you can select between appending
and prepending, independent of the default.

The INTERFACE, PUBLIC and PRIVATE keywords are required to specify
the scope of the following arguments.
PRIVATE and PUBLIC items will populate the INCLUDE_DIRECTORIES
property of <target>. PUBLIC and INTERFACE items will populate the
INTERFACE_INCLUDE_DIRECTORIES property of <target>.
The following arguments specify include directories.

New in version 3.11: Allow setting INTERFACE items on IMPORTED targets.

Repeated calls for the same <target> append items in the order called.

If SYSTEM is specified, the compiler will be told the directories
are meant as system include directories on some platforms.  This may
have effects such as suppressing warnings or skipping the contained
headers in dependency calculations (see compiler documentation).
Additionally, system include directories are searched after normal
include directories regardless of the order specified.

If SYSTEM is used together with PUBLIC or INTERFACE, the
INTERFACE_SYSTEM_INCLUDE_DIRECTORIES target property will be
populated with the specified directories.

Arguments to target_include_directories may use generator expressions
with the syntax $<...>. See the cmake-generator-expressions(7)
manual for available expressions.  See the cmake-buildsystem(7) manual
for more on defining buildsystem properties.

Specified include directories may be absolute paths or relative paths.
A relative path will be interpreted as relative to the current source
directory (i.e. CMAKE_CURRENT_SOURCE_DIR) and converted to an
absolute path before storing it in the associated target property.
If the path starts with a generator expression, it will always be assumed
to be an absolute path (with one exception noted below) and will be used
unmodified.

Include directories usage requirements commonly differ between the build-tree
and the install-tree.  The BUILD_INTERFACE and
INSTALL_INTERFACE generator expressions can be used to describe
separate usage requirements based on the usage location.  Relative paths
are allowed within the INSTALL_INTERFACE expression and are
interpreted as relative to the installation prefix.  Relative paths should not
be used in BUILD_INTERFACE expressions because they will not be
converted to absolute.  For example:

target_include_directories(mylib PUBLIC
  $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include/mylib>
  $<INSTALL_INTERFACE:include/mylib>  # <prefix>/include/mylib
)

Creating Relocatable Packages¶

Note that it is not advisable to populate the INSTALL_INTERFACE of
the INTERFACE_INCLUDE_DIRECTORIES of a target with absolute paths to the include
directories of dependencies.  That would hard-code into installed packages
the include directory paths for dependencies
as found on the machine the package was made on.

The INSTALL_INTERFACE of the INTERFACE_INCLUDE_DIRECTORIES is only
suitable for specifying the required include directories for headers
provided with the target itself, not those provided by the transitive
dependencies listed in its INTERFACE_LINK_LIBRARIES target
property.  Those dependencies should themselves be targets that specify
their own header locations in INTERFACE_INCLUDE_DIRECTORIES.

See the Creating Relocatable Packages section of the
cmake-packages(7) manual for discussion of additional care
that must be taken when specifying usage requirements while creating
packages for redistribution.

See Also¶

include_directories()

target_compile_definitions()

target_compile_features()

target_compile_options()

target_link_libraries()

target_link_directories()

target_link_options()

target_precompile_headers()

target_sources()

Table of Contents

target_include_directories

Creating Relocatable Packages

See Also

Previous topic

target_compile_options

Next topic

target_link_directories

This Page

Show Source

Quick search

    <form class="search" action="../search.html" method="get">
      <input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/>
      <input type="submit" value="Go" />
    </form>

Navigation

          index

          next |

          previous |

    CMake »

    3.29.0-rc3 Documentation »

cmake-commands(7) »

target_include_directories

        © Copyright 2000-2024 Kitware, Inc. and Contributors.
      Created using Sphinx 6.2.1.


code:
<!DOCTYPE html>

    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.19: https://docutils.sourceforge.io/" />

  <title>target_link_directories — CMake 3.29.0-rc3 Documentation</title>

    <link rel="stylesheet" type="text/css" href="../_static/pygments.css" />
    <link rel="stylesheet" type="text/css" href="../_static/cmake.css" />

    <link rel="icon" href="../_static/cmake-favicon.ico"/>
    <link rel="index" title="Index" href="../genindex.html" />
    <link rel="search" title="Search" href="../search.html" />
    <link rel="next" title="target_link_libraries" href="target_link_libraries.html" />
    <link rel="prev" title="target_include_directories" href="target_include_directories.html" />

Navigation

          index

          next |

          previous |

    CMake »

    3.29.0-rc3 Documentation »

cmake-commands(7) »

target_link_directories

target_link_directories¶

New in version 3.13.

Add link directories to a target.

target_link_directories(<target> [BEFORE]
  <INTERFACE|PUBLIC|PRIVATE> [items1...]
  [<INTERFACE|PUBLIC|PRIVATE> [items2...] ...])

Specifies the paths in which the linker should search for libraries when
linking a given target.  Each item can be an absolute or relative path,
with the latter being interpreted as relative to the current source
directory.  These items will be added to the link command.

The named <target> must have been created by a command such as
add_executable() or add_library() and must not be an
ALIAS target.

The INTERFACE, PUBLIC and PRIVATE keywords are required to
specify the scope of the items that follow
them. PRIVATE and PUBLIC items will populate the
LINK_DIRECTORIES property of <target>.  PUBLIC and
INTERFACE items will populate the INTERFACE_LINK_DIRECTORIES
property of <target> (IMPORTED targets only
support INTERFACE items).
Each item specifies a link directory and will be converted to an absolute
path if necessary before adding it to the relevant property.  Repeated
calls for the same <target> append items in the order called.

If BEFORE is specified, the content will be prepended to the relevant
property instead of being appended.

Arguments to target_link_directories may use generator expressions
with the syntax $<...>. See the cmake-generator-expressions(7)
manual for available expressions.  See the cmake-buildsystem(7) manual
for more on defining buildsystem properties.

Note

This command is rarely necessary and should be avoided where there are
other choices.  Prefer to pass full absolute paths to libraries where
possible, since this ensures the correct library will always be linked.
The find_library() command provides the full path, which can
generally be used directly in calls to target_link_libraries().
Situations where a library search path may be needed include:

Project generators like Xcode where the user can switch target
architecture at build time, but a full path to a library cannot
be used because it only provides one architecture (i.e. it is not
a universal binary).

Libraries may themselves have other private library dependencies
that expect to be found via RPATH mechanisms, but some linkers
are not able to fully decode those paths (e.g. due to the presence
of things like $ORIGIN).

See Also¶

link_directories()

target_compile_definitions()

target_compile_features()

target_compile_options()

target_include_directories()

target_link_libraries()

target_link_options()

target_precompile_headers()

target_sources()

Table of Contents

target_link_directories

See Also

Previous topic

target_include_directories

Next topic

target_link_libraries

This Page

Show Source

Quick search

    <form class="search" action="../search.html" method="get">
      <input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/>
      <input type="submit" value="Go" />
    </form>

Navigation

          index

          next |

          previous |

    CMake »

    3.29.0-rc3 Documentation »

cmake-commands(7) »

target_link_directories

        © Copyright 2000-2024 Kitware, Inc. and Contributors.
      Created using Sphinx 6.2.1.


code:
<!DOCTYPE html>

    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.19: https://docutils.sourceforge.io/" />

  <title>target_link_libraries — CMake 3.29.0-rc3 Documentation</title>

    <link rel="stylesheet" type="text/css" href="../_static/pygments.css" />
    <link rel="stylesheet" type="text/css" href="../_static/cmake.css" />

    <link rel="icon" href="../_static/cmake-favicon.ico"/>
    <link rel="index" title="Index" href="../genindex.html" />
    <link rel="search" title="Search" href="../search.html" />
    <link rel="next" title="target_link_options" href="target_link_options.html" />
    <link rel="prev" title="target_link_directories" href="target_link_directories.html" />

Navigation

          index

          next |

          previous |

    CMake »

    3.29.0-rc3 Documentation »

cmake-commands(7) »

target_link_libraries

target_link_libraries¶

Contents

target_link_libraries

Overview

Libraries for a Target and/or its Dependents

Libraries for both a Target and its Dependents

Libraries for a Target and/or its Dependents (Legacy)

Libraries for Dependents Only (Legacy)

Linking Object Libraries

Linking Object Libraries via $<TARGET_OBJECTS>

Cyclic Dependencies of Static Libraries

Creating Relocatable Packages

See Also

Specify libraries or flags to use when linking a given target and/or
its dependents.  Usage requirements
from linked library targets will be propagated.  Usage requirements
of a target's dependencies affect compilation of its own sources.

Overview¶

This command has several signatures as detailed in subsections below.
All of them have the general form

target_link_libraries(<target> ... <item>... ...)

The named <target> must have been created by a command such as
add_executable() or add_library() and must not be an
ALIAS target.  If policy CMP0079 is not
set to NEW then the target must have been created in the current
directory.  Repeated calls for the same <target> append items in
the order called.

New in version 3.13: The <target> doesn't have to be defined in the same directory as the
target_link_libraries call.

Each <item> may be:

A library target name: The generated link line will have the
full path to the linkable library file associated with the target.
The buildsystem will have a dependency to re-link <target> if
the library file changes.

The named target must be created by add_library() within
the project or as an IMPORTED library.
If it is created within the project an ordering dependency will
automatically be added in the build system to make sure the named
library target is up-to-date before the <target> links.

If an imported library has the IMPORTED_NO_SONAME
target property set, CMake may ask the linker to search for
the library instead of using the full path
(e.g. /usr/lib/libfoo.so becomes -lfoo).

The full path to the target's artifact will be quoted/escaped for
the shell automatically.

A full path to a library file: The generated link line will
normally preserve the full path to the file. The buildsystem will
have a dependency to re-link <target> if the library file changes.

There are some cases where CMake may ask the linker to search for
the library (e.g. /usr/lib/libfoo.so becomes -lfoo), such
as when a shared library is detected to have no SONAME field.
See policy CMP0060 for discussion of another case.

If the library file is in a macOS framework, the Headers directory
of the framework will also be processed as a
usage requirement.  This has the same
effect as passing the framework directory as an include directory.

New in version 3.28: The library file may point to a .xcframework folder on Apple platforms.
If it does, the target will get the selected library's Headers
directory as a usage requirement.

New in version 3.8: On Visual Studio Generators for VS 2010 and above, library files
ending in .targets will be treated as MSBuild targets files and
imported into generated project files.  This is not supported by other
generators.

The full path to the library file will be quoted/escaped for
the shell automatically.

A plain library name: The generated link line will ask the linker
to search for the library (e.g. foo becomes -lfoo or foo.lib).

The library name/flag is treated as a command-line string fragment and
will be used with no extra quoting or escaping.

A link flag: Item names starting with -, but not -l or
-framework, are treated as linker flags.  Note that such flags will
be treated like any other library link item for purposes of transitive
dependencies, so they are generally safe to specify only as private link
items that will not propagate to dependents.

Link flags specified here are inserted into the link command in the same
place as the link libraries. This might not be correct, depending on
the linker. Use the LINK_OPTIONS target property or
target_link_options() command to add link
flags explicitly. The flags will then be placed at the toolchain-defined
flag position in the link command.

New in version 3.13: LINK_OPTIONS target property and target_link_options()
command.  For earlier versions of CMake, use LINK_FLAGS
property instead.

The link flag is treated as a command-line string fragment and
will be used with no extra quoting or escaping.

A generator expression: A $<...> generator expression may evaluate to any of the above
items or to a semicolon-separated list of them.
If the ... contains any ; characters, e.g. after evaluation
of a ${list} variable, be sure to use an explicitly quoted
argument "$<...>" so that this command receives it as a
single <item>.

Additionally, a generator expression may be used as a fragment of
any of the above items, e.g. foo$<1:_d>.

Note that generator expressions will not be used in OLD handling of
policy CMP0003 or policy CMP0004.

A debug, optimized, or general keyword immediately followed
by another <item>.  The item following such a keyword will be used
only for the corresponding build configuration.  The debug keyword
corresponds to the Debug configuration (or to configurations named
in the DEBUG_CONFIGURATIONS global property if it is set).
The optimized keyword corresponds to all other configurations.  The
general keyword corresponds to all configurations, and is purely
optional.  Higher granularity may be achieved for per-configuration
rules by creating and linking to
IMPORTED library targets.
These keywords are interpreted immediately by this command and therefore
have no special meaning when produced by a generator expression.

Items containing ::, such as Foo::Bar, are assumed to be
IMPORTED or ALIAS library
target names and will cause an error if no such target exists.
See policy CMP0028.

See the cmake-buildsystem(7) manual for more on defining
buildsystem properties.

Libraries for a Target and/or its Dependents¶

target_link_libraries(<target>
                      <PRIVATE|PUBLIC|INTERFACE> <item>...
                     [<PRIVATE|PUBLIC|INTERFACE> <item>...]...)

The PUBLIC, PRIVATE and INTERFACE
scope keywords can be used to
specify both the link dependencies and the link interface in one command.

Libraries and targets following PUBLIC are linked to, and are made
part of the link interface.  Libraries and targets following PRIVATE
are linked to, but are not made part of the link interface.  Libraries
following INTERFACE are appended to the link interface and are not
used for linking <target>.

Libraries for both a Target and its Dependents¶

target_link_libraries(<target> <item>...)

Library dependencies are transitive by default with this signature.
When this target is linked into another target then the libraries
linked to this target will appear on the link line for the other
target too.  This transitive "link interface" is stored in the
INTERFACE_LINK_LIBRARIES target property and may be overridden
by setting the property directly.  When CMP0022 is not set to
NEW, transitive linking is built in but may be overridden by the
LINK_INTERFACE_LIBRARIES property.  Calls to other signatures
of this command may set the property making any libraries linked
exclusively by this signature private.

Libraries for a Target and/or its Dependents (Legacy)¶

target_link_libraries(<target>
                      <LINK_PRIVATE|LINK_PUBLIC> <lib>...
                     [<LINK_PRIVATE|LINK_PUBLIC> <lib>...]...)

The LINK_PUBLIC and LINK_PRIVATE modes can be used to specify both
the link dependencies and the link interface in one command.

This signature is for compatibility only.  Prefer the PUBLIC or
PRIVATE keywords instead.

Libraries and targets following LINK_PUBLIC are linked to, and are
made part of the INTERFACE_LINK_LIBRARIES.  If policy
CMP0022 is not NEW, they are also made part of the
LINK_INTERFACE_LIBRARIES.  Libraries and targets following
LINK_PRIVATE are linked to, but are not made part of the
INTERFACE_LINK_LIBRARIES (or LINK_INTERFACE_LIBRARIES).

Libraries for Dependents Only (Legacy)¶

target_link_libraries(<target> LINK_INTERFACE_LIBRARIES <item>...)

The LINK_INTERFACE_LIBRARIES mode appends the libraries to the
INTERFACE_LINK_LIBRARIES target property instead of using them
for linking.  If policy CMP0022 is not NEW, then this mode
also appends libraries to the LINK_INTERFACE_LIBRARIES and its
per-configuration equivalent.

This signature is for compatibility only.  Prefer the INTERFACE mode
instead.

Libraries specified as debug are wrapped in a generator expression to
correspond to debug builds.  If policy CMP0022 is
not NEW, the libraries are also appended to the
LINK_INTERFACE_LIBRARIES_DEBUG
property (or to the properties corresponding to configurations listed in
the DEBUG_CONFIGURATIONS global property if it is set).
Libraries specified as optimized are appended to the
INTERFACE_LINK_LIBRARIES property.  If policy CMP0022
is not NEW, they are also appended to the
LINK_INTERFACE_LIBRARIES property.  Libraries specified as
general (or without any keyword) are treated as if specified for both
debug and optimized.

Linking Object Libraries¶

New in version 3.12.

Object Libraries may be used as the <target> (first) argument
of target_link_libraries to specify dependencies of their sources
on other libraries.  For example, the code

add_library(A SHARED a.c)
target_compile_definitions(A PUBLIC A)

add_library(obj OBJECT obj.c)
target_compile_definitions(obj PUBLIC OBJ)
target_link_libraries(obj PUBLIC A)

compiles obj.c with -DA -DOBJ and establishes usage requirements
for obj that propagate to its dependents.

Normal libraries and executables may link to Object Libraries
to get their objects and usage requirements.  Continuing the above
example, the code

add_library(B SHARED b.c)
target_link_libraries(B PUBLIC obj)

compiles b.c with -DA -DOBJ, creates shared library B
with object files from b.c and obj.c, and links B to A.
Furthermore, the code

add_executable(main main.c)
target_link_libraries(main B)

compiles main.c with -DA -DOBJ and links executable main
to B and A.  The object library's usage requirements are
propagated transitively through B, but its object files are not.

Object Libraries may "link" to other object libraries to get
usage requirements, but since they do not have a link step nothing
is done with their object files.  Continuing from the above example,
the code:

add_library(obj2 OBJECT obj2.c)
target_link_libraries(obj2 PUBLIC obj)

add_executable(main2 main2.c)
target_link_libraries(main2 obj2)

compiles obj2.c with -DA -DOBJ, creates executable main2
with object files from main2.c and obj2.c, and links main2
to A.

In other words, when Object Libraries appear in a target's
INTERFACE_LINK_LIBRARIES property they will be
treated as Interface Libraries, but when they appear in
a target's LINK_LIBRARIES property their object files
will be included in the link too.

Linking Object Libraries via $<TARGET_OBJECTS>¶

New in version 3.21.

The object files associated with an object library may be referenced
by the $<TARGET_OBJECTS> generator expression.  Such object
files are placed on the link line before all libraries, regardless
of their relative order.  Additionally, an ordering dependency will be
added to the build system to make sure the object library is up-to-date
before the dependent target links.  For example, the code

add_library(obj3 OBJECT obj3.c)
target_compile_definitions(obj3 PUBLIC OBJ3)

add_executable(main3 main3.c)
target_link_libraries(main3 PRIVATE a3 $<TARGET_OBJECTS:obj3> b3)

links executable main3 with object files from main3.c
and obj3.c followed by the a3 and b3 libraries.
main3.c is not compiled with usage requirements from obj3,
such as -DOBJ3.

This approach can be used to achieve transitive inclusion of object
files in link lines as usage requirements.  Continuing the above
example, the code

add_library(iface_obj3 INTERFACE)
target_link_libraries(iface_obj3 INTERFACE obj3 $<TARGET_OBJECTS:obj3>)

creates an interface library iface_obj3 that forwards the obj3
usage requirements and adds the obj3 object files to dependents'
link lines.  The code

add_executable(use_obj3 use_obj3.c)
target_link_libraries(use_obj3 PRIVATE iface_obj3)

compiles use_obj3.c with -DOBJ3 and links executable use_obj3
with object files from use_obj3.c and obj3.c.

This also works transitively through a static library.  Since a static
library does not link, it does not consume the object files from
object libraries referenced this way.  Instead, the object files
become transitive link dependencies of the static library.
Continuing the above example, the code

add_library(static3 STATIC static3.c)
target_link_libraries(static3 PRIVATE iface_obj3)

add_executable(use_static3 use_static3.c)
target_link_libraries(use_static3 PRIVATE static3)

compiles static3.c with -DOBJ3 and creates libstatic3.a
using only its own object file.  use_static3.c is compiled without
-DOBJ3 because the usage requirement is not transitive through
the private dependency of static3.  However, the link dependencies
of static3 are propagated, including the iface_obj3 reference
to $<TARGET_OBJECTS:obj3>.  The use_static3 executable is
created with object files from use_static3.c and obj3.c, and
linked to library libstatic3.a.

When using this approach, it is the project's responsibility to avoid
linking multiple dependent binaries to iface_obj3, because they will
all get the obj3 object files on their link lines.

Note

Referencing $<TARGET_OBJECTS> in target_link_libraries
calls worked in versions of CMake prior to 3.21 for some cases,
but was not fully supported:

It did not place the object files before libraries on link lines.

It did not add an ordering dependency on the object library.

It did not work in Xcode with multiple architectures.

Cyclic Dependencies of Static Libraries¶

The library dependency graph is normally acyclic (a DAG), but in the case
of mutually-dependent STATIC libraries CMake allows the graph to
contain cycles (strongly connected components).  When another target links
to one of the libraries, CMake repeats the entire connected component.
For example, the code

add_library(A STATIC a.c)
add_library(B STATIC b.c)
target_link_libraries(A B)
target_link_libraries(B A)
add_executable(main main.c)
target_link_libraries(main A)

links main to A B A B.  While one repetition is usually
sufficient, pathological object file and symbol arrangements can require
more.  One may handle such cases by using the
LINK_INTERFACE_MULTIPLICITY target property or by manually
repeating the component in the last target_link_libraries call.
However, if two archives are really so interdependent they should probably
be combined into a single archive, perhaps by using Object Libraries.

Creating Relocatable Packages¶

Note that it is not advisable to populate the
INTERFACE_LINK_LIBRARIES of a target with absolute paths to dependencies.
That would hard-code into installed packages the library file paths
for dependencies as found on the machine the package was made on.

See the Creating Relocatable Packages section of the
cmake-packages(7) manual for discussion of additional care
that must be taken when specifying usage requirements while creating
packages for redistribution.

See Also¶

target_compile_definitions()

target_compile_features()

target_compile_options()

target_include_directories()

target_link_directories()

target_link_options()

target_precompile_headers()

target_sources()

Table of Contents

target_link_libraries

Overview

Libraries for a Target and/or its Dependents

Libraries for both a Target and its Dependents

Libraries for a Target and/or its Dependents (Legacy)

Libraries for Dependents Only (Legacy)

Linking Object Libraries

Linking Object Libraries via $<TARGET_OBJECTS>

Cyclic Dependencies of Static Libraries

Creating Relocatable Packages

See Also

Previous topic

target_link_directories

Next topic

target_link_options

This Page

Show Source

Quick search

    <form class="search" action="../search.html" method="get">
      <input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/>
      <input type="submit" value="Go" />
    </form>

Navigation

          index

          next |

          previous |

    CMake »

    3.29.0-rc3 Documentation »

cmake-commands(7) »

target_link_libraries

        © Copyright 2000-2024 Kitware, Inc. and Contributors.
      Created using Sphinx 6.2.1.


code:
<!DOCTYPE html>

    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.19: https://docutils.sourceforge.io/" />

  <title>target_link_options — CMake 3.29.0-rc3 Documentation</title>

    <link rel="stylesheet" type="text/css" href="../_static/pygments.css" />
    <link rel="stylesheet" type="text/css" href="../_static/cmake.css" />

    <link rel="icon" href="../_static/cmake-favicon.ico"/>
    <link rel="index" title="Index" href="../genindex.html" />
    <link rel="search" title="Search" href="../search.html" />
    <link rel="next" title="target_precompile_headers" href="target_precompile_headers.html" />
    <link rel="prev" title="target_link_libraries" href="target_link_libraries.html" />

Navigation

          index

          next |

          previous |

    CMake »

    3.29.0-rc3 Documentation »

cmake-commands(7) »

target_link_options

target_link_options¶

New in version 3.13.

Add options to the link step for an executable, shared library or module
library target.

target_link_options(<target> [BEFORE]
  <INTERFACE|PUBLIC|PRIVATE> [items1...]
  [<INTERFACE|PUBLIC|PRIVATE> [items2...] ...])

The named <target> must have been created by a command such as
add_executable() or add_library() and must not be an
ALIAS target.

This command can be used to add any link options, but alternative commands
exist to add libraries (target_link_libraries() or
link_libraries()).  See documentation of the
directory and
target LINK_OPTIONS properties.

Note

This command cannot be used to add options for static library targets,
since they do not use a linker.  To add archiver or MSVC librarian flags,
see the STATIC_LIBRARY_OPTIONS target property.

If BEFORE is specified, the content will be prepended to the property
instead of being appended.

The INTERFACE, PUBLIC and PRIVATE keywords are required to
specify the scope of the following arguments.
PRIVATE and PUBLIC items will populate the LINK_OPTIONS
property of <target>.  PUBLIC and INTERFACE items will populate the
INTERFACE_LINK_OPTIONS property of <target>.
The following arguments specify link options.  Repeated calls for the same
<target> append items in the order called.

Note

IMPORTED targets only support INTERFACE items.

Arguments to target_link_options may use generator expressions
with the syntax $<...>. See the cmake-generator-expressions(7)
manual for available expressions.  See the cmake-buildsystem(7) manual
for more on defining buildsystem properties.

Host And Device Specific Link Options¶

New in version 3.18: When a device link step is involved, which is controlled by
CUDA_SEPARABLE_COMPILATION and
CUDA_RESOLVE_DEVICE_SYMBOLS properties and policy CMP0105,
the raw options will be delivered to the host and device link steps (wrapped in
-Xcompiler or equivalent for device link). Options wrapped with
$<DEVICE_LINK:...> generator expression will be used
only for the device link step. Options wrapped with $<HOST_LINK:...>
generator expression will be used only for the host link step.

Option De-duplication¶

The final set of options used for a target is constructed by
accumulating options from the current target and the usage requirements of
its dependencies.  The set of options is de-duplicated to avoid repetition.

New in version 3.12: While beneficial for individual options, the de-duplication step can break
up option groups.  For example, -option A -option B becomes
-option A B.  One may specify a group of options using shell-like
quoting along with a SHELL: prefix.  The SHELL: prefix is dropped,
and the rest of the option string is parsed using the
separate_arguments() UNIX_COMMAND mode. For example,
"SHELL:-option A" "SHELL:-option B" becomes -option A -option B.

Handling Compiler Driver Differences¶

To pass options to the linker tool, each compiler driver has its own syntax.
The LINKER: prefix and , separator can be used to specify, in a portable
way, options to pass to the linker tool. LINKER: is replaced by the
appropriate driver option and , by the appropriate driver separator.
The driver prefix and driver separator are given by the values of the
CMAKE_<LANG>_LINKER_WRAPPER_FLAG and
CMAKE_<LANG>_LINKER_WRAPPER_FLAG_SEP variables.

For example, "LINKER:-z,defs" becomes -Xlinker -z -Xlinker defs for
Clang and -Wl,-z,defs for GNU GCC.

The LINKER: prefix can be specified as part of a SHELL: prefix
expression.

The LINKER: prefix supports, as an alternative syntax, specification of
arguments using the SHELL: prefix and space as separator. The previous
example then becomes "LINKER:SHELL:-z defs".

Note

Specifying the SHELL: prefix anywhere other than at the beginning of the
LINKER: prefix is not supported.

See Also¶

target_compile_definitions()

target_compile_features()

target_compile_options()

target_include_directories()

target_link_libraries()

target_link_directories()

target_precompile_headers()

target_sources()

CMAKE_<LANG>_FLAGS and CMAKE_<LANG>_FLAGS_<CONFIG>
add language-wide flags passed to all invocations of the compiler.
This includes invocations that drive compiling and those that drive linking.

Table of Contents

target_link_options

Host And Device Specific Link Options

Option De-duplication

Handling Compiler Driver Differences

See Also

Previous topic

target_link_libraries

Next topic

target_precompile_headers

This Page

Show Source

Quick search

    <form class="search" action="../search.html" method="get">
      <input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/>
      <input type="submit" value="Go" />
    </form>

Navigation

          index

          next |

          previous |

    CMake »

    3.29.0-rc3 Documentation »

cmake-commands(7) »

target_link_options

        © Copyright 2000-2024 Kitware, Inc. and Contributors.
      Created using Sphinx 6.2.1.


code:
<!DOCTYPE html>

    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.19: https://docutils.sourceforge.io/" />

  <title>target_precompile_headers — CMake 3.29.0-rc3 Documentation</title>

    <link rel="stylesheet" type="text/css" href="../_static/pygments.css" />
    <link rel="stylesheet" type="text/css" href="../_static/cmake.css" />

    <link rel="icon" href="../_static/cmake-favicon.ico"/>
    <link rel="index" title="Index" href="../genindex.html" />
    <link rel="search" title="Search" href="../search.html" />
    <link rel="next" title="target_sources" href="target_sources.html" />
    <link rel="prev" title="target_link_options" href="target_link_options.html" />

Navigation

          index

          next |

          previous |

    CMake »

    3.29.0-rc3 Documentation »

cmake-commands(7) »

target_precompile_headers

target_precompile_headers¶

New in version 3.16.

Add a list of header files to precompile.

Precompiling header files can speed up compilation by creating a partially
processed version of some header files, and then using that version during
compilations rather than repeatedly parsing the original headers.

Main Form¶

target_precompile_headers(<target>
  <INTERFACE|PUBLIC|PRIVATE> [header1...]
  [<INTERFACE|PUBLIC|PRIVATE> [header2...] ...])

The command adds header files to the PRECOMPILE_HEADERS and/or
INTERFACE_PRECOMPILE_HEADERS target properties of <target>.
The named <target> must have been created by a command such as
add_executable() or add_library() and must not be an
ALIAS target.

The INTERFACE, PUBLIC and PRIVATE keywords are required to
specify the scope of the following arguments.
PRIVATE and PUBLIC items will populate the PRECOMPILE_HEADERS
property of <target>.  PUBLIC and INTERFACE items will populate the
INTERFACE_PRECOMPILE_HEADERS property of <target>
(IMPORTED targets only support INTERFACE items).
Repeated calls for the same <target> will append items in the order called.

Projects should generally avoid using PUBLIC or INTERFACE for targets
that will be exported, or they should at least use
the $<BUILD_INTERFACE:...> generator expression to prevent precompile
headers from appearing in an installed exported target.  Consumers of a target
should typically be in control of what precompile headers they use, not have
precompile headers forced on them by the targets being consumed (since
precompile headers are not typically usage requirements).  A notable exception
to this is where an interface library is created
to define a commonly used set of precompile headers in one place and then other
targets link to that interface library privately.  In this case, the interface
library exists specifically to propagate the precompile headers to its
consumers and the consumer is effectively still in control, since it decides
whether to link to the interface library or not.

The list of header files is used to generate a header file named
cmake_pch.h|xx which is used to generate the precompiled header file
(.pch, .gch, .pchi) artifact.  The cmake_pch.h|xx header
file will be force included (-include for GCC, /FI for MSVC) to
all source files, so sources do not need to have #include "pch.h".

Header file names specified with angle brackets (e.g. <unordered_map>) or
explicit double quotes (escaped for the cmake-language(7),
e.g. [["other_header.h"]]) will be treated as is, and include directories
must be available for the compiler to find them.  Other header file names
(e.g. project_header.h) are interpreted as being relative to the current
source directory (e.g. CMAKE_CURRENT_SOURCE_DIR) and will be
included by absolute path.  For example:

target_precompile_headers(myTarget
  PUBLIC
    project_header.h
  PRIVATE
    [["other_header.h"]]
    <unordered_map>
)

for more on defining buildsystem properties.

Arguments to target_precompile_headers may use generator expressions
with the syntax $<...>. See the cmake-generator-expressions(7)
manual for available expressions.  The $<COMPILE_LANGUAGE:...> generator
expression is particularly useful for specifying a language-specific header
to precompile for only one language (e.g. CXX and not C).  In this
case, header file names that are not explicitly in double quotes or angle
brackets must be specified by absolute path.  Also, when specifying angle
brackets inside a generator expression, be sure to encode the closing
> as $<ANGLE-R>.  For example:

target_precompile_headers(mylib PRIVATE
  "$<$<COMPILE_LANGUAGE:CXX>:${CMAKE_CURRENT_SOURCE_DIR}/cxx_only.h>"
  "$<$<COMPILE_LANGUAGE:C>:<stddef.h$<ANGLE-R>>"
  "$<$<COMPILE_LANGUAGE:CXX>:<cstddef$<ANGLE-R>>"
)

Reusing Precompile Headers¶

The command also supports a second signature which can be used to specify that
one target reuses a precompiled header file artifact from another target
instead of generating its own:

target_precompile_headers(<target> REUSE_FROM <other_target>)

This form sets the PRECOMPILE_HEADERS_REUSE_FROM property to
<other_target> and adds a dependency such that <target> will depend
on <other_target>.  CMake will halt with an error if the
PRECOMPILE_HEADERS property of <target> is already set when
the REUSE_FROM form is used.

Note

The REUSE_FROM form requires the same set of compiler options,
compiler flags and compiler definitions for both <target> and
<other_target>.  Some compilers (e.g. GCC) may issue a warning if the
precompiled header file cannot be used (-Winvalid-pch).

See Also¶

To disable precompile headers for specific targets, see the
DISABLE_PRECOMPILE_HEADERS target property.

To prevent precompile headers from being used when compiling a specific
source file, see the SKIP_PRECOMPILE_HEADERS source file property.

target_compile_definitions()

target_compile_features()

target_compile_options()

target_include_directories()

target_link_libraries()

target_link_directories()

target_link_options()

target_sources()

Table of Contents

target_precompile_headers

Main Form

Reusing Precompile Headers

See Also

Previous topic

target_link_options

Next topic

target_sources

This Page

Show Source

Quick search

    <form class="search" action="../search.html" method="get">
      <input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/>
      <input type="submit" value="Go" />
    </form>

Navigation

          index

          next |

          previous |

    CMake »

    3.29.0-rc3 Documentation »

cmake-commands(7) »

target_precompile_headers

        © Copyright 2000-2024 Kitware, Inc. and Contributors.
      Created using Sphinx 6.2.1.