CMAKE-MODULES(7) CMake CMAKE-MODULES(7)

cmake-modules - CMake Modules Reference

The modules listed here are part of the CMake distribution. Projects may provide further modules; their location(s) can be specified in the CMAKE_MODULE_PATH variable.

These modules are loaded using the include() command.

Added in version 3.7.

Create a test that automatically loads specified data onto an Android device.

Use this module to push data needed for testing an Android device behavior onto a connected Android device. The module will accept files and libraries as well as separate destinations for each. It will create a test that loads the files into a device object store and link to them from the specified destination. The files are only uploaded if they are not already in the object store.

For example:

include(AndroidTestUtilities)
android_add_test_data(
  example_setup_test
  FILES <files>...
  LIBS <libs>...
  DEVICE_TEST_DIR "/data/local/tests/example"
  DEVICE_OBJECT_STORE "/sdcard/.ExternalData/SHA"
  )

At build time a test named "example_setup_test" will be created. Run this test on the command line with ctest(1) to load the data onto the Android device.

Module Functions

android_add_test_data(<test-name>
  [FILES <files>...] [FILES_DEST <device-dir>]
  [LIBS <libs>...]   [LIBS_DEST <device-dir>]
  [DEVICE_OBJECT_STORE <device-dir>]
  [DEVICE_TEST_DIR <device-dir>]
  [NO_LINK_REGEX <strings>...]
  )

The android_add_test_data function is used to copy files and libraries needed to run project-specific tests. On the host operating system, this is done at build time. For on-device testing, the files are loaded onto the device by the manufactured test at run time.

This function accepts the following named parameters:

zero or more files needed for testing
zero or more libraries needed for testing
absolute path where the data files are expected to be
absolute path where the libraries are expected to be
absolute path to the location where the data is stored on-device
absolute path to the root directory of the on-device test location
list of regex strings matching the names of files that should be copied from the object store to the testing directory

Functions to help assemble a standalone bundle application.

A collection of CMake utility functions useful for dealing with .app bundles on the Mac and bundle-like directories on any OS.

The following functions are provided by this module:

fixup_bundle
copy_and_fixup_bundle
verify_app
get_bundle_main_executable
get_dotapp_dir
get_bundle_and_executable
get_bundle_all_executables
get_item_key
get_item_rpaths
clear_bundle_keys
set_bundle_key_values
get_bundle_keys
copy_resolved_item_into_bundle
copy_resolved_framework_into_bundle
fixup_bundle_item
verify_bundle_prerequisites
verify_bundle_symlinks

Requires CMake 2.6 or greater because it uses function, break and PARENT_SCOPE. Also depends on GetPrerequisites.cmake.

DO NOT USE THESE FUNCTIONS AT CONFIGURE TIME (from CMakeLists.txt)! Instead, invoke them from an install(CODE) or install(SCRIPT) rule.

fixup_bundle(<app> <libs> <dirs>)

Fix up <app> bundle in-place and make it standalone, such that it can be drag-n-drop copied to another machine and run on that machine as long as all of the system libraries are compatible.

If you pass plugins to fixup_bundle as the libs parameter, you should install them or copy them into the bundle before calling fixup_bundle. The <libs> parameter is a list of libraries that must be fixed up, but that cannot be determined by otool output analysis (i.e. plugins).

Gather all the keys for all the executables and libraries in a bundle, and then, for each key, copy each prerequisite into the bundle. Then fix each one up according to its own list of prerequisites.

Then clear all the keys and call verify_app on the final bundle to ensure that it is truly standalone.

Added in version 3.6: As an optional parameter (IGNORE_ITEM) a list of file names can be passed, which are then ignored (e.g. IGNORE_ITEM "vcredist_x86.exe;vcredist_x64.exe").

copy_and_fixup_bundle(<src> <dst> <libs> <dirs>)

Makes a copy of the bundle <src> at location <dst> and then fixes up the new copied bundle in-place at <dst>.

verify_app(<app>)

Verifies that an application <app> appears valid based on running analysis tools on it. Calls message(FATAL_ERROR) if the application is not verified.

Added in version 3.6: As an optional parameter (IGNORE_ITEM) a list of file names can be passed, which are then ignored (e.g. IGNORE_ITEM "vcredist_x86.exe;vcredist_x64.exe")

get_bundle_main_executable(<bundle> <result_var>)

The result will be the full path name of the bundle's main executable file or an error: prefixed string if it could not be determined.

get_dotapp_dir(<exe> <dotapp_dir_var>)

Returns the nearest parent dir whose name ends with .app given the full path to an executable. If there is no such parent dir, then simply return the dir containing the executable.

The returned directory may or may not exist.

get_bundle_and_executable(<app> <bundle_var> <executable_var> <valid_var>)

Takes either a .app directory name or the name of an executable nested inside a .app directory and returns the path to the .app directory in <bundle_var> and the path to its main executable in <executable_var>.

get_bundle_all_executables(<bundle> <exes_var>)

Scans <bundle> bundle recursively for all <exes_var> executable files and accumulates them into a variable.

get_item_key(<item> <key_var>)

Given <item> file name, generate <key_var> key that should be unique considering the set of libraries that need copying or fixing up to make a bundle standalone. This is essentially the file name including extension with . replaced by _

This key is used as a prefix for CMake variables so that we can associate a set of variables with a given item based on its key.

clear_bundle_keys(<keys_var>)

Loop over the <keys_var> list of keys, clearing all the variables associated with each key. After the loop, clear the list of keys itself.

Caller of get_bundle_keys should call clear_bundle_keys when done with list of keys.

set_bundle_key_values(<keys_var> <context> <item> <exepath> <dirs>
                      <copyflag> [<rpaths>])

Add <keys_var> key to the list (if necessary) for the given item. If added, also set all the variables associated with that key.

get_bundle_keys(<app> <libs> <dirs> <keys_var>)

Loop over all the executable and library files within <app> bundle (and given as extra <libs>) and accumulate a list of keys representing them. Set values associated with each key such that we can loop over all of them and copy prerequisite libs into the bundle and then do appropriate install_name_tool fixups.

Added in version 3.6: As an optional parameter (IGNORE_ITEM) a list of file names can be passed, which are then ignored (e.g. IGNORE_ITEM "vcredist_x86.exe;vcredist_x64.exe")

copy_resolved_item_into_bundle(<resolved_item> <resolved_embedded_item>)

Copy a resolved item into the bundle if necessary. Copy is not necessary, if the <resolved_item> is "the same as" the <resolved_embedded_item>.

copy_resolved_framework_into_bundle(<resolved_item> <resolved_embedded_item>)

Copy a resolved framework into the bundle if necessary. Copy is not necessary, if the <resolved_item> is "the same as" the <resolved_embedded_item>.

By default, BU_COPY_FULL_FRAMEWORK_CONTENTS is not set. If you want full frameworks embedded in your bundles, set BU_COPY_FULL_FRAMEWORK_CONTENTS to ON before calling fixup_bundle. By default, COPY_RESOLVED_FRAMEWORK_INTO_BUNDLE copies the framework dylib itself plus the framework Resources directory.

fixup_bundle_item(<resolved_embedded_item> <exepath> <dirs>)

Get the direct/non-system prerequisites of the <resolved_embedded_item>. For each prerequisite, change the way it is referenced to the value of the _EMBEDDED_ITEM keyed variable for that prerequisite. (Most likely changing to an @executable_path style reference.)

This function requires that the <resolved_embedded_item> be inside the bundle already. In other words, if you pass plugins to fixup_bundle as the libs parameter, you should install them or copy them into the bundle before calling fixup_bundle. The libs parameter is a list of libraries that must be fixed up, but that cannot be determined by otool output analysis. (i.e., plugins)

Also, change the id of the item being fixed up to its own _EMBEDDED_ITEM value.

Accumulate changes in a local variable and make one call to install_name_tool at the end of the function with all the changes at once.

If the BU_CHMOD_BUNDLE_ITEMS variable is set then bundle items will be marked writable before install_name_tool tries to change them.

verify_bundle_prerequisites(<bundle> <result_var> <info_var>)

Verifies that the sum of all prerequisites of all files inside the bundle are contained within the bundle or are system libraries, presumed to exist everywhere.

Added in version 3.6: As an optional parameter (IGNORE_ITEM) a list of file names can be passed, which are then ignored (e.g. IGNORE_ITEM "vcredist_x86.exe;vcredist_x64.exe")

verify_bundle_symlinks(<bundle> <result_var> <info_var>)

Verifies that any symlinks found in the <bundle> bundle point to other files that are already also in the bundle... Anything that points to an external file causes this function to fail the verification.

Check whether the C compiler supports a given flag.

check_c_compiler_flag(<flag> <resultVar>)

Check that the <flag> is accepted by the compiler without a diagnostic. Stores the result in an internal cache entry named <resultVar>.

A positive result from this check indicates only that the compiler did not issue a diagnostic message when given the flag. Whether the flag has any effect or even a specific one is beyond the scope of this module.

The check is only performed once, with the result cached in the variable named by <resultVar>. Every subsequent CMake run will reuse this cached value rather than performing the check again, even if the <code> changes. In order to force the check to be re-evaluated, the variable named by <resultVar> must be manually removed from the cache.

The compile and link commands can be influenced by setting any of the following variables prior to calling check_c_compiler_flag()

String of additional flags to pass to the compiler. The string must be space-delimited--a ;-list will not work. The contents of CMAKE_<LANG>_FLAGS and its associated configuration-specific variable are automatically added to the compiler command before the contents of CMAKE_REQUIRED_FLAGS.
A ;-list of compiler definitions of the form -DFOO or -DFOO=bar. A definition for the name specified by <resultVar> will also be added automatically.
A ;-list of header search paths to pass to the compiler. These will be the only header search paths used--the contents of the INCLUDE_DIRECTORIES directory property will be ignored.
Added in version 3.14.

A ;-list of options to add to the link command (see try_compile() for further details).

A ;-list of libraries to add to the link command. These can be the name of system libraries or they can be Imported Targets (see try_compile() for further details).
Added in version 3.1.

If this variable evaluates to a boolean true value, all status messages associated with the check will be suppressed.

Added in version 3.19.

Check whether the compiler supports a given flag.

check_compiler_flag(<lang> <flag> <resultVar>)

Check that the <flag> is accepted by the compiler without a diagnostic. Stores the result in an internal cache entry named <resultVar>.

A positive result from this check indicates only that the compiler did not issue a diagnostic message when given the flag. Whether the flag has any effect or even a specific one is beyond the scope of this module.

The check is only performed once, with the result cached in the variable named by <resultVar>. Every subsequent CMake run will reuse this cached value rather than performing the check again, even if the <code> changes. In order to force the check to be re-evaluated, the variable named by <resultVar> must be manually removed from the cache.

The compile and link commands can be influenced by setting any of the following variables prior to calling check_compiler_flag()

String of additional flags to pass to the compiler. The string must be space-delimited--a ;-list will not work. The contents of CMAKE_<LANG>_FLAGS and its associated configuration-specific variable are automatically added to the compiler command before the contents of CMAKE_REQUIRED_FLAGS.
A ;-list of compiler definitions of the form -DFOO or -DFOO=bar. A definition for the name specified by <resultVar> will also be added automatically.
A ;-list of header search paths to pass to the compiler. These will be the only header search paths used--the contents of the INCLUDE_DIRECTORIES directory property will be ignored.
Added in version 3.14.

A ;-list of options to add to the link command (see try_compile() for further details).

A ;-list of libraries to add to the link command. These can be the name of system libraries or they can be Imported Targets (see try_compile() for further details).
Added in version 3.1.

If this variable evaluates to a boolean true value, all status messages associated with the check will be suppressed.

Check if given C source compiles and links into an executable.

check_c_source_compiles(<code> <resultVar>
                        [FAIL_REGEX <regex1> [<regex2>...]])

Check that the source supplied in <code> can be compiled as a C source file and linked as an executable (so it must contain at least a main() function). The result will be stored in the internal cache variable specified by <resultVar>, with a boolean true value for success and boolean false for failure. If FAIL_REGEX is provided, then failure is determined by checking if anything in the output matches any of the specified regular expressions.

The check is only performed once, with the result cached in the variable named by <resultVar>. Every subsequent CMake run will reuse this cached value rather than performing the check again, even if the <code> changes. In order to force the check to be re-evaluated, the variable named by <resultVar> must be manually removed from the cache.

The compile and link commands can be influenced by setting any of the following variables prior to calling check_c_source_compiles():

String of additional flags to pass to the compiler. The string must be space-delimited--a ;-list will not work. The contents of CMAKE_<LANG>_FLAGS and its associated configuration-specific variable are automatically added to the compiler command before the contents of CMAKE_REQUIRED_FLAGS.
A ;-list of compiler definitions of the form -DFOO or -DFOO=bar. A definition for the name specified by <resultVar> will also be added automatically.
A ;-list of header search paths to pass to the compiler. These will be the only header search paths used--the contents of the INCLUDE_DIRECTORIES directory property will be ignored.
Added in version 3.14.

A ;-list of options to add to the link command (see try_compile() for further details).

A ;-list of libraries to add to the link command. These can be the name of system libraries or they can be Imported Targets (see try_compile() for further details).
Added in version 3.1.

If this variable evaluates to a boolean true value, all status messages associated with the check will be suppressed.

Check if given C source compiles and links into an executable and can subsequently be run.

check_c_source_runs(<code> <resultVar>)

Check that the source supplied in <code> can be compiled as a C source file, linked as an executable and then run. The <code> must contain at least a main() function. If the <code> could be built and run successfully, the internal cache variable specified by <resultVar> will be set to 1, otherwise it will be set to an value that evaluates to boolean false (e.g. an empty string or an error message).

The check is only performed once, with the result cached in the variable named by <resultVar>. Every subsequent CMake run will reuse this cached value rather than performing the check again, even if the <code> changes. In order to force the check to be re-evaluated, the variable named by <resultVar> must be manually removed from the cache.

The compile and link commands can be influenced by setting any of the following variables prior to calling check_c_source_runs():

String of additional flags to pass to the compiler. The string must be space-delimited--a ;-list will not work. The contents of CMAKE_<LANG>_FLAGS and its associated configuration-specific variable are automatically added to the compiler command before the contents of CMAKE_REQUIRED_FLAGS.
A ;-list of compiler definitions of the form -DFOO or -DFOO=bar. A definition for the name specified by <resultVar> will also be added automatically.
A ;-list of header search paths to pass to the compiler. These will be the only header search paths used--the contents of the INCLUDE_DIRECTORIES directory property will be ignored.
Added in version 3.14.

A ;-list of options to add to the link command (see try_compile() for further details).

A ;-list of libraries to add to the link command. These can be the name of system libraries or they can be Imported Targets (see try_compile() for further details).
Added in version 3.1.

If this variable evaluates to a boolean true value, all status messages associated with the check will be suppressed.

Check whether the CXX compiler supports a given flag.

check_cxx_compiler_flag(<flag> <var>)

Check that the <flag> is accepted by the compiler without a diagnostic. Stores the result in an internal cache entry named <var>.

A positive result from this check indicates only that the compiler did not issue a diagnostic message when given the flag. Whether the flag has any effect or even a specific one is beyond the scope of this module.

NOTE:

Since the try_compile() command forwards flags from variables like CMAKE_CXX_FLAGS, unknown flags in such variables may cause a false negative for this check.

Check if given C++ source compiles and links into an executable.

check_cxx_source_compiles(<code> <resultVar>
                          [FAIL_REGEX <regex1> [<regex2>...]])

Check that the source supplied in <code> can be compiled as a C++ source file and linked as an executable (so it must contain at least a main() function). The result will be stored in the internal cache variable specified by <resultVar>, with a boolean true value for success and boolean false for failure. If FAIL_REGEX is provided, then failure is determined by checking if anything in the output matches any of the specified regular expressions.

The check is only performed once, with the result cached in the variable named by <resultVar>. Every subsequent CMake run will reuse this cached value rather than performing the check again, even if the <code> changes. In order to force the check to be re-evaluated, the variable named by <resultVar> must be manually removed from the cache.

The compile and link commands can be influenced by setting any of the following variables prior to calling check_cxx_source_compiles():

String of additional flags to pass to the compiler. The string must be space-delimited--a ;-list will not work. The contents of CMAKE_<LANG>_FLAGS and its associated configuration-specific variable are automatically added to the compiler command before the contents of CMAKE_REQUIRED_FLAGS.
A ;-list of compiler definitions of the form -DFOO or -DFOO=bar. A definition for the name specified by <resultVar> will also be added automatically.
A ;-list of header search paths to pass to the compiler. These will be the only header search paths used--the contents of the INCLUDE_DIRECTORIES directory property will be ignored.
Added in version 3.14.

A ;-list of options to add to the link command (see try_compile() for further details).

A ;-list of libraries to add to the link command. These can be the name of system libraries or they can be Imported Targets (see try_compile() for further details).
Added in version 3.1.

If this variable evaluates to a boolean true value, all status messages associated with the check will be suppressed.

Check if given C++ source compiles and links into an executable and can subsequently be run.

check_cxx_source_runs(<code> <resultVar>)

Check that the source supplied in <code> can be compiled as a C++ source file, linked as an executable and then run. The <code> must contain at least a main() function. If the <code> could be built and run successfully, the internal cache variable specified by <resultVar> will be set to 1, otherwise it will be set to an value that evaluates to boolean false (e.g. an empty string or an error message).

The check is only performed once, with the result cached in the variable named by <resultVar>. Every subsequent CMake run will reuse this cached value rather than performing the check again, even if the <code> changes. In order to force the check to be re-evaluated, the variable named by <resultVar> must be manually removed from the cache.

The compile and link commands can be influenced by setting any of the following variables prior to calling check_cxx_source_runs():

String of additional flags to pass to the compiler. The string must be space-delimited--a ;-list will not work. The contents of CMAKE_<LANG>_FLAGS and its associated configuration-specific variable are automatically added to the compiler command before the contents of CMAKE_REQUIRED_FLAGS.
A ;-list of compiler definitions of the form -DFOO or -DFOO=bar. A definition for the name specified by <resultVar> will also be added automatically.
A ;-list of header search paths to pass to the compiler. These will be the only header search paths used--the contents of the INCLUDE_DIRECTORIES directory property will be ignored.
Added in version 3.14.

A ;-list of options to add to the link command (see try_compile() for further details).

A ;-list of libraries to add to the link command. These can be the name of system libraries or they can be Imported Targets (see try_compile() for further details).
Added in version 3.1.

If this variable evaluates to a boolean true value, all status messages associated with the check will be suppressed.

Check if a symbol exists as a function, variable, or macro in C++.

check_cxx_symbol_exists(<symbol> <files> <variable>)

Check that the <symbol> is available after including given header <files> and store the result in a <variable>. Specify the list of files in one argument as a semicolon-separated list. check_cxx_symbol_exists() can be used to check for symbols as seen by the C++ compiler, as opposed to check_symbol_exists(), which always uses the C compiler.

If the header files define the symbol as a macro it is considered available and assumed to work. If the header files declare the symbol as a function or variable then the symbol must also be available for linking. If the symbol is a type, enum value, or C++ template it will not be recognized: consider using the CheckTypeSize or CheckSourceCompiles module instead.

NOTE:

This command is unreliable when <symbol> is (potentially) an overloaded function. Since there is no reliable way to predict whether a given function in the system environment may be defined as an overloaded function or may be an overloaded function on other systems or will become so in the future, it is generally advised to use the CheckSourceCompiles module for checking any function symbol (unless somehow you surely know the checked function is not overloaded on other systems or will not be so in the future).

The following variables may be set before calling this macro to modify the way the check is run:

String of additional flags to pass to the compiler. The string must be space-delimited--a ;-list will not work. The contents of CMAKE_<LANG>_FLAGS and its associated configuration-specific variable are automatically added to the compiler command before the contents of CMAKE_REQUIRED_FLAGS.
A ;-list of compiler definitions of the form -DFOO or -DFOO=bar. A definition for the name specified by <resultVar> will also be added automatically.
A ;-list of header search paths to pass to the compiler. These will be the only header search paths used--the contents of the INCLUDE_DIRECTORIES directory property will be ignored.
Added in version 3.14.

A ;-list of options to add to the link command (see try_compile() for further details).

A ;-list of libraries to add to the link command. These can be the name of system libraries or they can be Imported Targets (see try_compile() for further details).
Added in version 3.1.

If this variable evaluates to a boolean true value, all status messages associated with the check will be suppressed.

For example:

include(CheckCXXSymbolExists)
# Check for macro SEEK_SET
check_cxx_symbol_exists(SEEK_SET "cstdio" HAVE_SEEK_SET)
# Check for function std::fopen
check_cxx_symbol_exists(std::fopen "cstdio" HAVE_STD_FOPEN)

Added in version 3.3.

Check whether the Fortran compiler supports a given flag.

check_fortran_compiler_flag(<flag> <resultVar>)

Check that the <flag> is accepted by the compiler without a diagnostic. Stores the result in an internal cache entry named <resultVar>.

A positive result from this check indicates only that the compiler did not issue a diagnostic message when given the flag. Whether the flag has any effect or even a specific one is beyond the scope of this module.

The check is only performed once, with the result cached in the variable named by <resultVar>. Every subsequent CMake run will reuse this cached value rather than performing the check again, even if the <code> changes. In order to force the check to be re-evaluated, the variable named by <resultVar> must be manually removed from the cache.

The compile and link commands can be influenced by setting any of the following variables prior to calling check_fortran_compiler_flag()

String of additional flags to pass to the compiler. The string must be space-delimited--a ;-list will not work. The contents of CMAKE_<LANG>_FLAGS and its associated configuration-specific variable are automatically added to the compiler command before the contents of CMAKE_REQUIRED_FLAGS.
A ;-list of compiler definitions of the form -DFOO or -DFOO=bar. A definition for the name specified by <resultVar> will also be added automatically.
A ;-list of header search paths to pass to the compiler. These will be the only header search paths used--the contents of the INCLUDE_DIRECTORIES directory property will be ignored.
Added in version 3.14.

A ;-list of options to add to the link command (see try_compile() for further details).

A ;-list of libraries to add to the link command. These can be the name of system libraries or they can be Imported Targets (see try_compile() for further details).
Added in version 3.1.

If this variable evaluates to a boolean true value, all status messages associated with the check will be suppressed.

Check if a Fortran function exists.

CHECK_FORTRAN_FUNCTION_EXISTS(<function> <result>)

where

<function>
the name of the Fortran function
<result>
variable to store the result; will be created as an internal cache variable.

NOTE:

This command does not detect functions in Fortran modules. In general it is recommended to use CheckSourceCompiles instead to determine if a Fortran function or subroutine is available.

The following variables may be set before calling this macro to modify the way the check is run:

Added in version 3.14: A ;-list of options to add to the link command (see try_compile() for further details).
A ;-list of libraries to add to the link command. These can be the name of system libraries or they can be Imported Targets (see try_compile() for further details).

Added in version 3.1.

Check if given Fortran source compiles and links into an executable.

check_fortran_source_compiles(<code> <resultVar>
    [FAIL_REGEX <regex>...]
    [SRC_EXT <extension>]
)

Checks that the source supplied in <code> can be compiled as a Fortran source file and linked as an executable. The <code> must be a Fortran program.

check_fortran_source_compiles("program test
error stop
end program"
HAVE_ERROR_STOP
SRC_EXT .F90)

This command can help avoid costly build processes when a compiler lacks support for a necessary feature, or a particular vendor library is not compatible with the Fortran compiler version being used. This generate-time check may advise the user of such before the main build process. See also the check_fortran_source_runs() command to run the compiled code.

The result will be stored in the internal cache variable <resultVar>, with a boolean true value for success and boolean false for failure.

If FAIL_REGEX is provided, then failure is determined by checking if anything in the output matches any of the specified regular expressions.

By default, the test source file will be given a .F file extension. The SRC_EXT option can be used to override this with .<extension> instead-- .F90 is a typical choice.

The check is only performed once, with the result cached in the variable named by <resultVar>. Every subsequent CMake run will reuse this cached value rather than performing the check again, even if the <code> changes. In order to force the check to be re-evaluated, the variable named by <resultVar> must be manually removed from the cache.

The compile and link commands can be influenced by setting any of the following variables prior to calling check_fortran_source_compiles():

String of additional flags to pass to the compiler. The string must be space-delimited--a ;-list will not work. The contents of CMAKE_<LANG>_FLAGS and its associated configuration-specific variable are automatically added to the compiler command before the contents of CMAKE_REQUIRED_FLAGS.
A ;-list of compiler definitions of the form -DFOO or -DFOO=bar. A definition for the name specified by <resultVar> will also be added automatically.
A ;-list of header search paths to pass to the compiler. These will be the only header search paths used--the contents of the INCLUDE_DIRECTORIES directory property will be ignored.
Added in version 3.14.

A ;-list of options to add to the link command (see try_compile() for further details).

A ;-list of libraries to add to the link command. These can be the name of system libraries or they can be Imported Targets (see try_compile() for further details).
Added in version 3.1.

If this variable evaluates to a boolean true value, all status messages associated with the check will be suppressed.

Added in version 3.14.

Check if given Fortran source compiles and links into an executable and can subsequently be run.

check_fortran_source_runs(<code> <resultVar>
    [SRC_EXT <extension>])

Check that the source supplied in <code> can be compiled as a Fortran source file, linked as an executable and then run. The <code> must be a Fortran program.

check_fortran_source_runs("program test
real :: x[*]
call co_sum(x)
end program"
HAVE_COARRAY)

This command can help avoid costly build processes when a compiler lacks support for a necessary feature, or a particular vendor library is not compatible with the Fortran compiler version being used. Some of these failures only occur at runtime instead of linktime, and a trivial runtime example can catch the issue before the main build process.

If the <code> could be built and run successfully, the internal cache variable specified by <resultVar> will be set to 1, otherwise it will be set to an value that evaluates to boolean false (e.g. an empty string or an error message).

By default, the test source file will be given a .F90 file extension. The SRC_EXT option can be used to override this with .<extension> instead.

The check is only performed once, with the result cached in the variable named by <resultVar>. Every subsequent CMake run will reuse this cached value rather than performing the check again, even if the <code> changes. In order to force the check to be re-evaluated, the variable named by <resultVar> must be manually removed from the cache.

The compile and link commands can be influenced by setting any of the following variables prior to calling check_fortran_source_runs():

String of additional flags to pass to the compiler. The string must be space-delimited--a ;-list will not work. The contents of CMAKE_<LANG>_FLAGS and its associated configuration-specific variable are automatically added to the compiler command before the contents of CMAKE_REQUIRED_FLAGS.
A ;-list of compiler definitions of the form -DFOO or -DFOO=bar. A definition for the name specified by <resultVar> will also be added automatically.
A ;-list of header search paths to pass to the compiler. These will be the only header search paths used--the contents of the INCLUDE_DIRECTORIES directory property will be ignored.
Added in version 3.14.

A ;-list of options to add to the link command (see try_compile() for further details).

A ;-list of libraries to add to the link command. These can be the name of system libraries or they can be Imported Targets (see try_compile() for further details).
Added in version 3.1.

If this variable evaluates to a boolean true value, all status messages associated with the check will be suppressed.

Check if a C function can be linked

check_function_exists(<function> <variable>)

Checks that the <function> is provided by libraries on the system and store the result in a <variable>, which will be created as an internal cache variable.

The following variables may be set before calling this macro to modify the way the check is run:

String of additional flags to pass to the compiler. The string must be space-delimited--a ;-list will not work. The contents of CMAKE_<LANG>_FLAGS and its associated configuration-specific variable are automatically added to the compiler command before the contents of CMAKE_REQUIRED_FLAGS.
A ;-list of compiler definitions of the form -DFOO or -DFOO=bar. A definition for the name specified by <resultVar> will also be added automatically.
A ;-list of header search paths to pass to the compiler. These will be the only header search paths used--the contents of the INCLUDE_DIRECTORIES directory property will be ignored.
Added in version 3.14.

A ;-list of options to add to the link command (see try_compile() for further details).

A ;-list of libraries to add to the link command. These can be the name of system libraries or they can be Imported Targets (see try_compile() for further details).
Added in version 3.1.

If this variable evaluates to a boolean true value, all status messages associated with the check will be suppressed.

NOTE:

Prefer using CheckSymbolExists instead of this module, for the following reasons:
  • check_function_exists() can't detect functions that are inlined in headers or specified as a macro.
  • check_function_exists() can't detect anything in the 32-bit versions of the Win32 API, because of a mismatch in calling conventions.
  • check_function_exists() only verifies linking, it does not verify that the function is declared in system headers.

Provides a macro to check if a header file can be included in CXX.

CHECK_INCLUDE_FILE_CXX(<include> <variable> [<flags>])

Check if the given <include> file may be included in a CXX source file and store the result in an internal cache entry named <variable>. The optional third argument may be used to add compilation flags to the check (or use CMAKE_REQUIRED_FLAGS below).

The following variables may be set before calling this macro to modify the way the check is run:

String of additional flags to pass to the compiler. The string must be space-delimited--a ;-list will not work. The contents of CMAKE_<LANG>_FLAGS and its associated configuration-specific variable are automatically added to the compiler command before the contents of CMAKE_REQUIRED_FLAGS.
A ;-list of compiler definitions of the form -DFOO or -DFOO=bar. A definition for the name specified by <resultVar> will also be added automatically.
A ;-list of header search paths to pass to the compiler. These will be the only header search paths used--the contents of the INCLUDE_DIRECTORIES directory property will be ignored.
Added in version 3.14.

A ;-list of options to add to the link command (see try_compile() for further details).

A ;-list of libraries to add to the link command. These can be the name of system libraries or they can be Imported Targets (see try_compile() for further details).
Added in version 3.1.

If this variable evaluates to a boolean true value, all status messages associated with the check will be suppressed.

See modules CheckIncludeFile and CheckIncludeFiles to check for one or more C headers.

Provides a macro to check if a header file can be included in C.

CHECK_INCLUDE_FILE(<include> <variable> [<flags>])

Check if the given <include> file may be included in a C source file and store the result in an internal cache entry named <variable>. The optional third argument may be used to add compilation flags to the check (or use CMAKE_REQUIRED_FLAGS below).

The following variables may be set before calling this macro to modify the way the check is run:

String of additional flags to pass to the compiler. The string must be space-delimited--a ;-list will not work. The contents of CMAKE_<LANG>_FLAGS and its associated configuration-specific variable are automatically added to the compiler command before the contents of CMAKE_REQUIRED_FLAGS.
A ;-list of compiler definitions of the form -DFOO or -DFOO=bar. A definition for the name specified by <resultVar> will also be added automatically.
A ;-list of header search paths to pass to the compiler. These will be the only header search paths used--the contents of the INCLUDE_DIRECTORIES directory property will be ignored.
Added in version 3.14.

A ;-list of options to add to the link command (see try_compile() for further details).

A ;-list of libraries to add to the link command. These can be the name of system libraries or they can be Imported Targets (see try_compile() for further details).
Added in version 3.1.

If this variable evaluates to a boolean true value, all status messages associated with the check will be suppressed.

See the CheckIncludeFiles module to check for multiple headers at once. See the CheckIncludeFileCXX module to check for headers using the CXX language.

Provides a macro to check if a list of one or more header files can be included together.

CHECK_INCLUDE_FILES("<includes>" <variable> [LANGUAGE <language>])

Check if the given <includes> list may be included together in a source file and store the result in an internal cache entry named <variable>. Specify the <includes> argument as a ;-list of header file names.

If LANGUAGE is set, the specified compiler will be used to perform the check. Acceptable values are C and CXX. If not set, the C compiler will be used if enabled. If the C compiler is not enabled, the C++ compiler will be used if enabled.

The following variables may be set before calling this macro to modify the way the check is run:

String of additional flags to pass to the compiler. The string must be space-delimited--a ;-list will not work. The contents of CMAKE_<LANG>_FLAGS and its associated configuration-specific variable are automatically added to the compiler command before the contents of CMAKE_REQUIRED_FLAGS.
A ;-list of compiler definitions of the form -DFOO or -DFOO=bar. A definition for the name specified by <resultVar> will also be added automatically.
A ;-list of header search paths to pass to the compiler. These will be the only header search paths used--the contents of the INCLUDE_DIRECTORIES directory property will be ignored.
Added in version 3.14.

A ;-list of options to add to the link command (see try_compile() for further details).

A ;-list of libraries to add to the link command. These can be the name of system libraries or they can be Imported Targets (see try_compile() for further details).
Added in version 3.1.

If this variable evaluates to a boolean true value, all status messages associated with the check will be suppressed.

See modules CheckIncludeFile and CheckIncludeFileCXX to check for a single header file in C or CXX languages.

Added in version 3.9.

Check whether the compiler supports an interprocedural optimization (IPO/LTO). Use this before enabling the INTERPROCEDURAL_OPTIMIZATION target property.

check_ipo_supported([RESULT <result>] [OUTPUT <output>]
                    [LANGUAGES <lang>...])

Options are:

Set <result> variable to YES if IPO is supported by the compiler and NO otherwise. If this option is not given then the command will issue a fatal error if IPO is not supported.
Set <output> variable with details about any error.
Specify languages whose compilers to check. Languages C, CXX, and Fortran are supported.

It makes no sense to use this module when CMP0069 is set to OLD so module will return error in this case. See policy CMP0069 for details.

Added in version 3.13: Add support for Visual Studio generators.

Added in version 3.24: The check uses the caller's CMAKE_<LANG>_FLAGS and CMAKE_<LANG>_FLAGS_<CONFIG> values. See policy CMP0138.

check_ipo_supported() # fatal error if IPO is not supported
set_property(TARGET foo PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
# Optional IPO. Do not use IPO if it's not supported by compiler.
check_ipo_supported(RESULT result OUTPUT output)
if(result)
  set_property(TARGET foo PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
else()
  message(WARNING "IPO is not supported: ${output}")
endif()

Check whether a language can be enabled by the enable_language() or project() commands:

check_language(<lang>)

Try enabling language <lang> in a test project and record results in the cache:

If the language can be enabled, this variable is set to the compiler that was found. If the language cannot be enabled, this variable is set to NOTFOUND.

If this variable is already set, either explicitly or cached by a previous call, the check is skipped.

This variable is set when <lang> is CUDA or HIP.

If the check detects an explicit host compiler that is required for compilation, this variable will be set to that compiler. If the check detects that no explicit host compiler is needed, this variable will be cleared.

If this variable is already set, its value is preserved only if CMAKE_<LANG>_COMPILER is also set. Otherwise, the check runs and overwrites CMAKE_<LANG>_HOST_COMPILER with a new result. Note that CMAKE_<LANG>_HOST_COMPILER documents it should not be set without also setting CMAKE_<LANG>_COMPILER to a NVCC compiler.

This variable is set to the detected GPU platform when <lang> is HIP.

If the variable is already set its value is always preserved. Only compatible values will be considered for CMAKE_<LANG>_COMPILER.

For example:

check_language(Fortran)
if(CMAKE_Fortran_COMPILER)
  enable_language(Fortran)
else()
  message(STATUS "No Fortran support")
endif()

Check if the function exists.

CHECK_LIBRARY_EXISTS(LIBRARY FUNCTION LOCATION VARIABLE)
LIBRARY  - the name of the library you are looking for
FUNCTION - the name of the function
LOCATION - location where the library should be found
VARIABLE - variable to store the result
           Will be created as an internal cache variable.

The following variables may be set before calling this macro to modify the way the check is run:

String of additional flags to pass to the compiler. The string must be space-delimited--a ;-list will not work. The contents of CMAKE_<LANG>_FLAGS and its associated configuration-specific variable are automatically added to the compiler command before the contents of CMAKE_REQUIRED_FLAGS.
A ;-list of compiler definitions of the form -DFOO or -DFOO=bar. A definition for the name specified by <resultVar> will also be added automatically.
Added in version 3.14.

A ;-list of options to add to the link command (see try_compile() for further details).

A ;-list of libraries to add to the link command. These can be the name of system libraries or they can be Imported Targets (see try_compile() for further details).
Added in version 3.1.

If this variable evaluates to a boolean true value, all status messages associated with the check will be suppressed.

Added in version 3.18.

Check whether the compiler supports a given link flag.

check_linker_flag(<lang> <flag> <var>)

Check that the link <flag> is accepted by the <lang> compiler without a diagnostic. Stores the result in an internal cache entry named <var>.

This command temporarily sets the CMAKE_REQUIRED_LINK_OPTIONS variable and calls the check_source_compiles() command from the CheckSourceCompiles module. See that module's documentation for a listing of variables that can otherwise modify the build.

The underlying implementation relies on the LINK_OPTIONS property to check the specified flag. The LINKER: prefix, as described in the target_link_options() command, can be used as well.

A positive result from this check indicates only that the compiler did not issue a diagnostic message when given the link flag. Whether the flag has any effect or even a specific one is beyond the scope of this module.

NOTE:

Since the try_compile() command forwards flags from variables like CMAKE_<LANG>_FLAGS, unknown flags in such variables may cause a false negative for this check.

Added in version 3.16.

Check whether the Objective-C compiler supports a given flag.

check_objc_compiler_flag(<flag> <resultVar>)

Check that the <flag> is accepted by the compiler without a diagnostic. Stores the result in an internal cache entry named <resultVar>.

A positive result from this check indicates only that the compiler did not issue a diagnostic message when given the flag. Whether the flag has any effect or even a specific one is beyond the scope of this module.

The check is only performed once, with the result cached in the variable named by <resultVar>. Every subsequent CMake run will reuse this cached value rather than performing the check again, even if the <code> changes. In order to force the check to be re-evaluated, the variable named by <resultVar> must be manually removed from the cache.

The compile and link commands can be influenced by setting any of the following variables prior to calling check_objc_compiler_flag()

String of additional flags to pass to the compiler. The string must be space-delimited--a ;-list will not work. The contents of CMAKE_<LANG>_FLAGS and its associated configuration-specific variable are automatically added to the compiler command before the contents of CMAKE_REQUIRED_FLAGS.
A ;-list of compiler definitions of the form -DFOO or -DFOO=bar. A definition for the name specified by <resultVar> will also be added automatically.
A ;-list of header search paths to pass to the compiler. These will be the only header search paths used--the contents of the INCLUDE_DIRECTORIES directory property will be ignored.
Added in version 3.14.

A ;-list of options to add to the link command (see try_compile() for further details).

A ;-list of libraries to add to the link command. These can be the name of system libraries or they can be Imported Targets (see try_compile() for further details).
Added in version 3.1.

If this variable evaluates to a boolean true value, all status messages associated with the check will be suppressed.

Added in version 3.16.

Check if given Objective-C source compiles and links into an executable.

check_objc_source_compiles(<code> <resultVar>
                           [FAIL_REGEX <regex1> [<regex2>...]])

Check that the source supplied in <code> can be compiled as a Objectie-C source file and linked as an executable (so it must contain at least a main() function). The result will be stored in the internal cache variable specified by <resultVar>, with a boolean true value for success and boolean false for failure. If FAIL_REGEX is provided, then failure is determined by checking if anything in the output matches any of the specified regular expressions.

The check is only performed once, with the result cached in the variable named by <resultVar>. Every subsequent CMake run will reuse this cached value rather than performing the check again, even if the <code> changes. In order to force the check to be re-evaluated, the variable named by <resultVar> must be manually removed from the cache.

The compile and link commands can be influenced by setting any of the following variables prior to calling check_objc_source_compiles()

String of additional flags to pass to the compiler. The string must be space-delimited--a ;-list will not work. The contents of CMAKE_<LANG>_FLAGS and its associated configuration-specific variable are automatically added to the compiler command before the contents of CMAKE_REQUIRED_FLAGS.
A ;-list of compiler definitions of the form -DFOO or -DFOO=bar. A definition for the name specified by <resultVar> will also be added automatically.
A ;-list of header search paths to pass to the compiler. These will be the only header search paths used--the contents of the INCLUDE_DIRECTORIES directory property will be ignored.
Added in version 3.14.

A ;-list of options to add to the link command (see try_compile() for further details).

A ;-list of libraries to add to the link command. These can be the name of system libraries or they can be Imported Targets (see try_compile() for further details).
Added in version 3.1.

If this variable evaluates to a boolean true value, all status messages associated with the check will be suppressed.

Added in version 3.16.

Check if given Objective-C source compiles and links into an executable and can subsequently be run.

check_objc_source_runs(<code> <resultVar>)

Check that the source supplied in <code> can be compiled as a Objective-C source file, linked as an executable and then run. The <code> must contain at least a main() function. If the <code> could be built and run successfully, the internal cache variable specified by <resultVar> will be set to 1, otherwise it will be set to an value that evaluates to boolean false (e.g. an empty string or an error message).

The check is only performed once, with the result cached in the variable named by <resultVar>. Every subsequent CMake run will reuse this cached value rather than performing the check again, even if the <code> changes. In order to force the check to be re-evaluated, the variable named by <resultVar> must be manually removed from the cache.

The compile and link commands can be influenced by setting any of the following variables prior to calling check_objc_source_runs()

String of additional flags to pass to the compiler. The string must be space-delimited--a ;-list will not work. The contents of CMAKE_<LANG>_FLAGS and its associated configuration-specific variable are automatically added to the compiler command before the contents of CMAKE_REQUIRED_FLAGS.
A ;-list of compiler definitions of the form -DFOO or -DFOO=bar. A definition for the name specified by <resultVar> will also be added automatically.
A ;-list of header search paths to pass to the compiler. These will be the only header search paths used--the contents of the INCLUDE_DIRECTORIES directory property will be ignored.
Added in version 3.14.

A ;-list of options to add to the link command (see try_compile() for further details).

A ;-list of libraries to add to the link command. These can be the name of system libraries or they can be Imported Targets (see try_compile() for further details).
Added in version 3.1.

If this variable evaluates to a boolean true value, all status messages associated with the check will be suppressed.

Added in version 3.16.

Check whether the Objective-C++ compiler supports a given flag.

check_objcxx_compiler_flag(<flag> <resultVar>)

Check that the <flag> is accepted by the compiler without a diagnostic. Stores the result in an internal cache entry named <resultVar>.

A positive result from this check indicates only that the compiler did not issue a diagnostic message when given the flag. Whether the flag has any effect or even a specific one is beyond the scope of this module.

The check is only performed once, with the result cached in the variable named by <resultVar>. Every subsequent CMake run will reuse this cached value rather than performing the check again, even if the <code> changes. In order to force the check to be re-evaluated, the variable named by <resultVar> must be manually removed from the cache.

The compile and link commands can be influenced by setting any of the following variables prior to calling check_objcxx_compiler_flag()

String of additional flags to pass to the compiler. The string must be space-delimited--a ;-list will not work. The contents of CMAKE_<LANG>_FLAGS and its associated configuration-specific variable are automatically added to the compiler command before the contents of CMAKE_REQUIRED_FLAGS.
A ;-list of compiler definitions of the form -DFOO or -DFOO=bar. A definition for the name specified by <resultVar> will also be added automatically.
A ;-list of header search paths to pass to the compiler. These will be the only header search paths used--the contents of the INCLUDE_DIRECTORIES directory property will be ignored.
Added in version 3.14.

A ;-list of options to add to the link command (see try_compile() for further details).

A ;-list of libraries to add to the link command. These can be the name of system libraries or they can be Imported Targets (see try_compile() for further details).
Added in version 3.1.

If this variable evaluates to a boolean true value, all status messages associated with the check will be suppressed.

Added in version 3.16.

Check if given Objective-C++ source compiles and links into an executable.

check_objcxx_source_compiles(<code> <resultVar>
                             [FAIL_REGEX <regex1> [<regex2>...]])

Check that the source supplied in <code> can be compiled as a Objective-C++ source file and linked as an executable (so it must contain at least a main() function). The result will be stored in the internal cache variable specified by <resultVar>, with a boolean true value for success and boolean false for failure. If FAIL_REGEX is provided, then failure is determined by checking if anything in the output matches any of the specified regular expressions.

The check is only performed once, with the result cached in the variable named by <resultVar>. Every subsequent CMake run will reuse this cached value rather than performing the check again, even if the <code> changes. In order to force the check to be re-evaluated, the variable named by <resultVar> must be manually removed from the cache.

The compile and link commands can be influenced by setting any of the following variables prior to calling check_objcxx_source_compiles()

String of additional flags to pass to the compiler. The string must be space-delimited--a ;-list will not work. The contents of CMAKE_<LANG>_FLAGS and its associated configuration-specific variable are automatically added to the compiler command before the contents of CMAKE_REQUIRED_FLAGS.
A ;-list of compiler definitions of the form -DFOO or -DFOO=bar. A definition for the name specified by <resultVar> will also be added automatically.
A ;-list of header search paths to pass to the compiler. These will be the only header search paths used--the contents of the INCLUDE_DIRECTORIES directory property will be ignored.
Added in version 3.14.

A ;-list of options to add to the link command (see try_compile() for further details).

A ;-list of libraries to add to the link command. These can be the name of system libraries or they can be Imported Targets (see try_compile() for further details).
Added in version 3.1.

If this variable evaluates to a boolean true value, all status messages associated with the check will be suppressed.

Added in version 3.16.

Check if given Objective-C++ source compiles and links into an executable and can subsequently be run.

check_objcxx_source_runs(<code> <resultVar>)

Check that the source supplied in <code> can be compiled as a Objective-C++ source file, linked as an executable and then run. The <code> must contain at least a main() function. If the <code> could be built and run successfully, the internal cache variable specified by <resultVar> will be set to 1, otherwise it will be set to an value that evaluates to boolean false (e.g. an empty string or an error message).

The check is only performed once, with the result cached in the variable named by <resultVar>. Every subsequent CMake run will reuse this cached value rather than performing the check again, even if the <code> changes. In order to force the check to be re-evaluated, the variable named by <resultVar> must be manually removed from the cache.

The compile and link commands can be influenced by setting any of the following variables prior to calling check_objcxx_source_runs()

String of additional flags to pass to the compiler. The string must be space-delimited--a ;-list will not work. The contents of CMAKE_<LANG>_FLAGS and its associated configuration-specific variable are automatically added to the compiler command before the contents of CMAKE_REQUIRED_FLAGS.
A ;-list of compiler definitions of the form -DFOO or -DFOO=bar. A definition for the name specified by <resultVar> will also be added automatically.
A ;-list of header search paths to pass to the compiler. These will be the only header search paths used--the contents of the INCLUDE_DIRECTORIES directory property will be ignored.
Added in version 3.14.

A ;-list of options to add to the link command (see try_compile() for further details).

A ;-list of libraries to add to the link command. These can be the name of system libraries or they can be Imported Targets (see try_compile() for further details).
Added in version 3.1.

If this variable evaluates to a boolean true value, all status messages associated with the check will be suppressed.

Added in version 3.14.

Check whether the linker supports Position Independent Code (PIE) or No Position Independent Code (NO_PIE) for executables. Use this to ensure that the POSITION_INDEPENDENT_CODE target property for executables will be honored at link time.

check_pie_supported([OUTPUT_VARIABLE <output>]
                    [LANGUAGES <lang>...])

Options are:

Set <output> variable with details about any error. If the check is bypassed because it uses cached results from a previous call, the output will be empty even if errors were present in the previous call.
Check the linkers used for each of the specified languages. If this option is not provided, the command checks all enabled languages.

C, CXX, Fortran are supported.

Added in version 3.23: OBJC, OBJCXX, CUDA, and HIP are supported.

It makes no sense to use this module when CMP0083 is set to OLD, so the command will return an error in this case. See policy CMP0083 for details.

For each language checked, two boolean cache variables are defined.

Set to true if PIE is supported by the linker and false otherwise.
Set to true if NO_PIE is supported by the linker and false otherwise.

check_pie_supported()
set_property(TARGET foo PROPERTY POSITION_INDEPENDENT_CODE TRUE)
# Retrieve any error message.
check_pie_supported(OUTPUT_VARIABLE output LANGUAGES C)
set_property(TARGET foo PROPERTY POSITION_INDEPENDENT_CODE TRUE)
if(NOT CMAKE_C_LINK_PIE_SUPPORTED)
  message(WARNING "PIE is not supported at link time: ${output}.\n"
                  "PIE link options will not be passed to linker.")
endif()

Check if the prototype we expect is correct.

check_prototype_definition(FUNCTION PROTOTYPE RETURN HEADER VARIABLE)
FUNCTION - The name of the function (used to check if prototype exists)
PROTOTYPE- The prototype to check.
RETURN - The return value of the function.
HEADER - The header files required.
VARIABLE - The variable to store the result.
           Will be created as an internal cache variable.

Example:

check_prototype_definition(getpwent_r
 "struct passwd *getpwent_r(struct passwd *src, char *buf, int buflen)"
 "NULL"
 "unistd.h;pwd.h"
 SOLARIS_GETPWENT_R)

The following variables may be set before calling this function to modify the way the check is run:

String of additional flags to pass to the compiler. The string must be space-delimited--a ;-list will not work. The contents of CMAKE_<LANG>_FLAGS and its associated configuration-specific variable are automatically added to the compiler command before the contents of CMAKE_REQUIRED_FLAGS.
A ;-list of compiler definitions of the form -DFOO or -DFOO=bar. A definition for the name specified by <resultVar> will also be added automatically.
A ;-list of header search paths to pass to the compiler. These will be the only header search paths used--the contents of the INCLUDE_DIRECTORIES directory property will be ignored.
Added in version 3.14.

A ;-list of options to add to the link command (see try_compile() for further details).

A ;-list of libraries to add to the link command. These can be the name of system libraries or they can be Imported Targets (see try_compile() for further details).
Added in version 3.1.

If this variable evaluates to a boolean true value, all status messages associated with the check will be suppressed.

Added in version 3.19.

Check if given source compiles and links into an executable.

check_source_compiles(<lang> <code> <resultVar>
                      [FAIL_REGEX <regex1> [<regex2>...]]
                      [SRC_EXT <extension>])

Check that the source supplied in <code> can be compiled as a source file for the requested language and linked as an executable. The result will be stored in the internal cache variable specified by <resultVar>, with a boolean true value for success and boolean false for failure. If FAIL_REGEX is provided, then failure is determined by checking if anything in the compiler output matches any of the specified regular expressions.

By default, the test source file will be given a file extension that matches the requested language. The SRC_EXT option can be used to override this with .<extension> instead.

The <code> must contain a valid main program. For example:

check_source_compiles(C
"#include <stdlib.h>
#include <stdnoreturn.h>
noreturn void f(){ exit(0); }
int main(void) { f(); return 1; }"
HAVE_NORETURN)
check_source_compiles(Fortran
"program test
error stop
end program"
HAVE_ERROR_STOP)

The check is only performed once, with the result cached in the variable named by <resultVar>. Every subsequent CMake run will reuse this cached value rather than performing the check again, even if the <code> changes. In order to force the check to be re-evaluated, the variable named by <resultVar> must be manually removed from the cache.

The compile and link commands can be influenced by setting any of the following variables prior to calling check_source_compiles():

String of additional flags to pass to the compiler. The string must be space-delimited--a ;-list will not work. The contents of CMAKE_<LANG>_FLAGS and its associated configuration-specific variable are automatically added to the compiler command before the contents of CMAKE_REQUIRED_FLAGS.
A ;-list of compiler definitions of the form -DFOO or -DFOO=bar. A definition for the name specified by <resultVar> will also be added automatically.
A ;-list of header search paths to pass to the compiler. These will be the only header search paths used--the contents of the INCLUDE_DIRECTORIES directory property will be ignored.
Added in version 3.14.

A ;-list of options to add to the link command (see try_compile() for further details).

A ;-list of libraries to add to the link command. These can be the name of system libraries or they can be Imported Targets (see try_compile() for further details).
Added in version 3.1.

If this variable evaluates to a boolean true value, all status messages associated with the check will be suppressed.

Added in version 3.19.

Check if given source compiles and links into an executable and can subsequently be run.

check_source_runs(<lang> <code> <resultVar>
                  [SRC_EXT <extension>])

Check that the source supplied in <code> can be compiled as a source file for the requested language, linked as an executable and then run. If the <code> could be built and run successfully, the internal cache variable specified by <resultVar> will be set to 1, otherwise it will be set to a value that evaluates to boolean false (e.g. an empty string or an error message).

By default, the test source file will be given a file extension that matches the requested language. The SRC_EXT option can be used to override this with .<extension> instead.

The <code> must contain a valid main program. For example:

check_source_runs(C
"#include <stdlib.h>
#include <stdnoreturn.h>
noreturn void f(){ exit(0); }
int main(void) { f(); return 1; }"
HAVE_NORETURN)
check_source_runs(Fortran
"program test
real :: x[*]
call co_sum(x)
end program"
HAVE_COARRAY)

The check is only performed once, with the result cached in the variable named by <resultVar>. Every subsequent CMake run will reuse this cached value rather than performing the check again, even if the <code> changes. In order to force the check to be re-evaluated, the variable named by <resultVar> must be manually removed from the cache.

The compile and link commands can be influenced by setting any of the following variables prior to calling check_source_runs()

String of additional flags to pass to the compiler. The string must be space-delimited--a ;-list will not work. The contents of CMAKE_<LANG>_FLAGS and its associated configuration-specific variable are automatically added to the compiler command before the contents of CMAKE_REQUIRED_FLAGS.
A ;-list of compiler definitions of the form -DFOO or -DFOO=bar. A definition for the name specified by <resultVar> will also be added automatically.
A ;-list of header search paths to pass to the compiler. These will be the only header search paths used--the contents of the INCLUDE_DIRECTORIES directory property will be ignored.
Added in version 3.14.

A ;-list of options to add to the link command (see try_compile() for further details).

A ;-list of libraries to add to the link command. These can be the name of system libraries or they can be Imported Targets (see try_compile() for further details).
Added in version 3.1.

If this variable evaluates to a boolean true value, all status messages associated with the check will be suppressed.

Check if the given struct or class has the specified member variable

CHECK_STRUCT_HAS_MEMBER(<struct> <member> <header> <variable>
                        [LANGUAGE <language>])
<struct> - the name of the struct or class you are interested in
<member> - the member which existence you want to check
<header> - the header(s) where the prototype should be declared
<variable> - variable to store the result
<language> - the compiler to use (C or CXX)

The following variables may be set before calling this macro to modify the way the check is run:

String of additional flags to pass to the compiler. The string must be space-delimited--a ;-list will not work. The contents of CMAKE_<LANG>_FLAGS and its associated configuration-specific variable are automatically added to the compiler command before the contents of CMAKE_REQUIRED_FLAGS.
A ;-list of compiler definitions of the form -DFOO or -DFOO=bar. A definition for the name specified by <resultVar> will also be added automatically.
A ;-list of header search paths to pass to the compiler. These will be the only header search paths used--the contents of the INCLUDE_DIRECTORIES directory property will be ignored.
Added in version 3.14.

A ;-list of options to add to the link command (see try_compile() for further details).

A ;-list of libraries to add to the link command. These can be the name of system libraries or they can be Imported Targets (see try_compile() for further details).
Added in version 3.1.

If this variable evaluates to a boolean true value, all status messages associated with the check will be suppressed.

Example:

CHECK_STRUCT_HAS_MEMBER("struct timeval" tv_sec sys/select.h
                        HAVE_TIMEVAL_TV_SEC LANGUAGE C)

Provides a macro to check if a symbol exists as a function, variable, or macro in C.

check_symbol_exists(<symbol> <files> <variable>)

Check that the <symbol> is available after including given header <files> and store the result in a <variable>. Specify the list of files in one argument as a semicolon-separated list. <variable> will be created as an internal cache variable.

If the header files define the symbol as a macro it is considered available and assumed to work. If the header files declare the symbol as a function or variable then the symbol must also be available for linking (so intrinsics may not be detected). If the symbol is a type, enum value, or intrinsic it will not be recognized (consider using CheckTypeSize or CheckSourceCompiles). If the check needs to be done in C++, consider using CheckCXXSymbolExists instead.

The following variables may be set before calling this macro to modify the way the check is run:

String of additional flags to pass to the compiler. The string must be space-delimited--a ;-list will not work. The contents of CMAKE_<LANG>_FLAGS and its associated configuration-specific variable are automatically added to the compiler command before the contents of CMAKE_REQUIRED_FLAGS.
A ;-list of compiler definitions of the form -DFOO or -DFOO=bar. A definition for the name specified by <resultVar> will also be added automatically.
A ;-list of header search paths to pass to the compiler. These will be the only header search paths used--the contents of the INCLUDE_DIRECTORIES directory property will be ignored.
Added in version 3.14.

A ;-list of options to add to the link command (see try_compile() for further details).

A ;-list of libraries to add to the link command. These can be the name of system libraries or they can be Imported Targets (see try_compile() for further details).
Added in version 3.1.

If this variable evaluates to a boolean true value, all status messages associated with the check will be suppressed.

For example:

include(CheckSymbolExists)
# Check for macro SEEK_SET
check_symbol_exists(SEEK_SET "stdio.h" HAVE_SEEK_SET)
# Check for function fopen
check_symbol_exists(fopen "stdio.h" HAVE_FOPEN)

Check sizeof a type

check_type_size(<type> <variable> [BUILTIN_TYPES_ONLY]
                                  [LANGUAGE <language>])

Check if the type exists and determine its size. Results are reported in the following variables:

Holds a true or false value indicating whether the type exists.
<variable>
Holds one of the following values:
<size>
Type has non-zero size <size>.
0
Type has architecture-dependent size. This may occur when CMAKE_OSX_ARCHITECTURES has multiple architectures. In this case <variable>_CODE contains C preprocessor tests mapping from each architecture macro to the corresponding type size. The list of architecture macros is stored in <variable>_KEYS, and the value for each key is stored in <variable>-<key>.
"" (empty string)
Type does not exist.
<variable>_CODE
Holds C preprocessor code to define the macro <variable> to the size of the type, or to leave the macro undefined if the type does not exist.

The options are:

BUILTIN_TYPES_ONLY

Support only compiler-builtin types. If not given, the macro checks for headers <sys/types.h>, <stdint.h>, and <stddef.h>, and saves results in HAVE_SYS_TYPES_H, HAVE_STDINT_H, and HAVE_STDDEF_H. The type size check automatically includes the available headers, thus supporting checks of types defined in the headers.
Use the <language> compiler to perform the check. Acceptable values are C and CXX.

Despite the name of the macro you may use it to check the size of more complex expressions, too. To check e.g. for the size of a struct member you can do something like this:

check_type_size("((struct something*)0)->member" SIZEOF_MEMBER)

The following variables may be set before calling this macro to modify the way the check is run:

String of additional flags to pass to the compiler. The string must be space-delimited--a ;-list will not work. The contents of CMAKE_<LANG>_FLAGS and its associated configuration-specific variable are automatically added to the compiler command before the contents of CMAKE_REQUIRED_FLAGS.
A ;-list of compiler definitions of the form -DFOO or -DFOO=bar. A definition for the name specified by <resultVar> will also be added automatically.
A ;-list of header search paths to pass to the compiler. These will be the only header search paths used--the contents of the INCLUDE_DIRECTORIES directory property will be ignored.
Added in version 3.14.

A ;-list of options to add to the link command (see try_compile() for further details).

A ;-list of libraries to add to the link command. These can be the name of system libraries or they can be Imported Targets (see try_compile() for further details).
Added in version 3.1.

If this variable evaluates to a boolean true value, all status messages associated with the check will be suppressed.

list of extra headers to include.

Check if the variable exists.

CHECK_VARIABLE_EXISTS(VAR VARIABLE)
VAR      - the name of the variable
VARIABLE - variable to store the result
           Will be created as an internal cache variable.

This macro is only for C variables.

The following variables may be set before calling this macro to modify the way the check is run:

String of additional flags to pass to the compiler. The string must be space-delimited--a ;-list will not work. The contents of CMAKE_<LANG>_FLAGS and its associated configuration-specific variable are automatically added to the compiler command before the contents of CMAKE_REQUIRED_FLAGS.
A ;-list of compiler definitions of the form -DFOO or -DFOO=bar. A definition for the name specified by <resultVar> will also be added automatically.
Added in version 3.14.

A ;-list of options to add to the link command (see try_compile() for further details).

A ;-list of libraries to add to the link command. These can be the name of system libraries or they can be Imported Targets (see try_compile() for further details).
Added in version 3.1.

If this variable evaluates to a boolean true value, all status messages associated with the check will be suppressed.

Add a fortran-only subdirectory, find a fortran compiler, and build.

The cmake_add_fortran_subdirectory function adds a subdirectory to a project that contains a fortran-only subproject. The module will check the current compiler and see if it can support fortran. If no fortran compiler is found and the compiler is MSVC, then this module will find the MinGW gfortran. It will then use an external project to build with the MinGW tools. It will also create imported targets for the libraries created. This will only work if the fortran code is built into a dll, so BUILD_SHARED_LIBS is turned on in the project. In addition the CMAKE_GNUtoMS option is set to on, so that Microsoft .lib files are created. Usage is as follows:

cmake_add_fortran_subdirectory(
 <subdir>                # name of subdirectory
 PROJECT <project_name>  # project name in subdir top CMakeLists.txt
 ARCHIVE_DIR <dir>       # dir where project places .lib files
 RUNTIME_DIR <dir>       # dir where project places .dll files
 LIBRARIES <lib>...      # names of library targets to import
 LINK_LIBRARIES          # link interface libraries for LIBRARIES
  [LINK_LIBS <lib> <dep>...]...
 CMAKE_COMMAND_LINE ...  # extra command line flags to pass to cmake
 NO_EXTERNAL_INSTALL     # skip installation of external project
 )

Relative paths in ARCHIVE_DIR and RUNTIME_DIR are interpreted with respect to the build directory corresponding to the source directory in which the function is invoked.

Limitations:

NO_EXTERNAL_INSTALL is required for forward compatibility with a future version that supports installation of the external project binaries during make install.

define a bunch of backwards compatibility variables

CMAKE_ANSI_CXXFLAGS - flag for ansi c++
CMAKE_HAS_ANSI_STRING_STREAM - has <strstream>
include(TestForANSIStreamHeaders)
include(CheckIncludeFileCXX)
include(TestForSTDNamespace)
include(TestForANSIForScope)

Macro to provide an option dependent on other options.

This macro presents an option to the user only if a set of other conditions are true.

cmake_dependent_option(<option> "<help_text>" <value> <depends> <force>)

Makes <option> available to the user if the semicolon-separated list of conditions in <depends> are all true. Otherwise, a local variable named <option> is set to <force>.

When <option> is available, the given <help_text> and initial <value> are used. Otherwise, any value set by the user is preserved for when <depends> is satisfied in the future.

Note that the <option> variable only has a value which satisfies the <depends> condition within the scope of the caller because it is a local variable.

Example invocation:

cmake_dependent_option(USE_FOO "Use Foo" ON "USE_BAR;NOT USE_ZOT" OFF)

If USE_BAR is true and USE_ZOT is false, this provides an option called USE_FOO that defaults to ON. Otherwise, it sets USE_FOO to OFF and hides the option from the user. If the status of USE_BAR or USE_ZOT ever changes, any value for the USE_FOO option is saved so that when the option is re-enabled it retains its old value.

Added in version 3.22: Full Condition Syntax is now supported. See policy CMP0127.

The find_dependency() macro wraps a find_package() call for a package dependency:
find_dependency(<dep> [...])

It is designed to be used in a Package Configuration File (<PackageName>Config.cmake). find_dependency forwards the correct parameters for QUIET and REQUIRED which were passed to the original find_package() call. Any additional arguments specified are forwarded to find_package().

If the dependency could not be found it sets an informative diagnostic message and calls return() to end processing of the calling package configuration file and return to the find_package() command that loaded it.

NOTE:

The call to return() makes this macro unsuitable to call from Find Modules.

If find_dependency is called with arguments identical to a previous call in the same directory, perhaps due to diamond-shaped package dependencies, the underlying call to find_package() is optimized out. This optimization is important to support large package dependency graphs while avoiding a combinatorial explosion of repeated searches. However, the heuristic cannot account for ambient variables that affect package behavior, such as <PackageName>_USE_STATIC_LIBS, offered by some packages. Therefore package configuration files should avoid setting such variables before their calls to find_dependency.

Changed in version 3.15: Previously, the underlying call to find_package() was always optimized out if the package had already been found. CMake 3.15 removed the optimization to support cases in which find_dependency call arguments request different components.

Changed in version 3.26: The pre-3.15 optimization was restored, but with the above-described heuristic to account for varying find_dependency call arguments.

helper module to find OSX frameworks

This module reads hints about search locations from variables:

CMAKE_FIND_FRAMEWORK_EXTRA_LOCATIONS - Extra directories

This file is executed by cmake when invoked with --find-package. It expects that the following variables are set using -D:

NAME
name of the package
the CMake compiler ID for which the result is, i.e. GNU/Intel/Clang/MSVC, etc.
language for which the result will be used, i.e. C/CXX/Fortran/ASM
only check for existence of the given package
print the flags needed for compiling an object file which uses the given package
print the flags needed for linking when using the given package
if TRUE, don't print anything

The builtin Graphviz support of CMake.

CMake can generate Graphviz files showing the dependencies between the targets in a project, as well as external libraries which are linked against.

When running CMake with the --graphviz=foo.dot option, it produces:

  • a foo.dot file, showing all dependencies in the project
  • a foo.dot.<target> file for each target, showing on which other targets it depends
  • a foo.dot.<target>.dependers file for each target, showing which other targets depend on it

Those .dot files can be converted to images using the dot command from the Graphviz package:

dot -Tpng -o foo.png foo.dot

Added in version 3.10: The different dependency types PUBLIC, INTERFACE and PRIVATE are represented as solid, dashed and dotted edges.

The resulting graphs can be huge. The look and content of the generated graphs can be controlled using the file CMakeGraphVizOptions.cmake. This file is first searched in CMAKE_BINARY_DIR, and then in CMAKE_SOURCE_DIR. If found, the variables set in it are used to adjust options for the generated Graphviz files.

The graph name.
  • Mandatory: NO
  • Default: value of CMAKE_PROJECT_NAME
The header written at the top of the Graphviz files.
  • Mandatory: NO
  • Default: "node [ fontsize = "12" ];"
The prefix for each node in the Graphviz files.
  • Mandatory: NO
  • Default: "node"
Set to FALSE to exclude executables from the generated graphs.
  • Mandatory: NO
  • Default: TRUE
Set to FALSE to exclude static libraries from the generated graphs.
  • Mandatory: NO
  • Default: TRUE
Set to FALSE to exclude shared libraries from the generated graphs.
  • Mandatory: NO
  • Default: TRUE
Set to FALSE to exclude module libraries from the generated graphs.
  • Mandatory: NO
  • Default: TRUE
Set to FALSE to exclude interface libraries from the generated graphs.
  • Mandatory: NO
  • Default: TRUE
Set to FALSE to exclude object libraries from the generated graphs.
  • Mandatory: NO
  • Default: TRUE
Set to FALSE to exclude unknown libraries from the generated graphs.
  • Mandatory: NO
  • Default: TRUE
Set to FALSE to exclude external libraries from the generated graphs.
  • Mandatory: NO
  • Default: TRUE
Set to TRUE to include custom targets in the generated graphs.
  • Mandatory: NO
  • Default: FALSE
A list of regular expressions for names of targets to exclude from the generated graphs.
  • Mandatory: NO
  • Default: empty
Set to FALSE to not generate per-target graphs foo.dot.<target>.
  • Mandatory: NO
  • Default: TRUE
Set to FALSE to not generate depender graphs foo.dot.<target>.dependers.
  • Mandatory: NO
  • Default: TRUE

Helper functions for creating config files that can be included by other projects to find and use a package.

Create a config file for a project:
configure_package_config_file(<input> <output>
  INSTALL_DESTINATION <path>
  [PATH_VARS <var1> <var2> ... <varN>]
  [NO_SET_AND_CHECK_MACRO]
  [NO_CHECK_REQUIRED_COMPONENTS_MACRO]
  [INSTALL_PREFIX <path>]
  )

configure_package_config_file() should be used instead of the plain configure_file() command when creating the <PackageName>Config.cmake or <PackageName>-config.cmake file for installing a project or library. It helps make the resulting package relocatable by avoiding hardcoded paths in the installed <PackageName>Config.cmake file.

In a FooConfig.cmake file there may be code like this to make the install destinations known to the using project:

set(FOO_INCLUDE_DIR   "@CMAKE_INSTALL_FULL_INCLUDEDIR@" )
set(FOO_DATA_DIR   "@CMAKE_INSTALL_PREFIX@/@RELATIVE_DATA_INSTALL_DIR@" )
set(FOO_ICONS_DIR   "@CMAKE_INSTALL_PREFIX@/share/icons" )
#...logic to determine installedPrefix from the own location...
set(FOO_CONFIG_DIR  "${installedPrefix}/@CONFIG_INSTALL_DIR@" )

All four options shown above are not sufficient The first three hardcode the absolute directory locations. The fourth case works only if the logic to determine the installedPrefix is correct, and if CONFIG_INSTALL_DIR contains a relative path, which in general cannot be guaranteed. This has the effect that the resulting FooConfig.cmake file would work poorly under Windows and macOS, where users are used to choosing the install location of a binary package at install time, independent from how CMAKE_INSTALL_PREFIX was set at build/cmake time.

Using configure_package_config_file() helps. If used correctly, it makes the resulting FooConfig.cmake file relocatable. Usage:

1.
Write a FooConfig.cmake.in file as you are used to.
2.
Insert a line at the top containing only the string @PACKAGE_INIT@.
3.
Instead of set(FOO_DIR "@SOME_INSTALL_DIR@"), use set(FOO_DIR "@PACKAGE_SOME_INSTALL_DIR@") (this must be after the @PACKAGE_INIT@ line).
4.
Instead of using the normal configure_file() command, use configure_package_config_file().

The <input> and <output> arguments are the input and output file, the same way as in configure_file().

The <path> given to INSTALL_DESTINATION must be the destination where the FooConfig.cmake file will be installed to. This path can either be absolute, or relative to the INSTALL_PREFIX path.

The variables <var1> to <varN> given as PATH_VARS are the variables which contain install destinations. For each of them, the macro will create a helper variable PACKAGE_<var...>. These helper variables must be used in the FooConfig.cmake.in file for setting the installed location. They are calculated by configure_package_config_file() so that they are always relative to the installed location of the package. This works both for relative and also for absolute locations. For absolute locations, it works only if the absolute location is a subdirectory of INSTALL_PREFIX.

Added in version 3.30: The variable PACKAGE_PREFIX_DIR will always be defined after the @PACKAGE_INIT@ line. It will hold the value of the base install location. In general, variables defined via the PATH_VARS mechanism should be used instead, but PACKAGE_PREFIX_DIR can be used for those cases not easily handled by PATH_VARS, such as for files installed directly to the base install location rather than a subdirectory of it.

NOTE:

When consumers of the generated file use CMake 3.29 or older, the value of PACKAGE_PREFIX_DIR can be changed by a call to find_dependency() or find_package(). If a project relies on PACKAGE_PREFIX_DIR, it is the project's responsibility to ensure that the value of PACKAGE_PREFIX_DIR is preserved across any such calls, or any other calls which might include another file generated by configure_package_config_file().

Added in version 3.1: If the INSTALL_PREFIX argument is passed, this is used as the base path to calculate all the relative paths. The <path> argument must be an absolute path. If this argument is not passed, the CMAKE_INSTALL_PREFIX variable will be used instead. The default value is good when generating a FooConfig.cmake file to use your package from the install tree. When generating a FooConfig.cmake file to use your package from the build tree, this option should be used.

By default, configure_package_config_file() also generates two helper macros, set_and_check() and check_required_components(), into the FooConfig.cmake file.

set_and_check() should be used instead of the normal set() command for setting directories and file locations. In addition to setting the variable, it also checks that the referenced file or directory actually exists and fails with a fatal error if it doesn't. This ensures that the generated FooConfig.cmake file does not contain wrong references. Add the NO_SET_AND_CHECK_MACRO option to prevent the generation of the set_and_check() macro in the FooConfig.cmake file.

check_required_components(<PackageName>) should be called at the end of the FooConfig.cmake file. This macro checks whether all requested, non-optional components have been found, and if this is not the case, it sets the Foo_FOUND variable to FALSE so that the package is considered to be not found. It does that by testing the Foo_<Component>_FOUND variables for all requested required components. This macro should be called even if the package doesn't provide any components to make sure users are not specifying components erroneously. Add the NO_CHECK_REQUIRED_COMPONENTS_MACRO option to prevent the generation of the check_required_components() macro in the FooConfig.cmake file.

See also Example Generating Package Files.

Create a version file for a project:
write_basic_package_version_file(<filename>
  [VERSION <major.minor.patch>]
  COMPATIBILITY <AnyNewerVersion|SameMajorVersion|SameMinorVersion|ExactVersion>
  [ARCH_INDEPENDENT] )

Writes a file for use as a <PackageName>ConfigVersion.cmake file to <filename>. See the documentation of find_package() for details on such files.

<filename> is the output filename, which should be in the build tree. <major.minor.patch> is the version number of the project to be installed.

If no VERSION is given, the PROJECT_VERSION variable is used. If this hasn't been set, it errors out.

The COMPATIBILITY mode AnyNewerVersion means that the installed package version will be considered compatible if it is newer or exactly the same as the requested version. This mode should be used for packages which are fully backward compatible, also across major versions. If SameMajorVersion is used instead, then the behavior differs from AnyNewerVersion in that the major version number must be the same as requested, e.g. version 2.0 will not be considered compatible if 1.0 is requested. This mode should be used for packages which guarantee backward compatibility within the same major version. If SameMinorVersion is used, the behavior is the same as SameMajorVersion, but both major and minor version must be the same as requested, e.g version 0.2 will not be compatible if 0.1 is requested. If ExactVersion is used, then the package is only considered compatible if the requested version matches exactly its own version number (not considering the tweak version). For example, version 1.2.3 of a package is only considered compatible to requested version 1.2.3. This mode is for packages without compatibility guarantees. If your project has more elaborate version matching rules, you will need to write your own custom <PackageName>ConfigVersion.cmake file instead of using this macro.

Added in version 3.11: The SameMinorVersion compatibility mode.

Added in version 3.14: If ARCH_INDEPENDENT is given, the installed package version will be considered compatible even if it was built for a different architecture than the requested architecture. Otherwise, an architecture check will be performed, and the package will be considered compatible only if the architecture matches exactly. For example, if the package is built for a 32-bit architecture, the package is only considered compatible if it is used on a 32-bit architecture, unless ARCH_INDEPENDENT is given, in which case the package is considered compatible on any architecture.

NOTE:

ARCH_INDEPENDENT is intended for header-only libraries or similar packages with no binaries.

Added in version 3.19: The version file generated by AnyNewerVersion, SameMajorVersion and SameMinorVersion arguments of COMPATIBILITY handle the version range, if one is specified (see find_package() command for the details). ExactVersion mode is incompatible with version ranges and will display an author warning if one is specified.

Internally, this macro executes configure_file() to create the resulting version file. Depending on the COMPATIBILITY, the corresponding BasicConfigVersion-<COMPATIBILITY>.cmake.in file is used. Please note that these files are internal to CMake and you should not call configure_file() on them yourself, but they can be used as a starting point to create more sophisticated custom <PackageName>ConfigVersion.cmake files.

Added in version 3.29.

Create an Apple platform selection file:

generate_apple_platform_selection_file(<filename>
  INSTALL_DESTINATION <path>
  [INSTALL_PREFIX <path>]
  [MACOS_INCLUDE_FILE <file>]
  [IOS_INCLUDE_FILE <file>]
  [IOS_SIMULATOR_INCLUDE_FILE <file>]
  [TVOS_INCLUDE_FILE <file>]
  [TVOS_SIMULATOR_INCLUDE_FILE <file>]
  [WATCHOS_INCLUDE_FILE <file>]
  [WATCHOS_SIMULATOR_INCLUDE_FILE <file>]
  [VISIONOS_INCLUDE_FILE <file>]
  [VISIONOS_SIMULATOR_INCLUDE_FILE <file>]
  [ERROR_VARIABLE <variable>]
  )

Write a file that includes an Apple-platform-specific .cmake file, e.g., for use as <PackageName>Config.cmake. This can be used in conjunction with the XCFRAMEWORK_LOCATION argument of export(SETUP) to export packages in a way that a project built for any Apple platform can use them.

Path to which the generated file will be installed by the caller, e.g., via install(FILES). The path may be either relative to the INSTALL_PREFIX or absolute.
Path prefix to which the package will be installed by the caller. The <path> argument must be an absolute path. If this argument is not passed, the CMAKE_INSTALL_PREFIX variable will be used instead.
File to include if the platform is macOS.
File to include if the platform is iOS.
File to include if the platform is iOS Simulator.
File to include if the platform is tvOS.
File to include if the platform is tvOS Simulator.
File to include if the platform is watchOS.
File to include if the platform is watchOS Simulator.
File to include if the platform is visionOS.
File to include if the platform is visionOS Simulator.
If the consuming project is built for an unsupported platform, set <variable> to an error message. The includer may use this information to pretend the package was not found. If this option is not given, the default behavior is to issue a fatal error.

If any of the optional include files is not specified, and the consuming project is built for its corresponding platform, the generated file will consider the platform to be unsupported. The behavior is determined by the ERROR_VARIABLE option.

Added in version 3.29.

Create an Apple architecture selection file:

generate_apple_architecture_selection_file(<filename>
  INSTALL_DESTINATION <path>
  [INSTALL_PREFIX <path>]
  [SINGLE_ARCHITECTURES <arch>...
   SINGLE_ARCHITECTURE_INCLUDE_FILES <file>...]
  [UNIVERSAL_ARCHITECTURES <arch>...
   UNIVERSAL_INCLUDE_FILE <file>]
  [ERROR_VARIABLE <variable>]
  )

Write a file that includes an Apple-architecture-specific .cmake file based on CMAKE_OSX_ARCHITECTURES, e.g., for inclusion from an Apple-specific <PackageName>Config.cmake file.

Path to which the generated file will be installed by the caller, e.g., via install(FILES). The path may be either relative to the INSTALL_PREFIX or absolute.
Path prefix to which the package will be installed by the caller. The <path> argument must be an absolute path. If this argument is not passed, the CMAKE_INSTALL_PREFIX variable will be used instead.
Architectures provided by entries of SINGLE_ARCHITECTURE_INCLUDE_FILES.
Architecture-specific files. One of them will be loaded when CMAKE_OSX_ARCHITECTURES contains a single architecture matching the corresponding entry of SINGLE_ARCHITECTURES.
Architectures provided by the UNIVERSAL_INCLUDE_FILE.

The list may include $(ARCHS_STANDARD) to support consumption using the Xcode generator, but the architectures should always be listed individually too.

A file to load when CMAKE_OSX_ARCHITECTURES contains a (non-strict) subset of the UNIVERSAL_ARCHITECTURES and does not match any one of the SINGLE_ARCHITECTURES.
If the consuming project is built for an unsupported architecture, set <variable> to an error message. The includer may use this information to pretend the package was not found. If this option is not given, the default behavior is to issue a fatal error.

Example using both the configure_package_config_file() and write_basic_package_version_file() commands:

CMakeLists.txt

include(GNUInstallDirs)
set(INCLUDE_INSTALL_DIR ${CMAKE_INSTALL_INCLUDEDIR}/Foo
    CACHE PATH "Location of header files" )
set(SYSCONFIG_INSTALL_DIR ${CMAKE_INSTALL_SYSCONFDIR}/foo
    CACHE PATH "Location of configuration files" )
#...
include(CMakePackageConfigHelpers)
configure_package_config_file(FooConfig.cmake.in
  ${CMAKE_CURRENT_BINARY_DIR}/FooConfig.cmake
  INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/Foo
  PATH_VARS INCLUDE_INSTALL_DIR SYSCONFIG_INSTALL_DIR)
write_basic_package_version_file(
  ${CMAKE_CURRENT_BINARY_DIR}/FooConfigVersion.cmake
  VERSION 1.2.3
  COMPATIBILITY SameMajorVersion )
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/FooConfig.cmake
              ${CMAKE_CURRENT_BINARY_DIR}/FooConfigVersion.cmake
        DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/Foo )

FooConfig.cmake.in

set(FOO_VERSION x.y.z)
...
@PACKAGE_INIT@
...
set_and_check(FOO_INCLUDE_DIR "@PACKAGE_INCLUDE_INSTALL_DIR@")
set_and_check(FOO_SYSCONFIG_DIR "@PACKAGE_SYSCONFIG_INSTALL_DIR@")
check_required_components(Foo)

Convenience functions for printing properties and variables, useful e.g. for debugging.

cmake_print_properties(<TARGETS       [<target1> ...] |
                        SOURCES       [<source1> ...] |
                        DIRECTORIES   [<dir1> ...]    |
                        TESTS         [<test1> ...]   |
                        CACHE_ENTRIES [<entry1> ...]  >
                       PROPERTIES [<prop1> ...]         )

This function prints the values of the properties of the given targets, source files, directories, tests or cache entries. Exactly one of the scope keywords must be used. The scope keyword and its arguments must come before the PROPERTIES keyword, in the arguments list.

Example:

cmake_print_properties(TARGETS foo bar PROPERTIES
                       LOCATION INTERFACE_INCLUDE_DIRECTORIES)

This will print the LOCATION and INTERFACE_INCLUDE_DIRECTORIES properties for both targets foo and bar.

cmake_print_variables(var1 var2 ..  varN)

This function will print the name of each variable followed by its value. Example:

cmake_print_variables(CMAKE_C_COMPILER CMAKE_MAJOR_VERSION DOES_NOT_EXIST)

Gives:

-- CMAKE_C_COMPILER="/usr/bin/gcc" ; CMAKE_MAJOR_VERSION="2" ; DOES_NOT_EXIST=""

Print system information.

This module serves diagnostic purposes. Just include it in a project to see various internal CMake variables.

This module defines three macros: CMAKE_PUSH_CHECK_STATE() CMAKE_POP_CHECK_STATE() and CMAKE_RESET_CHECK_STATE() These macros can be used to save, restore and reset (i.e., clear contents) the state of the variables CMAKE_REQUIRED_FLAGS, CMAKE_REQUIRED_DEFINITIONS, CMAKE_REQUIRED_LINK_OPTIONS, CMAKE_REQUIRED_LIBRARIES, CMAKE_REQUIRED_INCLUDES and CMAKE_EXTRA_INCLUDE_FILES used by the various Check-files coming with CMake, like e.g. check_function_exists() etc. The variable contents are pushed on a stack, pushing multiple times is supported. This is useful e.g. when executing such tests in a Find-module, where they have to be set, but after the Find-module has been executed they should have the same value as they had before.

CMAKE_PUSH_CHECK_STATE() macro receives optional argument RESET. Whether it's specified, CMAKE_PUSH_CHECK_STATE() will set all CMAKE_REQUIRED_* variables to empty values, same as CMAKE_RESET_CHECK_STATE() call will do.

Usage:

cmake_push_check_state(RESET)
set(CMAKE_REQUIRED_DEFINITIONS -DSOME_MORE_DEF)
check_function_exists(...)
cmake_reset_check_state()
set(CMAKE_REQUIRED_DEFINITIONS -DANOTHER_DEF)
check_function_exists(...)
cmake_pop_check_state()

CMakeVerifyManifest.cmake

This script is used to verify that embedded manifests and side by side manifests for a project match. To run this script, cd to a directory and run the script with cmake -P. On the command line you can pass in versions that are OK even if not found in the .manifest files. For example, cmake -Dallow_versions=8.0.50608.0 -PCmakeVerifyManifest.cmake could be used to allow an embedded manifest of 8.0.50608.0 to be used in a project even if that version was not found in the .manifest file.

Configure generators for binary installers and source packages.

The CPack module generates the configuration files CPackConfig.cmake and CPackSourceConfig.cmake. They are intended for use in a subsequent run of the cpack program where they steer the generation of installers or/and source packages.

Depending on the CMake generator, the CPack module may also add two new build targets, package and package_source. See the packaging targets section below for details.

The generated binary installers will contain all files that have been installed via CMake's install() command (and the deprecated commands install_files(), install_programs(), and install_targets()). Note that the DESTINATION option of the install() command must be a relative path; otherwise installed files are ignored by CPack.

Certain kinds of binary installers can be configured such that users can select individual application components to install. See the CPackComponent module for further details.

Source packages (configured through CPackSourceConfig.cmake and generated by the CPack Archive Generator) will contain all source files in the project directory except those specified in CPACK_SOURCE_IGNORE_FILES.

The CPACK_GENERATOR variable has different meanings in different contexts. In a CMakeLists.txt file, CPACK_GENERATOR is a list of generators: and when cpack is run with no other arguments, it will iterate over that list and produce one package for each generator. In a CPACK_PROJECT_CONFIG_FILE, CPACK_GENERATOR is a string naming a single generator. If you need per-cpack-generator logic to control other cpack settings, then you need a CPACK_PROJECT_CONFIG_FILE. If set, the CPACK_PROJECT_CONFIG_FILE is included automatically on a per-generator basis. It only need contain overrides.

Here's how it works:

  • cpack runs
  • it includes CPackConfig.cmake
  • it iterates over the generators given by the -G command line option, or if no such option was specified, over the list of generators given by the CPACK_GENERATOR variable set in the CPackConfig.cmake input file.
  • foreach generator, it then
  • sets CPACK_GENERATOR to the one currently being iterated
  • includes the CPACK_PROJECT_CONFIG_FILE
  • produces the package for that generator

This is the key: For each generator listed in CPACK_GENERATOR in CPackConfig.cmake, cpack will reset CPACK_GENERATOR internally to the one currently being used and then include the CPACK_PROJECT_CONFIG_FILE.

For a list of available generators, see cpack-generators(7).

If CMake is run with the Makefile, Ninja, or Xcode generator, then include(CPack) generates a target package. This makes it possible to build a binary installer from CMake, Make, or Ninja: Instead of cpack, one may call cmake --build . --target package or make package or ninja package. The VS generator creates an uppercase target PACKAGE.

If CMake is run with the Makefile or Ninja generator, then include(CPack) also generates a target package_source. To build a source package, instead of cpack -G TGZ --config CPackSourceConfig.cmake one may call cmake --build . --target package_source, make package_source, or ninja package_source.

Before including this CPack module in your CMakeLists.txt file, there are a variety of variables that can be set to customize the resulting installers. The most commonly-used variables are:

The name of the package (or application). If not specified, it defaults to the project name.
The name of the package vendor. (e.g., "Kitware"). The default is "Humanity".
The directory in which CPack is doing its packaging. If it is not set then this will default (internally) to the build dir. This variable may be defined in a CPack config file or from the cpack command line option -B. If set, the command line option overrides the value found in the config file.
Package major version. This variable will always be set, but its default value depends on whether or not version details were given to the project() command in the top level CMakeLists.txt file. If version details were given, the default value will be CMAKE_PROJECT_VERSION_MAJOR. If no version details were given, a default version of 0.1.1 will be assumed, leading to CPACK_PACKAGE_VERSION_MAJOR having a default value of 0.
Package minor version. The default value is determined based on whether or not version details were given to the project() command in the top level CMakeLists.txt file. If version details were given, the default value will be CMAKE_PROJECT_VERSION_MINOR, but if no minor version component was specified then CPACK_PACKAGE_VERSION_MINOR will be left unset. If no project version was given at all, a default version of 0.1.1 will be assumed, leading to CPACK_PACKAGE_VERSION_MINOR having a default value of 1.
Package patch version. The default value is determined based on whether or not version details were given to the project() command in the top level CMakeLists.txt file. If version details were given, the default value will be CMAKE_PROJECT_VERSION_PATCH, but if no patch version component was specified then CPACK_PACKAGE_VERSION_PATCH will be left unset. If no project version was given at all, a default version of 0.1.1 will be assumed, leading to CPACK_PACKAGE_VERSION_PATCH having a default value of 1.
A description of the project, used in places such as the introduction screen of CPack-generated Windows installers. If not set, the value of this variable is populated from the file named by CPACK_PACKAGE_DESCRIPTION_FILE.
A text file used to describe the project when CPACK_PACKAGE_DESCRIPTION is not explicitly set. The default value for CPACK_PACKAGE_DESCRIPTION_FILE points to a built-in template file Templates/CPack.GenericDescription.txt.
Short description of the project (only a few words). If the CMAKE_PROJECT_DESCRIPTION variable is set, it is used as the default value, otherwise the default will be a string generated by CMake based on CMAKE_PROJECT_NAME.
Project homepage URL. The default value is taken from the CMAKE_PROJECT_HOMEPAGE_URL variable, which is set by the top level project() command, or else the default will be empty if no URL was provided to project().
The name of the package file to generate, not including the extension. For example, cmake-2.6.1-Linux-i686. The default value is:
${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-${CPACK_SYSTEM_NAME}
Installation directory on the target system. This may be used by some CPack generators like NSIS to create an installation directory e.g., "CMake 2.5" below the installation prefix. All installed elements will be put inside this directory.
A branding image that will be displayed inside the installer (used by GUI installers).
Added in version 3.7.

An algorithm that will be used to generate an additional file with the checksum of the package. The output file name will be:

${CPACK_PACKAGE_FILE_NAME}.${CPACK_PACKAGE_CHECKSUM}

Supported algorithms are those listed by the string(<HASH>) command.

CPack-time project CPack configuration file. This file is included at cpack time, once per generator after CPack has set CPACK_GENERATOR to the actual generator being used. It allows per-generator setting of CPACK_* variables at cpack time.
License to be embedded in the installer. It will typically be displayed to the user by the produced installer (often with an explicit "Accept" button, for graphical installers) prior to installation. This license file is NOT added to the installed files but is used by some CPack generators like NSIS. If you want to use UTF-8 characters, the file needs to be encoded in UTF-8 BOM. If you want to install a license file (may be the same as this one) along with your project, you must add an appropriate CMake install() command in your CMakeLists.txt.
ReadMe file to be embedded in the installer. It typically describes in some detail the purpose of the project during the installation. Not all CPack generators use this file.
Welcome file to be embedded in the installer. It welcomes users to this installer. Typically used in the graphical installers on Windows and Mac OS X.
Disables the component-based installation mechanism. When set, the component specification is ignored and all installed items are put in a single "MONOLITHIC" package. Some CPack generators do monolithic packaging by default and may be asked to do component packaging by setting CPACK_<GENNAME>_COMPONENT_INSTALL to TRUE.
List of CPack generators to use. If not specified, CPack will create a set of options following the naming pattern CPACK_BINARY_<GENNAME> (e.g. CPACK_BINARY_NSIS) allowing the user to enable/disable individual generators. If the -G option is given on the cpack command line, it will override this variable and any CPACK_BINARY_<GENNAME> options.
The name of the CPack binary configuration file. This file is the CPack configuration generated by the CPack module for binary installers. Defaults to CPackConfig.cmake.
Lists each of the executables and associated text label to be used to create Start Menu shortcuts. For example, setting this to the list ccmake;CMake will create a shortcut named "CMake" that will execute the installed executable ccmake. Not all CPack generators use it (at least NSIS, Inno Setup and WIX do).
List of files to be stripped. Starting with CMake 2.6.0, CPACK_STRIP_FILES will be a boolean variable which enables stripping of all files (a list of files evaluates to TRUE in CMake, so this change is compatible).
Added in version 3.4.

If set to TRUE, values of variables prefixed with CPACK_ will be escaped before being written to the configuration files, so that the cpack program receives them exactly as they were specified. If not, characters like quotes and backslashes can cause parsing errors or alter the value received by the cpack program. Defaults to FALSE for backwards compatibility.

Added in version 3.20.

Number of threads to use when performing parallelized operations, such as compressing the installer package.

Some compression methods used by CPack generators such as Debian or Archive may take advantage of multiple CPU cores to speed up compression. CPACK_THREADS can be set to specify how many threads will be used for compression.

A positive integer can be used to specify an exact desired thread count.

When given a negative integer CPack will use the absolute value as the upper limit but may choose a lower value based on the available hardware concurrency.

Given 0 CPack will try to use all available CPU cores.

By default CPACK_THREADS is set to 1.

The following compression methods may take advantage of multiple cores:

Supported if CMake is built with a liblzma that supports parallel compression.

Added in version 3.21: Official CMake binaries available on cmake.org now ship with a liblzma that supports parallel compression. Older versions did not.

Added in version 3.24.

Supported if CMake is built with libarchive 3.6 or higher. Official CMake binaries available on cmake.org support it.

Other compression methods ignore this value and use only one thread.

The following CPack variables are specific to source packages, and will not affect binary packages:

The name of the source package. For example cmake-2.6.1.
List of files in the source tree that will be stripped. Starting with CMake 2.6.0, CPACK_SOURCE_STRIP_FILES will be a boolean variable which enables stripping of all files (a list of files evaluates to TRUE in CMake, so this change is compatible).
List of generators used for the source packages. As with CPACK_GENERATOR, if this is not specified then CPack will create a set of options (e.g. CPACK_SOURCE_ZIP) allowing users to select which packages will be generated.
The name of the CPack source configuration file. This file is the CPack configuration generated by the CPack module for source installers. Defaults to CPackSourceConfig.cmake.
Pattern of files in the source tree that won't be packaged when building a source package. This is a list of regular expression patterns (that must be properly escaped), e.g., /CVS/;/\\.svn/;\\.swp$;\\.#;/#;.*~;cscope.*

The following variables are for advanced uses of CPack:

What CMake generator should be used if the project is a CMake project. Defaults to the value of CMAKE_GENERATOR. Few users will want to change this setting.
List of four values that specify what project to install. The four values are: Build directory, Project Name, Project Component, Directory. If omitted, CPack will build an installer that installs everything.
System name, defaults to the value of CMAKE_SYSTEM_NAME, except on Windows where it will be win32 or win64.
Package full version, used internally. By default, this is built from CPACK_PACKAGE_VERSION_MAJOR, CPACK_PACKAGE_VERSION_MINOR, and CPACK_PACKAGE_VERSION_PATCH.
Directory for the installed files.
Extra commands to install components. The environment variable CMAKE_INSTALL_PREFIX is set to the temporary install directory during execution.
Added in version 3.16.

Extra CMake scripts executed by CPack during its local staging installation. They are executed before installing the files to be packaged. The scripts are not called by a standalone install (e.g.: make install). For every script, the following variables will be set: CMAKE_CURRENT_SOURCE_DIR, CMAKE_CURRENT_BINARY_DIR and CMAKE_INSTALL_PREFIX (which is set to the staging install directory). The singular form CMAKE_INSTALL_SCRIPT is supported as an alternative variable for historical reasons, but its value is ignored if CMAKE_INSTALL_SCRIPTS is set and a warning will be issued.

See also CPACK_PRE_BUILD_SCRIPTS and CPACK_POST_BUILD_SCRIPTS which can be used to specify scripts to be executed later in the packaging process.

Added in version 3.19.

List of CMake scripts to execute after CPack has installed the files to be packaged into a staging directory and before producing the package(s) from those files. See also CPACK_INSTALL_SCRIPTS and CPACK_POST_BUILD_SCRIPTS.

Added in version 3.19.

List of CMake scripts to execute after CPack has produced the resultant packages and before copying them back to the build directory. See also CPACK_INSTALL_SCRIPTS, CPACK_PRE_BUILD_SCRIPTS and CPACK_PACKAGE_FILES.

Added in version 3.19.

List of package files created in the staging directory, with each file provided as a full absolute path. This variable is populated by CPack just before invoking the post-build scripts listed in CPACK_POST_BUILD_SCRIPTS. It is the preferred way for the post-build scripts to know the set of package files to operate on. Projects should not try to set this variable themselves.

Extra directories to install.
Registry key used when installing this project. This is only used by installers for Windows. The default value is based on the installation directory.
List of desktop links to create. Each desktop link requires a corresponding start menu shortcut as created by CPACK_PACKAGE_EXECUTABLES.
CPack generated options for binary generators. The CPack.cmake module generates (when CPACK_GENERATOR is not set) a set of CMake options (see CMake option() command) which may then be used to select the CPack generator(s) to be used when building the package target or when running cpack without the -G option.
Added in version 3.25.

Specify the readelf executable path used by CPack. The default value will be taken from the CMAKE_READELF variable, if set, which may be populated by an internal CMake module. If CMAKE_READELF is not set, CPack will use find_program() to determine the readelf path when needed.

Added in version 3.25.

Specify the objcopy executable path used by CPack. The default value will be taken from the CMAKE_OBJCOPY variable, if set, which may be populated by an internal CMake module. If CMAKE_OBJCOPY is not set, CPack will use find_program() to determine the objcopy path when needed.

Added in version 3.25.

Specify the objdump executable path used by CPack. The default value will be taken from the CMAKE_OBJDUMP variable, if set, which may be populated by an internal CMake module. If CMAKE_OBJDUMP is not set, CPack will use find_program() to determine the objdump path when needed.

Configure components for binary installers and source packages.

This module is automatically included by CPack.

Certain binary installers (especially the graphical installers) generated by CPack allow users to select individual application components to install. This module allows developers to configure the packaging of such components.

Contents is assigned to components by the COMPONENT argument of CMake's install() command. Components can be annotated with user-friendly names and descriptions, inter-component dependencies, etc., and grouped in various ways to customize the resulting installer, using the commands described below.

To specify different groupings for different CPack generators use a CPACK_PROJECT_CONFIG_FILE.

The following variables influence the component-specific packaging:

The list of component to install.

The default value of this variable is computed by CPack and contains all components defined by the project. The user may set it to only include the specified components.

Instead of specifying all the desired components, it is possible to obtain a list of all defined components and then remove the unwanted ones from the list. The get_cmake_property() command can be used to obtain the COMPONENTS property, then the list(REMOVE_ITEM) command can be used to remove the unwanted ones. For example, to use all defined components except foo and bar:

get_cmake_property(CPACK_COMPONENTS_ALL COMPONENTS)
list(REMOVE_ITEM CPACK_COMPONENTS_ALL "foo" "bar")
Enable/Disable component install for CPack generator <GENNAME>.

Each CPack Generator (RPM, DEB, ARCHIVE, NSIS, DMG, etc...) has a legacy default behavior. e.g. RPM builds monolithic whereas NSIS builds component. One can change the default behavior by setting this variable to 0/1 or OFF/ON.

Specify how components are grouped for multi-package component-aware CPack generators.

Some generators like RPM or ARCHIVE (TGZ, ZIP, ...) may generate several packages files when there are components, depending on the value of this variable:

  • ONE_PER_GROUP (default): create one package per component group
  • IGNORE : create one package per component (ignore the groups)
  • ALL_COMPONENTS_IN_ONE : create a single package with all requested components
The name to be displayed for a component.
The description of a component.
The group of a component.
The dependencies (list of components) on which this component depends.
True if this component is hidden from the user.
True if this component is required.
True if this component is not selected to be installed by default.

Describe an installation component.

cpack_add_component(compname
                    [DISPLAY_NAME name]
                    [DESCRIPTION description]
                    [HIDDEN | REQUIRED | DISABLED ]
                    [GROUP group]
                    [DEPENDS comp1 comp2 ... ]
                    [INSTALL_TYPES type1 type2 ... ]
                    [DOWNLOADED]
                    [ARCHIVE_FILE filename]
                    [PLIST filename])

compname is the name of an installation component, as defined by the COMPONENT argument of one or more CMake install() commands. With the cpack_add_component command one can set a name, a description, and other attributes of an installation component. One can also assign a component to a component group.

DISPLAY_NAME is the displayed name of the component, used in graphical installers to display the component name. This value can be any string.

DESCRIPTION is an extended description of the component, used in graphical installers to give the user additional information about the component. Descriptions can span multiple lines using \n as the line separator. Typically, these descriptions should be no more than a few lines long.

HIDDEN indicates that this component will be hidden in the graphical installer, so that the user cannot directly change whether it is installed or not.

REQUIRED indicates that this component is required, and therefore will always be installed. It will be visible in the graphical installer, but it cannot be unselected. (Typically, required components are shown grayed out).

DISABLED indicates that this component should be disabled (unselected) by default. The user is free to select this component for installation, unless it is also HIDDEN.

DEPENDS lists the components on which this component depends. If this component is selected, then each of the components listed must also be selected. The dependency information is encoded within the installer itself, so that users cannot install inconsistent sets of components.

GROUP names the component group of which this component is a part. If not provided, the component will be a standalone component, not part of any component group. Component groups are described with the cpack_add_component_group command, detailed below.

INSTALL_TYPES lists the installation types of which this component is a part. When one of these installations types is selected, this component will automatically be selected. Installation types are described with the cpack_add_install_type command, detailed below.

DOWNLOADED indicates that this component should be downloaded on-the-fly by the installer, rather than packaged in with the installer itself. For more information, see the cpack_configure_downloads command.

ARCHIVE_FILE provides a name for the archive file created by CPack to be used for downloaded components. If not supplied, CPack will create a file with some name based on CPACK_PACKAGE_FILE_NAME and the name of the component. See cpack_configure_downloads for more information.

PLIST gives a filename that is passed to pkgbuild with the --component-plist argument when using the productbuild generator.

Describes a group of related CPack installation components.

cpack_add_component_group(groupname
                         [DISPLAY_NAME name]
                         [DESCRIPTION description]
                         [PARENT_GROUP parent]
                         [EXPANDED]
                         [BOLD_TITLE])

The cpack_add_component_group describes a group of installation components, which will be placed together within the listing of options. Typically, component groups allow the user to select/deselect all of the components within a single group via a single group-level option. Use component groups to reduce the complexity of installers with many options. groupname is an arbitrary name used to identify the group in the GROUP argument of the cpack_add_component command, which is used to place a component in a group. The name of the group must not conflict with the name of any component.

DISPLAY_NAME is the displayed name of the component group, used in graphical installers to display the component group name. This value can be any string.

DESCRIPTION is an extended description of the component group, used in graphical installers to give the user additional information about the components within that group. Descriptions can span multiple lines using \n as the line separator. Typically, these descriptions should be no more than a few lines long.

PARENT_GROUP, if supplied, names the parent group of this group. Parent groups are used to establish a hierarchy of groups, providing an arbitrary hierarchy of groups.

EXPANDED indicates that, by default, the group should show up as "expanded", so that the user immediately sees all of the components within the group. Otherwise, the group will initially show up as a single entry.

BOLD_TITLE indicates that the group title should appear in bold, to call the user's attention to the group.

Add a new installation type containing a set of predefined component selections to the graphical installer.

cpack_add_install_type(typename
                       [DISPLAY_NAME name])

The cpack_add_install_type command identifies a set of preselected components that represents a common use case for an application. For example, a "Developer" install type might include an application along with its header and library files, while an "End user" install type might just include the application's executable. Each component identifies itself with one or more install types via the INSTALL_TYPES argument to cpack_add_component.

DISPLAY_NAME is the displayed name of the install type, which will typically show up in a drop-down box within a graphical installer. This value can be any string.

Configure CPack to download selected components on-the-fly as part of the installation process.

cpack_configure_downloads(site
                          [UPLOAD_DIRECTORY dirname]
                          [ALL]
                          [ADD_REMOVE|NO_ADD_REMOVE])

The cpack_configure_downloads command configures installation-time downloads of selected components. For each downloadable component, CPack will create an archive containing the contents of that component, which should be uploaded to the given site. When the user selects that component for installation, the installer will download and extract the component in place. This feature is useful for creating small installers that only download the requested components, saving bandwidth. Additionally, the installers are small enough that they will be installed as part of the normal installation process, and the "Change" button in Windows Add/Remove Programs control panel will allow one to add or remove parts of the application after the original installation. On Windows, the downloaded-components functionality requires the ZipDLL plug-in for NSIS, available at:

On macOS, installers that download components on-the-fly can only be built and installed on system using macOS 10.5 or later.

The site argument is a URL where the archives for downloadable components will reside, e.g., https://cmake.org/files/v3.25/ All of the archives produced by CPack should be uploaded to that location.

UPLOAD_DIRECTORY is the local directory where CPack will create the various archives for each of the components. The contents of this directory should be uploaded to a location accessible by the URL given in the site argument. If omitted, CPack will use the directory CPackUploads inside the CMake binary directory to store the generated archives.

The ALL flag indicates that all components be downloaded. Otherwise, only those components explicitly marked as DOWNLOADED or that have a specified ARCHIVE_FILE will be downloaded. Additionally, the ALL option implies ADD_REMOVE (unless NO_ADD_REMOVE is specified).

ADD_REMOVE indicates that CPack should install a copy of the installer that can be called from Windows' Add/Remove Programs dialog (via the "Modify" button) to change the set of installed components. NO_ADD_REMOVE turns off this behavior. This option is ignored on Mac OS X.

Added in version 3.1.

This module looks for the location of the command-line utilities supplied with the Qt Installer Framework (QtIFW).

The module also defines several commands to control the behavior of the CPack IFW Generator.

The module defines the following commands:

Sets the arguments specific to the CPack IFW generator.
cpack_ifw_configure_component(<compname> [COMMON] [ESSENTIAL] [VIRTUAL]
                    [FORCED_INSTALLATION] [REQUIRES_ADMIN_RIGHTS]
                    [NAME <name>]
                    [DISPLAY_NAME <display_name>] # Note: Internationalization supported
                    [DESCRIPTION <description>] # Note: Internationalization supported
                    [UPDATE_TEXT <update_text>]
                    [VERSION <version>]
                    [RELEASE_DATE <release_date>]
                    [SCRIPT <script>]
                    [PRIORITY|SORTING_PRIORITY <sorting_priority>] # Note: PRIORITY is deprecated
                    [DEPENDS|DEPENDENCIES <com_id> ...]
                    [AUTO_DEPEND_ON <comp_id> ...]
                    [LICENSES <display_name> <file_path> ...]
                    [DEFAULT <value>]
                    [USER_INTERFACES <file_path> <file_path> ...]
                    [TRANSLATIONS <file_path> <file_path> ...]
                    [REPLACES <comp_id> ...]
                    [CHECKABLE <value>])

This command should be called after cpack_add_component() command.

if set, then the component will be packaged and installed as part of a group to which it belongs.
Added in version 3.6.

if set, then the package manager stays disabled until that component is updated.

Added in version 3.8.

if set, then the component will be hidden from the installer. It is a equivalent of the HIDDEN option from the cpack_add_component() command.

Added in version 3.8.

if set, then the component must always be installed. It is a equivalent of the REQUIRED option from the cpack_add_component() command.

Added in version 3.8.

set it if the component needs to be installed with elevated permissions.

NAME
is used to create domain-like identification for this component. By default used origin component name.
Added in version 3.8.

set to rewrite original name configured by cpack_add_component() command.

Added in version 3.8.

set to rewrite original description configured by cpack_add_component() command.

Added in version 3.8.

will be added to the component description if this is an update to the component.

is version of component. By default used CPACK_PACKAGE_VERSION.
Added in version 3.8.

keep empty to auto generate.

is a relative or absolute path to operations script for this component.
Added in version 3.8.

is priority of the component in the tree.

Deprecated since version 3.8: Old name for SORTING_PRIORITY.
Added in version 3.8.

list of dependency component or component group identifiers in QtIFW style.

Added in version 3.21.

Component or group names listed as dependencies may contain hyphens. This requires QtIFW 3.1 or later.

Added in version 3.8.

list of identifiers of component or component group in QtIFW style that this component has an automatic dependency on.

pair of <display_name> and <file_path> of license text for this component. You can specify more then one license.
Added in version 3.8.

Possible values are: TRUE, FALSE, and SCRIPT. Set to FALSE to disable the component in the installer or to SCRIPT to resolved during runtime (don't forget add the file of the script as a value of the SCRIPT option).

Added in version 3.7.

is a list of <file_path> ('.ui' files) representing pages to load.

Added in version 3.8.

is a list of <file_path> ('.qm' files) representing translations to load.

Added in version 3.10.

list of identifiers of component or component group to replace.

Added in version 3.10.

Possible values are: TRUE, FALSE. Set to FALSE if you want to hide the checkbox for an item. This is useful when only a few subcomponents should be selected instead of all.

Sets the arguments specific to the CPack IFW generator.
cpack_ifw_configure_component_group(<groupname> [VIRTUAL]
                    [FORCED_INSTALLATION] [REQUIRES_ADMIN_RIGHTS]
                    [NAME <name>]
                    [DISPLAY_NAME <display_name>] # Note: Internationalization supported
                    [DESCRIPTION <description>] # Note: Internationalization supported
                    [UPDATE_TEXT <update_text>]
                    [VERSION <version>]
                    [RELEASE_DATE <release_date>]
                    [SCRIPT <script>]
                    [PRIORITY|SORTING_PRIORITY <sorting_priority>] # Note: PRIORITY is deprecated
                    [DEPENDS|DEPENDENCIES <com_id> ...]
                    [AUTO_DEPEND_ON <comp_id> ...]
                    [LICENSES <display_name> <file_path> ...]
                    [DEFAULT <value>]
                    [USER_INTERFACES <file_path> <file_path> ...]
                    [TRANSLATIONS <file_path> <file_path> ...]
                    [REPLACES <comp_id> ...]
                    [CHECKABLE <value>])

This command should be called after cpack_add_component_group() command.

Added in version 3.8.

if set, then the group will be hidden from the installer. Note that setting this on a root component does not work.

Added in version 3.8.

if set, then the group must always be installed.

Added in version 3.8.

set it if the component group needs to be installed with elevated permissions.

NAME
is used to create domain-like identification for this component group. By default used origin component group name.
Added in version 3.8.

set to rewrite original name configured by cpack_add_component_group() command.

Added in version 3.8.

set to rewrite original description configured by cpack_add_component_group() command.

Added in version 3.8.

will be added to the component group description if this is an update to the component group.

is version of component group. By default used CPACK_PACKAGE_VERSION.
Added in version 3.8.

keep empty to auto generate.

is a relative or absolute path to operations script for this component group.
is priority of the component group in the tree.
Deprecated since version 3.8: Old name for SORTING_PRIORITY.
Added in version 3.8.

list of dependency component or component group identifiers in QtIFW style.

Added in version 3.21.

Component or group names listed as dependencies may contain hyphens. This requires QtIFW 3.1 or later.

Added in version 3.8.

list of identifiers of component or component group in QtIFW style that this component group has an automatic dependency on.

pair of <display_name> and <file_path> of license text for this component group. You can specify more then one license.
Added in version 3.8.

Possible values are: TRUE, FALSE, and SCRIPT. Set to TRUE to preselect the group in the installer (this takes effect only on groups that have no visible child components) or to SCRIPT to resolved during runtime (don't forget add the file of the script as a value of the SCRIPT option).

Added in version 3.7.

is a list of <file_path> ('.ui' files) representing pages to load.

Added in version 3.8.

is a list of <file_path> ('.qm' files) representing translations to load.

Added in version 3.10.

list of identifiers of component or component group to replace.

Added in version 3.10.

Possible values are: TRUE, FALSE. Set to FALSE if you want to hide the checkbox for an item. This is useful when only a few subcomponents should be selected instead of all.

Add QtIFW specific remote repository to binary installer.
cpack_ifw_add_repository(<reponame> [DISABLED]
                    URL <url>
                    [USERNAME <username>]
                    [PASSWORD <password>]
                    [DISPLAY_NAME <display_name>])

This command will also add the <reponame> repository to a variable CPACK_IFW_REPOSITORIES_ALL.

if set, then the repository will be disabled by default.
URL
is points to a list of available components.
is used as user on a protected repository.
is password to use on a protected repository.
is string to display instead of the URL.
Added in version 3.6.

Update QtIFW specific repository from remote repository.

cpack_ifw_update_repository(<reponame>
                    [[ADD|REMOVE] URL <url>]|
                     [REPLACE OLD_URL <old_url> NEW_URL <new_url>]]
                    [USERNAME <username>]
                    [PASSWORD <password>]
                    [DISPLAY_NAME <display_name>])

This command will also add the <reponame> repository to a variable CPACK_IFW_REPOSITORIES_ALL.

URL
is points to a list of available components.
is points to a list that will replaced.
is points to a list that will replace to.
is used as user on a protected repository.
is password to use on a protected repository.
is string to display instead of the URL.
Added in version 3.7.

Add additional resources in the installer binary.

cpack_ifw_add_package_resources(<file_path> <file_path> ...)

This command will also add the specified files to a variable CPACK_IFW_PACKAGE_RESOURCES.

Added in version 3.8.

The module defines configure_file() similar command to configure file templates prepared in QtIFW/SDK/Creator style.

The module defines the following commands:

Copy a file to another location and modify its contents.
cpack_ifw_configure_file(<input> <output>)

Copies an <input> file to an <output> file and substitutes variable values referenced as %{VAR} or %VAR% in the input file content. Each variable reference will be replaced with the current value of the variable, or the empty string if the variable is not defined.

Added in version 3.8.

Functions to make configuration of CSharp/.NET targets easier.

A collection of CMake utility functions useful for dealing with CSharp targets for Visual Studio generators from version 2010 and later.

The following functions are provided by this module:

Main functions

  • csharp_set_windows_forms_properties()
  • csharp_set_designer_cs_properties()
  • csharp_set_xaml_cs_properties()

Helper functions

  • csharp_get_filename_keys()
  • csharp_get_filename_key_base()
  • csharp_get_dependentupon_name()

Sets source file properties for use of Windows Forms. Use this, if your CSharp target uses Windows Forms:
csharp_set_windows_forms_properties([<file1> [<file2> [...]]])
<fileN>
List of all source files which are relevant for setting the VS_CSHARP_<tagname> properties (including .cs, .resx and .Designer.cs extensions).

In the list of all given files for all files ending with .Designer.cs and .resx is searched. For every designer or resource file a file with the same base name but only .cs as extension is searched. If this is found, the VS_CSHARP_<tagname> properties are set as follows:

VS_CSHARP_SubType "Form"
  • VS_CSHARP_DependentUpon <cs-filename>
  • VS_CSHARP_DesignTime "" (delete tag if previously defined)
  • VS_CSHARP_AutoGen ""(delete tag if previously defined)
  • VS_RESOURCE_GENERATOR "" (delete tag if previously defined)
  • VS_CSHARP_DependentUpon <cs-filename>
  • VS_CSHARP_SubType "Designer"
Sets source file properties of .Designer.cs files depending on sibling filenames. Use this, if your CSharp target does not use Windows Forms (for Windows Forms use csharp_set_windows_forms_properties() instead):
csharp_set_designer_cs_properties([<file1> [<file2> [...]]])
<fileN>
List of all source files which are relevant for setting the VS_CSHARP_<tagname> properties (including .cs, .resx, .settings and .Designer.cs extensions).

In the list of all given files for all files ending with .Designer.cs is searched. For every designer file all files with the same base name but different extensions are searched. If a match is found, the source file properties of the designer file are set depending on the extension of the matched file:

  • VS_CSHARP_AutoGen "True"
  • VS_CSHARP_DesignTime "True"
  • VS_CSHARP_DependentUpon <resx-filename>
VS_CSHARP_DependentUpon <cs-filename>
  • VS_CSHARP_AutoGen "True"
  • VS_CSHARP_DesignTimeSharedInput "True"
  • VS_CSHARP_DependentUpon <settings-filename>

NOTE:

Because the source file properties of the .Designer.cs file are set according to the found matches and every match sets the VS_CSHARP_DependentUpon property, there should only be one match for each Designer.cs file.
Sets source file properties for use of Windows Presentation Foundation (WPF) and XAML. Use this, if your CSharp target uses WPF/XAML:
csharp_set_xaml_cs_properties([<file1> [<file2> [...]]])
<fileN>
List of all source files which are relevant for setting the VS_CSHARP_<tagname> properties (including .cs, .xaml, and .xaml.cs extensions).

In the list of all given files for all files ending with .xaml.cs is searched. For every xaml-cs file, a file with the same base name but extension .xaml is searched. If a match is found, the source file properties of the .xaml.cs file are set:

VS_CSHARP_DependentUpon <xaml-filename>

Helper function which computes a list of key values to identify source files independently of relative/absolute paths given in cmake and eliminates case sensitivity:
csharp_get_filename_keys(OUT [<file1> [<file2> [...]]])
Name of the variable in which the list of keys is stored
<fileN>
filename(s) as given to CSharp target using add_library() or add_executable()

In some way the function applies a canonicalization to the source names. This is necessary to find file matches if the files have been added to the target with different directory prefixes:

add_library(lib
  myfile.cs
  ${CMAKE_CURRENT_SOURCE_DIR}/myfile.Designer.cs)
set_source_files_properties(myfile.Designer.cs PROPERTIES
  VS_CSHARP_DependentUpon myfile.cs)
# this will fail, because in cmake
#  - ${CMAKE_CURRENT_SOURCE_DIR}/myfile.Designer.cs
#  - myfile.Designer.cs
# are not the same source file. The source file property is not set.
Returns the full filepath and name without extension of a key. KEY is expected to be a key from csharp_get_filename_keys. In BASE the value of KEY without the file extension is returned:
csharp_get_filename_key_base(BASE KEY)
Name of the variable with the computed "base" of KEY.
The key of which the base will be computed. Expected to be a upper case full filename.
Computes a string which can be used as value for the source file property VS_CSHARP_<tagname> with target being DependentUpon:
csharp_get_dependentupon_name(NAME FILE)
NAME
Name of the variable with the result value
Filename to convert to <DependentUpon> value

Actually this is only the filename without any path given at the moment.

Configure a project for testing with CTest/CDash

Include this module in the top CMakeLists.txt file of a project to enable testing with CTest and dashboard submissions to CDash:

project(MyProject)
...
include(CTest)

The module automatically creates a BUILD_TESTING option that selects whether to enable testing support (ON by default). After including the module, use code like:

if(BUILD_TESTING)
  # ... CMake code to create tests ...
endif()

to creating tests when testing is enabled.

To enable submissions to a CDash server, create a CTestConfig.cmake file at the top of the project with content such as:

set(CTEST_NIGHTLY_START_TIME "01:00:00 UTC")
set(CTEST_SUBMIT_URL "http://my.cdash.org/submit.php?project=MyProject")

(the CDash server can provide the file to a project administrator who configures MyProject). Settings in the config file are shared by both this CTest module and the ctest(1) command-line Dashboard Client mode (ctest -S).

While building a project for submission to CDash, CTest scans the build output for errors and warnings and reports them with surrounding context from the build log. This generic approach works for all build tools, but does not give details about the command invocation that produced a given problem. One may get more detailed reports by setting the CTEST_USE_LAUNCHERS variable:

set(CTEST_USE_LAUNCHERS 1)

in the CTestConfig.cmake file.

Added in version 3.2.

This module provides the ctest_coverage_collect_gcov function.

This function runs gcov on all .gcda files found in the binary tree and packages the resulting .gcov files into a tar file. This tarball also contains the following:

  • data.json defines the source and build directories for use by CDash.
  • Labels.json indicates any LABELS that have been set on the source files.
  • The uncovered directory holds any uncovered files found by CTEST_EXTRA_COVERAGE_GLOB.

After generating this tar file, it can be sent to CDash for display with the ctest_submit(CDASH_UPLOAD) command.

ctest_coverage_collect_gcov(TARBALL <tarfile>
  [SOURCE <source_dir>][BUILD <build_dir>]
  [GCOV_COMMAND <gcov_command>]
  [GCOV_OPTIONS <options>...]
  )

Run gcov and package a tar file for CDash. The options are:

Specify the location of the .tar file to be created for later upload to CDash. Relative paths will be interpreted with respect to the top-level build directory.
Added in version 3.18.

Specify a compression algorithm for the TARBALL data file. Using this option reduces the size of the data file before it is submitted to CDash. <option> must be one of GZIP, BZIP2, XZ, ZSTD, FROM_EXT, or an expression that CMake evaluates as FALSE. The default value is BZIP2.

If FROM_EXT is specified, the resulting file will be compressed based on the file extension of the <tarfile> (i.e. .tar.gz will use GZIP compression). File extensions that will produce compressed output include .tar.gz, .tgz, .tar.bzip2, .tbz, .tar.xz, and .txz.

Specify the top-level source directory for the build. Default is the value of CTEST_SOURCE_DIRECTORY.
Specify the top-level build directory for the build. Default is the value of CTEST_BINARY_DIRECTORY.
Specify the full path to the gcov command on the machine. Default is the value of CTEST_COVERAGE_COMMAND.
Specify options to be passed to gcov. The gcov command is run as gcov <options>... -o <gcov-dir> <file>.gcda. If not specified, the default option is just -b -x.
Added in version 3.6.

Recursively search for .gcda files in build_dir rather than determining search locations by reading TargetDirectories.txt.

Added in version 3.6.

Delete coverage files after they've been packaged into the .tar.

Suppress non-error messages that otherwise would have been printed out by this function.

Added in version 3.3: Added support for the CTEST_CUSTOM_COVERAGE_EXCLUDE variable.

This file is read by ctest in script mode (-S)

Set the RULE_LAUNCH_* global properties when CTEST_USE_LAUNCHERS is on.

CTestUseLaunchers is automatically included when you include(CTest). However, it is split out into its own module file so projects can use the CTEST_USE_LAUNCHERS functionality independently.

To use launchers, set CTEST_USE_LAUNCHERS to ON in a ctest -S dashboard script, and then also set it in the cache of the configured project. Both cmake and ctest need to know the value of it for the launchers to work properly. CMake needs to know in order to generate proper build rules, and ctest, in order to produce the proper error and warning analysis.

For convenience, you may set the ENV variable CTEST_USE_LAUNCHERS_DEFAULT in your ctest -S script, too. Then, as long as your CMakeLists uses include(CTest) or include(CTestUseLaunchers), it will use the value of the ENV variable to initialize a CTEST_USE_LAUNCHERS cache variable. This cache variable initialization only occurs if CTEST_USE_LAUNCHERS is not already defined.

Added in version 3.8: If CTEST_USE_LAUNCHERS is on in a ctest -S script the ctest_configure command will add -DCTEST_USE_LAUNCHERS:BOOL=TRUE to the cmake command used to configure the project.

Functions to help assemble a standalone Qt4 executable.

A collection of CMake utility functions useful for deploying Qt4 executables.

The following functions are provided by this module:

write_qt4_conf
resolve_qt4_paths
fixup_qt4_executable
install_qt4_plugin_path
install_qt4_plugin
install_qt4_executable

Requires CMake 2.6 or greater because it uses function and PARENT_SCOPE. Also depends on BundleUtilities.cmake.

write_qt4_conf(<qt_conf_dir> <qt_conf_contents>)

Writes a qt.conf file with the <qt_conf_contents> into <qt_conf_dir>.

resolve_qt4_paths(<paths_var> [<executable_path>])

Loop through <paths_var> list and if any don't exist resolve them relative to the <executable_path> (if supplied) or the CMAKE_INSTALL_PREFIX.

fixup_qt4_executable(<executable>
  [<qtplugins> <libs> <dirs> <plugins_dir> <request_qt_conf>])

Copies Qt plugins, writes a Qt configuration file (if needed) and fixes up a Qt4 executable using BundleUtilities so it is standalone and can be drag-and-drop copied to another machine as long as all of the system libraries are compatible.

<executable> should point to the executable to be fixed-up.

<qtplugins> should contain a list of the names or paths of any Qt plugins to be installed.

<libs> will be passed to BundleUtilities and should be a list of any already installed plugins, libraries or executables to also be fixed-up.

<dirs> will be passed to BundleUtilities and should contain and directories to be searched to find library dependencies.

<plugins_dir> allows an custom plugins directory to be used.

<request_qt_conf> will force a qt.conf file to be written even if not needed.

install_qt4_plugin_path(plugin executable copy installed_plugin_path_var
                        <plugins_dir> <component> <configurations>)

Install (or copy) a resolved <plugin> to the default plugins directory (or <plugins_dir>) relative to <executable> and store the result in <installed_plugin_path_var>.

If <copy> is set to TRUE then the plugins will be copied rather than installed. This is to allow this module to be used at CMake time rather than install time.

If <component> is set then anything installed will use this COMPONENT.

install_qt4_plugin(plugin executable copy installed_plugin_path_var
                   <plugins_dir> <component>)

Install (or copy) an unresolved <plugin> to the default plugins directory (or <plugins_dir>) relative to <executable> and store the result in <installed_plugin_path_var>. See documentation of INSTALL_QT4_PLUGIN_PATH.

install_qt4_executable(<executable>
  [<qtplugins> <libs> <dirs> <plugins_dir> <request_qt_conf> <component>])

Installs Qt plugins, writes a Qt configuration file (if needed) and fixes up a Qt4 executable using BundleUtilities so it is standalone and can be drag-and-drop copied to another machine as long as all of the system libraries are compatible. The executable will be fixed-up at install time. <component> is the COMPONENT used for bundle fixup and plugin installation. See documentation of FIXUP_QT4_BUNDLE.

Manage data files stored outside source tree

Use this module to unambiguously reference data files stored outside the source tree and fetch them at build time from arbitrary local and remote content-addressed locations. Functions provided by this module recognize arguments with the syntax DATA{<name>} as references to external data, replace them with full paths to local copies of those data, and create build rules to fetch and update the local copies.

For example:

include(ExternalData)
set(ExternalData_URL_TEMPLATES "file:///local/%(algo)/%(hash)"
                               "file:////host/share/%(algo)/%(hash)"
                               "http://data.org/%(algo)/%(hash)")
ExternalData_Add_Test(MyData
  NAME MyTest
  COMMAND MyExe DATA{MyInput.png}
  )
ExternalData_Add_Target(MyData)

When test MyTest runs the DATA{MyInput.png} argument will be replaced by the full path to a real instance of the data file MyInput.png on disk. If the source tree contains a content link such as MyInput.png.md5 then the MyData target creates a real MyInput.png in the build tree.

Module Functions

The ExternalData_Expand_Arguments function evaluates DATA{} references in its arguments and constructs a new list of arguments:
ExternalData_Expand_Arguments(
  <target>   # Name of data management target
  <outVar>   # Output variable
  [args...]  # Input arguments, DATA{} allowed
  )

It replaces each DATA{} reference in an argument with the full path of a real data file on disk that will exist after the <target> builds.

The ExternalData_Add_Test function wraps around the CMake add_test() command but supports DATA{} references in its arguments:
ExternalData_Add_Test(
  <target>   # Name of data management target
  ...        # Arguments of add_test(), DATA{} allowed
  )

It passes its arguments through ExternalData_Expand_Arguments and then invokes the add_test() command using the results.

The ExternalData_Add_Target function creates a custom target to manage local instances of data files stored externally:
ExternalData_Add_Target(
  <target>                  # Name of data management target
  [SHOW_PROGRESS <ON|OFF>]  # Show progress during the download
  )

It creates custom commands in the target as necessary to make data files available for each DATA{} reference previously evaluated by other functions provided by this module. Data files may be fetched from one of the URL templates specified in the ExternalData_URL_TEMPLATES variable, or may be found locally in one of the paths specified in the ExternalData_OBJECT_STORES variable.

Added in version 3.20: The SHOW_PROGRESS argument may be passed to suppress progress information during the download of objects. If not provided, it defaults to OFF for Ninja and Ninja Multi-Config generators and ON otherwise.

Typically only one target is needed to manage all external data within a project. Call this function once at the end of configuration after all data references have been processed.

Module Variables

The following variables configure behavior. They should be set before calling any of the functions provided by this module.

The ExternalData_BINARY_ROOT variable may be set to the directory to hold the real data files named by expanded DATA{} references. The default is CMAKE_BINARY_DIR. The directory layout will mirror that of content links under ExternalData_SOURCE_ROOT.
Added in version 3.2.

Specify a full path to a .cmake custom fetch script identified by <key> in entries of the ExternalData_URL_TEMPLATES list. See Custom Fetch Scripts.

The ExternalData_LINK_CONTENT variable may be set to the name of a supported hash algorithm to enable automatic conversion of real data files referenced by the DATA{} syntax into content links. For each such <file> a content link named <file><ext> is created. The original file is renamed to the form .ExternalData_<algo>_<hash> to stage it for future transmission to one of the locations in the list of URL templates (by means outside the scope of this module). The data fetch rule created for the content link will use the staged object if it cannot be found using any URL template.
Added in version 3.3.

The real data files named by expanded DATA{} references may be made available under ExternalData_BINARY_ROOT using symbolic links on some platforms. The ExternalData_NO_SYMLINKS variable may be set to disable use of symbolic links and enable use of copies instead.

The ExternalData_OBJECT_STORES variable may be set to a list of local directories that store objects using the layout <dir>/%(algo)/%(hash). These directories will be searched first for a needed object. If the object is not available in any store then it will be fetched remotely using the URL templates and added to the first local store listed. If no stores are specified the default is a location inside the build tree.
The ExternalData_SOURCE_ROOT variable may be set to the highest source directory containing any path named by a DATA{} reference. The default is CMAKE_SOURCE_DIR. ExternalData_SOURCE_ROOT and CMAKE_SOURCE_DIR must refer to directories within a single source distribution (e.g. they come together in one tarball).
The ExternalData_TIMEOUT_ABSOLUTE variable sets the download absolute timeout, in seconds, with a default of 300 seconds. Set to 0 to disable enforcement.
The ExternalData_TIMEOUT_INACTIVITY variable sets the download inactivity timeout, in seconds, with a default of 60 seconds. Set to 0 to disable enforcement.
Added in version 3.3.

Specify a custom URL component to be substituted for URL template placeholders of the form %(algo:<key>), where <key> is a valid C identifier, when fetching an object referenced via hash algorithm <algo>. If not defined, the default URL component is just <algo> for any <key>.

The ExternalData_URL_TEMPLATES may be set to provide a list of URL templates using the placeholders %(algo) and %(hash) in each template. Data fetch rules try each URL template in order by substituting the hash algorithm name for %(algo) and the hash value for %(hash). Alternatively one may use %(algo:<key>) with ExternalData_URL_ALGO_<algo>_<key> variables to gain more flexibility in remote URLs.

The DATA{} syntax is literal and the <name> is a full or relative path within the source tree. The source tree must contain either a real data file at <name> or a "content link" at <name><ext> containing a hash of the real file using a hash algorithm corresponding to <ext>. For example, the argument DATA{img.png} may be satisfied by either a real img.png file in the current source directory or a img.png.md5 file containing its MD5 sum.

Added in version 3.8: Multiple content links of the same name with different hash algorithms are supported (e.g. img.png.sha256 and img.png.sha1) so long as they all correspond to the same real file. This allows objects to be fetched from sources indexed by different hash algorithms.

The DATA{} syntax can be told to fetch a file series using the form DATA{<name>,:}, where the : is literal. If the source tree contains a group of files or content links named like a series then a reference to one member adds rules to fetch all of them. Although all members of a series are fetched, only the file originally named by the DATA{} argument is substituted for it. The default configuration recognizes file series names ending with #.ext, _#.ext, .#.ext, or -#.ext where # is a sequence of decimal digits and .ext is any single extension. Configure it with a regex that parses <number> and <suffix> parts from the end of <name>:

ExternalData_SERIES_PARSE = regex of the form (<number>)(<suffix>)$

For more complicated cases set:

ExternalData_SERIES_PARSE = regex with at least two () groups
ExternalData_SERIES_PARSE_PREFIX = <prefix> regex group number, if any
ExternalData_SERIES_PARSE_NUMBER = <number> regex group number
ExternalData_SERIES_PARSE_SUFFIX = <suffix> regex group number

Configure series number matching with a regex that matches the <number> part of series members named <prefix><number><suffix>:

ExternalData_SERIES_MATCH = regex matching <number> in all series members

Note that the <suffix> of a series does not include a hash-algorithm extension.

The DATA{} syntax can alternatively match files associated with the named file and contained in the same directory. Associated files may be specified by options using the syntax DATA{<name>,<opt1>,<opt2>,...}. Each option may specify one file by name or specify a regular expression to match file names using the syntax REGEX:<regex>. For example, the arguments:

DATA{MyData/MyInput.mhd,MyInput.img}                   # File pair
DATA{MyData/MyFrames00.png,REGEX:MyFrames[0-9]+\\.png} # Series

will pass MyInput.mha and MyFrames00.png on the command line but ensure that the associated files are present next to them.

The DATA{} syntax may reference a directory using a trailing slash and a list of associated files. The form DATA{<name>/,<opt1>,<opt2>,...} adds rules to fetch any files in the directory that match one of the associated file options. For example, the argument DATA{MyDataDir/,REGEX:.*} will pass the full path to a MyDataDir directory on the command line and ensure that the directory contains files corresponding to every file or content link in the MyDataDir source directory.

Added in version 3.3: In order to match associated files in subdirectories, specify a RECURSE: option, e.g. DATA{MyDataDir/,RECURSE:,REGEX:.*}.

The following hash algorithms are supported:

%(algo)     <ext>     Description
-------     -----     -----------
MD5         .md5      Message-Digest Algorithm 5, RFC 1321
SHA1        .sha1     US Secure Hash Algorithm 1, RFC 3174
SHA224      .sha224   US Secure Hash Algorithms, RFC 4634
SHA256      .sha256   US Secure Hash Algorithms, RFC 4634
SHA384      .sha384   US Secure Hash Algorithms, RFC 4634
SHA512      .sha512   US Secure Hash Algorithms, RFC 4634
SHA3_224    .sha3-224 Keccak SHA-3
SHA3_256    .sha3-256 Keccak SHA-3
SHA3_384    .sha3-384 Keccak SHA-3
SHA3_512    .sha3-512 Keccak SHA-3

Added in version 3.8: Added the SHA3_* hash algorithms.

Note that the hashes are used only for unique data identification and download verification.

Added in version 3.2.

When a data file must be fetched from one of the URL templates specified in the ExternalData_URL_TEMPLATES variable, it is normally downloaded using the file(DOWNLOAD) command. One may specify usage of a custom fetch script by using a URL template of the form ExternalDataCustomScript://<key>/<loc>. The <key> must be a C identifier, and the <loc> must contain the %(algo) and %(hash) placeholders. A variable corresponding to the key, ExternalData_CUSTOM_SCRIPT_<key>, must be set to the full path to a .cmake script file. The script will be included to perform the actual fetch, and provided with the following variables:

When a custom fetch script is loaded, this variable is set to the location part of the URL, which will contain the substituted hash algorithm name and content hash value.
When a custom fetch script is loaded, this variable is set to the full path to a file in which the script must store the fetched content. The name of the file is unspecified and should not be interpreted in any way.

The custom fetch script is expected to store fetched content in the file or set a variable:

When a custom fetch script fails to fetch the requested content, it must set this variable to a short one-line message describing the reason for failure.

The ExternalProject_Add() function creates a custom target to drive download, update/patch, configure, build, install and test steps of an external project:
ExternalProject_Add(<name> [<option>...])

The individual steps within the process can be driven independently if required (e.g. for CDash submission) and extra custom steps can be defined, along with the ability to control the step dependencies. The directory structure used for the management of the external project can also be customized. The function supports a large number of options which can be used to tailor the external project behavior.

Most of the time, the default directory layout is sufficient. It is largely an implementation detail that the main project usually doesn't need to change. In some circumstances, however, control over the directory layout can be useful or necessary. The directory options are potentially more useful from the point of view that the main build can use the ExternalProject_Get_Property() command to retrieve their values, thereby allowing the main project to refer to build artifacts of the external project.

Root directory for the external project. Unless otherwise noted below, all other directories associated with the external project will be created under here.
Directory in which to store temporary files.
Directory in which to store the timestamps of each step. Log files from individual steps are also created in here unless overridden by LOG_DIR (see Logging Options below).
Added in version 3.14.

Directory in which to store the logs of each step.

Directory in which to store downloaded files before unpacking them. This directory is only used by the URL download method, all other download methods use SOURCE_DIR directly instead.
Source directory into which downloaded contents will be unpacked, or for non-URL download methods, the directory in which the repository should be checked out, cloned, etc. If no download method is specified, this must point to an existing directory where the external project has already been unpacked or cloned/checked out.

NOTE:

If a download method is specified, any existing contents of the source directory may be deleted. Only the URL download method checks whether this directory is either missing or empty before initiating the download, stopping with an error if it is not empty. All other download methods silently discard any previous contents of the source directory.
Specify the build directory location. This option is ignored if BUILD_IN_SOURCE is enabled.
Installation prefix to be placed in the <INSTALL_DIR> placeholder. This does not actually configure the external project to install to the given prefix. That must be done by passing appropriate arguments to the external project configuration step, e.g. using <INSTALL_DIR>.

If any of the above ..._DIR options are not specified, their defaults are computed as follows. If the PREFIX option is given or the EP_PREFIX directory property is set, then an external project is built and installed under the specified prefix:

TMP_DIR      = <prefix>/tmp
STAMP_DIR    = <prefix>/src/<name>-stamp
DOWNLOAD_DIR = <prefix>/src
SOURCE_DIR   = <prefix>/src/<name>
BINARY_DIR   = <prefix>/src/<name>-build
INSTALL_DIR  = <prefix>
LOG_DIR      = <STAMP_DIR>

Otherwise, if the EP_BASE directory property is set then components of an external project are stored under the specified base:

TMP_DIR      = <base>/tmp/<name>
STAMP_DIR    = <base>/Stamp/<name>
DOWNLOAD_DIR = <base>/Download/<name>
SOURCE_DIR   = <base>/Source/<name>
BINARY_DIR   = <base>/Build/<name>
INSTALL_DIR  = <base>/Install/<name>
LOG_DIR      = <STAMP_DIR>

If no PREFIX, EP_PREFIX, or EP_BASE is specified, then the default is to set PREFIX to <name>-prefix. Relative paths are interpreted with respect to CMAKE_CURRENT_BINARY_DIR at the point where ExternalProject_Add() is called.

A download method can be omitted if the SOURCE_DIR option is used to point to an existing non-empty directory. Otherwise, one of the download methods below must be specified (multiple download methods should not be given) or a custom DOWNLOAD_COMMAND provided.

Overrides the command used for the download step (generator expressions are supported). If this option is specified, all other download options will be ignored. Providing an empty string for <cmd> effectively disables the download step.

URL <url1> [<url2>...]
List of paths and/or URL(s) of the external project's source. When more than one URL is given, they are tried in turn until one succeeds. A URL may be an ordinary path in the local file system (in which case it must be the only URL provided) or any downloadable URL supported by the file(DOWNLOAD) command. A local filesystem path may refer to either an existing directory or to an archive file, whereas a URL is expected to point to a file which can be treated as an archive. When an archive is used, it will be unpacked automatically unless the DOWNLOAD_NO_EXTRACT option is set to prevent it. The archive type is determined by inspecting the actual content rather than using logic based on the file extension.

Changed in version 3.7: Multiple URLs are allowed.

Hash of the archive file to be downloaded. The argument should be of the form <algo>=<hashValue> where algo can be any of the hashing algorithms supported by the file() command. Specifying this option is strongly recommended for URL downloads, as it ensures the integrity of the downloaded content. It is also used as a check for a previously downloaded file, allowing connection to the remote location to be avoided altogether if the local directory already has a file from an earlier download that matches the specified hash.
Equivalent to URL_HASH MD5=<md5>.
File name to use for the downloaded file. If not given, the end of the URL is used to determine the file name. This option is rarely needed, the default name is generally suitable and is not normally used outside of code internal to the ExternalProject module.
Added in version 3.24.

When specified with a true value, the timestamps of the extracted files will match those in the archive. When false, the timestamps of the extracted files will reflect the time at which the extraction was performed. If the download URL changes, timestamps based off those in the archive can result in dependent targets not being rebuilt when they potentially should have been. Therefore, unless the file timestamps are significant to the project in some way, use a false value for this option. If DOWNLOAD_EXTRACT_TIMESTAMP is not given, the default is false. See policy CMP0135.

Added in version 3.6.

Allows the extraction part of the download step to be disabled by passing a boolean true value for this option. If this option is not given, the downloaded contents will be unpacked automatically if required. If extraction has been disabled, the full path to the downloaded file is available as <DOWNLOADED_FILE> in subsequent steps or as the property DOWNLOADED_FILE with the ExternalProject_Get_Property() command.

Can be used to disable logging the download progress. If this option is not given, download progress messages will be logged.
Maximum time allowed for file download operations.
Added in version 3.19.

Terminate the operation after a period of inactivity.

Added in version 3.7.

Username for the download operation if authentication is required.

Added in version 3.7.

Password for the download operation if authentication is required.

Added in version 3.7.

Provides an arbitrary list of HTTP headers for the download operation. This can be useful for accessing content in systems like AWS, etc.

Added in version 3.30.

Specify minimum TLS version for https:// URLs. If this option is not provided, the value of the CMAKE_TLS_VERSION variable or the CMAKE_TLS_VERSION environment variable will be used instead (see file(DOWNLOAD)).

This option also applies to git clone invocations, although the default behavior is different. If none of the TLS_VERSION option, CMAKE_TLS_VERSION variable, or CMAKE_TLS_VERSION environment variable is specified, the behavior will be determined by git's default or a http.sslVersion git config option the user may have set at a global level.

Specifies whether certificate verification should be performed for https:// URLs. If this option is not provided, the value of the CMAKE_TLS_VERIFY variable or the CMAKE_TLS_VERIFY environment variable will be used instead (see file(DOWNLOAD)). If neither of those is set, certificate verification will not be performed. In situations where URL_HASH cannot be provided, this option can be an alternative verification measure.

This option also applies to git clone invocations, although the default behavior is different. If none of the TLS_VERIFY option, CMAKE_TLS_VERIFY variable, or CMAKE_TLS_VERIFY environment variable is specified, the behavior will be determined by git's default (true) or a http.sslVerify git config option the user may have set at a global level.

Changed in version 3.6: Previously this option did not apply to git clone invocations.

Changed in version 3.30: Previously the CMAKE_TLS_VERIFY environment variable was not checked.

Specify a custom certificate authority file to use if TLS_VERIFY is enabled. If this option is not specified, the value of the CMAKE_TLS_CAINFO variable will be used instead (see file(DOWNLOAD))
Added in version 3.11.

Specify whether the .netrc file is to be used for operation. If this option is not specified, the value of the CMAKE_NETRC variable will be used instead (see file(DOWNLOAD)). Valid levels are:

The .netrc file is ignored. This is the default.
The .netrc file is optional, and information in the URL is preferred. The file will be scanned to find which ever information is not specified in the URL.
The .netrc file is required, and information in the URL is ignored.
Added in version 3.11.

Specify an alternative .netrc file to the one in your home directory if the NETRC level is OPTIONAL or REQUIRED. If this option is not specified, the value of the CMAKE_NETRC_FILE variable will be used instead (see file(DOWNLOAD))

Added in version 3.1: Added support for tbz2, .tar.xz, .txz, and .7z extensions.

NOTE: A git version of 1.6.5 or later is required if this download method is used.

URL of the git repository. Any URL understood by the git command may be used.

Changed in version 3.27: A relative URL will be resolved based on the parent project's remote, subject to CMP0150. See the policy documentation for how the remote is selected, including conditions where the remote selection can fail. Local filesystem remotes should always use absolute paths.

Git branch name, tag or commit hash. Note that branch names and tags should generally be specified as remote names (i.e. origin/myBranch rather than simply myBranch). This ensures that if the remote end has its tag moved or branch rebased or history rewritten, the local clone will still be updated correctly. In general, however, specifying a commit hash should be preferred for a number of reasons:
  • If the local clone already has the commit corresponding to the hash, no git fetch needs to be performed to check for changes each time CMake is re-run. This can result in a significant speed up if many external projects are being used.
  • Using a specific git hash ensures that the main project's own history is fully traceable to a specific point in the external project's evolution. If a branch or tag name is used instead, then checking out a specific commit of the main project doesn't necessarily pin the whole build to a specific point in the life of the external project. The lack of such deterministic behavior makes the main project lose traceability and repeatability.

If GIT_SHALLOW is enabled then GIT_TAG works only with branch names and tags. A commit hash is not allowed.

Note that if not provided, GIT_TAG defaults to master, not the default Git branch name.

The optional name of the remote. If this option is not specified, it defaults to origin.
Specific git submodules that should also be updated. If this option is not provided, all git submodules will be updated.

Changed in version 3.16: When CMP0097 is set to NEW, if this value is set to an empty string then no submodules are initialized or updated.

Added in version 3.17.

Specify whether git submodules (if any) should update recursively by passing the --recursive flag to git submodule update. If not specified, the default is on.

Added in version 3.6.

When this option is enabled, the git clone operation will be given the --depth 1 option. This performs a shallow clone, which avoids downloading the whole history and instead retrieves just the commit denoted by the GIT_TAG option.

Added in version 3.8.

When enabled, this option instructs the git clone operation to report its progress by passing it the --progress option. Without this option, the clone step for large projects may appear to make the build stall, since nothing will be logged until the clone operation finishes. While this option can be used to provide progress to prevent the appearance of the build having stalled, it may also make the build overly noisy if lots of external projects are used.

Added in version 3.8.

Specify a list of config options to pass to git clone. Each option listed will be transformed into its own --config <option> on the git clone command line, with each option required to be in the form key=value.

Added in version 3.18.

When GIT_TAG refers to a remote branch, this option can be used to specify how the update step behaves. The <strategy> must be one of the following:

Ignore the local branch and always checkout the branch specified by GIT_TAG.
Try to rebase the current branch to the one specified by GIT_TAG. If there are local uncommitted changes, they will be stashed first and popped again after rebasing. If rebasing or popping stashed changes fail, abort the rebase and halt with an error. When GIT_REMOTE_UPDATE_STRATEGY is not present, this is the default strategy unless the default has been overridden with CMAKE_EP_GIT_REMOTE_UPDATE_STRATEGY (see below). Note that if the branch specified in GIT_TAG is different to the upstream branch currently being tracked, it is not safe to perform a rebase. In that situation, REBASE will silently be treated as CHECKOUT instead.
Same as REBASE except if the rebase fails, an annotated tag will be created at the original HEAD position from before the rebase and then checkout GIT_TAG just like the CHECKOUT strategy. The message stored on the annotated tag will give information about what was attempted and the tag name will include a timestamp so that each failed run will add a new tag. This strategy ensures no changes will be lost, but updates should always succeed if GIT_TAG refers to a valid ref unless there are uncommitted changes that cannot be popped successfully.

The variable CMAKE_EP_GIT_REMOTE_UPDATE_STRATEGY can be set to override the default strategy. This variable should not be set by a project, it is intended for the user to set. It is primarily intended for use in continuous integration scripts to ensure that when history is rewritten on a remote branch, the build doesn't end up with unintended changes or failed builds resulting from conflicts during rebase operations.

URL of the Subversion repository.
Revision to checkout from the Subversion repository.
Username for the Subversion checkout and update.
Password for the Subversion checkout and update.
Specifies whether to trust the Subversion server site certificate. If enabled, the --trust-server-cert option is passed to the svn checkout and update commands.

URL of the mercurial repository.
Mercurial branch name, tag or commit id.

CVSROOT of the CVS repository.
Module to checkout from the CVS repository.
Tag to checkout from the CVS repository.

Whenever CMake is re-run, by default the external project's sources will be updated if the download method supports updates (e.g. a git repository would be checked if the GIT_TAG does not refer to a specific commit).

Overrides the download method's update step with a custom command. The command may use generator expressions.
Added in version 3.2.

When enabled, this option causes the update step to be skipped (but see below for changed behavior where this is not the case). It does not prevent the download step. The update step can still be added as a step target (see ExternalProject_Add_StepTargets()) and called manually. This is useful if you want to allow developers to build the project when disconnected from the network (the network may still be needed for the download step though).

Changed in version 3.27: When UPDATE_DISCONNECTED is true, the update step will be executed if any details about the update or download step are changed. Furthermore, if using the git download/update method, the update logic will be modified to skip attempts to contact the remote. If the GIT_TAG mentions a ref that is not known locally, the update step will halt with a fatal error.

When this option is present, it is generally advisable to make the value a cache variable under the developer's control rather than hard-coding it. If this option is not present, the default value is taken from the EP_UPDATE_DISCONNECTED directory property. If that is also not defined, updates are performed as normal. The EP_UPDATE_DISCONNECTED directory property is intended as a convenience for controlling the UPDATE_DISCONNECTED behavior for an entire section of a project's directory hierarchy and may be a more convenient method of giving developers control over whether or not to perform updates (assuming the project also provides a cache variable or some other convenient method for setting the directory property).

This may cause a step target to be created automatically for the download step. See policy CMP0114.

Specifies a custom command to patch the sources after an update. By default, no patch command is defined. Note that it can be quite difficult to define an appropriate patch command that performs robustly, especially for download methods such as git where changing the GIT_TAG will not discard changes from a previous patch, but the patch command will be called again after updating to the new tag.

The configure step is run after the download and update steps. By default, the external project is assumed to be a CMake project, but this can be overridden if required.

The default configure command runs CMake with a few options based on the main project. The options added are typically only those needed to use the same generator as the main project, but the CMAKE_GENERATOR option can be given to override this. The project is responsible for adding any toolchain details, flags or other settings it wants to reuse from the main project or otherwise specify (see CMAKE_ARGS, CMAKE_CACHE_ARGS and CMAKE_CACHE_DEFAULT_ARGS below).

For non-CMake external projects, the CONFIGURE_COMMAND option must be used to override the default configure command (generator expressions are supported). For projects that require no configure step, specify this option with an empty string as the command to execute.

Specify an alternative cmake executable for the configure step (use an absolute path). This is generally not recommended, since it is usually desirable to use the same CMake version throughout the whole build. This option is ignored if a custom configure command has been specified with CONFIGURE_COMMAND.
Override the CMake generator used for the configure step. Without this option, the same generator as the main build will be used. This option is ignored if a custom configure command has been specified with the CONFIGURE_COMMAND option.
Added in version 3.1.

Pass a generator-specific platform name to the CMake command (see CMAKE_GENERATOR_PLATFORM). It is an error to provide this option without the CMAKE_GENERATOR option.

Pass a generator-specific toolset name to the CMake command (see CMAKE_GENERATOR_TOOLSET). It is an error to provide this option without the CMAKE_GENERATOR option.
Added in version 3.11.

Pass a generator-specific instance selection to the CMake command (see CMAKE_GENERATOR_INSTANCE). It is an error to provide this option without the CMAKE_GENERATOR option.

The specified arguments are passed to the cmake command line. They can be any argument the cmake command understands, not just cache values defined by -D... arguments (see also CMake Options).

Added in version 3.3: Arguments may use generator expressions.

This is an alternate way of specifying cache variables where command line length issues may become a problem. The arguments are expected to be in the form -Dvar:STRING=value, which are then transformed into CMake set() commands with the FORCE option used. These set() commands are written to a pre-load script which is then applied using the cmake -C command line option.

Added in version 3.3: Arguments may use generator expressions.

Added in version 3.2.

This is the same as the CMAKE_CACHE_ARGS option except the set() commands do not include the FORCE keyword. This means the values act as initial defaults only and will not override any variables already set from a previous run. Use this option with care, as it can lead to different behavior depending on whether the build starts from a fresh build directory or reuses previous build contents.

Added in version 3.15: If the CMake generator is the Green Hills MULTI and not overridden, the original project's settings for the GHS toolset and target system customization cache variables are propagated into the external project.

Added in version 3.7.

When no CONFIGURE_COMMAND option is specified, the configure step assumes the external project has a CMakeLists.txt file at the top of its source tree (i.e. in SOURCE_DIR). The SOURCE_SUBDIR option can be used to point to an alternative directory within the source tree to use as the top of the CMake source tree instead. This must be a relative path and it will be interpreted as being relative to SOURCE_DIR.

Added in version 3.14: When BUILD_IN_SOURCE option is enabled, the BUILD_COMMAND is used to point to an alternative directory within the source tree.

Added in version 3.20.

Enabling this option relaxes the dependencies of the configure step on other external projects to order-only. This means the configure step will be executed after its external project dependencies are built but it will not be marked dirty when one of its external project dependencies is rebuilt. This option can be enabled when the build step is smart enough to figure out if the configure step needs to be rerun. CMake and Meson are examples of build systems whose build step is smart enough to know if the configure step needs to be rerun.

If the configure step assumed the external project uses CMake as its build system, the build step will also. Otherwise, the build step will assume a Makefile-based build and simply run make with no arguments as the default build step. This can be overridden with custom build commands if required.

If both the main project and the external project use make as their build tool, the build step of the external project is invoked as a recursive make using $(MAKE). This will communicate some build tool settings from the main project to the external project. If either the main project or external project is not using make, no build tool settings will be passed to the external project other than those established by the configure step (i.e. running ninja -v in the main project will not pass -v to the external project's build step, even if it also uses ninja as its build tool).

Overrides the default build command (generator expressions are supported). If this option is not given, the default build command will be chosen to integrate with the main build in the most appropriate way (e.g. using recursive make for Makefile generators or cmake --build if the project uses a CMake build). This option can be specified with an empty string as the command to make the build step do nothing.
When this option is enabled, the build will be done directly within the external project's source tree. This should generally be avoided, the use of a separate build directory is usually preferred, but it can be useful when the external project assumes an in-source build. The BINARY_DIR option should not be specified if building in-source.
Enabling this option forces the build step to always be run. This can be the easiest way to robustly ensure that the external project's own build dependencies are evaluated rather than relying on the default success timestamp-based method. This option is not normally needed unless developers are expected to modify something the external project's build depends on in a way that is not detectable via the step target dependencies (e.g. SOURCE_DIR is used without a download method and developers might modify the sources in SOURCE_DIR).
Added in version 3.2.

Specifies files that will be generated by the build command but which might or might not have their modification time updated by subsequent builds. This may also be required to explicitly declare dependencies when using the Ninja generator. These ultimately get passed through as BYPRODUCTS to the build step's own underlying call to add_custom_command(), which has additional documentation.

Added in version 3.28.

Specifies that the build step is aware of the GNU Make job server. See the add_custom_command() documentation of its JOB_SERVER_AWARE option for details. This option is relevant only when an explicit BUILD_COMMAND is specified.

If the configure step assumed the external project uses CMake as its build system, the install step will also. Otherwise, the install step will assume a Makefile-based build and simply run make install as the default build step. This can be overridden with custom install commands if required.

The external project's own install step is invoked as part of the main project's build. It is done after the external project's build step and may be before or after the external project's test step (see the TEST_BEFORE_INSTALL option below). The external project's install rules are not part of the main project's install rules, so if anything from the external project should be installed as part of the main build, these need to be specified in the main build as additional install() commands. The default install step builds the install target of the external project, but this can be overridden with a custom command using this option (generator expressions are supported). Passing an empty string as the <cmd> makes the install step do nothing.
Added in version 3.26.

Specifies files that will be generated by the install command but which might or might not have their modification time updated by subsequent installs. This may also be required to explicitly declare dependencies when using the Ninja generator. These ultimately get passed through as BYPRODUCTS to the install step's own underlying call to add_custom_command(), which has additional documentation.

NOTE:

If the CMAKE_INSTALL_MODE environment variable is set when the main project is built, it will only have an effect if the following conditions are met:
  • The main project's configure step assumed the external project uses CMake as its build system.
  • The external project's install command actually runs. Note that due to the way ExternalProject may use timestamps internally, if nothing the install step depends on needs to be re-executed, the install command might also not need to run.

Note also that ExternalProject does not check whether the CMAKE_INSTALL_MODE environment variable changes from one run to another.

The test step is only defined if at least one of the following TEST_... options are provided.

Overrides the default test command (generator expressions are supported). If this option is not given, the default behavior of the test step is to build the external project's own test target. This option can be specified with <cmd> as an empty string, which allows the test step to still be defined, but it will do nothing. Do not specify any of the other TEST_... options if providing an empty string as the test command, but prefer to omit all TEST_... options altogether if the test step target is not needed.
When this option is enabled, the test step will be executed before the install step. The default behavior is for the test step to run after the install step.
This option is mainly useful as a way to indicate that the test step is desired but all default behavior is sufficient. Specifying this option with a boolean true value ensures the test step is defined and that it comes after the install step. If both TEST_BEFORE_INSTALL and TEST_AFTER_INSTALL are enabled, the latter is silently ignored.
Added in version 3.2.

If enabled, the main build's default ALL target will not depend on the test step. This can be a useful way of ensuring the test step is defined but only gets invoked when manually requested. This may cause a step target to be created automatically for either the install or build step. See policy CMP0114.

Each of the following LOG_... options can be used to wrap the relevant step in a script to capture its output to files. The log files will be created in LOG_DIR if supplied or otherwise the STAMP_DIR directory with step-specific file names.

When enabled, the output of the download step is logged to files.
When enabled, the output of the update step is logged to files.
Added in version 3.14.

When enabled, the output of the patch step is logged to files.

When enabled, the output of the configure step is logged to files.
When enabled, the output of the build step is logged to files.
When enabled, the output of the install step is logged to files.
When enabled, the output of the test step is logged to files.
Added in version 3.14.

When enabled, stdout and stderr will be merged for any step whose output is being logged to files.

Added in version 3.14.

This option only has an effect if at least one of the other LOG_<step> options is enabled. If an error occurs for a step which has logging to file enabled, that step's output will be printed to the console if LOG_OUTPUT_ON_FAILURE is set to true. For cases where a large amount of output is recorded, just the end of that output may be printed to the console.

Added in version 3.4.

Steps can be given direct access to the terminal in some cases. Giving a step access to the terminal may allow it to receive terminal input if required, such as for authentication details not provided by other options. With the Ninja generator, these options place the steps in the console job pool. Each step can be given access to the terminal individually via the following options:

Give the download step access to the terminal.
Give the update step access to the terminal.
Added in version 3.23.

Give the patch step access to the terminal.

Give the configure step access to the terminal.
Give the build step access to the terminal.
Give the install step access to the terminal.
Give the test step access to the terminal.

Specify other targets on which the external project depends. The other targets will be brought up to date before any of the external project's steps are executed. Because the external project uses additional custom targets internally for each step, the DEPENDS option is the most convenient way to ensure all of those steps depend on the other targets. Simply doing add_dependencies(<name> <targets>) will not make any of the steps dependent on <targets>.
When enabled, this option excludes the external project from the default ALL target of the main build.
Generate custom targets for the specified steps. This is required if the steps need to be triggered manually or if they need to be used as dependencies of other targets. If this option is not specified, the default value is taken from the EP_STEP_TARGETS directory property. See ExternalProject_Add_StepTargets() below for further discussion of the effects of this option.
Deprecated since version 3.19: This is allowed only if policy CMP0114 is not set to NEW.

Generates custom targets for the specified steps and prevent these targets from having the usual dependencies applied to them. If this option is not specified, the default value is taken from the EP_INDEPENDENT_STEP_TARGETS directory property. This option is mostly useful for allowing individual steps to be driven independently, such as for a CDash setup where each step should be initiated and reported individually rather than as one whole build. See ExternalProject_Add_StepTargets() below for further discussion of the effects of this option.

For any of the various ..._COMMAND options, and CMAKE_ARGS, ExternalProject will replace <sep> with ; in the specified command lines. This can be used to ensure a command has a literal ; in it where direct usage would otherwise be interpreted as argument separators to CMake APIs instead. Note that the separator should be chosen to avoid being confused for non-list-separator usages of the sequence. For example, using LIST_SEPARATOR allows for passing list values to CMake cache variables on the command line:
ExternalProject_Add(example
  ... # Download options, etc.
  LIST_SEPARATOR ","
  CMAKE_ARGS "-DCMAKE_PREFIX_PATH:STRING=${first_prefix},${second_prefix}"
)
Any of the other ..._COMMAND options can have additional commands appended to them by following them with as many COMMAND ... options as needed (generator expressions are supported). For example:
ExternalProject_Add(example
  ... # Download options, etc.
  BUILD_COMMAND ${CMAKE_COMMAND} -E echo "Starting $<CONFIG> build"
  COMMAND       ${CMAKE_COMMAND} --build <BINARY_DIR> --config $<CONFIG>
  COMMAND       ${CMAKE_COMMAND} -E echo "$<CONFIG> build complete"
)

It should also be noted that each build step is created via a call to ExternalProject_Add_Step(). See that command's documentation for the automatic substitutions that are supported for some options.

The ExternalProject_Get_Property() function retrieves external project target properties:
ExternalProject_Get_Property(<name> <prop1> [<prop2>...])

The function stores property values in variables of the same name. Property names correspond to the keyword argument names of ExternalProject_Add(). For example, the source directory might be retrieved like so:

ExternalProject_Get_property(myExtProj SOURCE_DIR)
message("Source dir of myExtProj = ${SOURCE_DIR}")

The ExternalProject_Add() function on its own is often sufficient for incorporating an external project into the main build. Certain scenarios require additional work to implement desired behavior, such as adding in a custom step or making steps available as manually triggerable targets. The ExternalProject_Add_Step(), ExternalProject_Add_StepTargets() and ExternalProject_Add_StepDependencies functions provide the lower level control needed to implement such step-level capabilities.

The ExternalProject_Add_Step() function specifies an additional custom step for an external project defined by an earlier call to ExternalProject_Add():
ExternalProject_Add_Step(<name> <step> [<option>...])

<name> is the same as the name passed to the original call to ExternalProject_Add(). The specified <step> must not be one of the pre-defined steps (mkdir, download, update, patch, configure, build, install or test). The supported options are:

The command line to be executed by this custom step (generator expressions are supported). This option can be repeated multiple times to specify multiple commands to be executed in order.
Text to be printed when the custom step executes.
Other steps (custom or pre-defined) on which this step depends.
Other steps (custom or pre-defined) that depend on this new custom step.
Files on which this custom step depends.
Added in version 3.19.

Specifies whether this step is independent of the external dependencies specified by the ExternalProject_Add()'s DEPENDS option. The default is FALSE. Steps marked as independent may depend only on other steps marked independent. See policy CMP0114.

Note that this use of the term "independent" refers only to independence from external targets specified by the DEPENDS option and is orthogonal to a step's dependencies on other steps.

If a step target is created for an independent step by the ExternalProject_Add() STEP_TARGETS option or by the ExternalProject_Add_StepTargets() function, it will not depend on the external targets, but may depend on targets for other steps.

Added in version 3.2.

Files that will be generated by this custom step but which might or might not have their modification time updated by subsequent builds. This may also be required to explicitly declare dependencies when using the Ninja generator. This list of files will ultimately be passed through as the BYPRODUCTS option to the add_custom_command() used to implement the custom step internally, which has additional documentation.

When enabled, this option specifies that the custom step should always be run (i.e. that it is always considered out of date).
Added in version 3.28.

Specifies that the custom step is aware of the GNU Make job server. See the add_custom_command() documentation of its JOB_SERVER_AWARE option for details.

When enabled, this option specifies that the external project's main target does not depend on the custom step. This may cause step targets to be created automatically for the steps on which this step depends. See policy CMP0114.
Specifies the working directory to set before running the custom step's command. If this option is not specified, the directory will be the value of the CMAKE_CURRENT_BINARY_DIR at the point where ExternalProject_Add_Step() was called.
If set, this causes the output from the custom step to be captured to files in the external project's LOG_DIR if supplied or STAMP_DIR.
If enabled, this gives the custom step direct access to the terminal if possible.

The command line, comment, working directory and byproducts of every standard and custom step are processed to replace the tokens <SOURCE_DIR>, <SOURCE_SUBDIR>, <BINARY_DIR>, <INSTALL_DIR> <TMP_DIR>, <DOWNLOAD_DIR> and <DOWNLOADED_FILE> with their corresponding property values defined in the original call to ExternalProject_Add().

Added in version 3.3: Token replacement is extended to byproducts.

Added in version 3.11: The <DOWNLOAD_DIR> substitution token.

The ExternalProject_Add_StepTargets() function generates targets for the steps listed. The name of each created target will be of the form <name>-<step>:
ExternalProject_Add_StepTargets(<name> <step1> [<step2>...])

Creating a target for a step allows it to be used as a dependency of another target or to be triggered manually. Having targets for specific steps also allows them to be driven independently of each other by specifying targets on build command lines. For example, you may be submitting to a sub-project based dashboard where you want to drive the configure portion of the build, then submit to the dashboard, followed by the build portion, followed by tests. If you invoke a custom target that depends on a step halfway through the step dependency chain, then all the previous steps will also run to ensure everything is up to date.

Internally, ExternalProject_Add() calls ExternalProject_Add_Step() to create each step. If any STEP_TARGETS were specified, then ExternalProject_Add_StepTargets() will also be called after ExternalProject_Add_Step(). Even if a step is not mentioned in the STEP_TARGETS option, ExternalProject_Add_StepTargets() can still be called later to manually define a target for the step.

The STEP_TARGETS option for ExternalProject_Add() is generally the easiest way to ensure targets are created for specific steps of interest. For custom steps, ExternalProject_Add_StepTargets() must be called explicitly if a target should also be created for that custom step. An alternative to these two options is to populate the EP_STEP_TARGETS directory property. It acts as a default for the step target options and can save having to repeatedly specify the same set of step targets when multiple external projects are being defined.

Added in version 3.19: If CMP0114 is set to NEW, step targets are fully responsible for holding the custom commands implementing their steps. The primary target created by ExternalProject_Add depends on the step targets, and the step targets depend on each other. The target-level dependencies match the file-level dependencies used by the custom commands for each step. The targets for steps created with ExternalProject_Add_Step()'s INDEPENDENT option do not depend on the external targets specified by ExternalProject_Add()'s DEPENDS option. The predefined steps mkdir, download, update, and patch are independent.

If CMP0114 is not NEW, the following deprecated behavior is available:

  • A deprecated NO_DEPENDS option may be specified immediately after the <name> and before the first step. If the NO_DEPENDS option is specified, the step target will not depend on the dependencies of the external project (i.e. on any dependencies of the <name> custom target created by ExternalProject_Add()). This is usually safe for the download, update and patch steps, since they do not typically require that the dependencies are updated and built. Using NO_DEPENDS for any of the other pre-defined steps, however, may break parallel builds. Only use NO_DEPENDS where it is certain that the named steps genuinely do not have dependencies. For custom steps, consider whether or not the custom commands require the dependencies to be configured, built and installed.
  • The INDEPENDENT_STEP_TARGETS option for ExternalProject_Add(), or the EP_INDEPENDENT_STEP_TARGETS directory property, tells the function to call ExternalProject_Add_StepTargets() internally using the NO_DEPENDS option for the specified steps.
Added in version 3.2.

The ExternalProject_Add_StepDependencies() function can be used to add dependencies to a step. The dependencies added must be targets CMake already knows about (these can be ordinary executable or library targets, custom targets or even step targets of another external project):

ExternalProject_Add_StepDependencies(<name> <step> <target1> [<target2>...])

This function takes care to set both target and file level dependencies and will ensure that parallel builds will not break. It should be used instead of add_dependencies() whenever adding a dependency for some of the step targets generated by the ExternalProject module.

The following example shows how to download and build a hypothetical project called FooBar from github:

include(ExternalProject)
ExternalProject_Add(foobar
  GIT_REPOSITORY    git@github.com:FooCo/FooBar.git
  GIT_TAG           origin/release/1.2.3
)

For the sake of the example, also define a second hypothetical external project called SecretSauce, which is downloaded from a web server. Two URLs are given to take advantage of a faster internal network if available, with a fallback to a slower external server. The project is a typical Makefile project with no configure step, so some of the default commands are overridden. The build is only required to build the sauce target:

find_program(MAKE_EXE NAMES gmake nmake make)
ExternalProject_Add(secretsauce
  URL               http://intranet.somecompany.com/artifacts/sauce-2.7.tgz
                    https://www.somecompany.com/downloads/sauce-2.7.zip
  URL_HASH          MD5=d41d8cd98f00b204e9800998ecf8427e
  CONFIGURE_COMMAND ""
  BUILD_COMMAND     ${MAKE_EXE} sauce
)

Suppose the build step of secretsauce requires that foobar must already be built. This could be enforced like so:

ExternalProject_Add_StepDependencies(secretsauce build foobar)

Another alternative would be to create a custom target for foobar's build step and make secretsauce depend on that rather than the whole foobar project. This would mean foobar only needs to be built, it doesn't need to run its install or test steps before secretsauce can be built. The dependency can also be defined along with the secretsauce project:

ExternalProject_Add_StepTargets(foobar build)
ExternalProject_Add(secretsauce
  URL               http://intranet.somecompany.com/artifacts/sauce-2.7.tgz
                    https://www.somecompany.com/downloads/sauce-2.7.zip
  URL_HASH          MD5=d41d8cd98f00b204e9800998ecf8427e
  CONFIGURE_COMMAND ""
  BUILD_COMMAND     ${MAKE_EXE} sauce
  DEPENDS           foobar-build
)

Instead of calling ExternalProject_Add_StepTargets(), the target could be defined along with the foobar project itself:

ExternalProject_Add(foobar
  GIT_REPOSITORY git@github.com:FooCo/FooBar.git
  GIT_TAG        origin/release/1.2.3
  STEP_TARGETS   build
)

If many external projects should have the same set of step targets, setting a directory property may be more convenient. The build step target could be created automatically by setting the EP_STEP_TARGETS directory property before creating the external projects with ExternalProject_Add():

set_property(DIRECTORY PROPERTY EP_STEP_TARGETS build)

Lastly, suppose that secretsauce provides a script called makedoc which can be used to generate its own documentation. Further suppose that the script expects the output directory to be provided as the only parameter and that it should be run from the secretsauce source directory. A custom step and a custom target to trigger the script can be defined like so:

ExternalProject_Add_Step(secretsauce docs
  COMMAND           <SOURCE_DIR>/makedoc <BINARY_DIR>
  WORKING_DIRECTORY <SOURCE_DIR>
  COMMENT           "Building secretsauce docs"
  ALWAYS            TRUE
  EXCLUDE_FROM_MAIN TRUE
)
ExternalProject_Add_StepTargets(secretsauce docs)

The custom step could then be triggered from the main build like so:

cmake --build . --target secretsauce-docs

Functions for generating a summary of enabled/disabled features.

These functions can be used to generate a summary of enabled and disabled packages and/or feature for a build tree such as:

-- The following OPTIONAL packages have been found:
LibXml2 (required version >= 2.4), XML processing lib, <http://xmlsoft.org>
   * Enables HTML-import in MyWordProcessor
   * Enables odt-export in MyWordProcessor
PNG, A PNG image library., <http://www.libpng.org/pub/png/>
   * Enables saving screenshots
-- The following OPTIONAL packages have not been found:
Lua51, The Lua scripting language., <https://www.lua.org>
   * Enables macros in MyWordProcessor
Foo, Foo provides cool stuff.

The global property FeatureSummary_PKG_TYPES defines the type of packages used by FeatureSummary.

The order in this list is important, the first package type in the list is the least important, the last is the most important. the of a package can only be changed to higher types.

The default package types are , RUNTIME, OPTIONAL, RECOMMENDED and REQUIRED, and their importance is RUNTIME < OPTIONAL < RECOMMENDED < REQUIRED.

The global property FeatureSummary_REQUIRED_PKG_TYPES defines which package types are required.

If one or more package in this categories has not been found, CMake will abort when calling feature_summary() with the 'FATAL_ON_MISSING_REQUIRED_PACKAGES' option enabled.

The default value for this global property is REQUIRED.

The global property FeatureSummary_DEFAULT_PKG_TYPE defines which package type is the default one. When calling feature_summary(), if the user did not set the package type explicitly, the package will be assigned to this category.

This value must be one of the types defined in the FeatureSummary_PKG_TYPES global property unless the package type is set for all the packages.

The default value for this global property is OPTIONAL.

Added in version 3.9.

The global property FeatureSummary_<TYPE>_DESCRIPTION can be defined for each type to replace the type name with the specified string whenever the package type is used in an output string.

If not set, the string "<TYPE> packages" is used.

feature_summary( [FILENAME <file>]
                 [APPEND]
                 [VAR <variable_name>]
                 [INCLUDE_QUIET_PACKAGES]
                 [FATAL_ON_MISSING_REQUIRED_PACKAGES]
                 [DESCRIPTION "<description>" | DEFAULT_DESCRIPTION]
                 [QUIET_ON_EMPTY]
                 WHAT (ALL
                      | PACKAGES_FOUND | PACKAGES_NOT_FOUND
                      | <TYPE>_PACKAGES_FOUND | <TYPE>_PACKAGES_NOT_FOUND
                      | ENABLED_FEATURES | DISABLED_FEATURES)
               )

The feature_summary() macro can be used to print information about enabled or disabled packages or features of a project. By default, only the names of the features/packages will be printed and their required version when one was specified. Use set_package_properties() to add more useful information, like e.g. a download URL for the respective package or their purpose in the project.

The WHAT option is the only mandatory option. Here you specify what information will be printed:

print everything
the list of all features which are enabled
the list of all features which are disabled
the list of all packages which have been found
the list of all packages which have not been found

For each package type <TYPE> defined by the FeatureSummary_PKG_TYPES global property, the following information can also be used:

<TYPE>_PACKAGES_FOUND
only those packages which have been found which have the type <TYPE>
<TYPE>_PACKAGES_NOT_FOUND
only those packages which have not been found which have the type <TYPE>

Changed in version 3.1: With the exception of the ALL value, these values can be combined in order to customize the output. For example:

feature_summary(WHAT ENABLED_FEATURES DISABLED_FEATURES)

If a FILENAME is given, the information is printed into this file. If APPEND is used, it is appended to this file, otherwise the file is overwritten if it already existed. If the VAR option is used, the information is "printed" into the specified variable. If FILENAME is not used, the information is printed to the terminal. Using the DESCRIPTION option a description or headline can be set which will be printed above the actual content. If only one type of package was requested, no title is printed, unless it is explicitly set using either DESCRIPTION to use a custom string, or DEFAULT_DESCRIPTION to use a default title for the requested type. If INCLUDE_QUIET_PACKAGES is given, packages which have been searched with find_package(... QUIET) will also be listed. By default they are skipped. If FATAL_ON_MISSING_REQUIRED_PACKAGES is given, CMake will abort if a package which is marked as one of the package types listed in the FeatureSummary_REQUIRED_PKG_TYPES global property has not been found. The default value for the FeatureSummary_REQUIRED_PKG_TYPES global property is REQUIRED.

Added in version 3.9: The DEFAULT_DESCRIPTION option.

The FeatureSummary_DEFAULT_PKG_TYPE global property can be modified to change the default package type assigned when not explicitly assigned by the user.

Added in version 3.8: If the QUIET_ON_EMPTY option is used, if only one type of package was requested, and no packages belonging to that category were found, then no output (including the DESCRIPTION) is printed or added to the VAR variable.

Example 1, append everything to a file:

include(FeatureSummary)
feature_summary(WHAT ALL
                FILENAME ${CMAKE_BINARY_DIR}/all.log APPEND)

Example 2, print the enabled features into the variable enabledFeaturesText, including QUIET packages:

include(FeatureSummary)
feature_summary(WHAT ENABLED_FEATURES
                INCLUDE_QUIET_PACKAGES
                DESCRIPTION "Enabled Features:"
                VAR enabledFeaturesText)
message(STATUS "${enabledFeaturesText}")

Example 3, change default package types and print only the categories that are not empty:

include(FeatureSummary)
set_property(GLOBAL APPEND PROPERTY FeatureSummary_PKG_TYPES BUILD)
find_package(FOO)
set_package_properties(FOO PROPERTIES TYPE BUILD)
feature_summary(WHAT BUILD_PACKAGES_FOUND
                Description "Build tools found:"
                QUIET_ON_EMPTY)
feature_summary(WHAT BUILD_PACKAGES_NOT_FOUND
                Description "Build tools not found:"
                QUIET_ON_EMPTY)
set_package_properties(<name> PROPERTIES
                       [ URL <url> ]
                       [ DESCRIPTION <description> ]
                       [ TYPE (RUNTIME|OPTIONAL|RECOMMENDED|REQUIRED) ]
                       [ PURPOSE <purpose> ]
                      )

Use this macro to set up information about the named package, which can then be displayed via FEATURE_SUMMARY(). This can be done either directly in the Find-module or in the project which uses the module after the find_package() call. The features for which information can be set are added automatically by the find_package() command.

URL <url>
This should be the homepage of the package, or something similar. Ideally this is set already directly in the Find-module.
A short description what that package is, at most one sentence. Ideally this is set already directly in the Find-module.
What type of dependency has the using project on that package. Default is OPTIONAL. In this case it is a package which can be used by the project when available at buildtime, but it also work without. RECOMMENDED is similar to OPTIONAL, i.e. the project will build if the package is not present, but the functionality of the resulting binaries will be severely limited. If a REQUIRED package is not available at buildtime, the project may not even build. This can be combined with the FATAL_ON_MISSING_REQUIRED_PACKAGES argument for feature_summary(). Last, a RUNTIME package is a package which is actually not used at all during the build, but which is required for actually running the resulting binaries. So if such a package is missing, the project can still be built, but it may not work later on. If set_package_properties() is called multiple times for the same package with different TYPEs, the TYPE is only changed to higher TYPEs (RUNTIME < OPTIONAL < RECOMMENDED < REQUIRED), lower TYPEs are ignored. The TYPE property is project-specific, so it cannot be set by the Find-module, but must be set in the project. Type accepted can be changed by setting the FeatureSummary_PKG_TYPES global property.
This describes which features this package enables in the project, i.e. it tells the user what functionality he gets in the resulting binaries. If set_package_properties() is called multiple times for a package, all PURPOSE properties are appended to a list of purposes of the package in the project. As the TYPE property, also the PURPOSE property is project-specific, so it cannot be set by the Find-module, but must be set in the project.

Example for setting the info for a package:

find_package(LibXml2)
set_package_properties(LibXml2 PROPERTIES
                       DESCRIPTION "A XML processing library."
                       URL "http://xmlsoft.org/")
# or
set_package_properties(LibXml2 PROPERTIES
                       TYPE RECOMMENDED
                       PURPOSE "Enables HTML-import in MyWordProcessor")
# or
set_package_properties(LibXml2 PROPERTIES
                       TYPE OPTIONAL
                       PURPOSE "Enables odt-export in MyWordProcessor")
find_package(DBUS)
set_package_properties(DBUS PROPERTIES
  TYPE RUNTIME
  PURPOSE "Necessary to disable the screensaver during a presentation")
add_feature_info(<name> <enabled> <description>)

Use this macro to add information about a feature with the given <name>. <enabled> contains whether this feature is enabled or not. It can be a variable or a list of conditions. <description> is a text describing the feature. The information can be displayed using feature_summary() for ENABLED_FEATURES and DISABLED_FEATURES respectively.

Changed in version 3.8: <enabled> can be a list of conditions.

Example for setting the info for a feature:

option(WITH_FOO "Help for foo" ON)
add_feature_info(Foo WITH_FOO "The Foo feature provides very cool stuff.")

The following macros are provided for compatibility with previous CMake versions:

set_package_info(<name> <description> [ <url> [<purpose>] ])

Use this macro to set up information about the named package, which can then be displayed via feature_summary(). This can be done either directly in the Find-module or in the project which uses the module after the find_package() call. The features for which information can be set are added automatically by the find_package() command.

set_feature_info(<name> <description> [<url>])

Does the same as:

set_package_info(<name> <description> <url>)
print_enabled_features()

Does the same as

feature_summary(WHAT ENABLED_FEATURES DESCRIPTION "Enabled features:")
print_disabled_features()

Does the same as

feature_summary(WHAT DISABLED_FEATURES DESCRIPTION "Disabled features:")

Added in version 3.11.

NOTE:

The Using Dependencies Guide provides a high-level introduction to this general topic. It provides a broader overview of where the FetchContent module fits into the bigger picture, including its relationship to the find_package() command. The guide is recommended pre-reading before moving on to the details below.

This module enables populating content at configure time via any method supported by the ExternalProject module. Whereas ExternalProject_Add() downloads at build time, the FetchContent module makes content available immediately, allowing the configure step to use the content in commands like add_subdirectory(), include() or file() operations.

Content population details should be defined separately from the command that performs the actual population. This separation ensures that all the dependency details are defined before anything might try to use them to populate content. This is particularly important in more complex project hierarchies where dependencies may be shared between multiple projects.

The following shows a typical example of declaring content details for some dependencies and then ensuring they are populated with a separate call:

FetchContent_Declare(
  googletest
  GIT_REPOSITORY https://github.com/google/googletest.git
  GIT_TAG        703bd9caab50b139428cea1aaff9974ebee5742e # release-1.10.0
)
FetchContent_Declare(
  myCompanyIcons
  URL      https://intranet.mycompany.com/assets/iconset_1.12.tar.gz
  URL_HASH MD5=5588a7b18261c20068beabfb4f530b87
)
FetchContent_MakeAvailable(googletest myCompanyIcons)

The FetchContent_MakeAvailable() command ensures the named dependencies have been populated, either by an earlier call, or by populating them itself. When performing the population, it will also add them to the main build, if possible, so that the main build can use the populated projects' targets, etc. See the command's documentation for how these steps are performed.

When using a hierarchical project arrangement, projects at higher levels in the hierarchy are able to override the declared details of content specified anywhere lower in the project hierarchy. The first details to be declared for a given dependency take precedence, regardless of where in the project hierarchy that occurs. Similarly, the first call that tries to populate a dependency "wins", with subsequent populations reusing the result of the first instead of repeating the population again. See the Examples which demonstrate this scenario.

The FetchContent module also supports defining and populating content in a single call, with no check for whether the content has been populated elsewhere already. This should not be done in projects, but may be appropriate for populating content in CMake script mode. See FetchContent_Populate() for details.

FetchContent_Declare(
  <name>
  <contentOptions>...
  [EXCLUDE_FROM_ALL]
  [SYSTEM]
  [OVERRIDE_FIND_PACKAGE |
   FIND_PACKAGE_ARGS args...]
)

The FetchContent_Declare() function records the options that describe how to populate the specified content. If such details have already been recorded earlier in this project (regardless of where in the project hierarchy), this and all later calls for the same content <name> are ignored. This "first to record, wins" approach is what allows hierarchical projects to have parent projects override content details of child projects.

The content <name> can be any string without spaces, but good practice would be to use only letters, numbers, and underscores. The name will be treated case-insensitively, and it should be obvious for the content it represents. It is often the name of the child project, or the value given to its top level project() command (if it is a CMake project). For well-known public projects, the name should generally be the official name of the project. Choosing an unusual name makes it unlikely that other projects needing that same content will use the same name, leading to the content being populated multiple times.

The <contentOptions> can be any of the download, update, or patch options that the ExternalProject_Add() command understands. The configure, build, install, and test steps are explicitly disabled, so options related to those steps will be ignored. The SOURCE_SUBDIR option is an exception, see FetchContent_MakeAvailable() for details on how that affects behavior.

Changed in version 3.30: When policy CMP0168 is set to NEW, some output-related and directory-related options are ignored. See the policy documentation for details.

In most cases, <contentOptions> will just be a couple of options defining the download method and method-specific details like a commit tag or archive hash. For example:

FetchContent_Declare(
  googletest
  GIT_REPOSITORY https://github.com/google/googletest.git
  GIT_TAG        703bd9caab50b139428cea1aaff9974ebee5742e # release-1.10.0
)
FetchContent_Declare(
  myCompanyIcons
  URL      https://intranet.mycompany.com/assets/iconset_1.12.tar.gz
  URL_HASH MD5=5588a7b18261c20068beabfb4f530b87
)
FetchContent_Declare(
  myCompanyCertificates
  SVN_REPOSITORY svn+ssh://svn.mycompany.com/srv/svn/trunk/certs
  SVN_REVISION   -r12345
)

Where contents are being fetched from a remote location and you do not control that server, it is advisable to use a hash for GIT_TAG rather than a branch or tag name. A commit hash is more secure and helps to confirm that the downloaded contents are what you expected.

Changed in version 3.14: Commands for the download, update, or patch steps can access the terminal. This may be needed for things like password prompts or real-time display of command progress.

Added in version 3.22: The CMAKE_TLS_VERIFY, CMAKE_TLS_CAINFO, CMAKE_NETRC, and CMAKE_NETRC_FILE variables now provide the defaults for their corresponding content options, just like they do for ExternalProject_Add(). Previously, these variables were ignored by the FetchContent module.

Added in version 3.24:

This option is for scenarios where the FetchContent_MakeAvailable() command may first try a call to find_package() to satisfy the dependency for <name>. By default, such a call would be simply find_package(<name>), but FIND_PACKAGE_ARGS can be used to provide additional arguments to be appended after the <name>. FIND_PACKAGE_ARGS can also be given with nothing after it, which indicates that find_package() can still be called if FETCHCONTENT_TRY_FIND_PACKAGE_MODE is set to OPT_IN, or is not set.

It would not normally be appropriate to specify REQUIRED as one of the additional arguments after FIND_PACKAGE_ARGS. Doing so would mean the find_package() call must succeed, so none of the other details specified in the FetchContent_Declare() call would get a chance to be used as a fall-back.

Everything after the FIND_PACKAGE_ARGS keyword is appended to the find_package() call, so all other <contentOptions> must come before the FIND_PACKAGE_ARGS keyword. If the CMAKE_FIND_PACKAGE_TARGETS_GLOBAL variable is set to true at the time FetchContent_Declare() is called, a GLOBAL keyword will be appended to the find_package() arguments if it was not already specified. It will also be appended if FIND_PACKAGE_ARGS was not given, but FETCHCONTENT_TRY_FIND_PACKAGE_MODE was set to ALWAYS.

OVERRIDE_FIND_PACKAGE cannot be used when FIND_PACKAGE_ARGS is given.

Dependency Providers discusses another way that FetchContent_MakeAvailable() calls can be redirected. FIND_PACKAGE_ARGS is intended for project control, whereas dependency providers allow users to override project behavior.

When a FetchContent_Declare(<name> ...) call includes this option, subsequent calls to find_package(<name> ...) will ensure that FetchContent_MakeAvailable(<name>) has been called, then use the config package files in the CMAKE_FIND_PACKAGE_REDIRECTS_DIR directory (which are usually created by FetchContent_MakeAvailable()). This effectively makes FetchContent_MakeAvailable() override find_package() for the named dependency, allowing the former to satisfy the package requirements of the latter. FIND_PACKAGE_ARGS cannot be used when OVERRIDE_FIND_PACKAGE is given.

If a dependency provider has been set and the project calls find_package() for the <name> dependency, OVERRIDE_FIND_PACKAGE will not prevent the provider from seeing that call. Dependency providers always have the opportunity to intercept any direct call to find_package(), except if that call contains the BYPASS_PROVIDER option.

Added in version 3.25:

If the SYSTEM argument is provided, the SYSTEM directory property of a subdirectory added by FetchContent_MakeAvailable() will be set to true. This will affect non-imported targets created as part of that command. See the SYSTEM target property documentation for a more detailed discussion of the effects.

Added in version 3.28:

If the EXCLUDE_FROM_ALL argument is provided, then targets in the subdirectory added by FetchContent_MakeAvailable() will not be included in the ALL target by default, and may be excluded from IDE project files. See the documentation for the directory property EXCLUDE_FROM_ALL for a detailed discussion of the effects.
Added in version 3.14.
FetchContent_MakeAvailable(<name1> [<name2>...])

This command ensures that each of the named dependencies are made available to the project by the time it returns. There must have been a call to FetchContent_Declare() for each dependency, and the first such call will control how that dependency will be made available, as described below.

If <lowercaseName>_SOURCE_DIR is not set:

  • Added in version 3.24: If a dependency provider is set, call the provider's command with FETCHCONTENT_MAKEAVAILABLE_SERIAL as the first argument, followed by the arguments of the first call to FetchContent_Declare() for <name>. If SOURCE_DIR or BINARY_DIR were not part of the original declared arguments, they will be added with their default values. If FETCHCONTENT_TRY_FIND_PACKAGE_MODE was set to NEVER when the details were declared, any FIND_PACKAGE_ARGS will be omitted. The OVERRIDE_FIND_PACKAGE keyword is also always omitted. If the provider fulfilled the request, FetchContent_MakeAvailable() will consider that dependency handled, skip the remaining steps below, and move on to the next dependency in the list.
  • Added in version 3.24: If permitted, find_package(<name> [<args>...]) will be called, where <args>... may be provided by the FIND_PACKAGE_ARGS option in FetchContent_Declare(). The value of the FETCHCONTENT_TRY_FIND_PACKAGE_MODE variable at the time FetchContent_Declare() was called determines whether FetchContent_MakeAvailable() can call find_package(). If the CMAKE_FIND_PACKAGE_TARGETS_GLOBAL variable is set to true when FetchContent_MakeAvailable() is called, it still affects any imported targets created when that in turn calls find_package(), even if that variable was false when the corresponding details were declared.

If the dependency was not satisfied by a provider or a find_package() call, FetchContent_MakeAvailable() then uses the following logic to make the dependency available:

  • If the dependency has already been populated earlier in this run, set the <lowercaseName>_POPULATED, <lowercaseName>_SOURCE_DIR, and <lowercaseName>_BINARY_DIR variables in the same way as a call to FetchContent_GetProperties(), then skip the remaining steps below and move on to the next dependency in the list.
  • Populate the dependency using the details recorded by an earlier call to FetchContent_Declare(). Halt with a fatal error if no such details have been recorded. FETCHCONTENT_SOURCE_DIR_<uppercaseName> can be used to override the declared details and use content provided at the specified location instead.
  • Added in version 3.24: Ensure the CMAKE_FIND_PACKAGE_REDIRECTS_DIR directory contains a <lowercaseName>-config.cmake and a <lowercaseName>-config-version.cmake file (or equivalently, <name>Config.cmake and <name>ConfigVersion.cmake). The directory that the CMAKE_FIND_PACKAGE_REDIRECTS_DIR variable points to is cleared at the start of every CMake run. If no config file exists after populating the dependency in the previous step, a minimal one will be written which includes any <lowercaseName>-extra.cmake or <name>Extra.cmake file with the OPTIONAL flag (so the files can be missing and won't generate a warning). Similarly, if no config version file exists, a very simple one will be written which sets PACKAGE_VERSION_COMPATIBLE and PACKAGE_VERSION_EXACT to true. This ensures all future calls to find_package() for the dependency will use the redirected config file, regardless of any version requirements. CMake cannot automatically determine an arbitrary dependency's version, so it cannot set PACKAGE_VERSION. When a dependency is pulled in via add_subdirectory() in the next step, it may choose to overwrite the generated config version file in CMAKE_FIND_PACKAGE_REDIRECTS_DIR with one that also sets PACKAGE_VERSION. The dependency may also write a <lowercaseName>-extra.cmake or <name>Extra.cmake file to perform custom processing, or define any variables that their normal (installed) package config file would otherwise usually define (many projects don't do any custom processing or set any variables and therefore have no need to do this). If required, the main project can write these files instead if the dependency project doesn't do so. This allows the main project to add missing details from older dependencies that haven't or can't be updated to support this functionality. See Integrating With find_package() for examples.
  • If the top directory of the populated content contains a CMakeLists.txt file, call add_subdirectory() to add it to the main build. It is not an error for there to be no CMakeLists.txt file, which allows the command to be used for dependencies that make downloaded content available at a known location, but which do not need or support being added directly to the build.

    Added in version 3.18: The SOURCE_SUBDIR option can be given in the declared details to look somewhere below the top directory instead (i.e. the same way that SOURCE_SUBDIR is used by the ExternalProject_Add() command). The path provided with SOURCE_SUBDIR must be relative, and it will be treated as relative to the top directory. It can also point to a directory that does not contain a CMakeLists.txt file, or even to a directory that doesn't exist. This can be used to avoid adding a project that contains a CMakeLists.txt file in its top directory.

    Added in version 3.25: If the SYSTEM keyword was included in the call to FetchContent_Declare(), the SYSTEM keyword will be added to the add_subdirectory() command.

    Added in version 3.28: If the EXCLUDE_FROM_ALL keyword was included in the call to FetchContent_Declare(), the EXCLUDE_FROM_ALL keyword will be added to the add_subdirectory() command.

    Added in version 3.29: CMAKE_EXPORT_FIND_PACKAGE_NAME is set to the dependency name before calling add_subdirectory().

Projects should aim to declare the details of all dependencies they might use before they call FetchContent_MakeAvailable() for any of them. This ensures that if any of the dependencies are also sub-dependencies of one or more of the others, the main project still controls the details that will be used (because it will declare them first before the dependencies get a chance to). In the following code samples, assume that the uses_other dependency also uses FetchContent to add the other dependency internally:

# WRONG: Should declare all details first
FetchContent_Declare(uses_other ...)
FetchContent_MakeAvailable(uses_other)
FetchContent_Declare(other ...)    # Will be ignored, uses_other beat us to it
FetchContent_MakeAvailable(other)  # Would use details declared by uses_other
# CORRECT: All details declared first, so they will take priority
FetchContent_Declare(uses_other ...)
FetchContent_Declare(other ...)
FetchContent_MakeAvailable(uses_other other)

Note that CMAKE_VERIFY_INTERFACE_HEADER_SETS is explicitly set to false upon entry to FetchContent_MakeAvailable(), and is restored to its original value before the command returns. Developers typically only want to verify header sets from the main project, not those from any dependencies. This local manipulation of the CMAKE_VERIFY_INTERFACE_HEADER_SETS variable provides that intuitive behavior. You can use variables like CMAKE_PROJECT_INCLUDE or CMAKE_PROJECT_<PROJECT-NAME>_INCLUDE to turn verification back on for all or some dependencies. You can also set the VERIFY_INTERFACE_HEADER_SETS property of individual targets.

The FetchContent_Populate() command is a self-contained call which can be used to perform content population as an isolated operation. It is rarely the right command to use, projects should almost always use FetchContent_Declare() and FetchContent_MakeAvailable() instead. The main use case for FetchContent_Populate() is in CMake script mode as part of implementing some other higher level custom feature.
FetchContent_Populate(
  <name>
  [QUIET]
  [SUBBUILD_DIR <subBuildDir>]
  [SOURCE_DIR <srcDir>]
  [BINARY_DIR <binDir>]
  ...
)

At least one option must be specified after <name>, otherwise the call is interpreted differently (see below). The supported options for FetchContent_Populate() are the same as those for FetchContent_Declare(), with a few exceptions. The following do not relate to populating content with FetchContent_Populate() and therefore are not supported:

  • EXCLUDE_FROM_ALL
  • SYSTEM
  • OVERRIDE_FIND_PACKAGE
  • FIND_PACKAGE_ARGS

The few options shown in the signature above are either specific to FetchContent_Populate(), or their behavior is slightly modified from how ExternalProject_Add() treats them:

The QUIET option can be given to hide the output associated with populating the specified content. If the population fails, the output will be shown regardless of whether this option was given or not so that the cause of the failure can be diagnosed. The FETCHCONTENT_QUIET variable has no effect on FetchContent_Populate() calls of this form where the content details are provided directly.

Changed in version 3.30: The QUIET option and FETCHCONTENT_QUIET variable have no effect when policy CMP0168 is set to NEW. The output is still quiet by default in that case, but verbosity is controlled by the message logging level (see CMAKE_MESSAGE_LOG_LEVEL and --log-level).

The SUBBUILD_DIR argument can be provided to change the location of the sub-build created to perform the population. The default value is ${CMAKE_CURRENT_BINARY_DIR}/<lowercaseName>-subbuild, and it would be unusual to need to override this default. If a relative path is specified, it will be interpreted as relative to CMAKE_CURRENT_BINARY_DIR. This option should not be confused with the SOURCE_SUBDIR option, which only affects the FetchContent_MakeAvailable() command.

Changed in version 3.30: SUBBUILD_DIR is ignored when policy CMP0168 is set to NEW, since there is no sub-build in that case.

The SOURCE_DIR and BINARY_DIR arguments are supported by ExternalProject_Add(), but different default values are used by FetchContent_Populate(). SOURCE_DIR defaults to ${CMAKE_CURRENT_BINARY_DIR}/<lowercaseName>-src, and BINARY_DIR defaults to ${CMAKE_CURRENT_BINARY_DIR}/<lowercaseName>-build. If a relative path is specified, it will be interpreted as relative to CMAKE_CURRENT_BINARY_DIR.

In addition to the above explicit options, any other unrecognized options are passed through unmodified to ExternalProject_Add() to set up the download, patch, and update steps. The following options are explicitly prohibited (they are disabled by the FetchContent_Populate() command):

  • CONFIGURE_COMMAND
  • BUILD_COMMAND
  • INSTALL_COMMAND
  • TEST_COMMAND

With this form, the FETCHCONTENT_FULLY_DISCONNECTED and FETCHCONTENT_UPDATES_DISCONNECTED variables and policy CMP0170 are ignored.

When this form of FetchContent_Populate() returns, the following variables will be set in the scope of the caller:

<lowercaseName>_SOURCE_DIR
The location where the populated content can be found upon return.
<lowercaseName>_BINARY_DIR
A directory originally intended for use as a corresponding build directory, but is unlikely to be relevant when using this form of the command.

If using FetchContent_Populate() within CMake script mode, be aware that the implementation sets up a sub-build which therefore requires a CMake generator and build tool to be available. If these cannot be found by default, then the CMAKE_GENERATOR and potentially the CMAKE_MAKE_PROGRAM variables will need to be set appropriately on the command line invoking the script.

Changed in version 3.30: If policy CMP0168 is set to NEW, no sub-build is used. Within CMake script mode, that allows FetchContent_Populate() to be called without any build tool or CMake generator.

Added in version 3.18: Added support for the DOWNLOAD_NO_EXTRACT option.

The command supports another form, although it should no longer be used:
FetchContent_Populate(<name>)

Changed in version 3.30: This form is deprecated. Policy CMP0169 provides backward compatibility for projects that still need to use this form, but projects should be updated to use FetchContent_MakeAvailable() instead.

In this form, the only argument given to FetchContent_Populate() is the <name>. When used this way, the command assumes the content details have been recorded by an earlier call to FetchContent_Declare(). The details are stored in a global property, so they are unaffected by things like variable or directory scope. Therefore, it doesn't matter where in the project the details were previously declared, as long as they have been declared before the call to FetchContent_Populate(). Those saved details are then used to populate the content using a method based on ExternalProject_Add() (see policy CMP0168 for important behavioral aspects of how that is done).

When this form of FetchContent_Populate() returns, the following variables will be set in the scope of the caller:

<lowercaseName>_POPULATED
This will always be set to TRUE by the call.
<lowercaseName>_SOURCE_DIR
The location where the populated content can be found upon return.
<lowercaseName>_BINARY_DIR
A directory intended for use as a corresponding build directory.

The values of the three variables can also be retrieved from anywhere in the project hierarchy using the FetchContent_GetProperties() command.

The implementation ensures that if the content has already been populated in a previous CMake run, that content will be reused rather than repopulating again. For the common case where population involves downloading content, the cost of the download is only paid once. But note that it is an error to call FetchContent_Populate(<name>) with the same <name> more than once within a single CMake run. See FetchContent_GetProperties() for how to determine if population of a <name> has already been performed in the current run.

When using saved content details, a call to FetchContent_MakeAvailable() or FetchContent_Populate() records information in global properties which can be queried at any time. This information may include the source and binary directories associated with the content, and also whether or not the content population has been processed during the current configure run.
FetchContent_GetProperties(
  <name>
  [SOURCE_DIR <srcDirVar>]
  [BINARY_DIR <binDirVar>]
  [POPULATED <doneVar>]
)

The SOURCE_DIR, BINARY_DIR, and POPULATED options can be used to specify which properties should be retrieved. Each option accepts a value which is the name of the variable in which to store that property. Most of the time though, only <name> is given, in which case the call will then set the same variables as a call to FetchContent_MakeAvailable(name) or FetchContent_Populate(name). Note that the SOURCE_DIR and BINARY_DIR values can be empty if the call is fulfilled by a dependency provider.

This command is rarely needed when using FetchContent_MakeAvailable(). It is more commonly used as part of implementing the deprecated pattern with FetchContent_Populate(), which ensures that the relevant variables will always be defined regardless of whether or not the population has been performed elsewhere in the project already:

# WARNING: This pattern is deprecated, don't use it!
#
# Check if population has already been performed
FetchContent_GetProperties(depname)
if(NOT depname_POPULATED)
  # Fetch the content using previously declared details
  FetchContent_Populate(depname)
  # Set custom variables, policies, etc.
  # ...
  # Bring the populated content into the build
  add_subdirectory(${depname_SOURCE_DIR} ${depname_BINARY_DIR})
endif()
Added in version 3.24.

NOTE:

This command should only be called by dependency providers. Calling it in any other context is unsupported and future CMake versions may halt with a fatal error in such cases.
FetchContent_SetPopulated(
  <name>
  [SOURCE_DIR <srcDir>]
  [BINARY_DIR <binDir>]
)

If a provider command fulfills a FETCHCONTENT_MAKEAVAILABLE_SERIAL request, it must call this function before returning. The SOURCE_DIR and BINARY_DIR arguments can be used to specify the values that FetchContent_GetProperties() should return for its corresponding arguments. Only provide SOURCE_DIR and BINARY_DIR if they have the same meaning as if they had been populated by the built-in FetchContent_MakeAvailable() implementation.

A number of cache variables can influence the behavior where details from a FetchContent_Declare() call are used to populate content.

NOTE:

All of these variables are intended for the developer to customize behavior. They should not normally be set by the project.
In most cases, the saved details do not specify any options relating to the directories to use for the internal sub-build, final source, and build areas. It is generally best to leave these decisions up to the FetchContent module to handle on the project's behalf. The FETCHCONTENT_BASE_DIR cache variable controls the point under which all content population directories are collected, but in most cases, developers would not need to change this. The default location is ${CMAKE_BINARY_DIR}/_deps, but if developers change this value, they should aim to keep the path short and just below the top level of the build tree to avoid running into path length problems on Windows.
The logging output during population can be quite verbose, making the configure stage quite noisy. This cache option (ON by default) hides all population output unless an error is encountered. If experiencing problems with hung downloads, temporarily switching this option off may help diagnose which content population is causing the issue.

Changed in version 3.30: FETCHCONTENT_QUIET is ignored if policy CMP0168 is set to NEW. The output is still quiet by default in that case, but verbosity is controlled by the message logging level (see CMAKE_MESSAGE_LOG_LEVEL and --log-level).

When this option is enabled, no attempt is made to download or update any content. It is assumed that all content has already been populated in a previous run, or the source directories have been pointed at existing contents the developer has provided manually (using options described further below). When the developer knows that no changes have been made to any content details, turning this option ON can speed up the configure stage. It is OFF by default.

NOTE:

The FETCHCONTENT_FULLY_DISCONNECTED variable is not an appropriate way to prevent any network access on the first run in a build directory. Doing so can break projects, lead to misleading error messages, and hide subtle population failures. This variable is specifically intended to only be turned on after the first time CMake has been run. If you want to prevent network access even on the first run, use a dependency provider and populate the dependency from local content instead.

Changed in version 3.30: The constraint that the source directory has already been populated when FETCHCONTENT_FULLY_DISCONNECTED is true is now enforced. See policy CMP0170.

This is a less severe download/update control compared to FETCHCONTENT_FULLY_DISCONNECTED. Instead of bypassing all download and update logic, FETCHCONTENT_UPDATES_DISCONNECTED only prevents the update step from making connections to remote servers when using the git or hg download methods. Updates still occur if details about the update step change, but the update is attempted with only the information already available locally (so switching to a different tag or commit that is already fetched locally will succeed, but switching to an unknown commit hash will fail). The download step is not affected, so if content has not been downloaded previously, it will still be downloaded when this option is enabled. This can speed up the configure step, but not as much as FETCHCONTENT_FULLY_DISCONNECTED. FETCHCONTENT_UPDATES_DISCONNECTED is OFF by default.
Added in version 3.24.

This variable modifies the details that FetchContent_Declare() records for a given dependency. While it ultimately controls the behavior of FetchContent_MakeAvailable(), it is the variable's value when FetchContent_Declare() is called that gets used. It makes no difference what the variable is set to when FetchContent_MakeAvailable() is called. Since the variable should only be set by the user and not by projects directly, it will typically have the same value throughout anyway, so this distinction is not usually noticeable.

FETCHCONTENT_TRY_FIND_PACKAGE_MODE ultimately controls whether FetchContent_MakeAvailable() is allowed to call find_package() to satisfy a dependency. The variable can be set to one of the following values:

FetchContent_MakeAvailable() will only call find_package() if the FetchContent_Declare() call included a FIND_PACKAGE_ARGS keyword. This is also the default behavior if FETCHCONTENT_TRY_FIND_PACKAGE_MODE is not set.
find_package() can be called by FetchContent_MakeAvailable() regardless of whether the FetchContent_Declare() call included a FIND_PACKAGE_ARGS keyword or not. If no FIND_PACKAGE_ARGS keyword was given, the behavior will be as though FIND_PACKAGE_ARGS had been provided, with no additional arguments after it.
FetchContent_MakeAvailable() will not call find_package(). Any FIND_PACKAGE_ARGS given to the FetchContent_Declare() call will be ignored.

As a special case, if the FETCHCONTENT_SOURCE_DIR_<uppercaseName> variable has a non-empty value for a dependency, it is assumed that the user is overriding all other methods of making that dependency available. FETCHCONTENT_TRY_FIND_PACKAGE_MODE will have no effect on that dependency and FetchContent_MakeAvailable() will not try to call find_package() for it.

In addition to the above, the following variables are also defined for each content name:

If this is set, no download or update steps are performed for the specified content and the <lowercaseName>_SOURCE_DIR variable returned to the caller is pointed at this location. This gives developers a way to have a separate checkout of the content that they can modify freely without interference from the build. The build simply uses that existing source, but it still defines <lowercaseName>_BINARY_DIR to point inside its own build area. Developers are strongly encouraged to use this mechanism rather than editing the sources populated in the default location, as changes to sources in the default location can be lost when content population details are changed by the project.
This is the per-content equivalent of FETCHCONTENT_UPDATES_DISCONNECTED. If the global option or this option is ON, then updates for the git and hg methods will not contact any remote for the named content. They will only use information already available locally. Disabling updates for individual content can be useful for content whose details rarely change, while still leaving other frequently changing content with updates enabled.

This first fairly straightforward example ensures that some popular testing frameworks are available to the main build:

include(FetchContent)
FetchContent_Declare(
  googletest
  GIT_REPOSITORY https://github.com/google/googletest.git
  GIT_TAG        703bd9caab50b139428cea1aaff9974ebee5742e # release-1.10.0
)
FetchContent_Declare(
  Catch2
  GIT_REPOSITORY https://github.com/catchorg/Catch2.git
  GIT_TAG        605a34765aa5d5ecbf476b4598a862ada971b0cc # v3.0.1
)
# After the following call, the CMake targets defined by googletest and
# Catch2 will be available to the rest of the build
FetchContent_MakeAvailable(googletest Catch2)

For the previous example, if the user wanted to try to find googletest and Catch2 via find_package() first before trying to download and build them from source, they could set the FETCHCONTENT_TRY_FIND_PACKAGE_MODE variable to ALWAYS. This would also affect any other calls to FetchContent_Declare() throughout the project, which might not be acceptable. The behavior can be enabled for just these two dependencies instead by adding FIND_PACKAGE_ARGS to the declared details and leaving FETCHCONTENT_TRY_FIND_PACKAGE_MODE unset, or set to OPT_IN:

include(FetchContent)
FetchContent_Declare(
  googletest
  GIT_REPOSITORY https://github.com/google/googletest.git
  GIT_TAG        703bd9caab50b139428cea1aaff9974ebee5742e # release-1.10.0
  FIND_PACKAGE_ARGS NAMES GTest
)
FetchContent_Declare(
  Catch2
  GIT_REPOSITORY https://github.com/catchorg/Catch2.git
  GIT_TAG        605a34765aa5d5ecbf476b4598a862ada971b0cc # v3.0.1
  FIND_PACKAGE_ARGS
)
# This will try calling find_package() first for both dependencies
FetchContent_MakeAvailable(googletest Catch2)

For Catch2, no additional arguments to find_package() are needed, so no additional arguments are provided after the FIND_PACKAGE_ARGS keyword. For googletest, its package is more commonly called GTest, so arguments are added to support it being found by that name.

If the user wanted to disable FetchContent_MakeAvailable() from calling find_package() for any dependency, even if it provided FIND_PACKAGE_ARGS in its declared details, they could set FETCHCONTENT_TRY_FIND_PACKAGE_MODE to NEVER.

If the project wanted to indicate that these two dependencies should be downloaded and built from source and that find_package() calls should be redirected to use the built dependencies, the OVERRIDE_FIND_PACKAGE option should be used when declaring the content details:

include(FetchContent)
FetchContent_Declare(
  googletest
  GIT_REPOSITORY https://github.com/google/googletest.git
  GIT_TAG        703bd9caab50b139428cea1aaff9974ebee5742e # release-1.10.0
  OVERRIDE_FIND_PACKAGE
)
FetchContent_Declare(
  Catch2
  GIT_REPOSITORY https://github.com/catchorg/Catch2.git
  GIT_TAG        605a34765aa5d5ecbf476b4598a862ada971b0cc # v3.0.1
  OVERRIDE_FIND_PACKAGE
)
# The following will automatically forward through to FetchContent_MakeAvailable()
find_package(googletest)
find_package(Catch2)

CMake provides a FindGTest module which defines some variables that older projects may use instead of linking to the imported targets. To support those cases, we can provide an extra file. In keeping with the "first to define, wins" philosophy of FetchContent, we only write out that file if something else hasn't already done so.

FetchContent_MakeAvailable(googletest)
if(NOT EXISTS ${CMAKE_FIND_PACKAGE_REDIRECTS_DIR}/googletest-extra.cmake AND
   NOT EXISTS ${CMAKE_FIND_PACKAGE_REDIRECTS_DIR}/googletestExtra.cmake)
  file(WRITE ${CMAKE_FIND_PACKAGE_REDIRECTS_DIR}/googletest-extra.cmake
[=[
if("${GTEST_LIBRARIES}" STREQUAL "" AND TARGET GTest::gtest)
  set(GTEST_LIBRARIES GTest::gtest)
endif()
if("${GTEST_MAIN_LIBRARIES}" STREQUAL "" AND TARGET GTest::gtest_main)
  set(GTEST_MAIN_LIBRARIES GTest::gtest_main)
endif()
if("${GTEST_BOTH_LIBRARIES}" STREQUAL "")
  set(GTEST_BOTH_LIBRARIES ${GTEST_LIBRARIES} ${GTEST_MAIN_LIBRARIES})
endif()
]=])
endif()

Projects will also likely be using find_package(GTest) rather than find_package(googletest), but it is possible to make use of the CMAKE_FIND_PACKAGE_REDIRECTS_DIR area to pull in the latter as a dependency of the former. This is likely to be sufficient to satisfy a typical find_package(GTest) call.

FetchContent_MakeAvailable(googletest)
if(NOT EXISTS ${CMAKE_FIND_PACKAGE_REDIRECTS_DIR}/gtest-config.cmake AND
   NOT EXISTS ${CMAKE_FIND_PACKAGE_REDIRECTS_DIR}/GTestConfig.cmake)
  file(WRITE ${CMAKE_FIND_PACKAGE_REDIRECTS_DIR}/gtest-config.cmake
[=[
include(CMakeFindDependencyMacro)
find_dependency(googletest)
]=])
endif()
if(NOT EXISTS ${CMAKE_FIND_PACKAGE_REDIRECTS_DIR}/gtest-config-version.cmake AND
   NOT EXISTS ${CMAKE_FIND_PACKAGE_REDIRECTS_DIR}/GTestConfigVersion.cmake)
  file(WRITE ${CMAKE_FIND_PACKAGE_REDIRECTS_DIR}/gtest-config-version.cmake
[=[
include(${CMAKE_FIND_PACKAGE_REDIRECTS_DIR}/googletest-config-version.cmake OPTIONAL)
if(NOT PACKAGE_VERSION_COMPATIBLE)
  include(${CMAKE_FIND_PACKAGE_REDIRECTS_DIR}/googletestConfigVersion.cmake OPTIONAL)
endif()
]=])
endif()

If the sub-project's CMakeLists.txt file is not at the top level of its source tree, the SOURCE_SUBDIR option can be used to tell FetchContent where to find it. The following example shows how to use that option, and it also sets a variable which is meaningful to the subproject before pulling it into the main build (set as an INTERNAL cache variable to avoid problems with policy CMP0077):

include(FetchContent)
FetchContent_Declare(
  protobuf
  GIT_REPOSITORY https://github.com/protocolbuffers/protobuf.git
  GIT_TAG        ae50d9b9902526efd6c7a1907d09739f959c6297 # v3.15.0
  SOURCE_SUBDIR  cmake
)
set(protobuf_BUILD_TESTS OFF CACHE INTERNAL "")
FetchContent_MakeAvailable(protobuf)

In more complex project hierarchies, the dependency relationships can be more complicated. Consider a hierarchy where projA is the top level project and it depends directly on projects projB and projC. Both projB and projC can be built standalone and they also both depend on another project projD. projB additionally depends on projE. This example assumes that all five projects are available on a company git server. The CMakeLists.txt of each project might have sections like the following:

projA

include(FetchContent)
FetchContent_Declare(
  projB
  GIT_REPOSITORY git@mycompany.com:git/projB.git
  GIT_TAG        4a89dc7e24ff212a7b5167bef7ab079d
)
FetchContent_Declare(
  projC
  GIT_REPOSITORY git@mycompany.com:git/projC.git
  GIT_TAG        4ad4016bd1d8d5412d135cf8ceea1bb9
)
FetchContent_Declare(
  projD
  GIT_REPOSITORY git@mycompany.com:git/projD.git
  GIT_TAG        origin/integrationBranch
)
FetchContent_Declare(
  projE
  GIT_REPOSITORY git@mycompany.com:git/projE.git
  GIT_TAG        v2.3-rc1
)
# Order is important, see notes in the discussion further below
FetchContent_MakeAvailable(projD projB projC)

projB

include(FetchContent)
FetchContent_Declare(
  projD
  GIT_REPOSITORY git@mycompany.com:git/projD.git
  GIT_TAG        20b415f9034bbd2a2e8216e9a5c9e632
)
FetchContent_Declare(
  projE
  GIT_REPOSITORY git@mycompany.com:git/projE.git
  GIT_TAG        68e20f674a48be38d60e129f600faf7d
)
FetchContent_MakeAvailable(projD projE)

projC

include(FetchContent)
FetchContent_Declare(
  projD
  GIT_REPOSITORY git@mycompany.com:git/projD.git
  GIT_TAG        7d9a17ad2c962aa13e2fbb8043fb6b8a
)
FetchContent_MakeAvailable(projD)

A few key points should be noted in the above:

  • projB and projC define different content details for projD, but projA also defines a set of content details for projD. Because projA will define them first, the details from projB and projC will not be used. The override details defined by projA are not required to match either of those from projB or projC, but it is up to the higher level project to ensure that the details it does define still make sense for the child projects.
  • In the projA call to FetchContent_MakeAvailable(), projD is listed ahead of projB and projC, so it will be populated before either projB or projC. It isn't required for projA to do this, doing so ensures that projA fully controls the environment in which projD is brought into the build (directory properties are particularly relevant).
  • While projA defines content details for projE, it does not need to explicitly call FetchContent_MakeAvailable(projE) or FetchContent_Populate(projD) itself. Instead, it leaves that to the child projB. For higher level projects, it is often enough to just define the override content details and leave the actual population to the child projects. This saves repeating the same thing at each level of the project hierarchy unnecessarily, but it should only be done if directory properties set by dependencies are not expected to influence the population of the shared dependency (projE in this case).

Projects don't always need to add the populated content to the build. Sometimes the project just wants to make the downloaded content available at a predictable location. The next example ensures that a set of standard company toolchain files (and potentially even the toolchain binaries themselves) is available early enough to be used for that same build.

cmake_minimum_required(VERSION 3.14)
include(FetchContent)
FetchContent_Declare(
  mycom_toolchains
  URL  https://intranet.mycompany.com//toolchains_1.3.2.tar.gz
)
FetchContent_MakeAvailable(mycom_toolchains)
project(CrossCompileExample)

The project could be configured to use one of the downloaded toolchains like so:

cmake -DCMAKE_TOOLCHAIN_FILE=_deps/mycom_toolchains-src/toolchain_arm.cmake /path/to/src

When CMake processes the CMakeLists.txt file, it will download and unpack the tarball into _deps/mycompany_toolchains-src relative to the build directory. The CMAKE_TOOLCHAIN_FILE variable is not used until the project() command is reached, at which point CMake looks for the named toolchain file relative to the build directory. Because the tarball has already been downloaded and unpacked by then, the toolchain file will be in place, even the very first time that cmake is run in the build directory.

This last example demonstrates how one might download and unpack a firmware tarball using CMake's script mode. The call to FetchContent_Populate() specifies all the content details and the unpacked firmware will be placed in a firmware directory below the current working directory.

getFirmware.cmake

# NOTE: Intended to be run in script mode with cmake -P
include(FetchContent)
FetchContent_Populate(
  firmware
  URL        https://mycompany.com/assets/firmware-1.23-arm.tar.gz
  URL_HASH   MD5=68247684da89b608d466253762b0ff11
  SOURCE_DIR firmware
)

This module provides functions intended to be used in Find Modules implementing find_package(<PackageName>) calls.

This command handles the REQUIRED, QUIET and version-related arguments of find_package(). It also sets the <PackageName>_FOUND variable. The package is considered found if all variables listed contain valid results, e.g. valid filepaths.

There are two signatures:

find_package_handle_standard_args(<PackageName>
  (DEFAULT_MSG|<custom-failure-message>)
  <required-var>...
  )
find_package_handle_standard_args(<PackageName>
  [FOUND_VAR <result-var>]
  [REQUIRED_VARS <required-var>...]
  [VERSION_VAR <version-var>]
  [HANDLE_VERSION_RANGE]
  [HANDLE_COMPONENTS]
  [CONFIG_MODE]
  [NAME_MISMATCHED]
  [REASON_FAILURE_MESSAGE <reason-failure-message>]
  [FAIL_MESSAGE <custom-failure-message>]
  )

The <PackageName>_FOUND variable will be set to TRUE if all the variables <required-var>... are valid and any optional constraints are satisfied, and FALSE otherwise. A success or failure message may be displayed based on the results and on whether the REQUIRED and/or QUIET option was given to the find_package() call.

The options are:

(DEFAULT_MSG|<custom-failure-message>)
In the simple signature this specifies the failure message. Use DEFAULT_MSG to ask for a default message to be computed (recommended). Not valid in the full signature.
Deprecated since version 3.3.

Specifies either <PackageName>_FOUND or <PACKAGENAME>_FOUND as the result variable. This exists only for compatibility with older versions of CMake and is now ignored. Result variables of both names are always set for compatibility.

Specify the variables which are required for this package. These may be named in the generated failure message asking the user to set the missing variable values. Therefore these should typically be cache entries such as FOO_LIBRARY and not output variables like FOO_LIBRARIES.

Changed in version 3.18: If HANDLE_COMPONENTS is specified, this option can be omitted.

Specify the name of a variable that holds the version of the package that has been found. This version will be checked against the (potentially) specified required version given to the find_package() call, including its EXACT option. The default messages include information about the required version and the version which has been actually found, both if the version is ok or not.
Added in version 3.19.

Enable handling of a version range, if one is specified. Without this option, a developer warning will be displayed if a version range is specified.

Enable handling of package components. In this case, the command will report which components have been found and which are missing, and the <PackageName>_FOUND variable will be set to FALSE if any of the required components (i.e. not the ones listed after the OPTIONAL_COMPONENTS option of find_package()) are missing.
Specify that the calling find module is a wrapper around a call to find_package(<PackageName> NO_MODULE). This implies a VERSION_VAR value of <PackageName>_VERSION. The command will automatically check whether the package configuration file was found.
Added in version 3.16.

Specify a custom message of the reason for the failure which will be appended to the default generated message.

Specify a custom failure message instead of using the default generated message. Not recommended.
Added in version 3.17.

Indicate that the <PackageName> does not match ${CMAKE_FIND_PACKAGE_NAME}. This is usually a mistake and raises a warning, but it may be intentional for usage of the command for components of a larger package.

Example for the simple signature:

find_package_handle_standard_args(LibXml2 DEFAULT_MSG
  LIBXML2_LIBRARY LIBXML2_INCLUDE_DIR)

The LibXml2 package is considered to be found if both LIBXML2_LIBRARY and LIBXML2_INCLUDE_DIR are valid. Then also LibXml2_FOUND is set to TRUE. If it is not found and REQUIRED was used, it fails with a message(FATAL_ERROR), independent whether QUIET was used or not. If it is found, success will be reported, including the content of the first <required-var>. On repeated CMake runs, the same message will not be printed again.

NOTE:

If <PackageName> does not match CMAKE_FIND_PACKAGE_NAME for the calling module, a warning that there is a mismatch is given. The FPHSA_NAME_MISMATCHED variable may be set to bypass the warning if using the old signature and the NAME_MISMATCHED argument using the new signature. To avoid forcing the caller to require newer versions of CMake for usage, the variable's value will be used if defined when the NAME_MISMATCHED argument is not passed for the new signature (but using both is an error)..

Example for the full signature:

find_package_handle_standard_args(LibArchive
  REQUIRED_VARS LibArchive_LIBRARY LibArchive_INCLUDE_DIR
  VERSION_VAR LibArchive_VERSION)

In this case, the LibArchive package is considered to be found if both LibArchive_LIBRARY and LibArchive_INCLUDE_DIR are valid. Also the version of LibArchive will be checked by using the version contained in LibArchive_VERSION. Since no FAIL_MESSAGE is given, the default messages will be printed.

Another example for the full signature:

find_package(Automoc4 QUIET NO_MODULE HINTS /opt/automoc4)
find_package_handle_standard_args(Automoc4  CONFIG_MODE)

In this case, a FindAutmoc4.cmake module wraps a call to find_package(Automoc4 NO_MODULE) and adds an additional search directory for automoc4. Then the call to find_package_handle_standard_args produces a proper success/failure message.

Added in version 3.19.

Helper function which can be used to check if a <version> is valid against version-related arguments of find_package().

find_package_check_version(<version> <result-var>
  [HANDLE_VERSION_RANGE]
  [RESULT_MESSAGE_VARIABLE <message-var>]
  )

The <result-var> will hold a boolean value giving the result of the check.

The options are:

Enable handling of a version range, if one is specified. Without this option, a developer warning will be displayed if a version range is specified.
Specify a variable to get back a message describing the result of the check.

Example for the usage:

find_package_check_version(1.2.3 result HANDLE_VERSION_RANGE
  RESULT_MESSAGE_VARIABLE reason)
if (result)
  message (STATUS "${reason}")
else()
  message (FATAL_ERROR "${reason}")
endif()

find_package_message(<name> "message for user" "find result details")

This function is intended to be used in FindXXX.cmake modules files. It will print a message once for each unique find result. This is useful for telling the user where a package was found. The first argument specifies the name (XXX) of the package. The second argument specifies the message to display. The third argument lists details about the find result so that if they change the message will be displayed again. The macro also obeys the QUIET argument to the find_package command.

Example:

if(X11_FOUND)
  find_package_message(X11 "Found X11: ${X11_X11_LIB}"
    "[${X11_X11_LIB}][${X11_INCLUDE_DIR}]")
else()
 ...
endif()

Fortran/C Interface Detection

This module automatically detects the API by which C and Fortran languages interact.

Module Variables

Variables that indicate if the mangling is found:

Global subroutines and functions.
Module subroutines and functions (declared by "MODULE PROCEDURE").

This module also provides the following variables to specify the detected mangling, though a typical use case does not need to reference them and can use the Module Functions below.

Prefix for a global symbol without an underscore.
Suffix for a global symbol without an underscore.
The case for a global symbol without an underscore, either UPPER or LOWER.
Prefix for a global symbol with an underscore.
Suffix for a global symbol with an underscore.
The case for a global symbol with an underscore, either UPPER or LOWER.
Prefix for a module symbol without an underscore.
Middle of a module symbol without an underscore that appears between the name of the module and the name of the symbol.
Suffix for a module symbol without an underscore.
The case for a module symbol without an underscore, either UPPER or LOWER.
Prefix for a module symbol with an underscore.
Middle of a module symbol with an underscore that appears between the name of the module and the name of the symbol.
Suffix for a module symbol with an underscore.
The case for a module symbol with an underscore, either UPPER or LOWER.

Module Functions

The FortranCInterface_HEADER function is provided to generate a C header file containing macros to mangle symbol names:
FortranCInterface_HEADER(<file>
                         [MACRO_NAMESPACE <macro-ns>]
                         [SYMBOL_NAMESPACE <ns>]
                         [SYMBOLS [<module>:]<function> ...])

It generates in <file> definitions of the following macros:

#define FortranCInterface_GLOBAL (name,NAME) ...
#define FortranCInterface_GLOBAL_(name,NAME) ...
#define FortranCInterface_MODULE (mod,name, MOD,NAME) ...
#define FortranCInterface_MODULE_(mod,name, MOD,NAME) ...

These macros mangle four categories of Fortran symbols, respectively:

  • Global symbols without '_': call mysub()
  • Global symbols with '_' : call my_sub()
  • Module symbols without '_': use mymod; call mysub()
  • Module symbols with '_' : use mymod; call my_sub()

If mangling for a category is not known, its macro is left undefined. All macros require raw names in both lower case and upper case.

The options are:

Replace the default FortranCInterface_ prefix with a given namespace <macro-ns>.
List symbols to mangle automatically with C preprocessor definitions:
<function>          ==> #define <ns><function> ...
<module>:<function> ==> #define <ns><module>_<function> ...

If the mangling for some symbol is not known then no preprocessor definition is created, and a warning is displayed.

Prefix all preprocessor definitions generated by the SYMBOLS option with a given namespace <ns>.
The FortranCInterface_VERIFY function is provided to verify that the Fortran and C/C++ compilers work together:
FortranCInterface_VERIFY([CXX] [QUIET])

It tests whether a simple test executable using Fortran and C (and C++ when the CXX option is given) compiles and links successfully. The result is stored in the cache entry FortranCInterface_VERIFIED_C (or FortranCInterface_VERIFIED_CXX if CXX is given) as a boolean. If the check fails and QUIET is not given the function terminates with a fatal error message describing the problem. The purpose of this check is to stop a build early for incompatible compiler combinations. The test is built in the Release configuration.

Example Usage

include(FortranCInterface)
FortranCInterface_HEADER(FC.h MACRO_NAMESPACE "FC_")

This creates a "FC.h" header that defines mangling macros FC_GLOBAL(), FC_GLOBAL_(), FC_MODULE(), and FC_MODULE_().

include(FortranCInterface)
FortranCInterface_HEADER(FCMangle.h
                         MACRO_NAMESPACE "FC_"
                         SYMBOL_NAMESPACE "FC_"
                         SYMBOLS mysub mymod:my_sub)

This creates a "FCMangle.h" header that defines the same FC_*() mangling macros as the previous example plus preprocessor symbols FC_mysub and FC_mymod_my_sub.

FortranCInterface is aware of possible GLOBAL and MODULE manglings for many Fortran compilers, but it also provides an interface to specify new possible manglings. Set the variables:

FortranCInterface_GLOBAL_SYMBOLS
FortranCInterface_MODULE_SYMBOLS

before including FortranCInterface to specify manglings of the symbols MySub, My_Sub, MyModule:MySub, and My_Module:My_Sub. For example, the code:

set(FortranCInterface_GLOBAL_SYMBOLS mysub_ my_sub__ MYSUB_)
  #                                  ^^^^^  ^^^^^^   ^^^^^
set(FortranCInterface_MODULE_SYMBOLS
    __mymodule_MOD_mysub __my_module_MOD_my_sub)
  #   ^^^^^^^^     ^^^^^   ^^^^^^^^^     ^^^^^^
include(FortranCInterface)

tells FortranCInterface to try given GLOBAL and MODULE manglings. (The carets point at raw symbol names for clarity in this example but are not needed.)

Function for generation of export macros for libraries

This module provides the function GENERATE_EXPORT_HEADER().

Added in version 3.12: Added support for C projects. Previous versions supported C++ project only.

The GENERATE_EXPORT_HEADER function can be used to generate a file suitable for preprocessor inclusion which contains EXPORT macros to be used in library classes:

GENERATE_EXPORT_HEADER( LIBRARY_TARGET
          [BASE_NAME <base_name>]
          [EXPORT_MACRO_NAME <export_macro_name>]
          [EXPORT_FILE_NAME <export_file_name>]
          [DEPRECATED_MACRO_NAME <deprecated_macro_name>]
          [NO_EXPORT_MACRO_NAME <no_export_macro_name>]
          [INCLUDE_GUARD_NAME <include_guard_name>]
          [STATIC_DEFINE <static_define>]
          [NO_DEPRECATED_MACRO_NAME <no_deprecated_macro_name>]
          [DEFINE_NO_DEPRECATED]
          [PREFIX_NAME <prefix_name>]
          [CUSTOM_CONTENT_FROM_VARIABLE <variable>]
)

The target properties CXX_VISIBILITY_PRESET and VISIBILITY_INLINES_HIDDEN can be used to add the appropriate compile flags for targets. See the documentation of those target properties, and the convenience variables CMAKE_CXX_VISIBILITY_PRESET and CMAKE_VISIBILITY_INLINES_HIDDEN.

By default GENERATE_EXPORT_HEADER() generates macro names in a file name determined by the name of the library. This means that in the simplest case, users of GenerateExportHeader will be equivalent to:

set(CMAKE_CXX_VISIBILITY_PRESET hidden)
set(CMAKE_VISIBILITY_INLINES_HIDDEN 1)
add_library(somelib someclass.cpp)
generate_export_header(somelib)
install(TARGETS somelib DESTINATION ${LIBRARY_INSTALL_DIR})
install(FILES
 someclass.h
 ${PROJECT_BINARY_DIR}/somelib_export.h DESTINATION ${INCLUDE_INSTALL_DIR}
)

And in the ABI header files:

#include "somelib_export.h"
class SOMELIB_EXPORT SomeClass {
  ...
};

The CMake fragment will generate a file in the ${CMAKE_CURRENT_BINARY_DIR} called somelib_export.h containing the macros SOMELIB_EXPORT, SOMELIB_NO_EXPORT, SOMELIB_DEPRECATED, SOMELIB_DEPRECATED_EXPORT and SOMELIB_DEPRECATED_NO_EXPORT. They will be followed by content taken from the variable specified by the CUSTOM_CONTENT_FROM_VARIABLE option, if any. The resulting file should be installed with other headers in the library.

The BASE_NAME argument can be used to override the file name and the names used for the macros:

add_library(somelib someclass.cpp)
generate_export_header(somelib
  BASE_NAME other_name
)

Generates a file called other_name_export.h containing the macros OTHER_NAME_EXPORT, OTHER_NAME_NO_EXPORT and OTHER_NAME_DEPRECATED etc.

The BASE_NAME may be overridden by specifying other options in the function. For example:

add_library(somelib someclass.cpp)
generate_export_header(somelib
  EXPORT_MACRO_NAME OTHER_NAME_EXPORT
)

creates the macro OTHER_NAME_EXPORT instead of SOMELIB_EXPORT, but other macros and the generated file name is as default:

add_library(somelib someclass.cpp)
generate_export_header(somelib
  DEPRECATED_MACRO_NAME KDE_DEPRECATED
)

creates the macro KDE_DEPRECATED instead of SOMELIB_DEPRECATED.

If LIBRARY_TARGET is a static library, macros are defined without values.

If the same sources are used to create both a shared and a static library, the uppercased symbol ${BASE_NAME}_STATIC_DEFINE should be used when building the static library:

add_library(shared_variant SHARED ${lib_SRCS})
add_library(static_variant ${lib_SRCS})
generate_export_header(shared_variant BASE_NAME libshared_and_static)
set_target_properties(static_variant PROPERTIES
  COMPILE_FLAGS -DLIBSHARED_AND_STATIC_STATIC_DEFINE)

This will cause the export macros to expand to nothing when building the static library.

If DEFINE_NO_DEPRECATED is specified, then a macro ${BASE_NAME}_NO_DEPRECATED will be defined This macro can be used to remove deprecated code from preprocessor output:

option(EXCLUDE_DEPRECATED "Exclude deprecated parts of the library" FALSE)
if (EXCLUDE_DEPRECATED)
  set(NO_BUILD_DEPRECATED DEFINE_NO_DEPRECATED)
endif()
generate_export_header(somelib ${NO_BUILD_DEPRECATED})

And then in somelib:

class SOMELIB_EXPORT SomeClass
{
public:
#ifndef SOMELIB_NO_DEPRECATED
  SOMELIB_DEPRECATED void oldMethod();
#endif
};
#ifndef SOMELIB_NO_DEPRECATED
void SomeClass::oldMethod() {  }
#endif

If PREFIX_NAME is specified, the argument will be used as a prefix to all generated macros.

For example:

generate_export_header(somelib PREFIX_NAME VTK_)

Generates the macros VTK_SOMELIB_EXPORT etc.

Added in version 3.1: Library target can be an OBJECT library.

Added in version 3.7: Added the CUSTOM_CONTENT_FROM_VARIABLE option.

Added in version 3.11: Added the INCLUDE_GUARD_NAME option.

ADD_COMPILER_EXPORT_FLAGS( [<output_variable>] )

Deprecated since version 3.0: Set the target properties CXX_VISIBILITY_PRESET and VISIBILITY_INLINES_HIDDEN instead.

The ADD_COMPILER_EXPORT_FLAGS function adds -fvisibility=hidden to CMAKE_CXX_FLAGS if supported, and is a no-op on Windows which does not need extra compiler flags for exporting support. You may optionally pass a single argument to ADD_COMPILER_EXPORT_FLAGS that will be populated with the CXX_FLAGS required to enable visibility support for the compiler/architecture in use.

Define GNU standard installation directories

Provides install directory variables as defined by the GNU Coding Standards.

Result Variables

Inclusion of this module defines the following variables:

CMAKE_INSTALL_<dir>

Destination for files of a given type. This value may be passed to the DESTINATION options of install() commands for the corresponding file type. It should be a path relative to the installation prefix so that it can be converted to an absolute path in a relocatable way.

While absolute paths are allowed, they are not recommended as they do not work with the cmake --install command's --prefix option, or with the cpack installer generators. In particular, there is no need to make paths absolute by prepending CMAKE_INSTALL_PREFIX; this prefix is used by default if the DESTINATION is a relative path.

CMAKE_INSTALL_FULL_<dir>

The absolute path generated from the corresponding CMAKE_INSTALL_<dir> value. If the value is not already an absolute path, an absolute path is constructed typically by prepending the value of the CMAKE_INSTALL_PREFIX variable. However, there are some special cases as documented below.

These variables shouldn't be used in install() commands as they do not work with the cmake --install command's --prefix option, or with the cpack installer generators.

where <dir> is one of:

user executables (bin)
system admin executables (sbin)
program executables (libexec)
read-only single-machine data (etc)
modifiable architecture-independent data (com)
modifiable single-machine data (var)
Added in version 3.9: run-time variable data (LOCALSTATEDIR/run)
object code libraries (lib or lib64)

On Debian, this may be lib/<multiarch-tuple> when CMAKE_INSTALL_PREFIX is /usr.

C header files (include)
C header files for non-gcc (/usr/include)
read-only architecture-independent data root (share)
read-only architecture-independent data (DATAROOTDIR)
info documentation (DATAROOTDIR/info)
locale-dependent data (DATAROOTDIR/locale)
man documentation (DATAROOTDIR/man)
documentation root (DATAROOTDIR/doc/PROJECT_NAME)

If the includer does not define a value the above-shown default will be used and the value will appear in the cache for editing by the user.

Added in version 3.4.

The following values of CMAKE_INSTALL_PREFIX are special:

/

For <dir> other than the SYSCONFDIR, LOCALSTATEDIR and RUNSTATEDIR, the value of CMAKE_INSTALL_<dir> is prefixed with usr/ if it is not user-specified as an absolute path. For example, the INCLUDEDIR value include becomes usr/include. This is required by the GNU Coding Standards, which state:
When building the complete GNU system, the prefix will be empty and /usr will be a symbolic link to /.

/usr

For <dir> equal to SYSCONFDIR, LOCALSTATEDIR or RUNSTATEDIR, the CMAKE_INSTALL_FULL_<dir> is computed by prepending just / to the value of CMAKE_INSTALL_<dir> if it is not user-specified as an absolute path. For example, the SYSCONFDIR value etc becomes /etc. This is required by the GNU Coding Standards.

/opt/...

For <dir> equal to SYSCONFDIR, LOCALSTATEDIR or RUNSTATEDIR, the CMAKE_INSTALL_FULL_<dir> is computed by appending the prefix to the value of CMAKE_INSTALL_<dir> if it is not user-specified as an absolute path. For example, the SYSCONFDIR value etc becomes /etc/opt/.... This is defined by the Filesystem Hierarchy Standard.

This behavior does not apply to paths under /opt/homebrew/....

GNUInstallDirs_get_absolute_install_dir(absvar var dirname)

Added in version 3.7.

Set the given variable absvar to the absolute path contained within the variable var. This is to allow the computation of an absolute path, accounting for all the special cases documented above. While this macro is used to compute the various CMAKE_INSTALL_FULL_<dir> variables, it is exposed publicly to allow users who create additional path variables to also compute absolute paths where necessary, using the same logic. dirname is the directory name to get, e.g. BINDIR.

Changed in version 3.20: Added the <dirname> parameter. Previous versions of CMake passed this value through the variable ${dir}.

Added in version 3.9.

This module defines functions to help use the Google Test infrastructure. Two mechanisms for adding tests are provided. gtest_add_tests() has been around for some time, originally via find_package(GTest). gtest_discover_tests() was introduced in CMake 3.10.

The (older) gtest_add_tests() scans source files to identify tests. This is usually effective, with some caveats, including in cross-compiling environments, and makes setting additional properties on tests more convenient. However, its handling of parameterized tests is less comprehensive, and it requires re-running CMake to detect changes to the list of tests.

The (newer) gtest_discover_tests() discovers tests by asking the compiled test executable to enumerate its tests. This is more robust and provides better handling of parameterized tests, and does not require CMake to be re-run when tests change. However, it may not work in a cross-compiling environment, and setting test properties is less convenient.

More details can be found in the documentation of the respective functions.

Both commands are intended to replace use of add_test() to register tests, and will create a separate CTest test for each Google Test test case. Note that this is in some cases less efficient, as common set-up and tear-down logic cannot be shared by multiple test cases executing in the same instance. However, it provides more fine-grained pass/fail information to CTest, which is usually considered as more beneficial. By default, the CTest test name is the same as the Google Test name (i.e. suite.testcase); see also TEST_PREFIX and TEST_SUFFIX.

Automatically add tests with CTest by scanning source code for Google Test macros:
gtest_add_tests(TARGET target
                [SOURCES src1...]
                [EXTRA_ARGS arg1...]
                [WORKING_DIRECTORY dir]
                [TEST_PREFIX prefix]
                [TEST_SUFFIX suffix]
                [SKIP_DEPENDENCY]
                [TEST_LIST outVar]
)

gtest_add_tests attempts to identify tests by scanning source files. Although this is generally effective, it uses only a basic regular expression match, which can be defeated by atypical test declarations, and is unable to fully "split" parameterized tests. Additionally, it requires that CMake be re-run to discover any newly added, removed or renamed tests (by default, this means that CMake is re-run when any test source file is changed, but see SKIP_DEPENDENCY). However, it has the advantage of declaring tests at CMake time, which somewhat simplifies setting additional properties on tests, and always works in a cross-compiling environment.

The options are:

Specifies the Google Test executable, which must be a known CMake executable target. CMake will substitute the location of the built executable when running the test.
When provided, only the listed files will be scanned for test cases. If this option is not given, the SOURCES property of the specified target will be used to obtain the list of sources.
Any extra arguments to pass on the command line to each test case.
Specifies the directory in which to run the discovered test cases. If this option is not provided, the current binary directory is used.
Specifies a prefix to be prepended to the name of each discovered test case. This can be useful when the same source files are being used in multiple calls to gtest_add_test() but with different EXTRA_ARGS.
Similar to TEST_PREFIX except the suffix is appended to the name of every discovered test case. Both TEST_PREFIX and TEST_SUFFIX may be specified.
Normally, the function creates a dependency which will cause CMake to be re-run if any of the sources being scanned are changed. This is to ensure that the list of discovered tests is updated. If this behavior is not desired (as may be the case while actually writing the test cases), this option can be used to prevent the dependency from being added.
The variable named by outVar will be populated in the calling scope with the list of discovered test cases. This allows the caller to do things like manipulate test properties of the discovered tests.

Usage example:

include(GoogleTest)
add_executable(FooTest FooUnitTest.cxx)
gtest_add_tests(TARGET      FooTest
                TEST_SUFFIX .noArgs
                TEST_LIST   noArgsTests
)
gtest_add_tests(TARGET      FooTest
                EXTRA_ARGS  --someArg someValue
                TEST_SUFFIX .withArgs
                TEST_LIST   withArgsTests
)
set_tests_properties(${noArgsTests}   PROPERTIES TIMEOUT 10)
set_tests_properties(${withArgsTests} PROPERTIES TIMEOUT 20)

For backward compatibility, the following form is also supported:

gtest_add_tests(exe args files...)
The path to the test executable or the name of a CMake target.
A ;-list of extra arguments to be passed to executable. The entire list must be passed as a single argument. Enclose it in quotes, or pass "" for no arguments.
A list of source files to search for tests and test fixtures. Alternatively, use AUTO to specify that exe is the name of a CMake executable target whose sources should be scanned.
include(GoogleTest)
set(FooTestArgs --foo 1 --bar 2)
add_executable(FooTest FooUnitTest.cxx)
gtest_add_tests(FooTest "${FooTestArgs}" AUTO)
Automatically add tests with CTest by querying the compiled test executable for available tests:
gtest_discover_tests(target
                     [EXTRA_ARGS arg1...]
                     [WORKING_DIRECTORY dir]
                     [TEST_PREFIX prefix]
                     [TEST_SUFFIX suffix]
                     [TEST_FILTER expr]
                     [NO_PRETTY_TYPES] [NO_PRETTY_VALUES]
                     [PROPERTIES name1 value1...]
                     [TEST_LIST var]
                     [DISCOVERY_TIMEOUT seconds]
                     [XML_OUTPUT_DIR dir]
                     [DISCOVERY_MODE <POST_BUILD|PRE_TEST>]
)

Added in version 3.10.

gtest_discover_tests() sets up a post-build command on the test executable that generates the list of tests by parsing the output from running the test with the --gtest_list_tests argument. Compared to the source parsing approach of gtest_add_tests(), this ensures that the full list of tests, including instantiations of parameterized tests, is obtained. Since test discovery occurs at build time, it is not necessary to re-run CMake when the list of tests changes. However, it requires that CROSSCOMPILING_EMULATOR is properly set in order to function in a cross-compiling environment.

Additionally, setting properties on tests is somewhat less convenient, since the tests are not available at CMake time. Additional test properties may be assigned to the set of tests as a whole using the PROPERTIES option. If more fine-grained test control is needed, custom content may be provided through an external CTest script using the TEST_INCLUDE_FILES directory property. The set of discovered tests is made accessible to such a script via the <target>_TESTS variable.

The options are:

Specifies the Google Test executable, which must be a known CMake executable target. CMake will substitute the location of the built executable when running the test.
Any extra arguments to pass on the command line to each test case.
Specifies the directory in which to run the discovered test cases. If this option is not provided, the current binary directory is used.
Specifies a prefix to be prepended to the name of each discovered test case. This can be useful when the same test executable is being used in multiple calls to gtest_discover_tests() but with different EXTRA_ARGS.
Similar to TEST_PREFIX except the suffix is appended to the name of every discovered test case. Both TEST_PREFIX and TEST_SUFFIX may be specified.
Added in version 3.22.

Filter expression to pass as a --gtest_filter argument during test discovery. Note that the expression is a wildcard-based format that matches against the original test names as used by gtest. For type or value-parameterized tests, these names may be different to the potentially pretty-printed test names that ctest uses.

By default, the type index of type-parameterized tests is replaced by the actual type name in the CTest test name. If this behavior is undesirable (e.g. because the type names are unwieldy), this option will suppress this behavior.
By default, the value index of value-parameterized tests is replaced by the actual value in the CTest test name. If this behavior is undesirable (e.g. because the value strings are unwieldy), this option will suppress this behavior.
Specifies additional properties to be set on all tests discovered by this invocation of gtest_discover_tests().
Make the list of tests available in the variable var, rather than the default <target>_TESTS. This can be useful when the same test executable is being used in multiple calls to gtest_discover_tests(). Note that this variable is only available in CTest.
Added in version 3.10.3.

Specifies how long (in seconds) CMake will wait for the test to enumerate available tests. If the test takes longer than this, discovery (and your build) will fail. Most test executables will enumerate their tests very quickly, but under some exceptional circumstances, a test may require a longer timeout. The default is 5. See also the TIMEOUT option of execute_process().

NOTE:

In CMake versions 3.10.1 and 3.10.2, this option was called TIMEOUT. This clashed with the TIMEOUT test property, which is one of the common properties that would be set with the PROPERTIES keyword, usually leading to legal but unintended behavior. The keyword was changed to DISCOVERY_TIMEOUT in CMake 3.10.3 to address this problem. The ambiguous behavior of the TIMEOUT keyword in 3.10.1 and 3.10.2 has not been preserved.
Added in version 3.18.

If specified, the parameter is passed along with --gtest_output=xml: to test executable. The actual file name is the same as the test target, including prefix and suffix. This should be used instead of EXTRA_ARGS --gtest_output=xml to avoid race conditions writing the XML result output when using parallel test execution.

Added in version 3.18.

Provides greater control over when gtest_discover_tests() performs test discovery. By default, POST_BUILD sets up a post-build command to perform test discovery at build time. In certain scenarios, like cross-compiling, this POST_BUILD behavior is not desirable. By contrast, PRE_TEST delays test discovery until just prior to test execution. This way test discovery occurs in the target environment where the test has a better chance at finding appropriate runtime dependencies.

DISCOVERY_MODE defaults to the value of the CMAKE_GTEST_DISCOVER_TESTS_DISCOVERY_MODE variable if it is not passed when calling gtest_discover_tests(). This provides a mechanism for globally selecting a preferred test discovery behavior without having to modify each call site.

Include this module to search for compiler-provided system runtime libraries and add install rules for them. Some optional variables may be set prior to including the module to adjust behavior:

Specify additional runtime libraries that may not be detected. After inclusion any detected libraries will be appended to this.
Set to TRUE to skip calling the install(PROGRAMS) command to allow the includer to specify its own install rule, using the value of CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS to get the list of libraries.
Set to TRUE to install the debug runtime libraries when available with MSVC tools.
Set to TRUE to install only the debug runtime libraries with MSVC tools even if the release runtime libraries are also available.
Added in version 3.6.

Set to TRUE to install the Windows Universal CRT libraries for app-local deployment (e.g. to Windows XP). This is meaningful only with MSVC from Visual Studio 2015 or higher.

Added in version 3.9: One may set a CMAKE_WINDOWS_KITS_10_DIR environment variable to an absolute path to tell CMake to look for Windows 10 SDKs in a custom location. The specified directory is expected to contain Redist/ucrt/DLLs/* directories.

Set to TRUE to install the MSVC MFC runtime libraries.
Set to TRUE to install the MSVC OpenMP runtime libraries
Specify the install(PROGRAMS) command DESTINATION option. If not specified, the default is bin on Windows and lib elsewhere.
Set to TRUE to disable warnings about required library files that do not exist. (For example, Visual Studio Express editions may not provide the redistributable files.)
Added in version 3.3.

Specify the install(PROGRAMS) command COMPONENT option. If not specified, no such option will be used.

Added in version 3.10: Support for installing Intel compiler runtimes.

ProcessorCount(var)

Determine the number of processors/cores and save value in ${var}

Sets the variable named ${var} to the number of physical cores available on the machine if the information can be determined. Otherwise it is set to 0. Currently this functionality is implemented for AIX, cygwin, FreeBSD, HPUX, Linux, macOS, QNX, Sun and Windows.

Changed in version 3.15: On Linux, returns the container CPU count instead of the host CPU count.

This function is guaranteed to return a positive integer (>=1) if it succeeds. It returns 0 if there's a problem determining the processor count.

More generally accurate physical CPU count can be obtained via cmake_host_system_information():

cmake_host_system_information(RESULT N
                              QUERY NUMBER_OF_PHYSICAL_CORES)

Example use, in a ctest -S dashboard script:

include(ProcessorCount)
ProcessorCount(N)
if(NOT N EQUAL 0)
  set(CTEST_BUILD_FLAGS -j${N})
  set(ctest_test_args ${ctest_test_args} PARALLEL_LEVEL ${N})
endif()

This function is intended to offer an approximation of the value of the number of compute cores available on the current machine, such that you may use that value for parallel building and parallel testing. It is meant to help utilize as much of the machine as seems reasonable. Of course, knowledge of what else might be running on the machine simultaneously should be used when deciding whether to request a machine's full capacity all for yourself.

select_library_configurations(basename)

This macro takes a library base name as an argument, and will choose good values for the variables

basename_LIBRARY
basename_LIBRARIES
basename_LIBRARY_DEBUG
basename_LIBRARY_RELEASE

depending on what has been found and set.

If only basename_LIBRARY_RELEASE is defined, basename_LIBRARY will be set to the release value, and basename_LIBRARY_DEBUG will be set to basename_LIBRARY_DEBUG-NOTFOUND. If only basename_LIBRARY_DEBUG is defined, then basename_LIBRARY will take the debug value, and basename_LIBRARY_RELEASE will be set to basename_LIBRARY_RELEASE-NOTFOUND.

If the generator supports configuration types, then basename_LIBRARY and basename_LIBRARIES will be set with debug and optimized flags specifying the library to be used for the given configuration. If no build type has been set or the generator in use does not support configuration types, then basename_LIBRARY and basename_LIBRARIES will take only the release value, or the debug value if the release one is not set.

This script launches a GUI test using Squish. You should not call the script directly; instead, you should access it via the SQUISH_ADD_TEST macro that is defined in FindSquish.cmake.

This script starts the Squish server, launches the test on the client, and finally stops the squish server. If any of these steps fail (including if the tests do not pass) then a fatal error is raised.

Check for ANSI for scope support

Check if the compiler restricts the scope of variables declared in a for-init-statement to the loop body.

CMAKE_NO_ANSI_FOR_SCOPE - holds result

Test for compiler support of ANSI stream headers iostream, etc.

check if the compiler supports the standard ANSI iostream header (without the .h)

CMAKE_NO_ANSI_STREAM_HEADERS - defined by the results

Test for compiler support of ANSI sstream header

check if the compiler supports the standard ANSI sstream header

CMAKE_NO_ANSI_STRING_STREAM - defined by the results

Test for std:: namespace support

check if the compiler supports std:: on stl classes

CMAKE_NO_STD_NAMESPACE - defined by the results

This module defines variables and macros required to build eCos application.

This file contains the following macros:

add the eCos include dirs
create an eCos executable
adjusts the path of the source files and puts the result into VAR

Macros for selecting the toolchain:

enable the ARM ELF toolchain for the directory where it is called
enable the i386 ELF toolchain for the directory where it is called
enable the PowerPC toolchain for the directory where it is called

It contains the following variables:

ECOS_DEFINITIONS

ECOSCONFIG_EXECUTABLE

defaults to ecos.ecc, if your eCos configuration file has a different name, adjust this variable for internal use only:
ECOS_ADD_TARGET_LIB

This file provides support for Java. It is assumed that FindJava has already been loaded. See FindJava for information on how to load Java into your CMake project.

Creating and Installing JARS
  add_jar (<target_name> [SOURCES] <source1> [<source2>...] ...)
  install_jar (<target_name> DESTINATION <destination> [COMPONENT <component>])
  install_jni_symlink (<target_name> DESTINATION <destination> [COMPONENT <component>])
Header Generation
  create_javah ((TARGET <target> | GENERATED_FILES <VAR>) CLASSES <class>... ...)
Exporting JAR Targets
  install_jar_exports (TARGETS <jars>... FILE <filename> DESTINATION <destination> ...)
  export_jars (TARGETS <jars>... [NAMESPACE <namespace>] FILE <filename>)
Finding JARs
  find_jar (<VAR> NAMES <name1> [<name2>...] [PATHS <path1> [<path2>... ENV <var>]] ...)
Creating Java Documentation
  create_javadoc (<VAR> (PACKAGES <pkg1> [<pkg2>...] | FILES <file1> [<file2>...]) ...)

Creates a jar file containing java objects and, optionally, resources:
add_jar(<target_name>
        [SOURCES] <source1> [<source2>...] [<resource1>...]
        [RESOURCES NAMESPACE <ns1> <resource1>... [NAMESPACE <nsX> <resourceX>...]... ]
        [INCLUDE_JARS <jar1> [<jar2>...]]
        [ENTRY_POINT <entry>]
        [VERSION <version>]
        [MANIFEST <manifest>]
        [OUTPUT_NAME <name>]
        [OUTPUT_DIR <dir>]
        [GENERATE_NATIVE_HEADERS <target>
                                 [DESTINATION (<dir>|INSTALL <dir> [BUILD <dir>])]]
        )

This command creates a <target_name>.jar. It compiles the given <source> files and adds the given <resource> files to the jar file. Source files can be java files or listing files (prefixed by @). If only resource files are given then just a jar file is created.

Compiles the specified source files and adds the result in the jar file.

Added in version 3.4: Support for response files, prefixed by @.

Added in version 3.21.

Adds the named <resource> files to the jar by stripping the source file path and placing the file beneath <ns> within the jar.

For example:

RESOURCES NAMESPACE "/com/my/namespace" "a/path/to/resource.txt"

results in a resource accessible via /com/my/namespace/resource.txt within the jar.

Resources may be added without adjusting the namespace by adding them to the list of SOURCES (original behavior), in this case, resource paths must be relative to CMAKE_CURRENT_SOURCE_DIR. Adding resources without using the RESOURCES parameter in out of source builds will almost certainly result in confusion.

NOTE:

Adding resources via the SOURCES parameter relies upon a hard-coded list of file extensions which are tested to determine whether they compile (e.g. File.java). SOURCES files which match the extensions are compiled. Files which do not match are treated as resources. To include uncompiled resources matching those file extensions use the RESOURCES parameter.
The list of jars are added to the classpath when compiling the java sources and also to the dependencies of the target. INCLUDE_JARS also accepts other target names created by add_jar(). For backwards compatibility, jar files listed as sources are ignored (as they have been since the first version of this module).
Defines an entry point in the jar file.
Adds a version to the target output name.

The following example will create a jar file with the name shibboleet-1.2.0.jar and will create a symlink shibboleet.jar pointing to the jar with the version information.

add_jar(shibboleet shibbotleet.java VERSION 1.2.0)
Defines a custom manifest for the jar.
Specify a different output name for the target.
Sets the directory where the jar file will be generated. If not specified, CMAKE_CURRENT_BINARY_DIR is used as the output directory.
Added in version 3.11.

Generates native header files for methods declared as native. These files provide the connective glue that allow your Java and C code to interact. An INTERFACE target will be created for an easy usage of generated files. Sub-option DESTINATION can be used to specify the output directory for generated header files.

This option requires, at least, version 1.8 of the JDK.

For an optimum usage of this option, it is recommended to include module JNI before any call to add_jar(). The produced target for native headers can then be used to compile C/C++ sources with the target_link_libraries() command.

find_package(JNI)
add_jar(foo foo.java GENERATE_NATIVE_HEADERS foo-native)
add_library(bar bar.cpp)
target_link_libraries(bar PRIVATE foo-native)

Added in version 3.20: DESTINATION sub-option now supports the possibility to specify different output directories for BUILD and INSTALL steps. If BUILD directory is not specified, a default directory will be used.

To export the interface target generated by GENERATE_NATIVE_HEADERS option, sub-option INSTALL of DESTINATION is required:

add_jar(foo foo.java GENERATE_NATIVE_HEADERS foo-native
                     DESTINATION INSTALL include)
install(TARGETS foo-native EXPORT native)
install(DIRECTORY "$<TARGET_PROPERTY:foo-native,NATIVE_HEADERS_DIRECTORY>/"
        DESTINATION include)
install(EXPORT native DESTINATION /to/export NAMESPACE foo)

Some variables can be set to customize the behavior of add_jar() as well as the java compiler:

Specify additional flags to java compiler.
Specify additional paths to the class path.
If the target is a JNI library, sets this boolean variable to TRUE to enable creation of a JNI symbolic link (see also install_jni_symlink()).
If multiple jars should be produced from the same java source filetree, to prevent the accumulation of duplicate class files in subsequent jars, set/reset CMAKE_JAR_CLASSES_PREFIX prior to calling the add_jar():
set(CMAKE_JAR_CLASSES_PREFIX com/redhat/foo)
add_jar(foo foo.java)
set(CMAKE_JAR_CLASSES_PREFIX com/redhat/bar)
add_jar(bar bar.java)

The add_jar() function sets the following target properties on <target_name>:

The files which should be installed. This is used by install_jar().
The JNI symlink which should be installed. This is used by install_jni_symlink().
The location of the jar file so that you can include it.
The directory where the class files can be found. For example to use them with javah.
Added in version 3.20.

The directory where native headers are generated. Defined when option GENERATE_NATIVE_HEADERS is specified.

This command installs the jar file to the given destination:
install_jar(<target_name> <destination>)
install_jar(<target_name> DESTINATION <destination> [COMPONENT <component>])

This command installs the <target_name> file to the given <destination>. It should be called in the same scope as add_jar() or it will fail.

Added in version 3.4: The second signature with DESTINATION and COMPONENT options.

Specify the directory on disk to which a file will be installed.
Specify an installation component name with which the install rule is associated, such as "runtime" or "development".

The install_jar() command sets the following target properties on <target_name>:

Holds the <destination> as described above, and is used by install_jar_exports().
Installs JNI symlinks for target generated by add_jar():
install_jni_symlink(<target_name> <destination>)
install_jni_symlink(<target_name> DESTINATION <destination> [COMPONENT <component>])

This command installs the <target_name> JNI symlinks to the given <destination>. It should be called in the same scope as add_jar() or it will fail.

Added in version 3.4: The second signature with DESTINATION and COMPONENT options.

Specify the directory on disk to which a file will be installed.
Specify an installation component name with which the install rule is associated, such as "runtime" or "development".

Utilize the following commands to create a JNI symbolic link:

set(CMAKE_JNI_TARGET TRUE)
add_jar(shibboleet shibbotleet.java VERSION 1.2.0)
install_jar(shibboleet ${LIB_INSTALL_DIR}/shibboleet)
install_jni_symlink(shibboleet ${JAVA_LIB_INSTALL_DIR})

Added in version 3.4.

Generates C header files for java classes:

create_javah(TARGET <target> | GENERATED_FILES <VAR>
             CLASSES <class>...
             [CLASSPATH <classpath>...]
             [DEPENDS <depend>...]
             [OUTPUT_NAME <path>|OUTPUT_DIR <path>]
             )

Deprecated since version 3.11: This command will no longer be supported starting with version 10 of the JDK due to the suppression of javah tool. The add_jar(GENERATE_NATIVE_HEADERS) command should be used instead.

Create C header files from java classes. These files provide the connective glue that allow your Java and C code to interact.

There are two main signatures for create_javah(). The first signature returns generated files through variable specified by the GENERATED_FILES option. For example:

create_javah(GENERATED_FILES files_headers
  CLASSES org.cmake.HelloWorld
  CLASSPATH hello.jar
)

The second signature for create_javah() creates a target which encapsulates header files generation. E.g.

create_javah(TARGET target_headers
  CLASSES org.cmake.HelloWorld
  CLASSPATH hello.jar
)

Both signatures share same options.

Specifies Java classes used to generate headers.
Specifies various paths to look up classes. Here .class files, jar files or targets created by command add_jar can be used.
Targets on which the javah target depends.
Concatenates the resulting header files for all the classes listed by option CLASSES into <path>. Same behavior as option -o of javah tool.
Sets the directory where the header files will be generated. Same behavior as option -d of javah tool. If not specified, CMAKE_CURRENT_BINARY_DIR is used as the output directory.

Added in version 3.7.

Installs a target export file:

install_jar_exports(TARGETS <jars>...
                    [NAMESPACE <namespace>]
                    FILE <filename>
                    DESTINATION <destination> [COMPONENT <component>])

This command installs a target export file <filename> for the named jar targets to the given <destination> directory. Its function is similar to that of install(EXPORT).

List of targets created by add_jar() command.
Added in version 3.9.

The <namespace> value will be prepend to the target names as they are written to the import file.

Specify name of the export file.
Specify the directory on disk to which a file will be installed.
Specify an installation component name with which the install rule is associated, such as "runtime" or "development".
Added in version 3.7.

Writes a target export file:

export_jars(TARGETS <jars>...
            [NAMESPACE <namespace>]
            FILE <filename>)

This command writes a target export file <filename> for the named <jars> targets. Its function is similar to that of export().

List of targets created by add_jar() command.
Added in version 3.9.

The <namespace> value will be prepend to the target names as they are written to the import file.

Specify name of the export file.

Finds the specified jar file:
find_jar(<VAR>
         <name> | NAMES <name1> [<name2>...]
         [PATHS <path1> [<path2>... ENV <var>]]
         [VERSIONS <version1> [<version2>]]
         [DOC "cache documentation string"]
        )

This command is used to find a full path to the named jar. A cache entry named by <VAR> is created to store the result of this command. If the full path to a jar is found the result is stored in the variable and the search will not repeated unless the variable is cleared. If nothing is found, the result will be <VAR>-NOTFOUND, and the search will be attempted again next time find_jar() is invoked with the same variable.

Specify one or more possible names for the jar file.
Specify directories to search in addition to the default locations. The ENV var sub-option reads paths from a system environment variable.
Specify jar versions.
Specify the documentation string for the <VAR> cache entry.

Creates java documentation based on files and packages:
create_javadoc(<VAR>
               (PACKAGES <pkg1> [<pkg2>...] | FILES <file1> [<file2>...])
               [SOURCEPATH <sourcepath>]
               [CLASSPATH <classpath>]
               [INSTALLPATH <install path>]
               [DOCTITLE <the documentation title>]
               [WINDOWTITLE <the title of the document>]
               [AUTHOR (TRUE|FALSE)]
               [USE (TRUE|FALSE)]
               [VERSION (TRUE|FALSE)]
               )

The create_javadoc() command can be used to create java documentation. There are two main signatures for create_javadoc().

The first signature works with package names on a path with source files:

create_javadoc(my_example_doc
               PACKAGES com.example.foo com.example.bar
               SOURCEPATH "${CMAKE_CURRENT_SOURCE_DIR}"
               CLASSPATH ${CMAKE_JAVA_INCLUDE_PATH}
               WINDOWTITLE "My example"
               DOCTITLE "<h1>My example</h1>"
               AUTHOR TRUE
               USE TRUE
               VERSION TRUE
              )

The second signature for create_javadoc() works on a given list of files:

create_javadoc(my_example_doc
               FILES java/A.java java/B.java
               CLASSPATH ${CMAKE_JAVA_INCLUDE_PATH}
               WINDOWTITLE "My example"
               DOCTITLE "<h1>My example</h1>"
               AUTHOR TRUE
               USE TRUE
               VERSION TRUE
              )

Both signatures share most of the options. For more details please read the javadoc manpage.

Specify java packages.
Specify java source files. If relative paths are specified, they are relative to CMAKE_CURRENT_SOURCE_DIR.
Specify the directory where to look for packages. By default, CMAKE_CURRENT_SOURCE_DIR directory is used.
Specify where to find user class files. Same behavior as option -classpath of javadoc tool.
Specify where to install the java documentation. If you specified, the documentation will be installed to ${CMAKE_INSTALL_PREFIX}/share/javadoc/<VAR>.
Specify the title to place near the top of the overview summary file. Same behavior as option -doctitle of javadoc tool.
Specify the title to be placed in the HTML <title> tag. Same behavior as option -windowtitle of javadoc tool.
When value TRUE is specified, includes the @author text in the generated docs. Same behavior as option -author of javadoc tool.
When value TRUE is specified, creates class and package usage pages. Includes one Use page for each documented class and package. Same behavior as option -use of javadoc tool.
When value TRUE is specified, includes the version text in the generated docs. Same behavior as option -version of javadoc tool.

This file provides support for SWIG. It is assumed that FindSWIG module has already been loaded.

The following command is defined for use with SWIG:

Added in version 3.8.

Define swig module with given name and specified language:

swig_add_library(<name>
                 [TYPE <SHARED|MODULE|STATIC|USE_BUILD_SHARED_LIBS>]
                 LANGUAGE <language>
                 [NO_PROXY]
                 [OUTPUT_DIR <directory>]
                 [OUTFILE_DIR <directory>]
                 SOURCES <file>...
                )

Targets created with the swig_add_library command have the same capabilities as targets created with the add_library() command, so those targets can be used with any command expecting a target (e.g. target_link_libraries()).

Changed in version 3.13: This command creates a target with the specified <name> when policy CMP0078 is set to NEW. Otherwise, the legacy behavior will choose a different target name and store it in the SWIG_MODULE_<name>_REAL_NAME variable.

Changed in version 3.15: Alternate library name (set with the OUTPUT_NAME property, for example) will be passed on to Python and CSharp wrapper libraries.

Changed in version 3.21: Generated library use standard naming conventions for CSharp language when policy CMP0122 is set to NEW. Otherwise, the legacy behavior is applied.

NOTE:

For multi-config generators, this module does not support configuration-specific files generated by SWIG. All build configurations must result in the same generated source file.

NOTE:

For Makefile Generators, if, for some sources, the USE_SWIG_DEPENDENCIES property is FALSE, swig_add_library does not track file dependencies, so depending on the <name>_swig_compilation custom target is required for targets which require the swig-generated files to exist. Other generators may depend on the source files that would be generated by SWIG.
SHARED, MODULE and STATIC have the same semantic as for the add_library() command. If USE_BUILD_SHARED_LIBS is specified, the library type will be STATIC or SHARED based on whether the current value of the BUILD_SHARED_LIBS variable is ON. If no type is specified, MODULE will be used.
Specify the target language.

Added in version 3.1: Go and Lua language support.

Added in version 3.2: R language support.

Added in version 3.18: Fortran language support.

Added in version 3.12.

Prevent the generation of the wrapper layer (swig -noproxy option).

Added in version 3.12.

Specify where to write the language specific files (swig -outdir option). If not given, the CMAKE_SWIG_OUTDIR variable will be used. If neither is specified, the default depends on the value of the UseSWIG_MODULE_VERSION variable as follows:

  • If UseSWIG_MODULE_VERSION is 1 or is undefined, output is written to the CMAKE_CURRENT_BINARY_DIR directory.
  • If UseSWIG_MODULE_VERSION is 2, a dedicated directory will be used. The path of this directory can be retrieved from the SWIG_SUPPORT_FILES_DIRECTORY target property.
Added in version 3.12.

Specify an output directory name where the generated source file will be placed (swig -o option). If not specified, the SWIG_OUTFILE_DIR variable will be used. If neither is specified, OUTPUT_DIR or CMAKE_SWIG_OUTDIR is used instead.

List of sources for the library. Files with extension .i will be identified as sources for the SWIG tool. Other files will be handled in the standard way.

Added in version 3.14: This behavior can be overridden by specifying the variable SWIG_SOURCE_FILE_EXTENSIONS.

NOTE:

If UseSWIG_MODULE_VERSION is set to 2, it is strongly recommended to use a dedicated directory unique to the target when either the OUTPUT_DIR option or the CMAKE_SWIG_OUTDIR variable are specified. The output directory contents are erased as part of the target build, so to prevent interference between targets or losing other important files, each target should have its own dedicated output directory.

Source file properties on module files must be set before the invocation of the swig_add_library command to specify special behavior of SWIG and ensure generated files will receive the required settings.

Call SWIG in c++ mode. For example:
set_property(SOURCE mymod.i PROPERTY CPLUSPLUS ON)
swig_add_library(mymod LANGUAGE python SOURCES mymod.i)
Deprecated since version 3.12: Replaced with the fine-grained properties that follow.

Pass custom flags to the SWIG executable.

Added in version 3.12.

Add custom flags to SWIG compiler and have same semantic as properties INCLUDE_DIRECTORIES, COMPILE_DEFINITIONS and COMPILE_OPTIONS.

Added in version 3.13.

If set to TRUE, contents of target property INCLUDE_DIRECTORIES will be forwarded to SWIG compiler. If set to FALSE target property INCLUDE_DIRECTORIES will be ignored. If not set, target property SWIG_USE_TARGET_INCLUDE_DIRECTORIES will be considered.

Added in version 3.12.

Add custom flags to the C/C++ generated source. They will fill, respectively, properties INCLUDE_DIRECTORIES, COMPILE_DEFINITIONS and COMPILE_OPTIONS of generated C/C++ file.

Added in version 3.12.

Specify additional dependencies to the source file.

Added in version 3.20.

If set to TRUE, implicit dependencies are generated by the swig tool itself. This property is only meaningful for Makefile, Ninja, Xcode, and Visual Studio (Visual Studio 12 2013 and above) generators. Default value is FALSE.

Added in version 3.21: Added the support of Xcode generator.

Added in version 3.22: Added the support of Visual Studio Generators.

Specify the actual import name of the module in the target language. This is required if it cannot be scanned automatically from source or different from the module file basename. For example:
set_property(SOURCE mymod.i PROPERTY SWIG_MODULE_NAME mymod_realname)

Changed in version 3.14: If policy CMP0086 is set to NEW, -module <module_name> is passed to SWIG compiler.

Added in version 3.19.

Specify where to write the language specific files (swig -outdir option) for the considered source file. If not specified, the other ways to define the output directory applies (see OUTPUT_DIR option of swig_add_library() command).

Added in version 3.19.

Specify an output directory where the generated source file will be placed (swig -o option) for the considered source file. If not specified, OUTPUT_DIR source property will be used. If neither are specified, the other ways to define output file directory applies (see OUTFILE_DIR option of swig_add_library() command).

Target library properties can be set to apply same configuration to all SWIG input files.

Added in version 3.12.

These properties will be applied to all SWIG input files and have same semantic as target properties INCLUDE_DIRECTORIES, COMPILE_DEFINITIONS and COMPILE_OPTIONS.

set (UseSWIG_TARGET_NAME_PREFERENCE STANDARD)
swig_add_library(mymod LANGUAGE python SOURCES mymod.i)
set_property(TARGET mymod PROPERTY SWIG_COMPILE_DEFINITIONS MY_DEF1 MY_DEF2)
set_property(TARGET mymod PROPERTY SWIG_COMPILE_OPTIONS -bla -blb)
Added in version 3.13.

If set to TRUE, contents of target property INCLUDE_DIRECTORIES will be forwarded to SWIG compiler. If set to FALSE or not defined, target property INCLUDE_DIRECTORIES will be ignored. This behavior can be overridden by specifying source property USE_TARGET_INCLUDE_DIRECTORIES.

Added in version 3.12.

These properties will populate, respectively, properties INCLUDE_DIRECTORIES, COMPILE_DEFINITIONS and COMPILE_FLAGS of all generated C/C++ files.

Added in version 3.12.

Add dependencies to all SWIG input files.

The following target properties are output properties and can be used to get information about support files generated by SWIG interface compilation.

Added in version 3.12.

This output property list of wrapper files generated during SWIG compilation.

set (UseSWIG_TARGET_NAME_PREFERENCE STANDARD)
swig_add_library(mymod LANGUAGE python SOURCES mymod.i)
get_property(support_files TARGET mymod PROPERTY SWIG_SUPPORT_FILES)

NOTE:

Only most principal support files are listed. In case some advanced features of SWIG are used (for example %template), associated support files may not be listed. Prefer to use the SWIG_SUPPORT_FILES_DIRECTORY property to handle support files.
Added in version 3.12.

This output property specifies the directory where support files will be generated.

NOTE:

When source property OUTPUT_DIR is defined, multiple directories can be specified as part of SWIG_SUPPORT_FILES_DIRECTORY.

Some variables can be set to customize the behavior of swig_add_library as well as SWIG:

Added in version 3.12.

Specify different behaviors for UseSWIG module.

  • Set to 1 or undefined: Legacy behavior is applied.
  • Set to 2: A new strategy is applied regarding support files: the output directory of support files is erased before SWIG interface compilation.
Add flags to all swig calls.
Specify where to write the language specific files (swig -outdir option).
Added in version 3.8.

Specify an output directory name where the generated source file will be placed. If not specified, CMAKE_SWIG_OUTDIR is used.

Specify extra dependencies for the generated module for <name>.
Added in version 3.14.

Specify a list of source file extensions to override the default behavior of considering only .i files as sources for the SWIG tool. For example:

set(SWIG_SOURCE_FILE_EXTENSIONS ".i" ".swg")
Added in version 3.20.

If set to TRUE, implicit dependencies are generated by the swig tool itself. This variable is only meaningful for Makefile, Ninja, Xcode, and Visual Studio (Visual Studio 12 2013 and above) generators. Default value is FALSE.

Source file property USE_SWIG_DEPENDENCIES, if not defined, will be initialized with the value of this variable.

Added in version 3.21: Added the support of Xcode generator.

Added in version 3.22: Added the support of Visual Studio Generators.

Deprecated since version 3.13: Use target_link_libraries() with the standard target name, or with ${SWIG_MODULE_<name>_REAL_NAME} for legacy target naming.

Link libraries to swig module:

swig_link_libraries(<name> <item>...)

This command has same capabilities as target_link_libraries() command.

NOTE:

When policy CMP0078 is set to NEW, swig_add_library() creates a standard target with the specified <name> and target_link_libraries() must be used instead of this command.

With the legacy behavior (when CMP0078 is set to OLD and the UseSWIG_TARGET_NAME_PREFERENCE variable is set to "LEGACY", or in CMake versions prior to 3.12), it is preferable to use target_link_libraries(${SWIG_MODULE_<name>_REAL_NAME} ...) instead of this command.

Convenience include for using wxWidgets library.

Determines if wxWidgets was FOUND and sets the appropriate libs, incdirs, flags, etc. INCLUDE_DIRECTORIES and LINK_DIRECTORIES are called.

USAGE

# Note that for MinGW users the order of libs is important!
find_package(wxWidgets REQUIRED net gl core base)
include(${wxWidgets_USE_FILE})
# and for each of your dependent executable/library targets:
target_link_libraries(<YourTarget> ${wxWidgets_LIBRARIES})

DEPRECATED

LINK_LIBRARIES is not called in favor of adding dependencies per target.

AUTHOR

Jan Woetzel <jw -at- mip.informatik.uni-kiel.de>

These modules search for third-party software. They are normally called through the find_package() command.

Find Advanced Linux Sound Architecture (ALSA)

Find the alsa libraries (asound)

IMPORTED Targets

Added in version 3.12.

This module defines IMPORTED target ALSA::ALSA, if ALSA has been found.

Result Variables

This module defines the following variables:

True if ALSA_INCLUDE_DIR & ALSA_LIBRARY are found
List of libraries when using ALSA.
Where to find the ALSA headers.

Cache variables

The following cache variables may also be set:

the ALSA include directory
the absolute path of the asound library

Find the Armadillo C++ library. Armadillo is a library for linear algebra & scientific computing.

Added in version 3.18: Support for linking wrapped libraries directly (ARMA_DONT_USE_WRAPPER).

Using Armadillo:

find_package(Armadillo REQUIRED)
include_directories(${ARMADILLO_INCLUDE_DIRS})
add_executable(foo foo.cc)
target_link_libraries(foo ${ARMADILLO_LIBRARIES})

This module sets the following variables:

ARMADILLO_FOUND - set to true if the library is found
ARMADILLO_INCLUDE_DIRS - list of required include directories
ARMADILLO_LIBRARIES - list of libraries to be linked
ARMADILLO_VERSION_MAJOR - major version number
ARMADILLO_VERSION_MINOR - minor version number
ARMADILLO_VERSION_PATCH - patch version number
ARMADILLO_VERSION_STRING - version number as a string (ex: "1.0.4")
ARMADILLO_VERSION_NAME - name of the version (ex: "Antipodean Antileech")

Try to find ASPELL

Once done this will define

ASPELL_FOUND - system has ASPELL
ASPELL_EXECUTABLE - the ASPELL executable
ASPELL_INCLUDE_DIR - the ASPELL include directory
ASPELL_LIBRARIES - The libraries needed to use ASPELL
ASPELL_DEFINITIONS - Compiler switches required for using ASPELL

Locate AVIFILE library and include paths

AVIFILE (https://avifile.sourceforge.net/) is a set of libraries for i386 machines to use various AVI codecs. Support is limited beyond Linux. Windows provides native AVI support, and so doesn't need this library. This module defines

AVIFILE_INCLUDE_DIR, where to find avifile.h , etc.
AVIFILE_LIBRARIES, the libraries to link against
AVIFILE_DEFINITIONS, definitions to use when compiling
AVIFILE_FOUND, If false, don't try to use AVIFILE

Find provider for backtrace(3).

Checks if OS supports backtrace(3) via either libc or custom library. This module defines the following variables:

The header file needed for backtrace(3). Cached. Could be forcibly set by user.
The include directories needed to use backtrace(3) header.
The libraries (linker flags) needed to use backtrace(3), if any.
Is set if and only if backtrace(3) support detected.

The following cache variables are also available to set or use:

The external library providing backtrace, if any.
The directory holding the backtrace(3) header.

Typical usage is to generate of header file using configure_file() with the contents like the following:

#cmakedefine01 Backtrace_FOUND
#if Backtrace_FOUND
# include <${Backtrace_HEADER}>
#endif

And then reference that generated header file in actual source.

Imported Targets

Added in version 3.30.

This module defines the following IMPORTED targets:

An interface library providing usage requirements for the found components.

Find bison executable and provide a macro to generate custom build rules.

The module defines the following variables:

path to the bison program
version of bison
"True" if the program was found

The minimum required version of bison can be specified using the standard CMake syntax, e.g. find_package(BISON 2.1.3).

If bison is found, the module defines the macro:

BISON_TARGET(<Name> <YaccInput> <CodeOutput>
             [COMPILE_FLAGS <flags>]
             [DEFINES_FILE <file>]
             [VERBOSE [<file>]]
             [REPORT_FILE <file>]
             )

which will create a custom rule to generate a parser. <YaccInput> is the path to a yacc file. <CodeOutput> is the name of the source file generated by bison. A header file is also be generated, and contains the token list.

Changed in version 3.14: When CMP0088 is set to NEW, bison runs in the CMAKE_CURRENT_BINARY_DIR directory.

The options are:

Specify flags to be added to the bison command line.
Added in version 3.4.

Specify a non-default header <file> to be generated by bison.

Tell bison to write a report file of the grammar and parser.

Deprecated since version 3.7: If <file> is given, it specifies path the report file is copied to. [<file>] is left for backward compatibility of this module. Use VERBOSE REPORT_FILE <file>.

Added in version 3.7.

Specify a non-default report <file>, if generated.

The macro defines the following variables:

True is the macro ran successfully
The input source file, an alias for <YaccInput>
The source file generated by bison
The header file generated by bison
All files generated by bison including the source, the header and the report
Options used in the bison command line

Example usage:

find_package(BISON)
BISON_TARGET(MyParser parser.y ${CMAKE_CURRENT_BINARY_DIR}/parser.cpp
             DEFINES_FILE ${CMAKE_CURRENT_BINARY_DIR}/parser.h)
add_executable(Foo main.cpp ${BISON_MyParser_OUTPUTS})

Find Basic Linear Algebra Subprograms (BLAS) library

This module finds an installed Fortran library that implements the BLAS linear-algebra interface.

At least one of the C, CXX, or Fortran languages must be enabled.

Input Variables

The following variables may be set to influence this module's behavior:

if ON use static linkage
Set to one of the BLAS/LAPACK Vendors to search for BLAS only from the specified vendor. If not set, all vendors are considered.
if ON tries to find the BLAS95 interfaces
Added in version 3.11.

if set pkg-config will be used to search for a BLAS library first and if one is found that is preferred

Added in version 3.25.

If set, the pkg-config method will look for this module name instead of just blas.

Added in version 3.22.

Specify the BLAS/LAPACK library integer size:

4
Search for a BLAS/LAPACK with 32-bit integer interfaces.
8
Search for a BLAS/LAPACK with 64-bit integer interfaces.
Search for any BLAS/LAPACK. Most likely, a BLAS/LAPACK with 32-bit integer interfaces will be found.

Imported targets

This module defines the following IMPORTED targets:

Added in version 3.18.

The libraries to use for BLAS, if found.

Result Variables

This module defines the following variables:

library implementing the BLAS interface is found
uncached list of required linker flags (excluding -l and -L).
uncached list of libraries (using full path name) to link against to use BLAS (may be empty if compiler implicitly links BLAS)
uncached list of libraries (using full path name) to link against to use BLAS95 interface
library implementing the BLAS95 interface is found

Generic reference implementation
AMD Core Math Library
Added in version 3.27.

AMD Optimizing CPU Libraries

Apple BLAS (Accelerate), and Apple NAS (vecLib)
Added in version 3.18.

Arm Performance Libraries

Automatically Tuned Linear Algebra Software
Compaq/Digital Extended Math Library
Added in version 3.20.

Elbrus Math Library

Added in version 3.11.

BLIS Framework

Added in version 3.19.
Added in version 3.20.

Fujitsu SSL2 serial and parallel blas/lapack with SVE instructions

GotoBLAS

IBMESSL, IBMESSL_SMP

IBM Engineering and Scientific Subroutine Library
Intel MKL 32 bit and 64 bit obsolete versions
Intel MKL v10 32 bit, threaded code
Intel MKL v10+ 64 bit, threaded code, lp64 model
Intel MKL v10+ 64 bit, sequential code, lp64 model
Added in version 3.13.

Intel MKL v10+ 64 bit, threaded code, ilp64 model

Added in version 3.13.

Intel MKL v10+ 64 bit, sequential code, ilp64 model

Added in version 3.17.

Intel MKL v10+ 64 bit, single dynamic library

Added in version 3.30.

A BLAS/LAPACK demuxing library using PLT trampolines

Added in version 3.21.

NVIDIA HPC SDK

Added in version 3.6.
Portable High Performance ANSI C (PHiPAC)
Scientific Computing Software Library
SGI Scientific Mathematical Library
Sun Performance Library

Intel MKL

To use the Intel MKL implementation of BLAS, a project must enable at least one of the C or CXX languages. Set BLA_VENDOR to an Intel MKL variant either on the command-line as -DBLA_VENDOR=Intel10_64lp or in project code:

set(BLA_VENDOR Intel10_64lp)
find_package(BLAS)

In order to build a project using Intel MKL, and end user must first establish an Intel MKL environment:

Source the full Intel environment script:
. /opt/intel/oneapi/setvars.sh

Or, source the MKL component environment script:

. /opt/intel/oneapi/mkl/latest/env/vars.sh
Source the full Intel environment script:
. /opt/intel/bin/compilervars.sh intel64

Or, source the MKL component environment script:

. /opt/intel/mkl/bin/mklvars.sh intel64

The above environment scripts set the MKLROOT environment variable to the top of the MKL installation. They also add the location of the runtime libraries to the dynamic library loader environment variable for your platform (e.g. LD_LIBRARY_PATH). This is necessary for programs linked against MKL to run.

NOTE:

As of Intel oneAPI 2021.2, loading only the MKL component does not make all of its dependencies available. In particular, the iomp5 library must be available separately, or provided by also loading the compiler component environment:
. /opt/intel/oneapi/compiler/latest/env/vars.sh

Try to find the Bullet physics engine

This module defines the following variables
BULLET_FOUND - Was bullet found
BULLET_INCLUDE_DIRS - the Bullet include directories
BULLET_LIBRARIES - Link to this, by default it includes
                   all bullet components (Dynamics,
                   Collision, LinearMath, & SoftBody)
This module accepts the following variables
BULLET_ROOT - Can be set to bullet install path or Windows build path

Try to find BZip2

IMPORTED Targets

Added in version 3.12.

This module defines IMPORTED target BZip2::BZip2, if BZip2 has been found.

Result Variables

This module defines the following variables:

system has BZip2
Added in version 3.12: the BZip2 include directories
Link these to use BZip2
this is set if the functions are prefixed with BZ2_
Added in version 3.26: the version of BZip2 found.

See also legacy variable BZIP2_VERSION_STRING.

Cache variables

The following cache variables may also be set:

the BZip2 include directory

Legacy Variables

The following variables are provided for backward compatibility:

the version of BZip2 found.

Changed in version 3.26: Superseded by BZIP2_VERSION.

Find CABLE

This module finds if CABLE is installed and determines where the include files and libraries are. This code sets the following variables:

CABLE             the path to the cable executable
CABLE_TCL_LIBRARY the path to the Tcl wrapper library
CABLE_INCLUDE_DIR the path to the include directory

To build Tcl wrappers, you should add shared library and link it to ${CABLE_TCL_LIBRARY}. You should also add ${CABLE_INCLUDE_DIR} as an include directory.

Find Coin3D (Open Inventor)

Coin3D is an implementation of the Open Inventor API. It provides data structures and algorithms for 3D visualization.

This module defines the following variables

COIN3D_FOUND         - system has Coin3D - Open Inventor
COIN3D_INCLUDE_DIRS  - where the Inventor include directory can be found
COIN3D_LIBRARIES     - Link to this to use Coin3D

Added in version 3.17.

This script locates the NVIDIA CUDA toolkit and the associated libraries, but does not require the CUDA language be enabled for a given project. This module does not search for the NVIDIA CUDA Samples.

Added in version 3.19: QNX support.

The CUDA Toolkit search behavior uses the following order:

1.
If the CUDA language has been enabled we will use the directory containing the compiler as the first search location for nvcc.
2.
If the variable CMAKE_CUDA_COMPILER or the environment variable CUDACXX is defined, it will be used as the path to the nvcc executable.
3.
If the CUDAToolkit_ROOT cmake configuration variable (e.g., -DCUDAToolkit_ROOT=/some/path) or environment variable is defined, it will be searched. If both an environment variable and a configuration variable are specified, the configuration variable takes precedence.

The directory specified here must be such that the executable nvcc or the appropriate version.txt or version.json file can be found underneath the specified directory.

4.
If the CUDA_PATH environment variable is defined, it will be searched for nvcc.
5.
The user's path is searched for nvcc using find_program(). If this is found, no subsequent search attempts are performed. Users are responsible for ensuring that the first nvcc to show up in the path is the desired path in the event that multiple CUDA Toolkits are installed.
6.
On Unix systems, if the symbolic link /usr/local/cuda exists, this is used. No subsequent search attempts are performed. No default symbolic link location exists for the Windows platform.
7.
The platform specific default install locations are searched. If exactly one candidate is found, this is used. The default CUDA Toolkit install locations searched are:
Platform Search Pattern
macOS /Developer/NVIDIA/CUDA-X.Y
Other Unix /usr/local/cuda-X.Y
Windows C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\vX.Y

Where X.Y would be a specific version of the CUDA Toolkit, such as /usr/local/cuda-9.0 or C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0

NOTE:

When multiple CUDA Toolkits are installed in the default location of a system (e.g., both /usr/local/cuda-9.0 and /usr/local/cuda-10.0 exist but the /usr/local/cuda symbolic link does not exist), this package is marked as not found.

There are too many factors involved in making an automatic decision in the presence of multiple CUDA Toolkits being installed. In this situation, users are encouraged to either (1) set CUDAToolkit_ROOT or (2) ensure that the correct nvcc executable shows up in $PATH for find_program() to find.

[<version>]
The [<version>] argument requests a version with which the package found should be compatible. See find_package version format for more details.

If specified, configuration will error if a suitable CUDA Toolkit is not found.
If specified, the search for a suitable CUDA Toolkit will not produce any messages.
If specified, the CUDA Toolkit is considered found only if the exact VERSION specified is recovered.

Imported targets

An imported target named CUDA::toolkit is provided.

This module defines IMPORTED targets for each of the following libraries that are part of the CUDAToolkit:

  • CUDA Runtime Library
  • CUDA Driver Library
  • cuBLAS
  • cuDLA
  • cuFile
  • cuFFT
  • cuRAND
  • cuSOLVER
  • cuSPARSE
  • cuPTI
  • NPP
  • nvBLAS
  • nvGRAPH
  • nvJPEG
  • nvidia-ML
  • nvPTX Compiler
  • nvRTC
  • nvJitLink
  • nvFatBin
  • nvToolsExt
  • nvtx3
  • OpenCL
  • cuLIBOS

The CUDA Runtime library (cudart) are what most applications will typically need to link against to make any calls such as cudaMalloc, and cudaFree.

Targets Created:

  • CUDA::cudart
  • CUDA::cudart_static

The CUDA Driver library (cuda) are used by applications that use calls such as cuMemAlloc, and cuMemFree.

Targets Created:

CUDA::cuda_driver

The cuBLAS library.

Targets Created:

  • CUDA::cublas
  • CUDA::cublas_static
  • CUDA::cublasLt starting in CUDA 10.1
  • CUDA::cublasLt_static starting in CUDA 10.1

Added in version 3.27.

The NVIDIA Tegra Deep Learning Accelerator cuDLA library.

Targets Created:

CUDA::cudla starting in CUDA 11.6

Added in version 3.25.

The NVIDIA GPUDirect Storage cuFile library.

Targets Created:

  • CUDA::cuFile starting in CUDA 11.4
  • CUDA::cuFile_static starting in CUDA 11.4
  • CUDA::cuFile_rdma starting in CUDA 11.4
  • CUDA::cuFile_rdma_static starting in CUDA 11.4

The cuFFT library.

Targets Created:

  • CUDA::cufft
  • CUDA::cufftw
  • CUDA::cufft_static
  • CUDA::cufft_static_nocallback starting in CUDA 9.2, requires CMake 3.23+
  • CUDA::cufftw_static

The cuRAND library.

Targets Created:

  • CUDA::curand
  • CUDA::curand_static

The cuSOLVER library.

Targets Created:

  • CUDA::cusolver
  • CUDA::cusolver_static

The cuSPARSE library.

Targets Created:

  • CUDA::cusparse
  • CUDA::cusparse_static

The NVIDIA CUDA Profiling Tools Interface.

Targets Created:

  • CUDA::cupti
  • CUDA::cupti_static

Added in version 3.27:

  • CUDA::nvperf_host starting in CUDA 10.2
  • CUDA::nvperf_host_static starting in CUDA 10.2
  • CUDA::nvperf_target starting in CUDA 10.2
  • CUDA::pcsamplingutil starting in CUDA 11.3

The NPP libraries.

Targets Created:

nppc:
  • CUDA::nppc
  • CUDA::nppc_static
nppial: Arithmetic and logical operation functions in nppi_arithmetic_and_logical_operations.h
  • CUDA::nppial
  • CUDA::nppial_static
nppicc: Color conversion and sampling functions in nppi_color_conversion.h
  • CUDA::nppicc
  • CUDA::nppicc_static
nppicom: JPEG compression and decompression functions in nppi_compression_functions.h Removed starting in CUDA 11.0, use nvJPEG instead.
  • CUDA::nppicom
  • CUDA::nppicom_static
nppidei: Data exchange and initialization functions in nppi_data_exchange_and_initialization.h
  • CUDA::nppidei
  • CUDA::nppidei_static
nppif: Filtering and computer vision functions in nppi_filter_functions.h
  • CUDA::nppif
  • CUDA::nppif_static
nppig: Geometry transformation functions found in nppi_geometry_transforms.h
  • CUDA::nppig
  • CUDA::nppig_static
nppim: Morphological operation functions found in nppi_morphological_operations.h
  • CUDA::nppim
  • CUDA::nppim_static
nppist: Statistics and linear transform in nppi_statistics_functions.h and nppi_linear_transforms.h
  • CUDA::nppist
  • CUDA::nppist_static
nppisu: Memory support functions in nppi_support_functions.h
  • CUDA::nppisu
  • CUDA::nppisu_static
nppitc: Threshold and compare operation functions in nppi_threshold_and_compare_operations.h
  • CUDA::nppitc
  • CUDA::nppitc_static
npps:
  • CUDA::npps
  • CUDA::npps_static

The nvBLAS libraries. This is a shared library only.

Targets Created:

CUDA::nvblas

The nvGRAPH library. Removed starting in CUDA 11.0

Targets Created:

  • CUDA::nvgraph
  • CUDA::nvgraph_static

The nvJPEG library. Introduced in CUDA 10.

Targets Created:

  • CUDA::nvjpeg
  • CUDA::nvjpeg_static

Added in version 3.25.

The nvPTX (PTX Compilation) library. The PTX Compiler APIs are a set of APIs which can be used to compile a PTX program into GPU assembly code. Introduced in CUDA 11.1 This is a static library only.

Targets Created:

CUDA::nvptxcompiler_static starting in CUDA 11.1

The nvRTC (Runtime Compilation) library.

Targets Created:

CUDA::nvrtc

Added in version 3.26:

  • CUDA::nvrtc_builtins
  • CUDA::nvrtc_static starting in CUDA 11.5
  • CUDA::nvrtc_builtins_static starting in CUDA 11.5

The nvJItLink (Runtime LTO Linking) library.

Targets Created:

  • CUDA::nvJitLink starting in CUDA 12.0
  • CUDA::nvJitLink_static starting in CUDA 12.0

Added in version 3.30.

The nvFatBin (Runtime fatbin creation) library.

Targets Created:

  • CUDA::nvfatbin starting in CUDA 12.4
  • CUDA::nvfatbin_static starting in CUDA 12.4

The NVIDIA Management Library. This is a shared library only.

Targets Created:

CUDA::nvml

Deprecated since version 3.25: With CUDA 10.0+, use nvtx3.

The NVIDIA Tools Extension. This is a shared library only.

Targets Created:

CUDA::nvToolsExt

Added in version 3.25.

The header-only NVIDIA Tools Extension Library. Introduced in CUDA 10.0.

Targets created:

CUDA::nvtx3

The NVIDIA OpenCL Library. This is a shared library only.

Targets Created:

CUDA::OpenCL

The cuLIBOS library is a backend thread abstraction layer library which is static only. The CUDA::cublas_static, CUDA::cusparse_static, CUDA::cufft_static, CUDA::curand_static, and (when implemented) NPP libraries all automatically have this dependency linked.

Target Created:

CUDA::culibos

Note: direct usage of this target by consumers should not be necessary.

Result variables

A boolean specifying whether or not the CUDA Toolkit was found.
The exact version of the CUDA Toolkit found (as reported by nvcc --version, version.txt, or version.json).
The major version of the CUDA Toolkit.
The minor version of the CUDA Toolkit.
The patch version of the CUDA Toolkit.
The path to the CUDA Toolkit library directory that contains the CUDA executable nvcc.
List of paths to all the CUDA Toolkit folders containing header files required to compile a project linking against CUDA.
The path to the CUDA Toolkit library directory that contains the CUDA Runtime library cudart.
Added in version 3.18.

The path to the CUDA Toolkit directory containing the nvvm directory and either version.txt or version.json.

The path to the CUDA Toolkit directory including the target architecture when cross-compiling. When not cross-compiling this will be equivalent to the parent directory of CUDAToolkit_BIN_DIR.
The path to the NVIDIA CUDA compiler nvcc. Note that this path may not be the same as CMAKE_CUDA_COMPILER. nvcc must be found to determine the CUDA Toolkit version as well as determining other features of the Toolkit. This variable is set for the convenience of modules that depend on this one.

Find the Common UNIX Printing System (CUPS).

Set CUPS_REQUIRE_IPP_DELETE_ATTRIBUTE to TRUE if you need a version which features this function (i.e. at least 1.1.19)

Imported targets

Added in version 3.15.

This module defines IMPORTED target Cups::Cups, if Cups has been found.

Result variables

This module will set the following variables in your project:

true if CUPS headers and libraries were found
the directory containing the Cups headers
the libraries to link against to use CUPS.
the version of CUPS found (since CMake 2.8.8)

Cache variables

The following cache variables may also be set:

the directory containing the Cups headers

Find the native CURL headers and libraries.

Added in version 3.14: This module accept optional COMPONENTS to check supported features and protocols:

PROTOCOLS: ICT FILE FTP FTPS GOPHER HTTP HTTPS IMAP IMAPS LDAP LDAPS POP3
           POP3S RTMP RTSP SCP SFTP SMB SMBS SMTP SMTPS TELNET TFTP
FEATURES:  SSL IPv6 UnixSockets libz AsynchDNS IDN GSS-API PSL SPNEGO
           Kerberos NTLM NTLM_WB TLS-SRP HTTP2 HTTPS-proxy

IMPORTED Targets

Added in version 3.12.

This module defines IMPORTED target CURL::libcurl, if curl has been found.

Result Variables

This module defines the following variables:

"True" if curl found.
where to find curl/curl.h, etc.
List of libraries when using curl.
The version of curl found.

Added in version 3.13: Debug and Release variants are found separately.

Added in version 3.17.

If CURL was built using the CMake buildsystem then it provides its own CURLConfig.cmake file for use with the find_package() command's config mode. This module looks for this file and, if found, returns its results with no further action.

Set CURL_NO_CURL_CMAKE to ON to disable this search.

CURL_USE_STATIC_LIBS

Added in version 3.28.

Set to TRUE to use static libraries.

This is meaningful only when CURL is not found via its CMake Package Configuration file.

Find the curses or ncurses include file and library.

Result Variables

This module defines the following variables:

True if Curses is found.
The include directories needed to use Curses.
The libraries needed to use Curses.
Added in version 3.16.

Parameters which ought be given to C/C++ compilers when using Curses.

True if curses.h is available.
True if ncurses.h is available.
True if ncurses/ncurses.h is available.
True if ncurses/curses.h is available.

Set CURSES_NEED_NCURSES to TRUE before the find_package(Curses) call if NCurses functionality is required.

Added in version 3.10: Set CURSES_NEED_WIDE to TRUE before the find_package(Curses) call if unicode functionality is required.

Backward Compatibility

The following variable are provided for backward compatibility:

Path to Curses include. Use CURSES_INCLUDE_DIRS instead.
Path to Curses library. Use CURSES_LIBRARIES instead.

Find the Concurrent Versions System (CVS).

The module defines the following variables:

CVS_EXECUTABLE - path to cvs command line client
CVS_FOUND - true if the command line client was found

Example usage:

find_package(CVS)
if(CVS_FOUND)
  message("CVS found: ${CVS_EXECUTABLE}")
endif()

Find CxxTest unit testing framework.

Find the CxxTest suite and declare a helper macro for creating unit tests and integrating them with CTest.

Input Variables

Deprecated since version 1.3.

Only used in the case both Python & Perl are detected on the system to control which CxxTest code generator is used. Valid only for CxxTest version 3.

In older versions of this Find Module, this variable controlled if the Python test generator was used instead of the Perl one, regardless of which scripting language the user had installed.

Added in version 2.8.3.

Specify a list of options to pass to the CxxTest code generator. If not defined, --error-printer is passed.

Result Variables

True if the CxxTest framework was found
Where to find the CxxTest include directory
The perl-based test generator
The python-based test generator
Added in version 2.8.3.

The test generator that is actually used (chosen using user preferences and interpreters found in the system)

Added in version 2.8.3.

The full path to the Perl or Python executable on the system, on platforms where the script cannot be executed using its shebang line.

Create a CxxTest runner and adds it to the CTest testing suite:
CXXTEST_ADD_TEST(<test_name> <gen_source_file>
                 <input_files_to_testgen>...)

Parameters:

The name of the test
The generated source filename to be generated by CxxTest
The list of header files containing the CxxTest::TestSuite's to be included in this runner

Example Usage

The following example, if CxxTest is found, will:

  • Invoke the testgen executable to autogenerate foo_test.cc in the binary tree from "foo_test.h" in the current source directory.
  • Create an executable and test called unittest_foo.
find_package(CxxTest)
if(CXXTEST_FOUND)
  include_directories(${CXXTEST_INCLUDE_DIR})
  enable_testing()
  CXXTEST_ADD_TEST(unittest_foo foo_test.cc
                   ${CMAKE_CURRENT_SOURCE_DIR}/foo_test.h)
  target_link_libraries(unittest_foo foo) # as needed
endif()

foo_test.h contains:

#include <cxxtest/TestSuite.h>
class MyTestSuite : public CxxTest::TestSuite
{
public:
   void testAddition( void )
   {
      TS_ASSERT( 1 + 1 > 1 );
      TS_ASSERT_EQUALS( 1 + 1, 2 );
   }
};

Find Cygwin, a POSIX-compatible environment that runs natively on Microsoft Windows

Find DICOM ToolKit (DCMTK) libraries and applications

The module defines the following variables:

DCMTK_INCLUDE_DIRS  - Directories to include to use DCMTK
DCMTK_LIBRARIES     - Files to link against to use DCMTK
DCMTK_FOUND         - If false, don't try to use DCMTK
DCMTK_DIR           - (optional) Source directory for DCMTK

This module is able to find a version of DCMTK that does or does not export a DCMTKConfig.cmake file. It applies a two step process:

  • Step 1: Attempt to find DCMTK version providing a DCMTKConfig.cmake file.
  • Step 2: If step 1 failed, rely on FindDCMTK.cmake to set DCMTK_* variables details below.

Recent DCMTK provides a DCMTKConfig.cmake package configuration file. To exclusively use the package configuration file (recommended when possible), pass the NO_MODULE option to find_package(). For example, find_package(DCMTK NO_MODULE). This requires official DCMTK snapshot 3.6.1_20140617 or newer.

Until all clients update to the more recent DCMTK, build systems will need to support different versions of DCMTK.

On any given system, the following combinations of DCMTK versions could be considered:

SYSTEM DCMTK LOCAL DCMTK Supported ?
Case A NA [ ] DCMTKConfig YES
Case B NA [X] DCMTKConfig YES
Case C [ ] DCMTKConfig NA YES
Case D [X] DCMTKConfig NA YES
Case E [ ] DCMTKConfig [ ] DCMTKConfig YES (*)
Case F [X] DCMTKConfig [ ] DCMTKConfig NO
Case G [ ] DCMTKConfig [X] DCMTKConfig YES
Case H [X] DCMTKConfig [X] DCMTKConfig YES
(*) See Troubleshooting section.

Legend:

NA ...............: Means that no System or Local DCMTK is available

[ ] DCMTKConfig ..: Means that the version of DCMTK does NOT export a DCMTKConfig.cmake file.

[X] DCMTKConfig ..: Means that the version of DCMTK exports a DCMTKConfig.cmake file.

What to do if my project finds a different version of DCMTK?

Remove DCMTK entry from the CMake cache per find_package() documentation.

This module locates the developer's image library. https://openil.sourceforge.net/

IMPORTED Targets

Added in version 3.21.

This module defines the IMPORTED targets:

Defined if the system has DevIL.
Defined if the system has DevIL Utilities.
Defined if the system has DevIL Utility Toolkit.

Result Variables

This module sets:

The name of the IL library. These include the full path to the core DevIL library. This one has to be linked into the application.
The name of the ILU library. Again, the full path. This library is for filters and effects, not actual loading. It doesn't have to be linked if the functionality it provides is not used.
The name of the ILUT library. Full path. This part of the library interfaces with OpenGL. It is not strictly needed in applications.
where to find the il.h, ilu.h and ilut.h files.
This is set to TRUE if all the above variables were set. This will be set to false if ILU or ILUT are not found, even if they are not needed. In most systems, if one library is found all the others are as well. That's the way the DevIL developers release it.
Added in version 3.21.

This is set to TRUE if the ILUT library is found.

Doxygen is a documentation generation tool (see https://www.doxygen.nl). This module looks for Doxygen and some optional tools it supports:

Graphviz dot utility used to render various graphs.
Message Chart Generator utility used by Doxygen's \msc and \mscfile commands.
Dia the diagram editor used by Doxygen's \diafile command.

Added in version 3.9: These tools are available as components in the find_package() command. For example:

# Require dot, treat the other components as optional
find_package(Doxygen
             REQUIRED dot
             OPTIONAL_COMPONENTS mscgen dia)

The following variables are defined by this module:

True if the doxygen executable was found.
The version reported by doxygen --version.

Added in version 3.9: The module defines IMPORTED targets for Doxygen and each component found. These can be used as part of custom commands, etc. and should be preferred over old-style (and now deprecated) variables like DOXYGEN_EXECUTABLE. The following import targets are defined if their corresponding executable could be found (the component import targets will only be defined if that component was requested):

Doxygen::doxygen
Doxygen::dot
Doxygen::mscgen
Doxygen::dia

Added in version 3.9.

This function is intended as a convenience for adding a target for generating documentation with Doxygen. It aims to provide sensible defaults so that projects can generally just provide the input files and directories and that will be sufficient to give sensible results. The function supports the ability to customize the Doxygen configuration used to build the documentation.

doxygen_add_docs(targetName
    [filesOrDirs...]
    [ALL]
    [USE_STAMP_FILE]
    [WORKING_DIRECTORY dir]
    [COMMENT comment]
    [CONFIG_FILE filename])

The function constructs a Doxyfile and defines a custom target that runs Doxygen on that generated file. The listed files and directories are used as the INPUT of the generated Doxyfile and they can contain wildcards. Any files that are listed explicitly will also be added as SOURCES of the custom target so they will show up in an IDE project's source list.

So that relative input paths work as expected, by default the working directory of the Doxygen command will be the current source directory (i.e. CMAKE_CURRENT_SOURCE_DIR). This can be overridden with the WORKING_DIRECTORY option to change the directory used as the relative base point. Note also that Doxygen's default behavior is to strip the working directory from relative paths in the generated documentation (see the STRIP_FROM_PATH Doxygen config option for details).

If provided, the optional comment will be passed as the COMMENT for the add_custom_target() command used to create the custom target internally.

Added in version 3.27: If CONFIG_FILE is set, the given file provided with full-path will be used as doxygen configuration file

Added in version 3.12: If ALL is set, the target will be added to the default build target.

Added in version 3.16: If USE_STAMP_FILE is set, the custom command defined by this function will create a stamp file with the name <targetName>.stamp in the current binary directory whenever doxygen is re-run. With this option present, all items in <filesOrDirs> must be files (i.e. no directories, symlinks or wildcards) and each of the files must exist at the time doxygen_add_docs() is called. An error will be raised if any of the items listed is missing or is not a file when USE_STAMP_FILE is given. A dependency will be created on each of the files so that doxygen will only be re-run if one of the files is updated. Without the USE_STAMP_FILE option, doxygen will always be re-run if the <targetName> target is built regardless of whether anything listed in <filesOrDirs> has changed.

The contents of the generated Doxyfile can be customized by setting CMake variables before calling doxygen_add_docs(). Any variable with a name of the form DOXYGEN_<tag> will have its value substituted for the corresponding <tag> configuration option in the Doxyfile. See the Doxygen documentation for the full list of supported configuration options.

Some of Doxygen's defaults are overridden to provide more appropriate behavior for a CMake project. Each of the following will be explicitly set unless the variable already has a value before doxygen_add_docs() is called (with some exceptions noted):

Set to YES if the dot component was requested and it was found, NO otherwise. Any existing value of DOXYGEN_HAVE_DOT is ignored.
Set to YES by this module (note that this requires a dot version newer than 1.8.10). This option is only meaningful if DOXYGEN_HAVE_DOT is also set to YES.
Set to NO by this module.
For Visual Studio based generators, this is set to the form recognized by the Visual Studio IDE: $file($line) : $text. For all other generators, Doxygen's default value is not overridden.
Populated with the name of the current project (i.e. PROJECT_NAME).
Populated with the version of the current project (i.e. PROJECT_VERSION).
Populated with the description of the current project (i.e. PROJECT_DESCRIPTION).
Projects should not set this variable. It will be populated with the set of files and directories passed to doxygen_add_docs(), thereby providing consistent behavior with the other built-in commands like add_executable(), add_library() and add_custom_target(). If a variable named DOXYGEN_INPUT is set by the project, it will be ignored and a warning will be issued.
Set to YES by this module.
If the set of inputs includes directories, this variable will specify patterns used to exclude files from them. The following patterns are added by doxygen_add_docs() to ensure CMake-specific files and directories are not included in the input. If the project sets DOXYGEN_EXCLUDE_PATTERNS, those contents are merged with these additional patterns rather than replacing them:
*/.git/*
*/.svn/*
*/.hg/*
*/CMakeFiles/*
*/_CPack_Packages/*
DartConfiguration.tcl
CMakeLists.txt
CMakeCache.txt
Set to CMAKE_CURRENT_BINARY_DIR by this module. Note that if the project provides its own value for this and it is a relative path, it will be converted to an absolute path relative to the current binary directory. This is necessary because doxygen will normally be run from a directory within the source tree so that relative source paths work as expected. If this directory does not exist, it will be recursively created prior to executing the doxygen commands.

To change any of these defaults or override any other Doxygen config option, set relevant variables before calling doxygen_add_docs(). For example:

set(DOXYGEN_GENERATE_HTML NO)
set(DOXYGEN_GENERATE_MAN YES)
doxygen_add_docs(
    doxygen
    ${PROJECT_SOURCE_DIR}
    COMMENT "Generate man pages"
)

A number of Doxygen config options accept lists of values, but Doxygen requires them to be separated by whitespace. CMake variables hold lists as a string with items separated by semi-colons, so a conversion needs to be performed. The doxygen_add_docs() command specifically checks the following Doxygen config options and will convert their associated CMake variable's contents into the required form if set. CMake variables are named DOXYGEN_<name> for the Doxygen settings specified here.

ABBREVIATE_BRIEF
ALIASES
CITE_BIB_FILES
DIAFILE_DIRS
DOTFILE_DIRS
DOT_FONTPATH
ENABLED_SECTIONS
EXAMPLE_PATH
EXAMPLE_PATTERNS
EXCLUDE
EXCLUDE_PATTERNS
EXCLUDE_SYMBOLS
EXPAND_AS_DEFINED
EXTENSION_MAPPING
EXTRA_PACKAGES
EXTRA_SEARCH_MAPPINGS
FILE_PATTERNS
FILTER_PATTERNS
FILTER_SOURCE_PATTERNS
HTML_EXTRA_FILES
HTML_EXTRA_STYLESHEET
IGNORE_PREFIX
IMAGE_PATH
INCLUDE_FILE_PATTERNS
INCLUDE_PATH
INPUT
LATEX_EXTRA_FILES
LATEX_EXTRA_STYLESHEET
MATHJAX_EXTENSIONS
MSCFILE_DIRS
PLANTUML_INCLUDE_PATH
PREDEFINED
QHP_CUST_FILTER_ATTRS
QHP_SECT_FILTER_ATTRS
STRIP_FROM_INC_PATH
STRIP_FROM_PATH
TAGFILES
TCL_SUBST

The following single value Doxygen options will be quoted automatically if they contain at least one space:

CHM_FILE
DIA_PATH
DOCBOOK_OUTPUT
DOCSET_FEEDNAME
DOCSET_PUBLISHER_NAME
DOT_FONTNAME
DOT_PATH
EXTERNAL_SEARCH_ID
FILE_VERSION_FILTER
GENERATE_TAGFILE
HHC_LOCATION
HTML_FOOTER
HTML_HEADER
HTML_OUTPUT
HTML_STYLESHEET
INPUT_FILTER
LATEX_FOOTER
LATEX_HEADER
LATEX_OUTPUT
LAYOUT_FILE
MAN_OUTPUT
MAN_SUBDIR
MATHJAX_CODEFILE
MSCGEN_PATH
OUTPUT_DIRECTORY
PERL_PATH
PLANTUML_JAR_PATH
PROJECT_BRIEF
PROJECT_LOGO
PROJECT_NAME
QCH_FILE
QHG_LOCATION
QHP_CUST_FILTER_NAME
QHP_VIRTUAL_FOLDER
RTF_EXTENSIONS_FILE
RTF_OUTPUT
RTF_STYLESHEET_FILE
SEARCHDATA_FILE
USE_MDFILE_AS_MAINPAGE
WARN_FORMAT
WARN_LOGFILE
XML_OUTPUT

Added in version 3.11: There are situations where it may be undesirable for a particular config option to be automatically quoted by doxygen_add_docs(), such as ALIASES which may need to include its own embedded quoting. The DOXYGEN_VERBATIM_VARS variable can be used to specify a list of Doxygen variables (including the leading DOXYGEN_ prefix) which should not be quoted. The project is then responsible for ensuring that those variables' values make sense when placed directly in the Doxygen input file. In the case of list variables, list items are still separated by spaces, it is only the automatic quoting that is skipped. For example, the following allows doxygen_add_docs() to apply quoting to DOXYGEN_PROJECT_BRIEF, but not each item in the DOXYGEN_ALIASES list (bracket syntax can also be used to make working with embedded quotes easier):

set(DOXYGEN_PROJECT_BRIEF "String with spaces")
set(DOXYGEN_ALIASES
    [[somealias="@some_command param"]]
    "anotherAlias=@foobar"
)
set(DOXYGEN_VERBATIM_VARS DOXYGEN_ALIASES)

The resultant Doxyfile will contain the following lines:

PROJECT_BRIEF = "String with spaces"
ALIASES       = somealias="@some_command param" anotherAlias=@foobar

Deprecated since version 3.9.

For compatibility with previous versions of CMake, the following variables are also defined but they are deprecated and should no longer be used:

The path to the doxygen command. If projects need to refer to the doxygen executable directly, they should use the Doxygen::doxygen import target instead.
True if the dot executable was found.
The path to the dot command. If projects need to refer to the dot executable directly, they should use the Doxygen::dot import target instead.
The path to the directory containing the dot executable as reported in DOXYGEN_DOT_EXECUTABLE. The path may have forward slashes even on Windows and is not suitable for direct substitution into a Doxyfile.in template. If you need this value, get the IMPORTED_LOCATION property of the Doxygen::dot target and use get_filename_component() to extract the directory part of that path. You may also want to consider using file(TO_NATIVE_PATH) to prepare the path for a Doxygen configuration file.

Deprecated since version 3.9.

This variable has no effect for the component form of find_package. In backward compatibility mode (i.e. without components list) it prevents the finder module from searching for Graphviz's dot utility.

Added in version 3.15.

Locate an environment module implementation and make commands available to CMake scripts to use them. This is compatible with both Lua-based Lmod and TCL-based EnvironmentModules.

This module is intended for the use case of setting up the compiler and library environment within a CTest Script (ctest -S). It can also be used in a CMake Script (cmake -P).

NOTE:

The loaded environment will not survive past the end of the calling process. Do not use this module in project code (CMakeLists.txt files) to load a compiler environment; it will not be available during the build. Instead load the environment manually before running CMake or using the generated build system.

Example Usage

set(CTEST_BUILD_NAME "CrayLinux-CrayPE-Cray-dynamic")
set(CTEST_BUILD_CONFIGURATION Release)
set(CTEST_BUILD_FLAGS "-k -j8")
set(CTEST_CMAKE_GENERATOR "Unix Makefiles")
...
find_package(EnvModules REQUIRED)
env_module(purge)
env_module(load modules)
env_module(load craype)
env_module(load PrgEnv-cray)
env_module(load craype-knl)
env_module(load cray-mpich)
env_module(load cray-libsci)
set(ENV{CRAYPE_LINK_TYPE} dynamic)
...

Result Variables

This module will set the following variables in your project:

True if a compatible environment modules framework was found.

Cache Variables

The following cache variable will be set:

The low level module command to use. Currently supported implementations are the Lua based Lmod and TCL based EnvironmentModules.

Usually set by the module environment implementation, used as a hint to locate the module command to execute.

This defines the following CMake functions for interacting with environment modules:

Execute an arbitrary module command:
env_module(cmd arg1 ... argN)
env_module(
  COMMAND cmd arg1 ... argN
  [OUTPUT_VARIABLE <out-var>]
  [RESULT_VARIABLE <ret-var>]
)

The options are:

The module sub-command and arguments to execute as if they were passed directly to the module command in your shell environment.
The standard output from executing the module command.
The return code from executing the module command.
Swap one module for another:
env_module_swap(out_mod in_mod
  [OUTPUT_VARIABLE <out-var>]
  [RESULT_VARIABLE <ret-var>]
)

This is functionally equivalent to the module swap out_mod in_mod shell command. The options are:

The standard output from executing the module command.
The return code from executing the module command.
Retrieve the list of currently loaded modules:
env_module_list(<out-var>)

This is functionally equivalent to the module list shell command. The result is stored in <out-var> as a properly formatted CMake semicolon-separated list variable.

Retrieve the list of available modules:
env_module_avail([<mod-prefix>] <out-var>)

This is functionally equivalent to the module avail <mod-prefix> shell command. The result is stored in <out-var> as a properly formatted CMake semicolon-separated list variable.

Find the native Expat headers and library. Expat is a stream-oriented XML parser library written in C.

Imported Targets

Added in version 3.10.

This module defines the following IMPORTED targets:

The Expat expat library, if found.

Result Variables

This module will set the following variables in your project:

where to find expat.h, etc.
the libraries to link against to use Expat.
true if the Expat headers and libraries were found.

EXPAT_USE_STATIC_LIBS

Added in version 3.28.

Set to TRUE to use static libraries.

Find Fast Lexical Analyzer (Flex) executable and provides a macro to generate custom build rules

The module defines the following variables:

FLEX_FOUND - True is flex executable is found
FLEX_EXECUTABLE - the path to the flex executable
FLEX_VERSION - the version of flex
FLEX_LIBRARIES - The flex libraries
FLEX_INCLUDE_DIRS - The path to the flex headers

The minimum required version of flex can be specified using the standard syntax, e.g. find_package(FLEX 2.5.13)

If flex is found on the system, the module provides the macro:

FLEX_TARGET(Name FlexInput FlexOutput
            [COMPILE_FLAGS <string>]
            [DEFINES_FILE <string>]
            )

which creates a custom command to generate the FlexOutput file from the FlexInput file. Name is an alias used to get details of this custom command. If COMPILE_FLAGS option is specified, the next parameter is added to the flex command line.

Added in version 3.5: If flex is configured to output a header file, the DEFINES_FILE option may be used to specify its name.

Changed in version 3.17: When CMP0098 is set to NEW, flex runs in the CMAKE_CURRENT_BINARY_DIR directory.

The macro defines the following variables:

FLEX_${Name}_DEFINED - true is the macro ran successfully
FLEX_${Name}_OUTPUTS - the source file generated by the custom rule, an
alias for FlexOutput
FLEX_${Name}_INPUT - the flex source file, an alias for ${FlexInput}
FLEX_${Name}_OUTPUT_HEADER - the header flex output, if any.

Flex scanners often use tokens defined by Bison: the code generated by Flex depends of the header generated by Bison. This module also defines a macro:

ADD_FLEX_BISON_DEPENDENCY(FlexTarget BisonTarget)

which adds the required dependency between a scanner and a parser where FlexTarget and BisonTarget are the first parameters of respectively FLEX_TARGET and BISON_TARGET macros.

====================================================================
Example:
find_package(BISON)
find_package(FLEX)
BISON_TARGET(MyParser parser.y ${CMAKE_CURRENT_BINARY_DIR}/parser.cpp)
FLEX_TARGET(MyScanner lexer.l  ${CMAKE_CURRENT_BINARY_DIR}/lexer.cpp)
ADD_FLEX_BISON_DEPENDENCY(MyScanner MyParser)
 include_directories(${CMAKE_CURRENT_BINARY_DIR})
 add_executable(Foo
    Foo.cc
    ${BISON_MyParser_OUTPUTS}
    ${FLEX_MyScanner_OUTPUTS}
 )
 target_link_libraries(Foo ${FLEX_LIBRARIES})
====================================================================

Find the Fast Light Toolkit (FLTK) library

Input Variables

By default this module will search for all of the FLTK components and add them to the FLTK_LIBRARIES variable. You can limit the components which get placed in FLTK_LIBRARIES by defining one or more of the following three options:

Set to true to disable searching for the FLTK GL library
Set to true to disable searching for the FLTK Forms library
Set to true to disable searching for the FLTK Images library

FLTK is composed also by a binary tool. You can set the following option:

Set to true to not look for the FLUID binary

Result Variables

The following variables will be defined:

True if all components not skipped were found
Path to the include directory for FLTK header files
List of the FLTK libraries found
Path to the FLUID binary tool
True if FLUID is found, used to enable the FLTK_WRAP_UI command

Cache Variables

The following cache variables are also available to set or use:

The FLTK base library (optimized)
The FLTK base library (debug)
The FLTK GL library (optimized)
The FLTK GL library (debug)
The FLTK Forms library (optimized)
The FLTK Forms library (debug)
The FLTK Images protobuf library (optimized)
The FLTK Images library (debug)

Added in version 3.11: Debug and Release variants are found separately and use per-configuration variables.

Find the native FLTK 2.0 includes and library

The following settings are defined

FLTK2_FLUID_EXECUTABLE, where to find the Fluid tool
FLTK2_WRAP_UI, This enables the FLTK2_WRAP_UI command
FLTK2_INCLUDE_DIR, where to find include files
FLTK2_LIBRARIES, list of fltk2 libraries
FLTK2_FOUND, Don't use FLTK2 if false.

The following settings should not be used in general.

FLTK2_BASE_LIBRARY   = the full path to fltk2.lib
FLTK2_GL_LIBRARY     = the full path to fltk2_gl.lib
FLTK2_IMAGES_LIBRARY = the full path to fltk2_images.lib

Added in version 3.14.

Find Fontconfig headers and library.

Imported Targets

The Fontconfig library, if found.

Result Variables

This will define the following variables in your project:

true if (the requested version of) Fontconfig is available.
the version of Fontconfig.
the libraries to link against to use Fontconfig.
where to find the Fontconfig headers.
this should be passed to target_compile_options(), if the target is not used for linking

Find the FreeType font renderer includes and library.

Imported Targets

Added in version 3.10.

This module defines the following IMPORTED target:

The Freetype freetype library, if found

Result Variables

This module will set the following variables in your project:

true if the Freetype headers and libraries were found
directories containing the Freetype headers. This is the concatenation of the variables:
directory holding the main Freetype API configuration header
directory holding Freetype public headers
the library to link against
the version of freetype found

Added in version 3.7: Debug and Release variants are found separately.

The user may set the environment variable FREETYPE_DIR to the root directory of a Freetype installation.

Find the GCC-XML front-end executable.

This module will define the following variables:

GCCXML - the GCC-XML front-end executable.

Find Geospatial Data Abstraction Library (GDAL).

IMPORTED Targets

Added in version 3.14.

This module defines IMPORTED target GDAL::GDAL if GDAL has been found.

Result Variables

This module will set the following variables in your project:

True if GDAL is found.
Include directories for GDAL headers.
Libraries to link to GDAL.
Added in version 3.14: The version of GDAL found.

Cache variables

The following cache variables may also be set:

The libgdal library file.
The directory containing gdal.h.

Set GDAL_DIR or GDAL_ROOT in the environment to specify the GDAL installation prefix.

The following variables may be set to modify the search strategy:

If set, gdal-config will not be used. This can be useful if there are GDAL libraries built with autotools (which provide the tool) and CMake (which do not) in the same environment.
Extra versions of library names to search for.

Find GNU gettext tools

This module looks for the GNU gettext tools. This module defines the following values:

GETTEXT_MSGMERGE_EXECUTABLE: the full path to the msgmerge tool.
GETTEXT_MSGFMT_EXECUTABLE: the full path to the msgfmt tool.
GETTEXT_FOUND: True if gettext has been found.
GETTEXT_VERSION_STRING: the version of gettext found (since CMake 2.8.8)

Additionally it provides the following macros:

GETTEXT_CREATE_TRANSLATIONS ( outputFile [ALL] file1 ... fileN )

This will create a target "translations" which will convert the
given input po files into the binary output mo file. If the
ALL option is used, the translations will also be created when
building the default target.

GETTEXT_PROCESS_POT_FILE( <potfile> [ALL] [INSTALL_DESTINATION <destdir>] LANGUAGES <lang1> <lang2> ... )

Process the given pot file to mo files.
If INSTALL_DESTINATION is given then automatically install rules will
be created, the language subdirectory will be taken into account
(by default use share/locale/).
If ALL is specified, the pot file is processed when building the all target.
It creates a custom target "potfile".

GETTEXT_PROCESS_PO_FILES( <lang> [ALL] [INSTALL_DESTINATION <dir>] PO_FILES <po1> <po2> ... )

Process the given po files to mo files for the given language.
If INSTALL_DESTINATION is given then automatically install rules will
be created, the language subdirectory will be taken into account
(by default use share/locale/).
If ALL is specified, the po files are processed when building the all target.
It creates a custom target "pofiles".

Added in version 3.2: If you wish to use the Gettext library (libintl), use FindIntl.

This finds the Graphics Interchange Format (GIF) library (giflib)

Imported targets

This module defines the following IMPORTED target:

The giflib library, if found.

Result variables

This module will set the following variables in your project:

If false, do not try to use GIF.
where to find gif_lib.h, etc.
the libraries needed to use GIF.
3, 4 or a full version string (eg 5.1.4) for versions >= 4.1.6.

Cache variables

The following cache variables may also be set:

where to find the GIF headers.
where to find the GIF library.

GIF_DIR is an environment variable that would correspond to the ./configure --prefix=$GIF_DIR.

The module defines the following variables:

Path to Git command-line client.
True if the Git command-line client was found.
The version of Git found.

Added in version 3.14: The module defines the following IMPORTED targets (when CMAKE_ROLE is PROJECT):

Executable of the Git command-line client.

Example usage:

find_package(Git)
if(Git_FOUND)
  message("Git found: ${GIT_EXECUTABLE}")
endif()

Find the OpenGL Extension Wrangler Library (GLEW)

Input Variables

The following variables may be set to influence this module's behavior:

to find and create IMPORTED target for static linkage.
to output a detailed log of this module.

Imported Targets

Added in version 3.1.

This module defines the following Imported Targets:

The GLEW shared library.
The GLEW static library, if GLEW_USE_STATIC_LIBS is set to TRUE.
Duplicates either GLEW::glew or GLEW::glew_s based on availability.

Result Variables

This module defines the following variables:

include directories for GLEW
libraries to link against GLEW
libraries to link against shared GLEW
libraries to link against static GLEW
true if GLEW has been found and can be used
GLEW version
GLEW major version
GLEW minor version
GLEW micro version

Added in version 3.7: Debug and Release variants are found separately.

Find OpenGL Utility Toolkit (GLUT) library and include files.

IMPORTED Targets

Added in version 3.1.

This module defines the IMPORTED targets:

Defined if the system has GLUT.

Result Variables

This module defines the following variables:

True if glut was found.
Added in version 3.23.

Where to find GL/glut.h, etc.

List of libraries for using glut.

Cache Variables

This module may set the following variables depending on platform. These variables may optionally be set to help this module find the correct files, but clients should not use these as results:

The full path to the directory containing GL/glut.h, not including GL/.
The full path to the glut library.
The full path to the Xmu library.
The full path to the Xi Library.

The following variables may also be provided, for backwards compatibility:

This is one of above Cache Variables, but prior to CMake 3.23 was also a result variable. Prefer to use GLUT_INCLUDE_DIRS instead in CMake 3.23 and above.

this module looks for gnuplot

Once done this will define

GNUPLOT_FOUND - system has Gnuplot
GNUPLOT_EXECUTABLE - the Gnuplot executable
GNUPLOT_VERSION_STRING - the version of Gnuplot found (since CMake 2.8.8)

GNUPLOT_VERSION_STRING will not work for old versions like 3.7.1.

Find the GNU Transport Layer Security library (gnutls)

IMPORTED Targets

Added in version 3.16.

This module defines IMPORTED target GnuTLS::GnuTLS, if gnutls has been found.

Result Variables

System has gnutls
The gnutls include directory
The libraries needed to use gnutls
Compiler switches required for using gnutls
version of gnutls.

Added in version 3.2.

Find the native GNU Scientific Library (GSL) includes and libraries.

The GNU Scientific Library (GSL) is a numerical library for C and C++ programmers. It is free software under the GNU General Public License.

Imported Targets

If GSL is found, this module defines the following IMPORTED targets:

GSL::gsl      - The main GSL library.
GSL::gslcblas - The CBLAS support library used by GSL.

Result Variables

This module will set the following variables in your project:

GSL_FOUND          - True if GSL found on the local system
GSL_INCLUDE_DIRS   - Location of GSL header files.
GSL_LIBRARIES      - The GSL libraries.
GSL_VERSION        - The version of the discovered GSL install.

Set GSL_ROOT_DIR to a directory that contains a GSL installation.

This script expects to find libraries at $GSL_ROOT_DIR/lib and the GSL headers at $GSL_ROOT_DIR/include/gsl. The library directory may optionally provide Release and Debug folders. If available, the libraries named gsld, gslblasd or cblasd are recognized as debug libraries. For Unix-like systems, this script will use $GSL_ROOT_DIR/bin/gsl-config (if found) to aid in the discovery of GSL.

Cache Variables

This module may set the following variables depending on platform and type of GSL installation discovered. These variables may optionally be set to help this module find the correct files:

GSL_CBLAS_LIBRARY       - Location of the GSL CBLAS library.
GSL_CBLAS_LIBRARY_DEBUG - Location of the debug GSL CBLAS library (if any).
GSL_CONFIG_EXECUTABLE   - Location of the ``gsl-config`` script (if any).
GSL_LIBRARY             - Location of the GSL library.
GSL_LIBRARY_DEBUG       - Location of the debug GSL library (if any).

Locate the Google C++ Testing Framework.

Added in version 3.20: Upstream GTestConfig.cmake is used if possible.

Imported targets

Added in version 3.20: This module defines the following IMPORTED targets:

The Google Test gtest library, if found; adds Thread::Thread automatically
The Google Test gtest_main library, if found

Added in version 3.23.

The Google Mock gmock library, if found; adds Thread::Thread automatically
The Google Mock gmock_main library, if found

Deprecated since version 3.20: For backwards compatibility, this module defines additionally the following deprecated IMPORTED targets (available since 3.5):

The Google Test gtest library, if found; adds Thread::Thread automatically
The Google Test gtest_main library, if found

Result variables

This module will set the following variables in your project:

Found the Google Testing framework
the directory containing the Google Test headers

The library variables below are set as normal variables. These contain debug/optimized keywords when a debugging library is found.

The Google Test gtest library; note it also requires linking with an appropriate thread library
The Google Test gtest_main library
Both gtest and gtest_main

Cache variables

The following cache variables may also be set:

The root directory of the Google Test installation (may also be set as an environment variable)
If compiling with MSVC, this variable can be set to MT or MD (the default) to enable searching a GTest build tree

enable_testing()
find_package(GTest REQUIRED)
add_executable(foo foo.cc)
target_link_libraries(foo GTest::gtest GTest::gtest_main)
add_test(AllTestsInFoo foo)

See GoogleTest for information on the gtest_add_tests() and gtest_discover_tests() commands.

Changed in version 3.9: Previous CMake versions defined gtest_add_tests() macro in this module.

Find GTK, glib and GTKGLArea

GTK_INCLUDE_DIR   - Directories to include to use GTK
GTK_LIBRARIES     - Files to link against to use GTK
GTK_FOUND         - GTK was found
GTK_GL_FOUND      - GTK's GL features were found

Find the GTK2 widget libraries and several of its other optional components like gtkmm, glade, and glademm.

Specify one or more of the following components as you call this find module. See example below.

  • gtk
  • gtkmm
  • glade
  • glademm

Imported Targets

This module defines the following IMPORTED targets (subject to component selection):

GTK2::atk, GTK2::atkmm, GTK2::cairo, GTK2::cairomm, GTK2::gdk_pixbuf, GTK2::gdk, GTK2::gdkmm, GTK2::gio, GTK2::giomm, GTK2::glade, GTK2::glademm, GTK2::glib, GTK2::glibmm, GTK2::gmodule, GTK2::gobject, GTK2::gthread, GTK2::gtk, GTK2::gtkmm, GTK2::harfbuzz, GTK2::pango, GTK2::pangocairo, GTK2::pangoft2, GTK2::pangomm, GTK2::pangoxft, GTK2::sigc.

Added in version 3.16.7: Added the GTK2::harfbuzz target.

Result Variables

The following variables will be defined for your use

Were all of your specified components found?
All include directories
All libraries
Added in version 3.5: All imported targets
Additional compiler flags
The version of GTK2 found (x.y.z)
The major version of GTK2
The minor version of GTK2
The patch version of GTK2

Added in version 3.5: When GTK2_USE_IMPORTED_TARGETS is set to TRUE, GTK2_LIBRARIES will list imported targets instead of library paths.

Input Variables

Optional variables you can define prior to calling this module:

Enables verbose debugging of the module
Allows defining additional directories to search for include files

Example Usage

Call find_package() once. Here are some examples to pick from:

Require GTK 2.6 or later:

find_package(GTK2 2.6 REQUIRED gtk)

Require GTK 2.10 or later and Glade:

find_package(GTK2 2.10 REQUIRED gtk glade)

Search for GTK/GTKMM 2.8 or later:

find_package(GTK2 2.8 COMPONENTS gtk gtkmm)

Use the results:

if(GTK2_FOUND)
  include_directories(${GTK2_INCLUDE_DIRS})
  add_executable(mygui mygui.cc)
  target_link_libraries(mygui ${GTK2_LIBRARIES})
endif()

Find Hierarchical Data Format (HDF5), a library for reading and writing self describing array data.

This module invokes the HDF5 wrapper compiler that should be installed alongside HDF5. Depending upon the HDF5 Configuration, the wrapper compiler is called either h5cc or h5pcc. If this succeeds, the module will then call the compiler with the show argument to see what flags are used when compiling an HDF5 client application.

The module will optionally accept the COMPONENTS argument. If no COMPONENTS are specified, then the find module will default to finding only the HDF5 C library. If one or more COMPONENTS are specified, the module will attempt to find the language bindings for the specified components. The valid components are C, CXX, Fortran, HL. HL refers to the "high-level" HDF5 functions for C and Fortran. If the COMPONENTS argument is not given, the module will attempt to find only the C bindings. For example, to use Fortran HDF5 and HDF5-HL functions, do: find_package(HDF5 COMPONENTS Fortran HL).

This module will read the variable HDF5_USE_STATIC_LIBRARIES to determine whether or not to prefer a static link to a dynamic link for HDF5 and all of it's dependencies. To use this feature, make sure that the HDF5_USE_STATIC_LIBRARIES variable is set before the call to find_package.

Added in version 3.10: Support for HDF5_USE_STATIC_LIBRARIES on Windows.

Both the serial and parallel HDF5 wrappers are considered and the first directory to contain either one will be used. In the event that both appear in the same directory the serial version is preferentially selected. This behavior can be reversed by setting the variable HDF5_PREFER_PARALLEL to TRUE.

In addition to finding the includes and libraries required to compile an HDF5 client application, this module also makes an effort to find tools that come with the HDF5 distribution that may be useful for regression testing.

Result Variables

This module will set the following variables in your project:

HDF5 was found on the system
Added in version 3.3: HDF5 library version
Location of the HDF5 header files
Required compiler definitions for HDF5
Required libraries for all requested bindings
Required libraries for the HDF5 high level API for all bindings, if the HL component is enabled

Available components are: C CXX Fortran and HL. For each enabled language binding, a corresponding HDF5_${LANG}_LIBRARIES variable, and potentially HDF5_${LANG}_DEFINITIONS, will be defined. If the HL component is enabled, then an HDF5_${LANG}_HL_LIBRARIES will also be defined. With all components enabled, the following variables will be defined:

Required compiler definitions for HDF5 C bindings
Required compiler definitions for HDF5 C++ bindings
Required compiler definitions for HDF5 Fortran bindings
Required include directories for HDF5 C bindings
Required include directories for HDF5 C++ bindings
Required include directories for HDF5 Fortran bindings
Required libraries for the HDF5 C bindings
Required libraries for the HDF5 C++ bindings
Required libraries for the HDF5 Fortran bindings
Required libraries for the high level C bindings
Required libraries for the high level C++ bindings
Required libraries for the high level Fortran bindings.
HDF5 library has parallel IO support
path to the HDF5 C wrapper compiler
path to the HDF5 C++ wrapper compiler
path to the HDF5 Fortran wrapper compiler
path to the primary C compiler which is also the HDF5 wrapper
path to the primary C++ compiler which is also the HDF5 wrapper
path to the primary Fortran compiler which is also the HDF5 wrapper
path to the HDF5 dataset comparison tool

With all components enabled, the following targets will be defined:

All detected HDF5_LIBRARIES.
C library.
C++ library.
Fortran library.
High-level C library.
High-level C++ library.
High-level Fortran library.
h5diff executable.

The following variables can be set to guide the search for HDF5 libraries and includes:

Added in version 3.4.

set true to prefer parallel HDF5 (by default, serial is preferred)

Added in version 3.9.

Set true to get extra debugging output.

Added in version 3.8.

Set true to skip trying to find hdf5-config.cmake.

Extract information from a mercurial working copy.

The module defines the following variables:

HG_EXECUTABLE - path to mercurial command line client (hg)
HG_FOUND - true if the command line client was found
HG_VERSION_STRING - the version of mercurial found

Added in version 3.1: If the command line client executable is found the following macro is defined:

HG_WC_INFO(<dir> <var-prefix>)

Hg_WC_INFO extracts information of a mercurial working copy at a given location. This macro defines the following variables:

<var-prefix>_WC_CHANGESET - current changeset
<var-prefix>_WC_REVISION - current revision

Example usage:

find_package(Hg)
if(HG_FOUND)
  message("hg found: ${HG_EXECUTABLE}")
  HG_WC_INFO(${PROJECT_SOURCE_DIR} Project)
  message("Current revision is ${Project_WC_REVISION}")
  message("Current changeset is ${Project_WC_CHANGESET}")
endif()

Try to find Hebrew spell-checker (Hspell) and morphology engine.

Once done this will define

HSPELL_FOUND - system has Hspell
HSPELL_INCLUDE_DIR - the Hspell include directory
HSPELL_LIBRARIES - The libraries needed to use Hspell
HSPELL_DEFINITIONS - Compiler switches required for using Hspell
HSPELL_VERSION_STRING - The version of Hspell found (x.y)
HSPELL_MAJOR_VERSION  - the major version of Hspell
HSPELL_MINOR_VERSION  - The minor version of Hspell

This module looks for Microsoft HTML Help Compiler

It defines:

HTML_HELP_COMPILER     : full path to the Compiler (hhc.exe)
HTML_HELP_INCLUDE_PATH : include path to the API (htmlhelp.h)
HTML_HELP_LIBRARY      : full path to the library (htmlhelp.lib)

Added in version 3.1.

Find the ZeroC Internet Communication Engine (ICE) programs, libraries and datafiles.

This module supports multiple components. Components can include any of: Freeze, Glacier2, Ice, IceBox, IceDB, IceDiscovery, IceGrid, IceLocatorDiscovery, IcePatch, IceSSL, IceStorm, IceUtil, IceXML, or Slice.

Ice 3.7 and later also include C++11-specific components: Glacier2++11, Ice++11, IceBox++11, IceDiscovery++11 IceGrid, IceLocatorDiscovery++11, IceSSL++11, IceStorm++11

Note that the set of supported components is Ice version-specific.

Added in version 3.4: Imported targets for components and most EXECUTABLE variables.

Added in version 3.7: Debug and Release variants are found separately.

Added in version 3.10: Ice 3.7 support, including new components, programs and the Nuget package.

This module reports information about the Ice installation in several variables. General variables:

Ice_VERSION - Ice release version
Ice_FOUND - true if the main programs and libraries were found
Ice_LIBRARIES - component libraries to be linked
Ice_INCLUDE_DIRS - the directories containing the Ice headers
Ice_SLICE_DIRS - the directories containing the Ice slice interface
                 definitions

Imported targets:

Ice::<C>

Where <C> is the name of an Ice component, for example Ice::Glacier2 or Ice++11.

Ice slice programs are reported in:

Ice_SLICE2CONFLUENCE_EXECUTABLE - path to slice2confluence executable
Ice_SLICE2CPP_EXECUTABLE - path to slice2cpp executable
Ice_SLICE2CS_EXECUTABLE - path to slice2cs executable
Ice_SLICE2FREEZEJ_EXECUTABLE - path to slice2freezej executable
Ice_SLICE2FREEZE_EXECUTABLE - path to slice2freeze executable
Ice_SLICE2HTML_EXECUTABLE - path to slice2html executable
Ice_SLICE2JAVA_EXECUTABLE - path to slice2java executable
Ice_SLICE2JS_EXECUTABLE - path to slice2js executable
Ice_SLICE2MATLAB_EXECUTABLE - path to slice2matlab executable
Ice_SLICE2OBJC_EXECUTABLE - path to slice2objc executable
Ice_SLICE2PHP_EXECUTABLE - path to slice2php executable
Ice_SLICE2PY_EXECUTABLE - path to slice2py executable
Ice_SLICE2RB_EXECUTABLE - path to slice2rb executable

Added in version 3.14: Variables for slice2confluence and slice2matlab.

Ice programs are reported in:

Ice_GLACIER2ROUTER_EXECUTABLE - path to glacier2router executable
Ice_ICEBOX_EXECUTABLE - path to icebox executable
Ice_ICEBOXXX11_EXECUTABLE - path to icebox++11 executable
Ice_ICEBOXADMIN_EXECUTABLE - path to iceboxadmin executable
Ice_ICEBOXD_EXECUTABLE - path to iceboxd executable
Ice_ICEBOXNET_EXECUTABLE - path to iceboxnet executable
Ice_ICEBRIDGE_EXECUTABLE - path to icebridge executable
Ice_ICEGRIDADMIN_EXECUTABLE - path to icegridadmin executable
Ice_ICEGRIDDB_EXECUTABLE - path to icegriddb executable
Ice_ICEGRIDNODE_EXECUTABLE - path to icegridnode executable
Ice_ICEGRIDNODED_EXECUTABLE - path to icegridnoded executable
Ice_ICEGRIDREGISTRY_EXECUTABLE - path to icegridregistry executable
Ice_ICEGRIDREGISTRYD_EXECUTABLE - path to icegridregistryd executable
Ice_ICEPATCH2CALC_EXECUTABLE - path to icepatch2calc executable
Ice_ICEPATCH2CLIENT_EXECUTABLE - path to icepatch2client executable
Ice_ICEPATCH2SERVER_EXECUTABLE - path to icepatch2server executable
Ice_ICESERVICEINSTALL_EXECUTABLE - path to iceserviceinstall executable
Ice_ICESTORMADMIN_EXECUTABLE - path to icestormadmin executable
Ice_ICESTORMDB_EXECUTABLE - path to icestormdb executable
Ice_ICESTORMMIGRATE_EXECUTABLE - path to icestormmigrate executable

Ice db programs (Windows only; standard system versions on all other platforms) are reported in:

Ice_DB_ARCHIVE_EXECUTABLE - path to db_archive executable
Ice_DB_CHECKPOINT_EXECUTABLE - path to db_checkpoint executable
Ice_DB_DEADLOCK_EXECUTABLE - path to db_deadlock executable
Ice_DB_DUMP_EXECUTABLE - path to db_dump executable
Ice_DB_HOTBACKUP_EXECUTABLE - path to db_hotbackup executable
Ice_DB_LOAD_EXECUTABLE - path to db_load executable
Ice_DB_LOG_VERIFY_EXECUTABLE - path to db_log_verify executable
Ice_DB_PRINTLOG_EXECUTABLE - path to db_printlog executable
Ice_DB_RECOVER_EXECUTABLE - path to db_recover executable
Ice_DB_STAT_EXECUTABLE - path to db_stat executable
Ice_DB_TUNER_EXECUTABLE - path to db_tuner executable
Ice_DB_UPGRADE_EXECUTABLE - path to db_upgrade executable
Ice_DB_VERIFY_EXECUTABLE - path to db_verify executable
Ice_DUMPDB_EXECUTABLE - path to dumpdb executable
Ice_TRANSFORMDB_EXECUTABLE - path to transformdb executable

Ice component libraries are reported in:

Ice_<C>_FOUND - ON if component was found
Ice_<C>_LIBRARIES - libraries for component

Note that <C> is the uppercased name of the component.

This module reads hints about search results from:

Ice_HOME - the root of the Ice installation

The environment variable ICE_HOME may also be used; the Ice_HOME variable takes precedence.

NOTE:

On Windows, Ice 3.7.0 and later provide libraries via the NuGet package manager. Appropriate NuGet packages will be searched for using CMAKE_PREFIX_PATH, or alternatively Ice_HOME may be set to the location of a specific NuGet package to restrict the search.

The following cache variables may also be set:

Ice_<P>_EXECUTABLE - the path to executable <P>
Ice_INCLUDE_DIR - the directory containing the Ice headers
Ice_SLICE_DIR - the directory containing the Ice slice interface
                definitions
Ice_<C>_LIBRARY - the library for component <C>

NOTE:

In most cases none of the above variables will require setting, unless multiple Ice versions are available and a specific version is required. On Windows, the most recent version of Ice will be found through the registry. On Unix, the programs, headers and libraries will usually be in standard locations, but Ice_SLICE_DIRS might not be automatically detected (commonly known locations are searched). All the other variables are defaulted using Ice_HOME, if set. It's possible to set Ice_HOME and selectively specify alternative locations for the other components; this might be required for e.g. newer versions of Visual Studio if the heuristics are not sufficient to identify the correct programs and libraries for the specific Visual Studio version.

Other variables one may set to control this module are:

Ice_DEBUG - Set to ON to enable debug output from FindIce.

Added in version 3.11.

This module finds the iconv() POSIX.1 functions on the system. These functions might be provided in the regular C library or externally in the form of an additional library.

The following variables are provided to indicate iconv support:

Variable indicating if the iconv support was found.
The directories containing the iconv headers.
The iconv libraries to be linked.
Added in version 3.21.

The version of iconv found (x.y)

Added in version 3.21.

The major version of iconv

Added in version 3.21.

The minor version of iconv

A variable indicating whether iconv support is stemming from the C library or not. Even if the C library provides iconv(), the presence of an external libiconv implementation might lead to this being false.

Additionally, the following IMPORTED target is being provided:

Imported target for using iconv.

The following cache variables may also be set:

The directory containing the iconv headers.
The iconv library (if not implicitly given in the C library).

NOTE:

On POSIX platforms, iconv might be part of the C library and the cache variables Iconv_INCLUDE_DIR and Iconv_LIBRARY might be empty.

NOTE:

Some libiconv implementations don't embed the version number in their header files. In this case the variables Iconv_VERSION* will be empty.

Find icotool

This module looks for icotool. Convert and create Win32 icon and cursor files. This module defines the following values:

ICOTOOL_EXECUTABLE: the full path to the icotool tool.
ICOTOOL_FOUND: True if icotool has been found.
ICOTOOL_VERSION_STRING: the version of icotool found.

Added in version 3.7.

Find the International Components for Unicode (ICU) libraries and programs.

This module supports multiple components. Components can include any of: data, i18n, io, le, lx, test, tu and uc.

Note that on Windows data is named dt and i18n is named in; any of the names may be used, and the appropriate platform-specific library name will be automatically selected.

Added in version 3.11: Added support for static libraries on Windows.

This module reports information about the ICU installation in several variables. General variables:

ICU_FOUND - true if the main programs and libraries were found
ICU_INCLUDE_DIRS - the directories containing the ICU headers
ICU_LIBRARIES - component libraries to be linked
ICU_VERSION - ICU release version

Imported targets:

ICU::<C>

Where <C> is the name of an ICU component, for example ICU::i18n; <C> is lower-case.

ICU programs are reported in:

ICU_GENCNVAL_EXECUTABLE - path to gencnval executable
ICU_ICUINFO_EXECUTABLE - path to icuinfo executable
ICU_GENBRK_EXECUTABLE - path to genbrk executable
ICU_ICU-CONFIG_EXECUTABLE - path to icu-config executable
ICU_GENRB_EXECUTABLE - path to genrb executable
ICU_GENDICT_EXECUTABLE - path to gendict executable
ICU_DERB_EXECUTABLE - path to derb executable
ICU_PKGDATA_EXECUTABLE - path to pkgdata executable
ICU_UCONV_EXECUTABLE - path to uconv executable
ICU_GENCFU_EXECUTABLE - path to gencfu executable
ICU_MAKECONV_EXECUTABLE - path to makeconv executable
ICU_GENNORM2_EXECUTABLE - path to gennorm2 executable
ICU_GENCCODE_EXECUTABLE - path to genccode executable
ICU_GENSPREP_EXECUTABLE - path to gensprep executable
ICU_ICUPKG_EXECUTABLE - path to icupkg executable
ICU_GENCMN_EXECUTABLE - path to gencmn executable

ICU component libraries are reported in:

ICU_<C>_FOUND - ON if component was found; ``<C>`` is upper-case.
ICU_<C>_LIBRARIES - libraries for component; ``<C>`` is upper-case.

ICU datafiles are reported in:

ICU_MAKEFILE_INC - Makefile.inc
ICU_PKGDATA_INC - pkgdata.inc

This module reads hints about search results from:

ICU_ROOT - the root of the ICU installation

The environment variable ICU_ROOT may also be used; the ICU_ROOT variable takes precedence.

The following cache variables may also be set:

ICU_<P>_EXECUTABLE - the path to executable <P>; ``<P>`` is upper-case.
ICU_INCLUDE_DIR - the directory containing the ICU headers
ICU_<C>_LIBRARY - the library for component <C>; ``<C>`` is upper-case.

NOTE:

In most cases none of the above variables will require setting, unless multiple ICU versions are available and a specific version is required.

Find ImageMagick, software suite for displaying, converting and manipulating raster images.

Added in version 3.9: Added support for ImageMagick 7.

This module will search for a set of ImageMagick tools specified as components in the find_package() call. Typical components include, but are not limited to (future versions of ImageMagick might have additional components not listed here):

  • animate
  • compare
  • composite
  • conjure
  • convert
  • display
  • identify
  • import
  • mogrify
  • montage
  • stream

If no component is specified in the find_package() call, then it only searches for the ImageMagick executable directory.

There are also components for the following ImageMagick APIs:

  • Magick++: ImageMagick C++ API, if found.
  • MagickWand: ImageMagick MagickWand C API, if found.
  • MagickCore: ImageMagick MagickCore low-level C API, if found.

Imported targets

Added in version 3.26.

This module defines the following IMPORTED targets:

ImageMagick C++ API, if found.
ImageMagick MagickWand C API, if found.
ImageMagick MagickCore low-level C API, if found.

Result Variables

TRUE if all components are found.
Full path to executables directory.
Full paths to all include dirs.
Full paths to all libraries.
Compile options of all libraries.
The version of ImageMagick found (since CMake 2.8.8). Will not work for old versions like 5.2.3.
TRUE if <component> is found.
Full path to <component> executable.
Full path to <component> include dirs.
Added in version 3.26.

Compile options of <component>.

Full path to <component> libraries.

Example Usage

find_package(ImageMagick COMPONENTS Magick++)
target_link_libraries(example PRIVATE ImageMagick::Magick++)

Added in version 3.2.

Find the Gettext libintl headers and libraries.

This module reports information about the Gettext libintl installation in several variables.

True if libintl is found.
The directory containing the libintl headers.
The intl libraries to be linked.
Added in version 3.21.

The version of intl found (x.y.z)

Added in version 3.21.

The major version of intl

Added in version 3.21.

The minor version of intl

Added in version 3.21.

The patch version of intl

Added in version 3.20: This module defines IMPORTED target Intl::Intl.

The following cache variables may also be set:

The directory containing the libintl headers
The libintl library (if any)
Added in version 3.20.

whether intl is a part of the C library.

NOTE:

On some platforms, such as Linux with GNU libc, the gettext functions are present in the C standard library and libintl is not required. Intl_LIBRARIES will be empty in this case.

NOTE:

Some libintl implementations don't embed the version number in their header files. In this case the variables Intl_VERSION* will be empty.

NOTE:

If you wish to use the Gettext tools (msgmerge, msgfmt, etc.), use FindGettext.

Find the Jasper JPEG2000 library.

IMPORTED Targets

The jasper library, if found.

Result Variables

This module defines the following variables:

system has Jasper
Added in version 3.22.

the Jasper include directory

the libraries needed to use Jasper
the version of Jasper found

Cache variables

The following cache variables may also be set:

where to find jasper/jasper.h, etc.
where to find the Jasper library (optimized).
where to find the Jasper library (debug).

Find Java

This module finds if Java is installed and determines where the include files and libraries are. The caller may set variable JAVA_HOME to specify a Java installation prefix explicitly.

See also the FindJNI module to find Java Native Interface (JNI).

Added in version 3.10: Added support for Java 9+ version parsing.

Specify one or more of the following components as you call this find module. See example below.

Runtime     = Java Runtime Environment used to execute Java byte-compiled applications
Development = Development tools (java, javac, javah, jar and javadoc), includes Runtime component
IdlJ        = Interface Description Language (IDL) to Java compiler
JarSigner   = Signer and verifier tool for Java Archive (JAR) files

This module sets the following result variables:

Java_JAVA_EXECUTABLE      = the full path to the Java runtime
Java_JAVAC_EXECUTABLE     = the full path to the Java compiler
Java_JAVAH_EXECUTABLE     = the full path to the Java header generator
Java_JAVADOC_EXECUTABLE   = the full path to the Java documentation generator
Java_IDLJ_EXECUTABLE      = the full path to the Java idl compiler
Java_JAR_EXECUTABLE       = the full path to the Java archiver
Java_JARSIGNER_EXECUTABLE = the full path to the Java jar signer
Java_VERSION_STRING       = Version of java found, eg. 1.6.0_12
Java_VERSION_MAJOR        = The major version of the package found.
Java_VERSION_MINOR        = The minor version of the package found.
Java_VERSION_PATCH        = The patch version of the package found.
Java_VERSION_TWEAK        = The tweak version of the package found (after '_')
Java_VERSION              = This is set to: $major[.$minor[.$patch[.$tweak]]]

Added in version 3.4: Added the Java_IDLJ_EXECUTABLE and Java_JARSIGNER_EXECUTABLE variables.

The minimum required version of Java can be specified using the find_package() syntax, e.g.

find_package(Java 1.8)

NOTE: ${Java_VERSION} and ${Java_VERSION_STRING} are not guaranteed to be identical. For example some java version may return: Java_VERSION_STRING = 1.8.0_17 and Java_VERSION = 1.8.0.17

another example is the Java OEM, with: Java_VERSION_STRING = 1.8.0-oem and Java_VERSION = 1.8.0

For these components the following variables are set:

Java_FOUND                    - TRUE if all components are found.
Java_<component>_FOUND        - TRUE if <component> is found.

Example Usages:

find_package(Java)
find_package(Java 1.8 REQUIRED)
find_package(Java COMPONENTS Runtime)
find_package(Java COMPONENTS Development)

Find Java Native Interface (JNI) headers and libraries.

JNI enables Java code running in a Java Virtual Machine (JVM) or Dalvik Virtual Machine (DVM) on Android to call and be called by native applications and libraries written in other languages such as C and C++.

This module finds if Java is installed and determines where the include files and libraries are. It also determines what the name of the library is. The caller may set variable JAVA_HOME to specify a Java installation prefix explicitly.

Added in version 3.24: Added imported targets, components AWT, JVM, and Android NDK support. If no components are specified, the module defaults to an empty components list while targeting Android, and all available components otherwise.

When using Android NDK, the corresponding package version is reported and a specific release can be requested. At Android API level 31 and above, the additional NativeHelper component can be requested. NativeHelper is also exposed as an implicit dependency of the JVM component (only if this does not cause a conflict) which provides a uniform access to JVM functions.

Imported Targets

Added in version 3.24.

Main JNI target, defined only if jni.h was found.
Java AWT Native Interface (JAWT) library, defined only if component AWT was found.
Java Virtual Machine (JVM) library, defined only if component JVM was found.
When targeting Android API level 31 and above, the import target will provide access to libnativehelper.so that exposes JVM functions such as JNI_CreateJavaVM.

Result Variables

This module sets the following result variables:

The include directories to use.
The libraries to use (JAWT and JVM).
TRUE if JNI headers and libraries were found.
Added in version 3.24.

TRUE if <component> was found.

Full Android NDK package version (including suffixes such as -beta3 and -rc1) or undefined otherwise.
Added in version 3.24.

Android NDK major version or undefined otherwise.

Added in version 3.24.

Android NDK minor version or undefined otherwise.

Added in version 3.24.

Android NDK patch version or undefined otherwise.

Cache Variables

The following cache variables are also available to set or use:

The path to the Java AWT Native Interface (JAWT) library.
The path to the Java Virtual Machine (JVM) library.
The include path to jni.h.
The include path to machine-dependant headers jni_md.h and jniport.h. The variable is defined only if jni.h depends on one of these headers. In contrast, Android NDK jni.h can be typically used standalone.
The include path to jawt.h.

Find the Joint Photographic Experts Group (JPEG) library (libjpeg)

Imported targets

Added in version 3.12.

This module defines the following IMPORTED targets:

The JPEG library, if found.

Result variables

This module will set the following variables in your project:

If false, do not try to use JPEG.
where to find jpeglib.h, etc.
the libraries needed to use JPEG.
Added in version 3.12: the version of the JPEG library found

Cache variables

The following cache variables may also be set:

where to find jpeglib.h, etc.
where to find the JPEG library (optimized).
where to find the JPEG library (debug).

Added in version 3.12: Debug and Release variand are found separately.

Obsolete variables

where to find jpeglib.h, etc. (same as JPEG_INCLUDE_DIRS)
where to find the JPEG library.

Find the KDE3 include and library dirs, KDE preprocessors and define a some macros

This module defines the following variables:

compiler definitions required for compiling KDE software
the KDE include directory
the KDE and the Qt include directory, for use with include_directories()
the directory where the KDE libraries are installed, for use with link_directories()
this contains both the Qt and the kdecore library
the dcopidl executable
the dcopidl2cpp executable
the kconfig_compiler executable
set to TRUE if all of the above has been found

The following user adjustable options are provided:

enable this to build KDE testcases

It also adds the following macros (from KDE3Macros.cmake) SRCS_VAR is always the variable which contains the list of source files for your application or library.

KDE3_AUTOMOC(file1 ... fileN)

Call this if you want to have automatic moc file handling.
This means if you include "foo.moc" in the source file foo.cpp
a moc file for the header foo.h will be created automatically.
You can set the property SKIP_AUTOMAKE using set_source_files_properties()
to exclude some files in the list from being processed.

KDE3_ADD_MOC_FILES(SRCS_VAR file1 ... fileN )

If you don't use the KDE3_AUTOMOC() macro, for the files
listed here moc files will be created (named "foo.moc.cpp")

KDE3_ADD_DCOP_SKELS(SRCS_VAR header1.h ... headerN.h )

Use this to generate DCOP skeletions from the listed headers.

KDE3_ADD_DCOP_STUBS(SRCS_VAR header1.h ... headerN.h )

Use this to generate DCOP stubs from the listed headers.

KDE3_ADD_UI_FILES(SRCS_VAR file1.ui ... fileN.ui )

Use this to add the Qt designer ui files to your application/library.

KDE3_ADD_KCFG_FILES(SRCS_VAR file1.kcfgc ... fileN.kcfgc )

Use this to add KDE kconfig compiler files to your application/library.

KDE3_INSTALL_LIBTOOL_FILE(target)

This will create and install a simple libtool file for the given target.

KDE3_ADD_EXECUTABLE(name file1 ... fileN )

Currently identical to add_executable(), may provide some advanced
features in the future.

KDE3_ADD_KPART(name [WITH_PREFIX] file1 ... fileN )

Create a KDE plugin (KPart, kioslave, etc.) from the given source files.
If WITH_PREFIX is given, the resulting plugin will have the prefix "lib",
otherwise it won't.
It creates and installs an appropriate libtool la-file.

KDE3_ADD_KDEINIT_EXECUTABLE(name file1 ... fileN )

Create a KDE application in the form of a module loadable via kdeinit.
A library named kdeinit_<name> will be created and a small executable
which links to it.

The option KDE3_ENABLE_FINAL to enable all-in-one compilation is no longer supported.

Author: Alexander Neundorf <neundorf@kde.org>

Find KDE4 and provide all necessary variables and macros to compile software for it. It looks for KDE 4 in the following directories in the given order:

CMAKE_INSTALL_PREFIX
KDEDIRS
/opt/kde4

Please look in FindKDE4Internal.cmake and KDE4Macros.cmake for more information. They are installed with the KDE 4 libraries in $KDEDIRS/share/apps/cmake/modules/.

Author: Alexander Neundorf <neundorf@kde.org>

Find Linear Algebra PACKage (LAPACK) library

This module finds an installed Fortran library that implements the LAPACK linear-algebra interface.

At least one of the C, CXX, or Fortran languages must be enabled.

Input Variables

The following variables may be set to influence this module's behavior:

if ON use static linkage
Set to one of the BLAS/LAPACK Vendors to search for BLAS only from the specified vendor. If not set, all vendors are considered.
if ON tries to find the BLAS95/LAPACK95 interfaces
Added in version 3.20.

if set pkg-config will be used to search for a LAPACK library first and if one is found that is preferred

Added in version 3.25.

If set, the pkg-config method will look for this module name instead of just lapack.

Added in version 3.22.

Specify the BLAS/LAPACK library integer size:

4
Search for a BLAS/LAPACK with 32-bit integer interfaces.
8
Search for a BLAS/LAPACK with 64-bit integer interfaces.
Search for any BLAS/LAPACK. Most likely, a BLAS/LAPACK with 32-bit integer interfaces will be found.

Imported targets

This module defines the following IMPORTED targets:

Added in version 3.18.

The libraries to use for LAPACK, if found.

Result Variables

This module defines the following variables:

library implementing the LAPACK interface is found
uncached list of required linker flags (excluding -l and -L).
uncached list of libraries (using full path name) to link against to use LAPACK
uncached list of libraries (using full path name) to link against to use LAPACK95
library implementing the LAPACK95 interface is found

Intel MKL

To use the Intel MKL implementation of LAPACK, a project must enable at least one of the C or CXX languages. Set BLA_VENDOR to an Intel MKL variant either on the command-line as -DBLA_VENDOR=Intel10_64lp or in project code:

set(BLA_VENDOR Intel10_64lp)
find_package(LAPACK)

In order to build a project using Intel MKL, and end user must first establish an Intel MKL environment. See the FindBLAS module section on Intel MKL for details.

Find LaTeX

This module finds an installed LaTeX and determines the location of the compiler. Additionally the module looks for Latex-related software like BibTeX.

Added in version 3.2: Component processing; support for htlatex, pdftops, Biber, xindy, XeLaTeX, LuaLaTeX.

This module sets the following result variables:

LATEX_FOUND:          whether found Latex and requested components
LATEX_<component>_FOUND:  whether found <component>
LATEX_COMPILER:       path to the LaTeX compiler
PDFLATEX_COMPILER:    path to the PdfLaTeX compiler
XELATEX_COMPILER:     path to the XeLaTeX compiler
LUALATEX_COMPILER:    path to the LuaLaTeX compiler
BIBTEX_COMPILER:      path to the BibTeX compiler
BIBER_COMPILER:       path to the Biber compiler
MAKEINDEX_COMPILER:   path to the MakeIndex compiler
XINDY_COMPILER:       path to the xindy compiler
DVIPS_CONVERTER:      path to the DVIPS converter
DVIPDF_CONVERTER:     path to the DVIPDF converter
PS2PDF_CONVERTER:     path to the PS2PDF converter
PDFTOPS_CONVERTER:    path to the pdftops converter
LATEX2HTML_CONVERTER: path to the LaTeX2Html converter
HTLATEX_COMPILER:     path to the htlatex compiler

Possible components are:

PDFLATEX
XELATEX
LUALATEX
BIBTEX
BIBER
MAKEINDEX
XINDY
DVIPS
DVIPDF
PS2PDF
PDFTOPS
LATEX2HTML
HTLATEX

Example Usages:

find_package(LATEX)
find_package(LATEX COMPONENTS PDFLATEX)
find_package(LATEX COMPONENTS BIBTEX PS2PDF)

Find libarchive library and headers. Libarchive is multi-format archive and compression library.

The module defines the following variables:

LibArchive_FOUND        - true if libarchive was found
LibArchive_INCLUDE_DIRS - include search path
LibArchive_LIBRARIES    - libraries to link
LibArchive_VERSION      - libarchive 3-component version number

The module defines the following IMPORTED targets:

LibArchive::LibArchive  - target for linking against libarchive

Added in version 3.6: Support for new libarchive 3.2 version string format.

Added in version 3.17: Provides an imported target.

Added in version 3.14.

Find libinput headers and library.

Imported Targets

The libinput library, if found.

Result Variables

This will define the following variables in your project:

true if (the requested version of) libinput is available.
the version of libinput.
the libraries to link against to use libinput.
where to find the libinput headers.
this should be passed to target_compile_options(), if the target is not used for linking

Find LZMA compression algorithm headers and library.

Imported Targets

Added in version 3.14.

This module defines IMPORTED target LibLZMA::LibLZMA, if liblzma has been found.

Result variables

This module will set the following variables in your project:

True if liblzma headers and library were found.
Directory where liblzma headers are located.
Lzma libraries to link against.
True if lzma_auto_decoder() is found (required).
True if lzma_easy_encoder() is found (required).
True if lzma_lzma_preset() is found (required).
Added in version 3.26: the version of LZMA found.

See also legacy variable LIBLZMA_VERSION_STRING.

Legacy Variables

The following variables are provided for backward compatibility:

The major version of lzma
The minor version of lzma
The patch version of lzma
version number as a string (ex: "5.0.3")

Changed in version 3.26: Superseded by LIBLZMA_VERSION.

Find the XML processing library (libxml2).

IMPORTED Targets

Added in version 3.12.

The following IMPORTED targets may be defined:

libxml2 library.
Added in version 3.17.

xmllint command-line executable.

Result variables

This module will set the following variables in your project:

true if libxml2 headers and libraries were found
the directory containing LibXml2 headers
list of the include directories needed to use LibXml2
LibXml2 libraries to be linked
the compiler switches required for using LibXml2
path to the XML checking tool xmllint coming with LibXml2
the version of LibXml2 found (since CMake 2.8.8)

Cache variables

The following cache variables may also be set:

the directory containing LibXml2 headers
path to the LibXml2 library

Find the XSL Transformations, Extensible Stylesheet Language Transformations (XSLT) library (LibXslt)

IMPORTED Targets

Added in version 3.18.

The following IMPORTED targets may be defined:

If the libxslt library has been found
If the libexslt library has been found
If the xsltproc command-line executable has been found

Result variables

This module will set the following variables in your project:

LIBXSLT_FOUND - system has LibXslt LIBXSLT_INCLUDE_DIR - the LibXslt include directory LIBXSLT_LIBRARIES - Link these to LibXslt LIBXSLT_DEFINITIONS - Compiler switches required for using LibXslt LIBXSLT_VERSION_STRING - version of LibXslt found (since CMake 2.8.8)

Additionally, the following two variables are set (but not required for using xslt):

Added in version 3.18: The include directory for exslt.
Link to these if you need to link against the exslt library.
Contains the full path to the xsltproc executable if found.

Added in version 3.6.

Find Linux Trace Toolkit Next Generation (LTTng-UST) library.

This module defines the following IMPORTED target:

The LTTng-UST library, if found

Result variables

This module sets the following

TRUE if system has LTTng-UST
The LTTng-UST include directories
The libraries needed to use LTTng-UST
The LTTng-UST version
TRUE if the tracef() API is available in the system's LTTng-UST
TRUE if the tracelog() API is available in the system's LTTng-UST

Locate Lua library.

Added in version 3.18: Support for Lua 5.4.

This module defines:

if false, do not try to link to Lua
both lua and lualib
where to find lua.h
the version of Lua found
the major version of Lua
the minor version of Lua
the patch version of Lua

Note that the expected include convention is

#include "lua.h"

and not

#include <lua/lua.h>

This is because, the lua location is not standardized and may exist in locations other than lua/

Locate Lua library.

This module defines:

LUA50_FOUND, if false, do not try to link to Lua
LUA_LIBRARIES, both lua and lualib
LUA_INCLUDE_DIR, where to find lua.h and lualib.h (and probably lauxlib.h)

Note that the expected include convention is:

#include "lua.h"

and not:

#include <lua/lua.h>

This is because, the lua location is not standardized and may exist in locations other than lua/

Locate Lua library. This module defines:

LUA51_FOUND, if false, do not try to link to Lua
LUA_LIBRARIES
LUA_INCLUDE_DIR, where to find lua.h
LUA_VERSION_STRING, the version of Lua found (since CMake 2.8.8)

Note that the expected include convention is:

#include "lua.h"

and not:

#include <lua/lua.h>

This is because, the lua location is not standardized and may exist in locations other than lua/

Finds Matlab or Matlab Compiler Runtime (MCR) and provides Matlab tools, libraries and compilers to CMake.

This package primary purpose is to find the libraries associated with Matlab or the MCR in order to be able to build Matlab extensions (mex files). It can also be used:

  • to run specific commands in Matlab in case Matlab is available
  • for declaring Matlab unit test
  • to retrieve various information from Matlab (mex extensions, versions and release queries, ...)

Added in version 3.12: Added Matlab Compiler Runtime (MCR) support.

The module supports the following components:

  • ENG_LIBRARY and MAT_LIBRARY: respectively the ENG and MAT libraries of Matlab
  • MAIN_PROGRAM the Matlab binary program. Note that this component is not available on the MCR version, and will yield an error if the MCR is found instead of the regular Matlab installation.
  • MEX_COMPILER the MEX compiler.
  • MCC_COMPILER the MCC compiler, included with the Matlab Compiler add-on.
  • SIMULINK the Simulink environment.

Added in version 3.7: Added the MAT_LIBRARY component.

Added in version 3.13: Added the ENGINE_LIBRARY, DATAARRAY_LIBRARY and MCC_COMPILER components.

Changed in version 3.14: Removed the MX_LIBRARY, ENGINE_LIBRARY and DATAARRAY_LIBRARY components. These libraries are found unconditionally.

Added in version 3.30: Added support for specifying a version range to find_package() and added support for specifying REGISTRY_VIEW to find_package(), matlab_extract_all_installed_versions_from_registry() and matlab_get_all_valid_matlab_roots_from_registry(). The default behavior remained unchanged, by using the registry view TARGET.

NOTE:

The version given to the find_package() directive is the Matlab version, which should not be confused with the Matlab release name (e.g. R2023b). The matlab_get_version_from_release_name() and matlab_get_release_name_from_version() provide a mapping between the release name and the version.

The variable Matlab_ROOT_DIR may be specified in order to give the path of the desired Matlab version. Otherwise, the behavior is platform specific:

  • Windows: The installed versions of Matlab/MCR are retrieved from the Windows registry. The REGISTRY_VIEW argument may optionally be specified to manually control whether 32bit or 64bit versions shall be searched for.
  • macOS: The installed versions of Matlab/MCR are given by the MATLAB default installation paths in /Application. If no such application is found, it falls back to the one that might be accessible from the PATH.
  • Unix: The desired Matlab should be accessible from the PATH. This does not work for MCR installation and Matlab_ROOT_DIR should be specified on this platform.

Additional information is provided when MATLAB_FIND_DEBUG is set. When a Matlab/MCR installation is found automatically and the MATLAB_VERSION is not given, the version is queried from Matlab directly (on Windows this may pop up a Matlab window) or from the MCR installation.

The mapping of the release names and the version of Matlab is performed by defining pairs (name, version). The variable MATLAB_ADDITIONAL_VERSIONS may be provided before the call to the find_package() in order to handle additional versions.

A Matlab scripts can be added to the set of tests using the matlab_add_unit_test(). By default, the Matlab unit test framework will be used (>= 2013a) to run this script, but regular .m files returning an exit code can be used as well (0 indicating a success).

Users or projects may set the following variables to configure the module behavior:

Added in version 3.25.

Default value for Matlab_ROOT_DIR, the root of the Matlab installation.

Matlab_ROOT_DIR
The root of the Matlab installation.
MATLAB_FIND_DEBUG
outputs debug information
MATLAB_ADDITIONAL_VERSIONS
additional versions of Matlab for the automatic retrieval of the installed versions.

Imported targets

Added in version 3.22.

This module defines the following IMPORTED targets:

The mex library, always available for MATLAB installations. Available for MCR installations if provided by MCR.
The mx library of Matlab (arrays), always available for MATLAB installations. Available for MCR installations if provided by MCR.
Matlab engine library. Available only if the ENG_LIBRARY component is requested.
Matlab matrix library. Available only if the MAT_LIBRARY component is requested.
Matlab C++ engine library, always available for MATLAB R2018a and newer. Available for MCR installations if provided by MCR.
Matlab C++ data array library, always available for MATLAB R2018a and newer. Available for MCR installations if provided by MCR.

Result variables

TRUE if the Matlab installation is found, FALSE otherwise. All variable below are defined if Matlab is found.
Added in version 3.27.

the numerical version (e.g. 23.2.0) of Matlab found. Not to be confused with Matlab release name (e.g. R2023b) that can be obtained with matlab_get_release_name_from_version().

Matlab_ROOT_DIR
the final root of the Matlab installation determined by the FindMatlab module.
the Matlab binary program. Available only if the component MAIN_PROGRAM is given in the find_package() directive.
the path of the Matlab libraries headers
library for mex, always available for MATLAB installations. Available for MCR installations if provided by MCR.
mx library of Matlab (arrays), always available for MATLAB installations. Available for MCR installations if provided by MCR.
Matlab engine library. Available only if the component ENG_LIBRARY is requested.
Matlab matrix library. Available only if the component MAT_LIBRARY is requested.
Added in version 3.13.

Matlab C++ engine library, always available for MATLAB R2018a and newer. Available for MCR installations if provided by MCR.

Added in version 3.13.

Matlab C++ data array library, always available for MATLAB R2018a and newer. Available for MCR installations if provided by MCR.

the whole set of libraries of Matlab
the mex compiler of Matlab. Currently not used. Available only if the component MEX_COMPILER is requested.
Added in version 3.13.

the mcc compiler of Matlab. Included with the Matlab Compiler add-on. Available only if the component MCC_COMPILER is requested.

the extension of the mex files for the current platform (given by Matlab).
Matlab_ROOT_DIR
the location of the root of the Matlab installation found. If this value is changed by the user, the result variables are recomputed.

returns the version from the Matlab release name
returns the release name from the Matlab version
adds a target compiling a MEX file.
adds a Matlab unit test file as a test to the project.
parses the registry for all Matlab versions. Available on Windows only. The part of the registry parsed is dependent on the host processor
returns all the possible Matlab or MCR paths, according to a previously given list. Only the existing/accessible paths are kept. This is mainly useful for the searching all possible Matlab installation.
returns the suffix to be used for the mex files (platform/architecture dependent)
returns the version of Matlab/MCR, given the full directory of the Matlab/MCR installation path.

By default, every symbols inside a MEX file defined with the command matlab_add_mex() have hidden visibility, except for the entry point. This is the default behavior of the MEX compiler, which lowers the risk of symbol collision between the libraries shipped with Matlab, and the libraries to which the MEX file is linking to. This is also the default on Windows platforms.

However, this is not sufficient in certain case, where for instance your MEX file is linking against libraries that are already loaded by Matlab, even if those libraries have different SONAMES. A possible solution is to hide the symbols of the libraries to which the MEX target is linking to. This can be achieved in GNU GCC compilers with the linker option -Wl,--exclude-libs,ALL.

in case your MEX file is using the GPU and in order to be able to run unit tests on this MEX file, the GPU resources should be properly released by Matlab. A possible solution is to make Matlab aware of the use of the GPU resources in the session, which can be performed by a command such as D = gpuDevice() at the beginning of the test script (or via a fixture).

The root folder of the Matlab installation. If set before the call to find_package(), the module will look for the components in that path. If not set, then an automatic search of Matlab will be performed. If set, it should point to a valid version of Matlab.
If set, the lookup of Matlab and the intermediate configuration steps are outputted to the console.
If set, specifies additional versions of Matlab that may be looked for. The variable should be a list of strings, organized by pairs of release name and versions, such as follows:
set(MATLAB_ADDITIONAL_VERSIONS
    "release_name1=corresponding_version1"
    "release_name2=corresponding_version2"
    ...
    )

Example:

set(MATLAB_ADDITIONAL_VERSIONS
    "R2013b=8.2"
    "R2013a=8.1"
    "R2012b=8.0")

The order of entries in this list matters when several versions of Matlab are installed. The priority is set according to the ordering in this list.

matlab_get_version_from_release_name(release version)
  • Input: release is the release name (e.g. R2023b)
  • Output: version is the version of Matlab (e.g. 23.2.0)

Returns the version of Matlab from a release name

NOTE:

This command provides correct versions mappings for Matlab but not MCR.
matlab_get_release_name_from_version(version release_name)
  • Input: version is the version of Matlab (e.g. 23.2.0)
  • Output: release_name is the release name (R2023b)

Returns the release name from the version of Matlab

NOTE:

This command provides correct version mappings for Matlab but not MCR.
This function parses the Windows registry and finds the Matlab versions that are installed. The found versions are stored in matlab_versions.
Added in version 3.30.
  • Output: matlab_versions is a list of all the versions of Matlab found
  • Input: REGISTRY_VIEW Optional registry view to use for registry interaction. The argument is passed (or omitted) to cmake_host_system_information() without further checks or modification.
  • Input: win64 is a boolean to search for the 64 bit version of Matlab. Set to ON to use the 64bit registry view or OFF to use the 32bit registry view. If finer control is needed, see signature above.
  • Output: matlab_versions is a list of all the versions of Matlab found

The returned list contains all versions under HKLM\SOFTWARE\Mathworks\MATLAB, HKLM\SOFTWARE\Mathworks\MATLAB Runtime and HKLM\SOFTWARE\Mathworks\MATLAB Compiler Runtime or an empty list in case an error occurred (or nothing found).

NOTE:

Only the versions are provided. No check is made over the existence of the installation referenced in the registry,
Populates the Matlab root with valid versions of Matlab or Matlab Runtime (MCR). The returned matlab_roots is organized in triplets (type,version_number,matlab_root_path), where type indicates either MATLAB or MCR.
matlab_get_all_valid_matlab_roots_from_registry(matlab_versions matlab_roots [REGISTRY_VIEW view])
  • Input: matlab_versions of each of the Matlab or MCR installations
  • Output: matlab_roots location of each of the Matlab or MCR installations
  • Input: REGISTRY_VIEW Optional registry view to use for registry interaction. The argument is passed (or omitted) to cmake_host_system_information() without further checks or modification.

Added in version 3.30: The optional REGISTRY_VIEW argument was added to provide a more precise interface on how to interact with the Windows Registry.

Returns the extension of the mex files (the suffixes). This function should not be called before the appropriate Matlab root has been found.
matlab_get_mex_suffix(matlab_root mex_suffix)
  • Input: matlab_root root of Matlab/MCR install e.g. Matlab_ROOT_DIR
  • Output: mex_suffix variable name in which the suffix will be returned.
This function runs Matlab program specified on arguments and extracts its version. If the path provided for the Matlab installation points to an MCR installation, the version is extracted from the installed files.
matlab_get_version_from_matlab_run(matlab_binary_path matlab_list_versions)
  • Input: matlab_binary_path path of the matlab binary executable
  • Output: matlab_list_versions the version extracted from Matlab
Adds a Matlab unit test to the test set of cmake/ctest. This command requires the component MAIN_PROGRAM and hence is not available for an MCR installation.

The unit test uses the Matlab unittest framework (default, available starting Matlab 2013b+) except if the option NO_UNITTEST_FRAMEWORK is given.

The function expects one Matlab test script file to be given. In the case NO_UNITTEST_FRAMEWORK is given, the unittest script file should contain the script to be run, plus an exit command with the exit value. This exit value will be passed to the ctest framework (0 success, non 0 failure). Additional arguments accepted by add_test() can be passed through TEST_ARGS (eg. CONFIGURATION <config> ...).

matlab_add_unit_test(
    NAME <name>
    UNITTEST_FILE matlab_file_containing_unittest.m
    [CUSTOM_TEST_COMMAND matlab_command_to_run_as_test]
    [UNITTEST_PRECOMMAND matlab_command_to_run]
    [TIMEOUT timeout]
    [ADDITIONAL_PATH path1 [path2 ...]]
    [MATLAB_ADDITIONAL_STARTUP_OPTIONS option1 [option2 ...]]
    [TEST_ARGS arg1 [arg2 ...]]
    [NO_UNITTEST_FRAMEWORK]
    )

Function Parameters:

NAME
name of the unittest in ctest.
the matlab unittest file. Its path will be automatically added to the Matlab path.
Matlab script command to run as the test. If this is not set, then the following is run: runtests('matlab_file_name'), exit(max([ans(1,:).Failed])) where matlab_file_name is the UNITTEST_FILE without the extension.
Matlab script command to be ran before the file containing the test (eg. GPU device initialization based on CMake variables).
the test timeout in seconds. Defaults to 180 seconds as the Matlab unit test may hang.
a list of paths to add to the Matlab path prior to running the unit test.
a list of additional option in order to run Matlab from the command line. -nosplash -nodesktop -nodisplay are always added.
Additional options provided to the add_test command. These options are added to the default options (eg. "CONFIGURATIONS Release")
when set, indicates that the test should not use the unittest framework of Matlab (available for versions >= R2013a).
This will be the working directory for the test. If specified it will also be the output directory used for the log file of the test run. If not specified the temporary directory ${CMAKE_BINARY_DIR}/Matlab will be used as the working directory and the log location.
Adds a Matlab MEX target. This commands compiles the given sources with the current tool-chain in order to produce a MEX file. The final name of the produced output may be specified, as well as additional link libraries, and a documentation entry for the MEX file. Remaining arguments of the call are passed to the add_library() or add_executable() command.
matlab_add_mex(
    NAME <name>
    [EXECUTABLE | MODULE | SHARED]
    SRC src1 [src2 ...]
    [OUTPUT_NAME output_name]
    [DOCUMENTATION file.txt]
    [LINK_TO target1 target2 ...]
    [R2017b | R2018a]
    [EXCLUDE_FROM_ALL]
    [NO_IMPLICIT_LINK_TO_MATLAB_LIBRARIES]
    [...]
)

Function Parameters:

NAME
name of the target.
list of source files.
a list of additional link dependencies. The target links to libmex and libmx by default, unless the NO_IMPLICIT_LINK_TO_MATLAB_LIBRARIES option is passed.
if given, overrides the default name. The default name is the name of the target without any prefix and with Matlab_MEX_EXTENSION suffix.
if given, the file file.txt will be considered as being the documentation file for the MEX file. This file is copied into the same folder without any processing, with the same name as the final mex file, and with extension .m. In that case, typing help <name> in Matlab prints the documentation contained in this file.
Added in version 3.14.

May be given to specify the version of the C API to use: R2017b specifies the traditional (separate complex) C API, and corresponds to the -R2017b flag for the mex command. R2018a specifies the new interleaved complex C API, and corresponds to the -R2018a flag for the mex command. Ignored if MATLAB version prior to R2018a. Defaults to R2017b.

Added in version 3.7.

May be given to specify the type of library to be created.

Added in version 3.7.

May be given to create an executable instead of a library. If no type is given explicitly, the type is SHARED.

This option has the same meaning as for EXCLUDE_FROM_ALL and is forwarded to add_library() or add_executable() commands.
Added in version 3.24.

This option permits to disable the automatic linking of MATLAB libraries, so that only the libraries that are actually required can be linked via the LINK_TO option.

The documentation file is not processed and should be in the following format:

% This is the documentation
function ret = mex_target_output_name(input1)

Find Microsoft Foundation Class Library (MFC) on Windows

Find the native MFC - i.e. decide if an application can link to the MFC libraries.

MFC_FOUND - Was MFC support found

You don't need to include anything or link anything to use it.

Try to find Motif (or lesstif)

Once done this will define:

MOTIF_FOUND        - system has MOTIF
MOTIF_INCLUDE_DIR  - include paths to use Motif
MOTIF_LIBRARIES    - Link these to use Motif

Find the native MPEG includes and library

This module defines

MPEG_INCLUDE_DIR, where to find MPEG.h, etc.
MPEG_LIBRARIES, the libraries required to use MPEG.
MPEG_FOUND, If false, do not try to use MPEG.

also defined, but not for general use are

MPEG_mpeg2_LIBRARY, where to find the MPEG library.
MPEG_vo_LIBRARY, where to find the vo library.

Find the native MPEG2 includes and library

This module defines

MPEG2_INCLUDE_DIR, path to mpeg2dec/mpeg2.h, etc.
MPEG2_LIBRARIES, the libraries required to use MPEG2.
MPEG2_FOUND, If false, do not try to use MPEG2.

also defined, but not for general use are

MPEG2_mpeg2_LIBRARY, where to find the MPEG2 library.
MPEG2_vo_LIBRARY, where to find the vo library.

Find a Message Passing Interface (MPI) implementation.

The Message Passing Interface (MPI) is a library used to write high-performance distributed-memory parallel applications, and is typically deployed on a cluster. MPI is a standard interface (defined by the MPI forum) for which many implementations are available.

Added in version 3.10: Major overhaul of the module: many new variables, per-language components, support for a wider variety of runtimes.

The module exposes the components C, CXX, MPICXX and Fortran. Each of these controls the various MPI languages to search for. The difference between CXX and MPICXX is that CXX refers to the MPI C API being usable from C++, whereas MPICXX refers to the MPI-2 C++ API that was removed again in MPI-3.

Depending on the enabled components the following variables will be set:

Variable indicating that MPI settings for all requested languages have been found. If no components are specified, this is true if MPI settings for all enabled languages were detected. Note that the MPICXX component does not affect this variable.
Minimal version of MPI detected among the requested languages, or all enabled languages if no components were specified.

This module will set the following variables per language in your project, where <lang> is one of C, CXX, or Fortran:

Variable indicating the MPI settings for <lang> were found and that simple MPI test programs compile with the provided settings.
MPI compiler for <lang> if such a program exists.
Compilation options for MPI programs in <lang>, given as a ;-list.
Compilation definitions for MPI programs in <lang>, given as a ;-list.
Include path(s) for MPI header.
Linker flags for MPI programs.
All libraries to link MPI programs against.

Added in version 3.9: Additionally, the following IMPORTED targets are defined:

Target for using MPI from <lang>.

The following variables indicating which bindings are present will be defined:

Variable indicating whether the MPI-2 C++ bindings are present (introduced in MPI-2, removed with MPI-3).
True if the Fortran 77 header mpif.h is available.
True if the Fortran 90 module mpi can be used for accessing MPI (MPI-2 and higher only).
True if the Fortran 2008 mpi_f08 is available to MPI programs (MPI-3 and higher only).

If possible, the MPI version will be determined by this module. The facilities to detect the MPI version were introduced with MPI-1.2, and therefore cannot be found for older MPI versions.

Major version of MPI implemented for <lang> by the MPI distribution.
Minor version of MPI implemented for <lang> by the MPI distribution.
MPI version implemented for <lang> by the MPI distribution.

Note that there's no variable for the C bindings being accessible through mpi.h, since the MPI standards always have required this binding to work in both C and C++ code.

For running MPI programs, the module sets the following variables

Executable for running MPI programs, if such exists.
Flag to pass to mpiexec before giving it the number of processors to run on.
Number of MPI processors to utilize. Defaults to the number of processors detected on the host system.
Flags to pass to mpiexec directly before the executable to run.
Flags to pass to mpiexec after other flags.

This module performs a four step search for an MPI implementation:

1.
Search for MPIEXEC_EXECUTABLE and, if found, use its base directory.
2.
Check if the compiler has MPI support built-in. This is the case if the user passed a compiler wrapper as CMAKE_<LANG>_COMPILER or if they use Cray system compiler wrappers.
3.
Attempt to find an MPI compiler wrapper and determine the compiler information from it.
4.
Try to find an MPI implementation that does not ship such a wrapper by guessing settings. Currently, only Microsoft MPI and MPICH2 on Windows are supported.

For controlling the MPIEXEC_EXECUTABLE step, the following variables may be set:

Manually specify the location of mpiexec.
Specify the base directory of the MPI installation.
Environment variable to specify the base directory of the MPI installation.
Environment variable to specify the base directory of the MPI installation.

For controlling the compiler wrapper step, the following variables may be set:

Search for the specified compiler wrapper and use it.
Flags to pass to the MPI compiler wrapper during interrogation. Some compiler wrappers support linking debug or tracing libraries if a specific flag is passed and this variable may be used to obtain them.
Used to initialize MPI_<lang>_COMPILER_FLAGS if no language specific flag has been given. Empty by default.
A suffix which is appended to all names that are being looked for. For instance you may set this to .mpich or .openmpi to prefer the one or the other on Debian and its derivatives.

In order to control the guessing step, the following variable may be set:

Valid values are MSMPI and MPICH2. If set, only the given library will be searched for. By default, MSMPI will be preferred over MPICH2 if both are available. This also sets MPI_SKIP_COMPILER_WRAPPER to true, which may be overridden.

Each of the search steps may be skipped with the following control variables:

If true, the module assumes that the compiler itself does not provide an MPI implementation and skips to step 2.
If true, no compiler wrapper will be searched for.
If true, the guessing step will be skipped.

Additionally, the following control variable is available to change search behavior:

Add some definitions that will disable the MPI-2 C++ bindings. Currently supported are MPICH, Open MPI, Platform MPI and derivatives thereof, for example MVAPICH or Intel MPI.

If the find procedure fails for a variable MPI_<lang>_WORKS, then the settings detected by or passed to the module did not work and even a simple MPI test program failed to compile.

If all of these parameters were not sufficient to find the right MPI implementation, a user may disable the entire autodetection process by specifying both a list of libraries in MPI_<lang>_LIBRARIES and a list of include directories in MPI_<lang>_ADDITIONAL_INCLUDE_DIRS. Any other variable may be set in addition to these two. The module will then validate the MPI settings and store the settings in the cache.

The variable MPI_<lang>_INCLUDE_DIRS will be assembled from the following variables. For C and CXX:

Location of the mpi.h header on disk.

For Fortran:

Location of the Fortran 77 header mpif.h, if it exists.
Location of the mpi or mpi_f08 modules, if available.

For all languages the following variables are additionally considered:

A ;-list of paths needed in addition to the normal include directories.
Path variables for include folders referred to by <include_name>.
A ;-list of <include_name> that will be added to the include locations of <lang>.

The variable MPI_<lang>_LIBRARIES will be assembled from the following variables:

The location of a library called <lib_name> for use with MPI.
A ;-list of <lib_name> that will be added to the include locations of <lang>.

When using MPIEXEC_EXECUTABLE to execute MPI applications, you should typically use all of the MPIEXEC_EXECUTABLE flags as follows:

${MPIEXEC_EXECUTABLE} ${MPIEXEC_NUMPROC_FLAG} ${MPIEXEC_MAX_NUMPROCS}
  ${MPIEXEC_PREFLAGS} EXECUTABLE ${MPIEXEC_POSTFLAGS} ARGS

where EXECUTABLE is the MPI program, and ARGS are the arguments to pass to the MPI program.

The module can perform some advanced feature detections upon explicit request.

Important notice: The following checks cannot be performed without executing an MPI test program. Consider the special considerations for the behavior of try_run() during cross compilation. Moreover, running an MPI program can cause additional issues, like a firewall notification on some systems. You should only enable these detections if you absolutely need the information.

If the following variables are set to true, the respective search will be performed:

Determine for all available Fortran bindings what the values of MPI_SUBARRAYS_SUPPORTED and MPI_ASYNC_PROTECTS_NONBLOCKING are and make their values available as MPI_Fortran_<binding>_SUBARRAYS and MPI_Fortran_<binding>_ASYNCPROT, where <binding> is one of F77_HEADER, F90_MODULE and F08_MODULE.
For each language, find the output of MPI_Get_library_version and make it available as MPI_<lang>_LIBRARY_VERSION_STRING. This information is usually tied to the runtime component of an MPI implementation and might differ depending on <lang>. Note that the return value is entirely implementation defined. This information might be used to identify the MPI vendor and for example pick the correct one of multiple third party binaries that matches the MPI vendor.

Backward Compatibility

Deprecated since version 3.10.

For backward compatibility with older versions of FindMPI, these variables are set:

MPI_COMPILER        MPI_LIBRARY        MPI_EXTRA_LIBRARY
MPI_COMPILE_FLAGS   MPI_INCLUDE_PATH   MPI_LINK_FLAGS
MPI_LIBRARIES

In new projects, please use the MPI_<lang>_XXX equivalents. Additionally, the following variables are deprecated:

Use MPI_<lang>_COMPILE_OPTIONS and MPI_<lang>_COMPILE_DEFINITIONS instead.
For consumption use MPI_<lang>_INCLUDE_DIRS and for specifying folders use MPI_<lang>_ADDITIONAL_INCLUDE_DIRS instead.
Use MPIEXEC_EXECUTABLE instead.

Added in version 3.21.

Find MSYS, a POSIX-compatible environment that runs natively on Microsoft Windows

Added in version 3.12.

Find an Open Database Connectivity (ODBC) include directory and library.

On Windows, when building with Visual Studio, this module assumes the ODBC library is provided by the available Windows SDK.

On Unix, this module allows to search for ODBC library provided by unixODBC or iODBC implementations of ODBC API. This module reads hint about location of the config program:

Location of odbc_config or iodbc-config program

Otherwise, this module tries to find the config program, first from unixODBC, then from iODBC. If no config program found, this module searches for ODBC header and library in list of known locations.

Imported targets

This module defines the following IMPORTED targets:

Imported target for using the ODBC library, if found.

Result variables

Set to true if ODBC library found, otherwise false or undefined.
Paths to include directories listed in one variable for use by ODBC client. May be empty on Windows, where the include directory corresponding to the expected Windows SDK is already available in the compilation environment.
Paths to libraries to linked against to use ODBC. May just a library name on Windows, where the library directory corresponding to the expected Windows SDK is already available in the compilation environment.
Path to unixODBC or iODBC config program, if found or specified.

Cache variables

For users who wish to edit and control the module behavior, this module reads hints about search locations from the following variables:

Path to ODBC include directory with sql.h header.
Path to ODBC library to be linked.

These variables should not be used directly by project code.

On Windows, this module does not search for iODBC. On Unix, there is no way to prefer unixODBC over iODBC, or vice versa, other than providing the config program location using the ODBC_CONFIG. This module does not allow to search for a specific ODBC driver.

Added in version 3.10.

Detect OpenACC support by the compiler.

This module can be used to detect OpenACC support in a compiler. If the compiler supports OpenACC, the flags required to compile with OpenACC support are returned in variables for the different languages. Currently, only NVHPC, PGI, GNU and Cray compilers are supported.

Imported Targets

Added in version 3.16.

The module provides IMPORTED targets:

Target for using OpenACC from <lang>.

The module defines the following variables:

Added in version 3.25.

Variable indicating that OpenACC flags for at least one languages have been found.

This module will set the following variables per language in your project, where <lang> is one of C, CXX, or Fortran:

Variable indicating if OpenACC support for <lang> was detected.
OpenACC compiler flags for <lang>, separated by spaces.
Added in version 3.16.

OpenACC compiler flags for <lang>, as a list. Suitable for usage with target_compile_options or target_link_options.

The module will also try to provide the OpenACC version variables:

Date of the OpenACC specification implemented by the <lang> compiler.
Major version of OpenACC implemented by the <lang> compiler.
Minor version of OpenACC implemented by the <lang> compiler.
OpenACC version implemented by the <lang> compiler.

The specification date is formatted as given in the OpenACC standard: yyyymm where yyyy and mm represents the year and month of the OpenACC specification implemented by the <lang> compiler.

Input Variables

OpenACC_ACCEL_TARGET=<target> If set, will the correct target accelerator flag set to the <target> will be returned with OpenACC_<lang>_FLAGS.

Finds Open Audio Library (OpenAL).

Projects using this module should use #include "al.h" to include the OpenAL header file, not #include <AL/al.h>. The reason for this is that the latter is not entirely portable. Windows/Creative Labs does not by default put their headers in AL/ and macOS uses the convention <OpenAL/al.h>.

Environment variable $OPENALDIR can be used to set the prefix of OpenAL installation to be found.

By default on macOS, system framework is search first. In other words, OpenAL is searched in the following order:

1.
System framework: /System/Library/Frameworks, whose priority can be changed via setting the CMAKE_FIND_FRAMEWORK variable.
2.
Environment variable $OPENALDIR.
3.
System paths.
4.
User-compiled framework: ~/Library/Frameworks.
5.
Manually compiled framework: /Library/Frameworks.
6.
Add-on package: /opt.

IMPORTED Targets

Added in version 3.25.

This module defines the IMPORTED target:

The OpenAL library, if found.

Result Variables

This module defines the following variables:

If false, do not try to link to OpenAL
OpenAL include directory
Path to the OpenAL library
Human-readable string containing the version of OpenAL

Added in version 3.1.

Finds Open Computing Language (OpenCL)

Added in version 3.10: Detection of OpenCL 2.1 and 2.2.

IMPORTED Targets

Added in version 3.7.

This module defines IMPORTED target OpenCL::OpenCL, if OpenCL has been found.

Result Variables

This module defines the following variables:

OpenCL_FOUND          - True if OpenCL was found
OpenCL_INCLUDE_DIRS   - include directories for OpenCL
OpenCL_LIBRARIES      - link against this library to use OpenCL
OpenCL_VERSION_STRING - Highest supported OpenCL version (eg. 1.2)
OpenCL_VERSION_MAJOR  - The major version of the OpenCL implementation
OpenCL_VERSION_MINOR  - The minor version of the OpenCL implementation

The module will also define two cache variables:

OpenCL_INCLUDE_DIR    - the OpenCL include directory
OpenCL_LIBRARY        - the path to the OpenCL library

FindModule for OpenGL and OpenGL Utility Library (GLU).

Changed in version 3.2: X11 is no longer added as a dependency on Unix/Linux systems.

Added in version 3.10: GLVND support on Linux. See the Linux-specific section below.

Optional COMPONENTS

Added in version 3.10.

This module respects several optional COMPONENTS:

The EGL interface between OpenGL, OpenGL ES and the underlying windowing system.
An extension to X that interfaces OpenGL, OpenGL ES with X window system.
The cross platform API for 3D graphics.
Added in version 3.27.

A subset of OpenGL API for embedded systems with limited capabilities.

Added in version 3.27.

A subset of OpenGL API for embedded systems with more capabilities.

IMPORTED Targets

Added in version 3.8.

This module defines the IMPORTED targets:

Defined to the platform-specific OpenGL libraries if the system has OpenGL.
Defined if the system has OpenGL Utility Library (GLU).

Added in version 3.10: Additionally, the following GLVND-specific library targets are defined:

Defined to libOpenGL if the system is GLVND-based.
Defined if the system has OpenGL Extension to the X Window System (GLX).
Defined if the system has EGL.
Added in version 3.27.

Defined if the system has GLES2.

Added in version 3.27.

Defined if the system has GLES3.

Result Variables

This module sets the following variables:

True, if the system has OpenGL and all components are found.
True, if the system has XMESA.
True, if the system has GLU.
True, if the system has an OpenGL library.
True, if the system has GLX.
True, if the system has EGL.
Defined if the system has GLES2.
Defined if the system has GLES3.
Path to the OpenGL include directory. The OPENGL_INCLUDE_DIRS variable is preferred.
Path to the EGL include directory.
Paths to the OpenGL library, windowing system libraries, and GLU libraries. On Linux, this assumes GLX and is never correct for EGL-based targets. Clients are encouraged to use the OpenGL::* import targets instead.
Added in version 3.29.

Paths to the OpenGL include directories.

Added in version 3.10: Variables for GLVND-specific libraries OpenGL, EGL and GLX.

Cache variables

The following cache variables may also be set:

Path to the EGL library.
Path to the GLU library.
Path to the GLVND 'GLX' library.
Path to the GLVND 'OpenGL' library
Path to the OpenGL library. New code should prefer the OpenGL::* import targets.
Added in version 3.27.

Path to the OpenGL GLES2 library.

Added in version 3.27.

Path to the OpenGL GLES3 library.

Added in version 3.29.

Path to the OpenGL GLU include directory.

Added in version 3.10: Variables for GLVND-specific libraries OpenGL, EGL and GLX.

Some Linux systems utilize GLVND as a new ABI for OpenGL. GLVND separates context libraries from OpenGL itself; OpenGL lives in "libOpenGL", and contexts are defined in "libGLX" or "libEGL". GLVND is currently the only way to get OpenGL 3+ functionality via EGL in a manner portable across vendors. Projects may use GLVND explicitly with target OpenGL::OpenGL and either OpenGL::GLX or OpenGL::EGL.

Projects may use the OpenGL::GL target (or OPENGL_LIBRARIES variable) to use legacy GL interfaces. These will use the legacy GL library located by OPENGL_gl_LIBRARY, if available. If OPENGL_gl_LIBRARY is empty or not found and GLVND is available, the OpenGL::GL target will use GLVND OpenGL::OpenGL and OpenGL::GLX (and the OPENGL_LIBRARIES variable will use the corresponding libraries). Thus, for non-EGL-based Linux targets, the OpenGL::GL target is most portable.

A OpenGL_GL_PREFERENCE variable may be set to specify the preferred way to provide legacy GL interfaces in case multiple choices are available. The value may be one of:

If the GLVND OpenGL and GLX libraries are available, prefer them. This forces OPENGL_gl_LIBRARY to be empty.

Changed in version 3.11: This is the default, unless policy CMP0072 is set to OLD and no components are requested (since components correspond to GLVND libraries).

Prefer to use the legacy libGL library, if available.

For EGL targets the client must rely on GLVND support on the user's system. Linking should use the OpenGL::OpenGL OpenGL::EGL targets. Using GLES* libraries is theoretically possible in place of OpenGL::OpenGL, but this module does not currently support that; contributions welcome.

OPENGL_egl_LIBRARY and OPENGL_EGL_INCLUDE_DIRS are defined in the case of GLVND. For non-GLVND Linux and other systems these are left undefined.

On macOS this module defaults to using the macOS-native framework version of OpenGL. To use the X11 version of OpenGL on macOS, one can disable searching of frameworks. For example:

find_package(X11)
if(APPLE AND X11_FOUND)
  set(CMAKE_FIND_FRAMEWORK NEVER)
  find_package(OpenGL)
  unset(CMAKE_FIND_FRAMEWORK)
else()
  find_package(OpenGL)
endif()

An end user building this project may need to point CMake at their X11 installation, e.g., with -DOpenGL_ROOT=/opt/X11.

Finds Open Multi-Processing (OpenMP) support.

This module can be used to detect OpenMP support in a compiler. If the compiler supports OpenMP, the flags required to compile with OpenMP support are returned in variables for the different languages. The variables may be empty if the compiler does not need a special flag to support OpenMP.

Added in version 3.5: Clang support.

Input Variables

The following variables may be set to influence this module's behavior:

Added in version 3.30.

Specify the OpenMP Runtime when compiling with MSVC. If set to a non-empty value, such as experimental or llvm, it will be passed as the value of the -openmp: flag.

Result Variables

Added in version 3.10: The module exposes the components C, CXX, and Fortran. Each of these controls the various languages to search OpenMP support for.

Depending on the enabled components the following variables will be set:

Variable indicating that OpenMP flags for all requested languages have been found. If no components are specified, this is true if OpenMP settings for all enabled languages were detected.
Minimal version of the OpenMP standard detected among the requested languages, or all enabled languages if no components were specified.

This module will set the following variables per language in your project, where <lang> is one of C, CXX, or Fortran:

Variable indicating if OpenMP support for <lang> was detected.
OpenMP compiler flags for <lang>, separated by spaces.
Directories that must be added to the header search path for <lang> when using OpenMP.

For linking with OpenMP code written in <lang>, the following variables are provided:

;-list of libraries for OpenMP programs for <lang>.
Location of the individual libraries needed for OpenMP support in <lang>.
A list of libraries needed to link with OpenMP code written in <lang>.

Additionally, the module provides IMPORTED targets:

Target for using OpenMP from <lang>.

Specifically for Fortran, the module sets the following variables:

Boolean indicating if OpenMP is accessible through omp_lib.h.
Boolean indicating if OpenMP is accessible through the omp_lib Fortran module.

The module will also try to provide the OpenMP version variables:

Added in version 3.7.

Date of the OpenMP specification implemented by the <lang> compiler.

Major version of OpenMP implemented by the <lang> compiler.
Minor version of OpenMP implemented by the <lang> compiler.
OpenMP version implemented by the <lang> compiler.

The specification date is formatted as given in the OpenMP standard: yyyymm where yyyy and mm represents the year and month of the OpenMP specification implemented by the <lang> compiler.

For some compilers, it may be necessary to add a header search path to find the relevant OpenMP headers. This location may be language-specific. Where this is needed, the module may attempt to find the location, but it can be provided directly by setting the OpenMP_<lang>_INCLUDE_DIR cache variable. Note that this variable is an _input_ control to the module. Project code should use the OpenMP_<lang>_INCLUDE_DIRS _output_ variable if it needs to know what include directories are needed.

Find OpenSceneGraph (3D graphics application programming interface)

This module searches for the OpenSceneGraph core "osg" library as well as FindOpenThreads, and whatever additional COMPONENTS (nodekits) that you specify.

See http://www.openscenegraph.org

NOTE: To use this module effectively you must either require CMake >= 2.6.3 with cmake_minimum_required(VERSION 2.6.3) or download and place FindOpenThreads, Findosg functions, Findosg and Find<etc>.cmake files into your CMAKE_MODULE_PATH.


----



This module accepts the following variables (note mixed case)

OpenSceneGraph_DEBUG - Enable debugging output
OpenSceneGraph_MARK_AS_ADVANCED - Mark cache variables as advanced
                                  automatically

The following environment variables are also respected for finding the OSG and it's various components. CMAKE_PREFIX_PATH can also be used for this (see find_library() CMake documentation).

<MODULE>_DIR
(where MODULE is of the form "OSGVOLUME" and there is a FindosgVolume.cmake` file)

[CMake 2.8.10]: The CMake variable OSG_DIR can now be used as well to influence detection, instead of needing to specify an environment variable.

This module defines the following output variables:

OPENSCENEGRAPH_FOUND - Was the OSG and all of the specified components found?
OPENSCENEGRAPH_VERSION - The version of the OSG which was found
OPENSCENEGRAPH_INCLUDE_DIRS - Where to find the headers
OPENSCENEGRAPH_LIBRARIES - The OSG libraries

================================== Example Usage:

find_package(OpenSceneGraph 2.0.0 REQUIRED osgDB osgUtil)
    # libOpenThreads & libosg automatically searched
include_directories(${OPENSCENEGRAPH_INCLUDE_DIRS})
add_executable(foo foo.cc)
target_link_libraries(foo ${OPENSCENEGRAPH_LIBRARIES})

Added in version 3.25.

Try to find the OpenSP library.

Result Variables

This will define the following variables:

True if (the requested version of) OpenSP is available
The version of OpenSP
The major version of OpenSP
The minor version of OpenSP
The patch version of OpenSP
The include dirs of OpenSP with its headers
The OpenSP library for use with target_link_libraries(). This can be passed to target_link_libraries() instead of the IMPORTED OpenSP::OpenSP target
True if SP_MULTI_BYTE was found to be defined in OpenSP's config.h header file, which indicates that the OpenSP library was compiled with support for multi-byte characters. The consuming target needs to define the SP_MULTI_BYTE to match this value in order to avoid issues with character decoding.

IMPORTED Targets

This module defines the IMPORTED target OpenSP::OpenSP, if OpenSP has been found.

Cache variables

The following cache variables may also be set:

the OpenSP include directory
the absolute path of the osp library

Find the OpenSSL encryption library.

This module finds an installed OpenSSL library and determines its version.

Added in version 3.19: When a version is requested, it can be specified as a simple value or as a range. For a detailed description of version range usage and capabilities, refer to the find_package() command.

Added in version 3.18: Support for OpenSSL 3.0.

Optional COMPONENTS

Added in version 3.12.

This module supports two optional COMPONENTS: Crypto and SSL. Both components have associated imported targets, as described below.

Imported Targets

Added in version 3.4.

This module defines the following IMPORTED targets:

The OpenSSL ssl library, if found.
The OpenSSL crypto library, if found.
Added in version 3.18.

The OpenSSL applink components that might be need to be compiled into projects under MSVC. This target is available only if found OpenSSL version is not less than 0.9.8. By linking this target the above OpenSSL targets can be linked even if the project has different MSVC runtime configurations with the above OpenSSL targets. This target has no effect on platforms other than MSVC.

NOTE: Due to how INTERFACE_SOURCES are consumed by the consuming target, unless you certainly know what you are doing, it is always preferred to link OpenSSL::applink target as PRIVATE and to make sure that this target is linked at most once for the whole dependency graph of any library or executable:

target_link_libraries(myTarget PRIVATE OpenSSL::applink)

Otherwise you would probably encounter unexpected random problems when building and linking, as both the ISO C and the ISO C++ standard claims almost nothing about what a link process should be.

Result Variables

This module will set the following variables in your project:

System has the OpenSSL library. If no components are requested it only requires the crypto library.
The OpenSSL include directory.
The OpenSSL crypto library.
The OpenSSL crypto library and its dependencies.
The OpenSSL SSL library.
The OpenSSL SSL library and its dependencies.
All OpenSSL libraries and their dependencies.
This is set to $major.$minor.$revision$patch (e.g. 0.9.8s).
The sources in the target OpenSSL::applink that is mentioned above. This variable shall always be undefined if found openssl version is less than 0.9.8 or if platform is not MSVC.

The following variables may be set to control search behavior:

Set to the root directory of an OpenSSL installation.
Added in version 3.4.

Set to TRUE to look for static libraries.

Added in version 3.5.

Set to TRUE to choose the MT version of the lib.

On UNIX-like systems, pkg-config is used to locate the system OpenSSL. Set the PKG_CONFIG_PATH environment variable to look in alternate locations. Useful on multi-lib systems.

OpenThreads is a C++ based threading library. Its largest userbase seems to OpenSceneGraph so you might notice I accept OSGDIR as an environment path. I consider this part of the Findosg* suite used to find OpenSceneGraph components. Each component is separate and you must opt in to each module.

This module defines:

OPENTHREADS_LIBRARY

if false, do not try to link to OpenThreads
where to find the headers

$OPENTHREADS_DIR is an environment variable that would correspond to the:

./configure --prefix=$OPENTHREADS_DIR

used in building osg.

Added in version 2.8.10: The CMake variables OPENTHREADS_DIR or OSG_DIR can now be used as well to influence detection, instead of needing to specify an environment variable.

NOTE:

It is highly recommended that you use the new FindOpenSceneGraph introduced in CMake 2.6.3 and not use this Find module directly.

This is part of the Findosg* suite used to find OpenSceneGraph components. Each component is separate and you must opt in to each module. You must also opt into OpenGL and OpenThreads (and Producer if needed) as these modules won't do it for you. This is to allow you control over your own system piece by piece in case you need to opt out of certain components or change the Find behavior for a particular module (perhaps because the default FindOpenGL module doesn't work with your system as an example). If you want to use a more convenient module that includes everything, use the FindOpenSceneGraph instead of the Findosg*.cmake modules.

Locate osg This module defines:

Was the Osg found?
Where to find theheaders
The libraries to link against for the OSG (use this)
The OSG library
The OSG debug library

$OSGDIR is an environment variable that would correspond to:

./configure --prefix=$OSGDIR

used in building osg.

Created by Eric Wing.

This CMake file contains two macros to assist with searching for OSG libraries and nodekits. Please see FindOpenSceneGraph for full documentation.

This is part of the Findosg* suite used to find OpenSceneGraph components. Each component is separate and you must opt in to each module. You must also opt into OpenGL and OpenThreads (and Producer if needed) as these modules won't do it for you. This is to allow you control over your own system piece by piece in case you need to opt out of certain components or change the Find behavior for a particular module (perhaps because the default FindOpenGL module doesn't work with your system as an example). If you want to use a more convenient module that includes everything, use the FindOpenSceneGraph instead of the Findosg*.cmake modules.

Locate osgAnimation This module defines:

Was osgAnimation found?
Where to find the headers
The libraries to link against for the OSG (use this)
The OSG library
The OSG debug library

$OSGDIR is an environment variable that would correspond to:

./configure --prefix=$OSGDIR

used in building osg. Created by Eric Wing.

This is part of the Findosg* suite used to find OpenSceneGraph components. Each component is separate and you must opt in to each module. You must also opt into OpenGL and OpenThreads (and Producer if needed) as these modules won't do it for you. This is to allow you control over your own system piece by piece in case you need to opt out of certain components or change the Find behavior for a particular module (perhaps because the default FindOpenGL module doesn't work with your system as an example). If you want to use a more convenient module that includes everything, use the FindOpenSceneGraph instead of the Findosg*.cmake modules.

Locate osgDB This module defines:

Was osgDB found?
Where to find the headers
The libraries to link against for the osgDB
The osgDB library
The osgDB debug library

$OSGDIR is an environment variable that would correspond to:

./configure --prefix=$OSGDIR

used in building osg.

This is part of the Findosg* suite used to find OpenSceneGraph components. Each component is separate and you must opt in to each module. You must also opt into OpenGL and OpenThreads (and Producer if needed) as these modules won't do it for you. This is to allow you control over your own system piece by piece in case you need to opt out of certain components or change the Find behavior for a particular module (perhaps because the default FindOpenGL module doesn't work with your system as an example). If you want to use a more convenient module that includes everything, use the FindOpenSceneGraph instead of the Findosg*.cmake modules.

Locate osgFX This module defines:

Was osgFX found?
Where to find the headers
The libraries to link against for the osgFX (use this)
The osgFX library
The osgFX debug library

$OSGDIR is an environment variable that would correspond to:

./configure --prefix=$OSGDIR

used in building osg.

Created by Eric Wing.

This is part of the Findosg* suite used to find OpenSceneGraph components. Each component is separate and you must opt in to each module. You must also opt into OpenGL and OpenThreads (and Producer if needed) as these modules won't do it for you. This is to allow you control over your own system piece by piece in case you need to opt out of certain components or change the Find behavior for a particular module (perhaps because the default FindOpenGL module doesn't work with your system as an example). If you want to use a more convenient module that includes everything, use the FindOpenSceneGraph instead of the Findosg*.cmake modules.

Locate osgGA This module defines:

Was osgGA found?
Where to find the headers
The libraries to link against for the osgGA (use this)
The osgGA library
The osgGA debug library

$OSGDIR is an environment variable that would correspond to:

./configure --prefix=$OSGDIR

used in building osg.

Created by Eric Wing.

This is part of the Findosg* suite used to find OpenSceneGraph components. Each component is separate and you must opt in to each module. You must also opt into OpenGL and OpenThreads (and Producer if needed) as these modules won't do it for you. This is to allow you control over your own system piece by piece in case you need to opt out of certain components or change the Find behavior for a particular module (perhaps because the default FindOpenGL module doesn't work with your system as an example). If you want to use a more convenient module that includes everything, use the FindOpenSceneGraph instead of the Findosg*.cmake modules.

Locate osgINTROSPECTION This module defines:

Was osgIntrospection found?
Where to find the headers
The libraries to link for osgIntrospection (use this)
The osgIntrospection library
The osgIntrospection debug library

$OSGDIR is an environment variable that would correspond to:

./configure --prefix=$OSGDIR

used in building osg.

Created by Eric Wing.

This is part of the Findosg* suite used to find OpenSceneGraph components. Each component is separate and you must opt in to each module. You must also opt into OpenGL and OpenThreads (and Producer if needed) as these modules won't do it for you. This is to allow you control over your own system piece by piece in case you need to opt out of certain components or change the Find behavior for a particular module (perhaps because the default FindOpenGL module doesn't work with your system as an example). If you want to use a more convenient module that includes everything, use the FindOpenSceneGraph instead of the Findosg*.cmake modules.

Locate osgManipulator This module defines:

Was osgManipulator found?
Where to find the headers
The libraries to link for osgManipulator (use this)
The osgManipulator library
The osgManipulator debug library

$OSGDIR is an environment variable that would correspond to:

./configure --prefix=$OSGDIR

used in building osg.

Created by Eric Wing.

This is part of the Findosg* suite used to find OpenSceneGraph components. Each component is separate and you must opt in to each module. You must also opt into OpenGL and OpenThreads (and Producer if needed) as these modules won't do it for you. This is to allow you control over your own system piece by piece in case you need to opt out of certain components or change the Find behavior for a particular module (perhaps because the default FindOpenGL module doesn't work with your system as an example). If you want to use a more convenient module that includes everything, use the FindOpenSceneGraph instead of the Findosg*.cmake modules.

Locate osgParticle This module defines:

Was osgParticle found?
Where to find the headers
The libraries to link for osgParticle (use this)
The osgParticle library
The osgParticle debug library

$OSGDIR is an environment variable that would correspond to:

./configure --prefix=$OSGDIR

used in building osg.

Created by Eric Wing.

This is part of the Findosg* suite used to find OpenSceneGraph components. Each component is separate and you must opt in to each module. You must also opt into OpenGL and OpenThreads (and Producer if needed) as these modules won't do it for you. This is to allow you control over your own system piece by piece in case you need to opt out of certain components or change the Find behavior for a particular module (perhaps because the default FindOpenGL module doesn't work with your system as an example). If you want to use a more convenient module that includes everything, use the FindOpenSceneGraph instead of the Findosg*.cmake modules.

Locate osgPresentation This module defines:

Was osgPresentation found?
Where to find the headers
The libraries to link for osgPresentation (use this)
The osgPresentation library
The osgPresentation debug library

$OSGDIR is an environment variable that would correspond to:

./configure --prefix=$OSGDIR

used in building osg. Created by Eric Wing. Modified to work with osgPresentation by Robert Osfield, January 2012.

This is part of the Findosg* suite used to find OpenSceneGraph components. Each component is separate and you must opt in to each module. You must also opt into OpenGL and OpenThreads (and Producer if needed) as these modules won't do it for you. This is to allow you control over your own system piece by piece in case you need to opt out of certain components or change the Find behavior for a particular module (perhaps because the default FindOpenGL module doesn't work with your system as an example). If you want to use a more convenient module that includes everything, use the FindOpenSceneGraph instead of the Findosg*.cmake modules.

Locate osgProducer This module defines:

Was osgProducer found?
Where to find the headers
The libraries to link for osgProducer (use this)
The osgProducer library
The osgProducer debug library

$OSGDIR is an environment variable that would correspond to:

./configure --prefix=$OSGDIR

used in building osg.

Created by Eric Wing.

This is part of the Findosg* suite used to find OpenSceneGraph components. Each component is separate and you must opt in to each module. You must also opt into OpenGL and OpenThreads (and Producer if needed) as these modules won't do it for you. This is to allow you control over your own system piece by piece in case you need to opt out of certain components or change the Find behavior for a particular module (perhaps because the default FindOpenGL module doesn't work with your system as an example). If you want to use a more convenient module that includes everything, use the FindOpenSceneGraph instead of the Findosg*.cmake modules.

Locate osgQt This module defines:

Was osgQt found?
Where to find the headers
The libraries to link for osgQt (use this)
The osgQt library
The osgQt debug library

$OSGDIR is an environment variable that would correspond to:

./configure --prefix=$OSGDIR

used in building osg.

Created by Eric Wing. Modified to work with osgQt by Robert Osfield, January 2012.

This is part of the Findosg* suite used to find OpenSceneGraph components. Each component is separate and you must opt in to each module. You must also opt into OpenGL and OpenThreads (and Producer if needed) as these modules won't do it for you. This is to allow you control over your own system piece by piece in case you need to opt out of certain components or change the Find behavior for a particular module (perhaps because the default FindOpenGL module doesn't work with your system as an example). If you want to use a more convenient module that includes everything, use the FindOpenSceneGraph instead of the Findosg*.cmake modules.

Locate osgShadow This module defines:

Was osgShadow found?
Where to find the headers
The libraries to link for osgShadow (use this)
The osgShadow library
The osgShadow debug library

$OSGDIR is an environment variable that would correspond to:

./configure --prefix=$OSGDIR

used in building osg.

Created by Eric Wing.

This is part of the Findosg* suite used to find OpenSceneGraph components. Each component is separate and you must opt in to each module. You must also opt into OpenGL and OpenThreads (and Producer if needed) as these modules won't do it for you. This is to allow you control over your own system piece by piece in case you need to opt out of certain components or change the Find behavior for a particular module (perhaps because the default FindOpenGL module doesn't work with your system as an example). If you want to use a more convenient module that includes everything, use the FindOpenSceneGraph instead of the Findosg*.cmake modules.

Locate osgSim This module defines:

Was osgSim found?
Where to find the headers
The libraries to link for osgSim (use this)
The osgSim library
The osgSim debug library

$OSGDIR is an environment variable that would correspond to:

./configure --prefix=$OSGDIR

used in building osg.

Created by Eric Wing.

This is part of the Findosg* suite used to find OpenSceneGraph components. Each component is separate and you must opt in to each module. You must also opt into OpenGL and OpenThreads (and Producer if needed) as these modules won't do it for you. This is to allow you control over your own system piece by piece in case you need to opt out of certain components or change the Find behavior for a particular module (perhaps because the default FindOpenGL module doesn't work with your system as an example). If you want to use a more convenient module that includes everything, use the FindOpenSceneGraph instead of the Findosg*.cmake modules.

Locate osgTerrain This module defines:

Was osgTerrain found?
Where to find the headers
The libraries to link for osgTerrain (use this)
The osgTerrain library
The osgTerrain debug library

$OSGDIR is an environment variable that would correspond to:

./configure --prefix=$OSGDIR

used in building osg.

Created by Eric Wing.

This is part of the Findosg* suite used to find OpenSceneGraph components. Each component is separate and you must opt in to each module. You must also opt into OpenGL and OpenThreads (and Producer if needed) as these modules won't do it for you. This is to allow you control over your own system piece by piece in case you need to opt out of certain components or change the Find behavior for a particular module (perhaps because the default FindOpenGL module doesn't work with your system as an example). If you want to use a more convenient module that includes everything, use the FindOpenSceneGraph instead of the Findosg*.cmake modules.

Locate osgText This module defines:

Was osgText found?
Where to find the headers
The libraries to link for osgText (use this)
The osgText library
The osgText debug library

$OSGDIR is an environment variable that would correspond to:

./configure --prefix=$OSGDIR

used in building osg.

Created by Eric Wing.

This is part of the Findosg* suite used to find OpenSceneGraph components. Each component is separate and you must opt in to each module. You must also opt into OpenGL and OpenThreads (and Producer if needed) as these modules won't do it for you. This is to allow you control over your own system piece by piece in case you need to opt out of certain components or change the Find behavior for a particular module (perhaps because the default FindOpenGL module doesn't work with your system as an example). If you want to use a more convenient module that includes everything, use the FindOpenSceneGraph instead of the Findosg*.cmake modules.

Locate osgUtil This module defines:

Was osgUtil found?
Where to find the headers
The libraries to link for osgUtil (use this)
The osgUtil library
The osgUtil debug library

$OSGDIR is an environment variable that would correspond to:

./configure --prefix=$OSGDIR

used in building osg.

Created by Eric Wing.

This is part of the Findosg* suite used to find OpenSceneGraph components. Each component is separate and you must opt in to each module. You must also opt into OpenGL and OpenThreads (and Producer if needed) as these modules won't do it for you. This is to allow you control over your own system piece by piece in case you need to opt out of certain components or change the Find behavior for a particular module (perhaps because the default FindOpenGL module doesn't work with your system as an example). If you want to use a more convenient module that includes everything, use the FindOpenSceneGraph instead of the Findosg*.cmake modules.

Locate osgViewer This module defines:

Was osgViewer found?
Where to find the headers
The libraries to link for osgViewer (use this)
The osgViewer library
The osgViewer debug library

$OSGDIR is an environment variable that would correspond to:

./configure --prefix=$OSGDIR

used in building osg.

Created by Eric Wing.

This is part of the Findosg* suite used to find OpenSceneGraph components. Each component is separate and you must opt in to each module. You must also opt into OpenGL and OpenThreads (and Producer if needed) as these modules won't do it for you. This is to allow you control over your own system piece by piece in case you need to opt out of certain components or change the Find behavior for a particular module (perhaps because the default FindOpenGL module doesn't work with your system as an example). If you want to use a more convenient module that includes everything, use the FindOpenSceneGraph instead of the Findosg*.cmake modules.

Locate osgVolume This module defines:

Was osgVolume found?
Where to find the headers
The libraries to link for osgVolume (use this)
The osgVolume library
The osgVolume debug library

$OSGDIR is an environment variable that would correspond to:

./configure --prefix=$OSGDIR

used in building osg.

Created by Eric Wing.

This is part of the Findosg* suite used to find OpenSceneGraph components. Each component is separate and you must opt in to each module. You must also opt into OpenGL and OpenThreads (and Producer if needed) as these modules won't do it for you. This is to allow you control over your own system piece by piece in case you need to opt out of certain components or change the Find behavior for a particular module (perhaps because the default FindOpenGL module doesn't work with your system as an example). If you want to use a more convenient module that includes everything, use the FindOpenSceneGraph instead of the Findosg*.cmake modules.

Locate osgWidget This module defines:

Was osgWidget found?
Where to find the headers
The libraries to link for osgWidget (use this)
The osgWidget library
The osgWidget debug library

$OSGDIR is an environment variable that would correspond to:

./configure --prefix=$OSGDIR

used in building osg.

FindosgWidget.cmake tweaked from Findosg* suite as created by Eric Wing.

Added in version 3.10.

The module defines the following variables:

Path to patch command-line executable.
True if the patch command-line executable was found.

The following IMPORTED targets are also defined:

The command-line executable.

Example usage:

find_package(Patch)
if(Patch_FOUND)
  message("Patch found: ${Patch_EXECUTABLE}")
endif()

Find a Perl interpreter.

This module defines the following variables:

The full path to Perl.
True if the Perl executable was found.
Added in version 2.8.8.

The version of Perl found.

Find Perl libraries

This module finds if PERL is installed and determines where the include files and libraries are. It also determines what the name of the library is. This code sets the following variables:

PERLLIBS_FOUND    = True if perl.h & libperl were found
PERL_INCLUDE_PATH = path to where perl.h is found
PERL_LIBRARY      = path to libperl
PERL_EXECUTABLE   = full path to the perl binary

The minimum required version of Perl can be specified using the standard syntax, e.g. find_package(PerlLibs 6.0)

The following variables are also available if needed
(introduced after CMake 2.6.4)
PERL_SITESEARCH     = path to the sitesearch install dir (-V:installsitesearch)
PERL_SITEARCH       = path to the sitelib install directory (-V:installsitearch)
PERL_SITELIB        = path to the sitelib install directory (-V:installsitelib)
PERL_VENDORARCH     = path to the vendor arch install directory (-V:installvendorarch)
PERL_VENDORLIB      = path to the vendor lib install directory (-V:installvendorlib)
PERL_ARCHLIB        = path to the core arch lib install directory (-V:archlib)
PERL_PRIVLIB        = path to the core priv lib install directory (-V:privlib)
PERL_UPDATE_ARCHLIB = path to the update arch lib install directory (-V:installarchlib)
PERL_UPDATE_PRIVLIB = path to the update priv lib install directory (-V:installprivlib)
PERL_EXTRA_C_FLAGS = Compilation flags used to build perl

Find PHP4

This module finds if PHP4 is installed and determines where the include files and libraries are. It also determines what the name of the library is. This code sets the following variables:

PHP4_INCLUDE_PATH       = path to where php.h can be found
PHP4_EXECUTABLE         = full path to the php4 binary

Locate PhysFS library This module defines:

the name of the library to link against
if false, do not try to link to PHYSFS
where to find physfs.h

$PHYSFSDIR is an environment variable that would correspond to:

./configure --prefix=$PHYSFSDIR

used in building PHYSFS.

Find Pike

This module finds if PIKE is installed and determines where the include files and libraries are. It also determines what the name of the library is. This code sets the following variables:

PIKE_INCLUDE_PATH       = path to where program.h is found
PIKE_EXECUTABLE         = full path to the pike binary

A pkg-config module for CMake.

Finds the pkg-config executable and adds the pkg_get_variable(), pkg_check_modules() and pkg_search_module() commands. The following variables will also be set:

True if a pkg-config executable was found.
Added in version 2.8.8.

The version of pkg-config that was found.

PKG_CONFIG_EXECUTABLE
The pathname of the pkg-config program.
PKG_CONFIG_ARGN
Added in version 3.22.

A list of arguments to pass to pkg-config.

Both PKG_CONFIG_EXECUTABLE and PKG_CONFIG_ARGN are initialized by the module, but may be overridden by the user. See Variables Affecting Behavior for how these variables are initialized.

Checks for all the given modules, setting a variety of result variables in the calling scope.
pkg_check_modules(<prefix>
                  [REQUIRED] [QUIET]
                  [NO_CMAKE_PATH]
                  [NO_CMAKE_ENVIRONMENT_PATH]
                  [IMPORTED_TARGET [GLOBAL]]
                  <moduleSpec> [<moduleSpec>...])

When the REQUIRED argument is given, the command will fail with an error if module(s) could not be found.

When the QUIET argument is given, no status messages will be printed.

Added in version 3.1: The CMAKE_PREFIX_PATH, CMAKE_FRAMEWORK_PATH, and CMAKE_APPBUNDLE_PATH cache and environment variables will be added to the pkg-config search path. The NO_CMAKE_PATH and NO_CMAKE_ENVIRONMENT_PATH arguments disable this behavior for the cache variables and environment variables respectively. The PKG_CONFIG_USE_CMAKE_PREFIX_PATH variable set to FALSE disables this behavior globally.

Added in version 3.6: The IMPORTED_TARGET argument will create an imported target named PkgConfig::<prefix> that can be passed directly as an argument to target_link_libraries().

Added in version 3.13: The GLOBAL argument will make the imported target available in global scope.

Added in version 3.15: Non-library linker options reported by pkg-config are stored in the INTERFACE_LINK_OPTIONS target property.

Changed in version 3.18: Include directories specified with -isystem are stored in the INTERFACE_INCLUDE_DIRECTORIES target property. Previous versions of CMake left them in the INTERFACE_COMPILE_OPTIONS property.

Each <moduleSpec> can be either a bare module name or it can be a module name with a version constraint (operators =, <, >, <= and >= are supported). The following are examples for a module named foo with various constraints:

  • foo matches any version.
  • foo<2 only matches versions before 2.
  • foo>=3.1 matches any version from 3.1 or later.
  • foo=1.2.3 requires that foo must be exactly version 1.2.3.

The following variables may be set upon return. Two sets of values exist: One for the common case (<XXX> = <prefix>) and another for the information pkg-config provides when called with the --static option (<XXX> = <prefix>_STATIC).

<XXX>_FOUND
set to 1 if module(s) exist
<XXX>_LIBRARIES
only the libraries (without the '-l')
<XXX>_LINK_LIBRARIES
the libraries and their absolute paths
<XXX>_LIBRARY_DIRS
the paths of the libraries (without the '-L')
<XXX>_LDFLAGS
all required linker flags
<XXX>_LDFLAGS_OTHER
all other linker flags
<XXX>_INCLUDE_DIRS
the '-I' preprocessor flags (without the '-I')
<XXX>_CFLAGS
all required cflags
<XXX>_CFLAGS_OTHER
the other compiler flags

All but <XXX>_FOUND may be a ;-list if the associated variable returned from pkg-config has multiple values.

Changed in version 3.18: Include directories specified with -isystem are stored in the <XXX>_INCLUDE_DIRS variable. Previous versions of CMake left them in <XXX>_CFLAGS_OTHER.

There are some special variables whose prefix depends on the number of <moduleSpec> given. When there is only one <moduleSpec>, <YYY> will simply be <prefix>, but if two or more <moduleSpec> items are given, <YYY> will be <prefix>_<moduleName>.

<YYY>_VERSION
version of the module
<YYY>_PREFIX
prefix directory of the module
<YYY>_INCLUDEDIR
include directory of the module
<YYY>_LIBDIR
lib directory of the module

Changed in version 3.8: For any given <prefix>, pkg_check_modules() can be called multiple times with different parameters. Previous versions of CMake cached and returned the first successful result.

Changed in version 3.16: If a full path to the found library can't be determined, but it's still visible to the linker, pass it through as -l<name>. Previous versions of CMake failed in this case.

Examples:

pkg_check_modules (GLIB2 glib-2.0)

Looks for any version of glib2. If found, the output variable GLIB2_VERSION will hold the actual version found.

pkg_check_modules (GLIB2 glib-2.0>=2.10)

Looks for at least version 2.10 of glib2. If found, the output variable GLIB2_VERSION will hold the actual version found.

pkg_check_modules (FOO glib-2.0>=2.10 gtk+-2.0)

Looks for both glib2-2.0 (at least version 2.10) and any version of gtk2+-2.0. Only if both are found will FOO be considered found. The FOO_glib-2.0_VERSION and FOO_gtk+-2.0_VERSION variables will be set to their respective found module versions.

pkg_check_modules (XRENDER REQUIRED xrender)

Requires any version of xrender. Example output variables set by a successful call:

XRENDER_LIBRARIES=Xrender;X11
XRENDER_STATIC_LIBRARIES=Xrender;X11;pthread;Xau;Xdmcp
The behavior of this command is the same as pkg_check_modules(), except that rather than checking for all the specified modules, it searches for just the first successful match.
pkg_search_module(<prefix>
                  [REQUIRED] [QUIET]
                  [NO_CMAKE_PATH]
                  [NO_CMAKE_ENVIRONMENT_PATH]
                  [IMPORTED_TARGET [GLOBAL]]
                  <moduleSpec> [<moduleSpec>...])

Added in version 3.16: If a module is found, the <prefix>_MODULE_NAME variable will contain the name of the matching module. This variable can be used if you need to run pkg_get_variable().

Example:

pkg_search_module (BAR libxml-2.0 libxml2 libxml>=2)
Added in version 3.4.

Retrieves the value of a pkg-config variable varName and stores it in the result variable resultVar in the calling scope.

pkg_get_variable(<resultVar> <moduleName> <varName>
                 [DEFINE_VARIABLES <key>=<value>...])

If pkg-config returns multiple values for the specified variable, resultVar will contain a ;-list.

Options:

Added in version 3.28.

Specify key-value pairs to redefine variables affecting the variable retrieved with pkg-config.

For example:

pkg_get_variable(GI_GIRDIR gobject-introspection-1.0 girdir)

Variables Affecting Behavior

This cache variable can be set to the path of the pkg-config executable. find_program() is called internally by the module with this variable.

Added in version 3.1: The PKG_CONFIG environment variable can be used as a hint if PKG_CONFIG_EXECUTABLE has not yet been set.

Changed in version 3.22: If the PKG_CONFIG environment variable is set, only the first argument is taken from it when using it as a hint.

Added in version 3.22.

This cache variable can be set to a list of arguments to additionally pass to pkg-config if needed. If not provided, it will be initialized from the PKG_CONFIG environment variable, if set. The first argument in that environment variable is assumed to be the pkg-config program, while all remaining arguments after that are used to initialize PKG_CONFIG_ARGN. If no such environment variable is defined, PKG_CONFIG_ARGN is initialized to an empty string. The module does not update the variable once it has been set in the cache.

Added in version 3.1.

Specifies whether pkg_check_modules() and pkg_search_module() should add the paths in the CMAKE_PREFIX_PATH, CMAKE_FRAMEWORK_PATH and CMAKE_APPBUNDLE_PATH cache and environment variables to the pkg-config search path.

If this variable is not set, this behavior is enabled by default if CMAKE_MINIMUM_REQUIRED_VERSION is 3.1 or later, disabled otherwise.

Find libpng, the official reference library for the PNG image format.

Imported targets

Added in version 3.5.

This module defines the following IMPORTED target:

The libpng library, if found.

Result variables

This module will set the following variables in your project:

where to find png.h, etc.
the libraries to link against to use PNG.
You should add_definitions(${PNG_DEFINITIONS}) before compiling code that includes png library files.
If false, do not try to use PNG.
the version of the PNG library found (since CMake 2.8.8)

Obsolete variables

The following variables may also be set, for backwards compatibility:

where to find the PNG library.
where to find the PNG headers (same as PNG_INCLUDE_DIRS)

Since PNG depends on the ZLib compression library, none of the above will be defined unless ZLib can be found.

Find the PostgreSQL installation.

IMPORTED Targets

Added in version 3.14.

This module defines IMPORTED target PostgreSQL::PostgreSQL if PostgreSQL has been found.

Result Variables

This module will set the following variables in your project:

True if PostgreSQL is found.
the PostgreSQL libraries needed for linking
the directories of the PostgreSQL headers
the link directories for PostgreSQL libraries
the version of PostgreSQL found
the directories of the PostgreSQL server headers

This module contains additional Server component, that forcibly checks for the presence of server headers. Note that PostgreSQL_TYPE_INCLUDE_DIR is set regardless of the presence of the Server component in find_package call.

Though Producer isn't directly part of OpenSceneGraph, its primary user is OSG so I consider this part of the Findosg* suite used to find OpenSceneGraph components. You'll notice that I accept OSGDIR as an environment path.

Each component is separate and you must opt in to each module. You must also opt into OpenGL (and OpenThreads?) as these modules won't do it for you. This is to allow you control over your own system piece by piece in case you need to opt out of certain components or change the Find behavior for a particular module (perhaps because the default FindOpenGL module doesn't work with your system as an example). If you want to use a more convenient module that includes everything, use the FindOpenSceneGraph instead of the Findosg*.cmake modules.

Locate Producer This module defines:

PRODUCER_LIBRARY

if false, do not try to link to Producer
where to find the headers

$PRODUCER_DIR is an environment variable that would correspond to:

./configure --prefix=$PRODUCER_DIR

used in building osg.

Locate and configure the Google Protocol Buffers library.

Added in version 3.6: Support for find_package() version checks.

Changed in version 3.6: All input and output variables use the Protobuf_ prefix. Variables with PROTOBUF_ prefix are still supported for compatibility.

The following variables can be set and are optional:

When compiling with MSVC, if this cache variable is set the protobuf-default VS project build locations (vsprojects/Debug and vsprojects/Release or vsprojects/x64/Debug and vsprojects/x64/Release) will be searched for libraries and binaries.
List of additional directories to be searched for imported .proto files.
Added in version 3.6.

Show debug messages.

Added in version 3.9.

Set to ON to force the use of the static libraries. Default is OFF.

Defines the following variables:

Found the Google Protocol Buffers library (libprotobuf & header files)
Added in version 3.6.

Version of package found.

Include directories for Google Protocol Buffers
The protobuf libraries
The protoc libraries
The protobuf-lite libraries

Added in version 3.9: The following IMPORTED targets are also defined:

The protobuf library.
The protobuf lite library.
The protoc library.
Added in version 3.10: The protoc compiler.

The following cache variables are also available to set or use:

The protobuf library
The protoc library
The include directory for protocol buffers
The protoc compiler
The protobuf library (debug)
The protoc library (debug)
The protobuf lite library
The protobuf lite library (debug)

Example:

find_package(Protobuf REQUIRED)
include_directories(${Protobuf_INCLUDE_DIRS})
include_directories(${CMAKE_CURRENT_BINARY_DIR})
protobuf_generate_cpp(PROTO_SRCS PROTO_HDRS foo.proto)
protobuf_generate_cpp(PROTO_SRCS PROTO_HDRS EXPORT_MACRO DLL_EXPORT foo.proto)
protobuf_generate_cpp(PROTO_SRCS PROTO_HDRS DESCRIPTORS PROTO_DESCS foo.proto)
protobuf_generate_python(PROTO_PY foo.proto)
add_executable(bar bar.cc ${PROTO_SRCS} ${PROTO_HDRS})
target_link_libraries(bar ${Protobuf_LIBRARIES})

NOTE:

The protobuf_generate_cpp and protobuf_generate_python functions and add_executable() or add_library() calls only work properly within the same directory.
Add custom commands to process .proto files to C++:
protobuf_generate_cpp (<SRCS> <HDRS>
    [DESCRIPTORS <DESC>] [EXPORT_MACRO <MACRO>] [<ARGN>...])
Variable to define with autogenerated source files
Variable to define with autogenerated header files
Added in version 3.10: Variable to define with autogenerated descriptor files, if requested.
is a macro which should expand to __declspec(dllexport) or __declspec(dllimport) depending on what is being compiled.
.proto files
Added in version 3.4.

Add custom commands to process .proto files to Python:

protobuf_generate_python (<PY> [<ARGN>...])
Variable to define with autogenerated Python files
.proto files
Added in version 3.13.

Automatically generate source files from .proto schema files at build time:

protobuf_generate (
    TARGET <target>
    [LANGUAGE <lang>]
    [OUT_VAR <out_var>]
    [EXPORT_MACRO <macro>]
    [PROTOC_OUT_DIR <dir>]
    [PLUGIN <plugin>]
    [PLUGIN_OPTIONS <plugin_options>]
    [DEPENDENCIES <depends]
    [PROTOS <protobuf_files>]
    [IMPORT_DIRS <dirs>]
    [GENERATE_EXTENSIONS <extensions>]
    [PROTOC_OPTIONS <protoc_options>]
    [APPEND_PATH])
A flag that causes the base path of all proto schema files to be added to IMPORT_DIRS.
A single value: cpp or python. Determines what kind of source files are being generated. Defaults to cpp.
Name of a CMake variable that will be filled with the paths to the generated source files.
Name of a macro that is applied to all generated Protobuf message classes and extern variables. It can, for example, be used to declare DLL exports.
Output directory of generated source files. Defaults to CMAKE_CURRENT_BINARY_DIR.
Added in version 3.21.

An optional plugin executable. This could, for example, be the path to grpc_cpp_plugin.

Added in version 3.28.

Additional options provided to the plugin, such as generate_mock_code=true for the gRPC cpp plugin.

Added in version 3.28.

Arguments forwarded to the DEPENDS of the underlying add_custom_command invocation.

CMake target that will have the generated files added as sources.
List of proto schema files. If omitted, then every source file ending in proto of TARGET will be used.
A common parent directory for the schema files. For example, if the schema file is proto/helloworld/helloworld.proto and the import directory proto/ then the generated files are ${PROTOC_OUT_DIR}/helloworld/helloworld.pb.h and ${PROTOC_OUT_DIR}/helloworld/helloworld.pb.cc.
If LANGUAGE is omitted then this must be set to the extensions that protoc generates.
Added in version 3.28.

Additional arguments that are forwarded to protoc.

Example:

find_package(gRPC CONFIG REQUIRED)
find_package(Protobuf REQUIRED)
add_library(ProtoTest Test.proto)
target_link_libraries(ProtoTest PUBLIC gRPC::grpc++)
protobuf_generate(TARGET ProtoTest)
protobuf_generate(
    TARGET ProtoTest
    LANGUAGE grpc
    PLUGIN protoc-gen-grpc=$<TARGET_FILE:gRPC::grpc_cpp_plugin>
    PLUGIN_OPTIONS generate_mock_code=true
    GENERATE_EXTENSIONS .grpc.pb.h .grpc.pb.cc)

Added in version 3.12.

Find Python interpreter, compiler and development environment (include directories and libraries).

Added in version 3.19: When a version is requested, it can be specified as a simple value or as a range. For a detailed description of version range usage and capabilities, refer to the find_package() command.

The following components are supported:

  • Interpreter: search for Python interpreter.
  • Compiler: search for Python compiler. Only offered by IronPython.
  • Development: search for development artifacts (include directories and libraries).

    Added in version 3.18: This component includes two sub-components which can be specified independently:

  • Development.Module: search for artifacts for Python module developments.
  • Development.Embed: search for artifacts for Python embedding developments.

Added in version 3.26:

Development.SABIModule: search for artifacts for Python module developments using the Stable Application Binary Interface. This component is available only for version 3.2 and upper.
NumPy: search for NumPy include directories.

Added in version 3.14: Added the NumPy component.

If no COMPONENTS are specified, Interpreter is assumed.

If component Development is specified, it implies sub-components Development.Module and Development.Embed.

To ensure consistent versions between components Interpreter, Compiler, Development (or one of its sub-components) and NumPy, specify all components at the same time:

find_package (Python COMPONENTS Interpreter Development)

This module looks preferably for version 3 of Python. If not found, version 2 is searched. To manage concurrent versions 3 and 2 of Python, use FindPython3 and FindPython2 modules rather than this one.

NOTE:

If components Interpreter and Development (or one of its sub-components) are both specified, this module search only for interpreter with same platform architecture as the one defined by CMake configuration. This constraint does not apply if only Interpreter component is specified.

Imported Targets

This module defines the following Imported Targets:

Changed in version 3.14: Imported Targets are only created when CMAKE_ROLE is PROJECT.

Python interpreter. This target is defined only if the Interpreter component is found.
Added in version 3.30.

Python debug interpreter. This target is defined only if the Interpreter component is found and the Python_EXECUTABLE_DEBUG variable is defined. The target is only defined on the Windows platform.

Added in version 3.30.

Python interpreter. The release or debug version of the interpreter will be used, based on the context (platform, configuration). This target is defined only if the Interpreter component is found

Python compiler. This target is defined only if the Compiler component is found.
Added in version 3.15.

Python library for Python module. Target defined if component Development.Module is found.

Added in version 3.26.

Python library for Python module using the Stable Application Binary Interface. Target defined if component Development.SABIModule is found.

Python library for Python embedding. Target defined if component Development.Embed is found.
Added in version 3.14.

NumPy Python library. Target defined if component NumPy is found.

Result Variables

This module will set the following variables in your project (see Standard Variable Names):

System has the Python requested components.
System has the Python interpreter.
Path to the Python interpreter.
Added in version 3.30.

Path to the debug Python interpreter. It is only defined on the Windows platform.

Added in version 3.30.

Path to the Python interpreter, defined as a generator expression selecting the Python_EXECUTABLE or Python_EXECUTABLE_DEBUG variable based on the context (platform, configuration).

  • Python
  • ActivePython
  • Anaconda
  • Canopy
  • IronPython
  • PyPy
Standard platform independent installation directory.

Information returned by sysconfig.get_path('stdlib').

Standard platform dependent installation directory.

Information returned by sysconfig.get_path('platstdlib').

Third-party platform independent installation directory.

Information returned by sysconfig.get_path('purelib').

Third-party platform dependent installation directory.

Information returned by sysconfig.get_path('platlib').

Added in version 3.17.

Extension suffix for modules.

Information computed from sysconfig.get_config_var('EXT_SUFFIX') or sysconfig.get_config_var('SOABI') or python3-config --extension-suffix.

Added in version 3.26.

Extension suffix for modules using the Stable Application Binary Interface.

Information computed from importlib.machinery.EXTENSION_SUFFIXES if the COMPONENT Interpreter was specified. Otherwise, the extension is abi3 except for Windows, MSYS and CYGWIN for which this is an empty string.

System has the Python compiler.
Path to the Python compiler. Only offered by IronPython.
Added in version 3.18.

The .Net interpreter. Only used by IronPython implementation.

System has the Python development artifacts.
Added in version 3.18.

System has the Python development artifacts for Python module.

Added in version 3.26.

System has the Python development artifacts for Python module using the Stable Application Binary Interface.

Added in version 3.18.

System has the Python development artifacts for Python embedding.

Python_INCLUDE_DIRS

The Python include directories.
Added in version 3.30.3.

The Python preprocessor definitions.

Postfix of debug python module. This variable can be used to define the DEBUG_POSTFIX target property.
Added in version 3.19.

The Python link options. Some configurations require specific link options for a correct build and execution.

The Python libraries.
The Python library directories.
The Python runtime library directories.
Added in version 3.26.

The Python libraries for the Stable Application Binary Interface.

Added in version 3.26.

The Python SABI library directories.

Added in version 3.26.

The Python runtime SABI library directories.

Python version.
Python major version.
Python minor version.
Python patch version.
Added in version 3.18.

Python PyPy version.

Added in version 3.14.

System has the NumPy.

Added in version 3.14.

The NumPy include directories.

Added in version 3.14.

The NumPy version.

Define the root directory of a Python installation.
  • If not defined, search for shared libraries and static libraries in that order.
  • If set to TRUE, search only for static libraries.
  • If set to FALSE, search only for shared libraries.

NOTE:

This hint will be ignored on Windows because static libraries are not available on this platform.
Added in version 3.16.

This variable defines which ABIs, as defined in PEP 3149, should be searched.

NOTE:

This hint will be honored only when searched for Python version 3.

The Python_FIND_ABI variable is a 4-tuple specifying, in that order, pydebug (d), pymalloc (m), unicode (u) and gil_disabled (t) flags.

Added in version 3.30: A fourth element, specifying the gil_disabled flag (i.e. free threaded python), is added and is optional. If not specified, the value is OFF.

Each element can be set to one of the following:

  • ON: Corresponding flag is selected.
  • OFF: Corresponding flag is not selected.
  • ANY: The two possibilities (ON and OFF) will be searched.

NOTE:

If Python3_FIND_ABI is not defined, any ABI, excluding the gil_disabled flag, will be searched.

From this 4-tuple, various ABIs will be searched starting from the most specialized to the most general. Moreover, when ANY is specified for pydebug and gil_disabled, debug and free threaded versions will be searched after non-debug and non-gil-disabled ones.

For example, if we have:

set (Python_FIND_ABI "ON" "ANY" "ANY" "ON")

The following flags combinations will be appended, in that order, to the artifact names: tdmu, tdm, tdu, and td.

And to search any possible ABIs:

set (Python_FIND_ABI "ANY" "ANY" "ANY" "ANY")

The following combinations, in that order, will be used: mu, m, u, <empty>, dmu, dm, du, d, tmu, tm, tu, t, tdmu, tdm, tdu, and td.

NOTE:

This hint is useful only on POSIX systems except for the gil_disabled flag. So, on Windows systems, when Python_FIND_ABI is defined, Python distributions from python.org will be found only if the value for each flag is OFF or ANY except for the fourth one (gil_disabled).
Added in version 3.15.

This variable defines how lookup will be done. The Python_FIND_STRATEGY variable can be set to one of the following:

  • VERSION: Try to find the most recent version in all specified locations. This is the default if policy CMP0094 is undefined or set to OLD.
  • LOCATION: Stops lookup as soon as a version satisfying version constraints is founded. This is the default if policy CMP0094 is set to NEW.

See also Python_FIND_UNVERSIONED_NAMES.

Added in version 3.13.

On Windows the Python_FIND_REGISTRY variable determine the order of preference between registry and environment variables. the Python_FIND_REGISTRY variable can be set to one of the following:

  • FIRST: Try to use registry before environment variables. This is the default.
  • LAST: Try to use registry after environment variables.
  • NEVER: Never try to use registry.
Added in version 3.15.

On macOS the Python_FIND_FRAMEWORK variable determine the order of preference between Apple-style and unix-style package components. This variable can take same values as CMAKE_FIND_FRAMEWORK variable.

NOTE:

Value ONLY is not supported so FIRST will be used instead.

If Python_FIND_FRAMEWORK is not defined, CMAKE_FIND_FRAMEWORK variable will be used, if any.

Added in version 3.15.

This variable defines the handling of virtual environments managed by virtualenv or conda. It is meaningful only when a virtual environment is active (i.e. the activate script has been evaluated). In this case, it takes precedence over Python_FIND_REGISTRY and CMAKE_FIND_FRAMEWORK variables. The Python_FIND_VIRTUALENV variable can be set to one of the following:

  • FIRST: The virtual environment is used before any other standard paths to look-up for the interpreter. This is the default.
  • ONLY: Only the virtual environment is used to look-up for the interpreter.
  • STANDARD: The virtual environment is not used to look-up for the interpreter but environment variable PATH is always considered. In this case, variable Python_FIND_REGISTRY (Windows) or CMAKE_FIND_FRAMEWORK (macOS) can be set with value LAST or NEVER to select preferably the interpreter from the virtual environment.

Added in version 3.17: Added support for conda environments.

NOTE:

If the component Development is requested, it is strongly recommended to also include the component Interpreter to get expected result.
Added in version 3.18.

This variable defines, in an ordered list, the different implementations which will be searched. The Python_FIND_IMPLEMENTATIONS variable can hold the following values:

  • CPython: this is the standard implementation. Various products, like Anaconda or ActivePython, rely on this implementation.
  • IronPython: This implementation use the CSharp language for .NET Framework on top of the Dynamic Language Runtime (DLR). See IronPython.
  • PyPy: This implementation use RPython language and RPython translation toolchain to produce the python interpreter. See PyPy.

The default value is:

  • Windows platform: CPython, IronPython
  • Other platforms: CPython

NOTE:

This hint has the lowest priority of all hints, so even if, for example, you specify IronPython first and CPython in second, a python product based on CPython can be selected because, for example with Python_FIND_STRATEGY=LOCATION, each location will be search first for IronPython and second for CPython.

NOTE:

When IronPython is specified, on platforms other than Windows, the .Net interpreter (i.e. mono command) is expected to be available through the PATH variable.
Added in version 3.20.

This variable defines how the generic names will be searched. Currently, it only applies to the generic names of the interpreter, namely, python3 or python2 and python. The Python_FIND_UNVERSIONED_NAMES variable can be set to one of the following values:

  • FIRST: The generic names are searched before the more specialized ones (such as python2.5 for example).
  • LAST: The generic names are searched after the more specialized ones. This is the default.
  • NEVER: The generic name are not searched at all.

See also Python_FIND_STRATEGY.

Artifacts Specification

Added in version 3.16.

To solve special cases, it is possible to specify directly the artifacts by setting the following variables:

The path to the interpreter.
The path to the compiler.
Added in version 3.18.

The .Net interpreter. Only used by IronPython implementation.

The path to the library. It will be used to compute the variables Python_LIBRARIES, Python_LIBRARY_DIRS and Python_RUNTIME_LIBRARY_DIRS.
Added in version 3.26.

The path to the library for Stable Application Binary Interface. It will be used to compute the variables Python_SABI_LIBRARIES, Python_SABI_LIBRARY_DIRS and Python_RUNTIME_SABI_LIBRARY_DIRS.

The path to the directory of the Python headers. It will be used to compute the variable Python_INCLUDE_DIRS.
The path to the directory of the NumPy headers. It will be used to compute the variable Python_NumPy_INCLUDE_DIRS.

NOTE:

All paths must be absolute. Any artifact specified with a relative path will be ignored.

NOTE:

When an artifact is specified, all HINTS will be ignored and no search will be performed for this artifact.

If more than one artifact is specified, it is the user's responsibility to ensure the consistency of the various artifacts.

By default, this module supports multiple calls in different directories of a project with different version/component requirements while providing correct and consistent results for each call. To support this behavior, CMake cache is not used in the traditional way which can be problematic for interactive specification. So, to enable also interactive specification, module behavior can be controlled with the following variable:

Added in version 3.18.

Selects the behavior of the module. This is a boolean variable:

  • If set to TRUE: Create CMake cache entries for the above artifact specification variables so that users can edit them interactively. This disables support for multiple version/component requirements.
  • If set to FALSE or undefined: Enable multiple version/component requirements.

This module defines the command Python_add_library (when CMAKE_ROLE is PROJECT), which has the same semantics as add_library() and adds a dependency to target Python::Python or, when library type is MODULE, to target Python::Module or Python::SABIModule (when USE_SABI option is specified) and takes care of Python module naming rules:

Python_add_library (<name> [STATIC | SHARED | MODULE [USE_SABI <version>] [WITH_SOABI]]
                    <source1> [<source2> ...])

If the library type is not specified, MODULE is assumed.

Added in version 3.17: For MODULE library type, if option WITH_SOABI is specified, the module suffix will include the Python_SOABI value, if any.

Added in version 3.26: For MODULE type, if the option USE_SABI is specified, the preprocessor definition Py_LIMITED_API will be specified, as PRIVATE, for the target <name> with the value computed from <version> argument. The expected format for <version> is major[.minor], where each component is a numeric value. If minor component is specified, the version should be, at least, 3.2 which is the version where the Stable Application Binary Interface was introduced. Specifying only major version 3 is equivalent to 3.2.

When option WITH_SOABI is also specified, the module suffix will include the Python_SOSABI value, if any.

Added in version 3.30: For MODULE type, the DEBUG_POSTFIX target property is initialized with the value of Python_DEBUG_POSTFIX variable if defined.

Added in version 3.12.

Find Python 2 interpreter, compiler and development environment (include directories and libraries).

Added in version 3.19: When a version is requested, it can be specified as a simple value or as a range. For a detailed description of version range usage and capabilities, refer to the find_package() command.

The following components are supported:

  • Interpreter: search for Python 2 interpreter
  • Compiler: search for Python 2 compiler. Only offered by IronPython.
  • Development: search for development artifacts (include directories and libraries).

    Added in version 3.18: This component includes two sub-components which can be specified independently:

  • Development.Module: search for artifacts for Python 2 module developments.
  • Development.Embed: search for artifacts for Python 2 embedding developments.
NumPy: search for NumPy include directories.

Added in version 3.14: Added the NumPy component.

If no COMPONENTS are specified, Interpreter is assumed.

If component Development is specified, it implies sub-components Development.Module and Development.Embed.

To ensure consistent versions between components Interpreter, Compiler, Development (or one of its sub-components) and NumPy, specify all components at the same time:

find_package (Python2 COMPONENTS Interpreter Development)

This module looks only for version 2 of Python. This module can be used concurrently with FindPython3 module to use both Python versions.

The FindPython module can be used if Python version does not matter for you.

NOTE:

If components Interpreter and Development (or one of its sub-components) are both specified, this module search only for interpreter with same platform architecture as the one defined by CMake configuration. This constraint does not apply if only Interpreter component is specified.

Imported Targets

This module defines the following Imported Targets:

Changed in version 3.14: Imported Targets are only created when CMAKE_ROLE is PROJECT.

Python 2 interpreter. This target is defined only if the Interpreter component is found.
Added in version 3.30.

Python 2 debug interpreter. This target is defined only if the Interpreter component is found and the Python2_EXECUTABLE_DEBUG variable is defined. The target is only defined on the Windows platform.

Added in version 3.30.

Python 2 interpreter. The release or debug version of the interpreter will be used, based on the context (platform, configuration). This target is defined only if the Interpreter component is found

Python 2 compiler. This target is defined only if the Compiler component is found.
Added in version 3.15.

Python 2 library for Python module. Target defined if component Development.Module is found.

Python 2 library for Python embedding. Target defined if component Development.Embed is found.
Added in version 3.14.

NumPy library for Python 2. Target defined if component NumPy is found.

Result Variables

This module will set the following variables in your project (see Standard Variable Names):

System has the Python 2 requested components.
System has the Python 2 interpreter.
Path to the Python 2 interpreter.
Added in version 3.30.

Path to the debug Python 2 interpreter. It is only defined on the Windows platform.

Added in version 3.30.

Path to the Python 2 interpreter, defined as a generator expression selecting the Python2_EXECUTABLE or Python2_EXECUTABLE_DEBUG variable based on the context (platform, configuration).

  • Python
  • ActivePython
  • Anaconda
  • Canopy
  • IronPython
  • PyPy
Standard platform independent installation directory.

Information returned by sysconfig.get_path('stdlib') or else distutils.sysconfig.get_python_lib(plat_specific=False,standard_lib=True).

Standard platform dependent installation directory.

Information returned by sysconfig.get_path('platstdlib') or else distutils.sysconfig.get_python_lib(plat_specific=True,standard_lib=True).

Third-party platform independent installation directory.

Information returned by sysconfig.get_path('purelib') or else distutils.sysconfig.get_python_lib(plat_specific=False,standard_lib=False).

Third-party platform dependent installation directory.

Information returned by sysconfig.get_path('platlib') or else distutils.sysconfig.get_python_lib(plat_specific=True,standard_lib=False).

System has the Python 2 compiler.
Path to the Python 2 compiler. Only offered by IronPython.
Added in version 3.18.

The .Net interpreter. Only used by IronPython implementation.

System has the Python 2 development artifacts.
Added in version 3.18.

System has the Python 2 development artifacts for Python module.

Added in version 3.18.

System has the Python 2 development artifacts for Python embedding.

The Python 2 include directories.
Postfix of debug python module. This variable can be used to define the DEBUG_POSTFIX target property.
Added in version 3.19.

The Python 2 link options. Some configurations require specific link options for a correct build and execution.

The Python 2 libraries.
The Python 2 library directories.
The Python 2 runtime library directories.
Python 2 version.
Python 2 major version.
Python 2 minor version.
Python 2 patch version.
Added in version 3.18.

Python 2 PyPy version.

Added in version 3.14.

System has the NumPy.

Added in version 3.14.

The NumPy include directories.

Added in version 3.14.

The NumPy version.

Define the root directory of a Python 2 installation.
  • If not defined, search for shared libraries and static libraries in that order.
  • If set to TRUE, search only for static libraries.
  • If set to FALSE, search only for shared libraries.

NOTE:

This hint will be ignored on Windows because static libraries are not available on this platform.
Added in version 3.15.

This variable defines how lookup will be done. The Python2_FIND_STRATEGY variable can be set to one of the following:

  • VERSION: Try to find the most recent version in all specified locations. This is the default if policy CMP0094 is undefined or set to OLD.
  • LOCATION: Stops lookup as soon as a version satisfying version constraints is founded. This is the default if policy CMP0094 is set to NEW.

See also Python2_FIND_UNVERSIONED_NAMES.

Added in version 3.13.

On Windows the Python2_FIND_REGISTRY variable determine the order of preference between registry and environment variables. the Python2_FIND_REGISTRY variable can be set to one of the following:

  • FIRST: Try to use registry before environment variables. This is the default.
  • LAST: Try to use registry after environment variables.
  • NEVER: Never try to use registry.
Added in version 3.15.

On macOS the Python2_FIND_FRAMEWORK variable determine the order of preference between Apple-style and unix-style package components. This variable can take same values as CMAKE_FIND_FRAMEWORK variable.

NOTE:

Value ONLY is not supported so FIRST will be used instead.

If Python2_FIND_FRAMEWORK is not defined, CMAKE_FIND_FRAMEWORK variable will be used, if any.

Added in version 3.15.

This variable defines the handling of virtual environments managed by virtualenv or conda. It is meaningful only when a virtual environment is active (i.e. the activate script has been evaluated). In this case, it takes precedence over Python2_FIND_REGISTRY and CMAKE_FIND_FRAMEWORK variables. The Python2_FIND_VIRTUALENV variable can be set to one of the following:

  • FIRST: The virtual environment is used before any other standard paths to look-up for the interpreter. This is the default.
  • ONLY: Only the virtual environment is used to look-up for the interpreter.
  • STANDARD: The virtual environment is not used to look-up for the interpreter but environment variable PATH is always considered. In this case, variable Python2_FIND_REGISTRY (Windows) or CMAKE_FIND_FRAMEWORK (macOS) can be set with value LAST or NEVER to select preferably the interpreter from the virtual environment.

Added in version 3.17: Added support for conda environments.

NOTE:

If the component Development is requested, it is strongly recommended to also include the component Interpreter to get expected result.
Added in version 3.18.

This variable defines, in an ordered list, the different implementations which will be searched. The Python2_FIND_IMPLEMENTATIONS variable can hold the following values:

  • CPython: this is the standard implementation. Various products, like Anaconda or ActivePython, rely on this implementation.
  • IronPython: This implementation use the CSharp language for .NET Framework on top of the Dynamic Language Runtime (DLR). See IronPython.
  • PyPy: This implementation use RPython language and RPython translation toolchain to produce the python interpreter. See PyPy.

The default value is:

  • Windows platform: CPython, IronPython
  • Other platforms: CPython

NOTE:

This hint has the lowest priority of all hints, so even if, for example, you specify IronPython first and CPython in second, a python product based on CPython can be selected because, for example with Python2_FIND_STRATEGY=LOCATION, each location will be search first for IronPython and second for CPython.

NOTE:

When IronPython is specified, on platforms other than Windows, the .Net interpreter (i.e. mono command) is expected to be available through the PATH variable.
Added in version 3.20.

This variable defines how the generic names will be searched. Currently, it only applies to the generic names of the interpreter, namely, python2 and python. The Python2_FIND_UNVERSIONED_NAMES variable can be set to one of the following values:

  • FIRST: The generic names are searched before the more specialized ones (such as python2.5 for example).
  • LAST: The generic names are searched after the more specialized ones. This is the default.
  • NEVER: The generic name are not searched at all.

See also Python2_FIND_STRATEGY.

Artifacts Specification

Added in version 3.16.

To solve special cases, it is possible to specify directly the artifacts by setting the following variables:

The path to the interpreter.
The path to the compiler.
Added in version 3.18.

The .Net interpreter. Only used by IronPython implementation.

The path to the library. It will be used to compute the variables Python2_LIBRARIES, Python2_LIBRARY_DIRS and Python2_RUNTIME_LIBRARY_DIRS.
The path to the directory of the Python headers. It will be used to compute the variable Python2_INCLUDE_DIRS.
The path to the directory of the NumPy headers. It will be used to compute the variable Python2_NumPy_INCLUDE_DIRS.

NOTE:

All paths must be absolute. Any artifact specified with a relative path will be ignored.

NOTE:

When an artifact is specified, all HINTS will be ignored and no search will be performed for this artifact.

If more than one artifact is specified, it is the user's responsibility to ensure the consistency of the various artifacts.

By default, this module supports multiple calls in different directories of a project with different version/component requirements while providing correct and consistent results for each call. To support this behavior, CMake cache is not used in the traditional way which can be problematic for interactive specification. So, to enable also interactive specification, module behavior can be controlled with the following variable:

Added in version 3.18.

Selects the behavior of the module. This is a boolean variable:

  • If set to TRUE: Create CMake cache entries for the above artifact specification variables so that users can edit them interactively. This disables support for multiple version/component requirements.
  • If set to FALSE or undefined: Enable multiple version/component requirements.

This module defines the command Python2_add_library (when CMAKE_ROLE is PROJECT), which has the same semantics as add_library() and adds a dependency to target Python2::Python or, when library type is MODULE, to target Python2::Module and takes care of Python module naming rules:

Python2_add_library (<name> [STATIC | SHARED | MODULE]
                     <source1> [<source2> ...])

If library type is not specified, MODULE is assumed.

Added in version 3.30: For MODULE type, the DEBUG_POSTFIX target property is initialized with the value of Python2_DEBUG_POSTFIX variable if defined.

Added in version 3.12.

Find Python 3 interpreter, compiler and development environment (include directories and libraries).

Added in version 3.19: When a version is requested, it can be specified as a simple value or as a range. For a detailed description of version range usage and capabilities, refer to the find_package() command.

The following components are supported:

  • Interpreter: search for Python 3 interpreter
  • Compiler: search for Python 3 compiler. Only offered by IronPython.
  • Development: search for development artifacts (include directories and libraries).

    Added in version 3.18: This component includes two sub-components which can be specified independently:

  • Development.Module: search for artifacts for Python 3 module developments.
  • Development.Embed: search for artifacts for Python 3 embedding developments.

Added in version 3.26:

Development.SABIModule: search for artifacts for Python 3 module developments using the Stable Application Binary Interface. This component is available only for version 3.2 and upper.
NumPy: search for NumPy include directories.

Added in version 3.14: Added the NumPy component.

If no COMPONENTS are specified, Interpreter is assumed.

If component Development is specified, it implies sub-components Development.Module and Development.Embed.

To ensure consistent versions between components Interpreter, Compiler, Development (or one of its sub-components) and NumPy, specify all components at the same time:

find_package (Python3 COMPONENTS Interpreter Development)

This module looks only for version 3 of Python. This module can be used concurrently with FindPython2 module to use both Python versions.

The FindPython module can be used if Python version does not matter for you.

NOTE:

If components Interpreter and Development (or one of its sub-components) are both specified, this module search only for interpreter with same platform architecture as the one defined by CMake configuration. This constraint does not apply if only Interpreter component is specified.

Imported Targets

This module defines the following Imported Targets:

Changed in version 3.14: Imported Targets are only created when CMAKE_ROLE is PROJECT.

Python 3 interpreter. This target is defined only if the Interpreter component is found.
Added in version 3.30.

Python 3 debug interpreter. This target is defined only if the Interpreter component is found and the Python3_EXECUTABLE_DEBUG variable is defined. The target is only defined on the Windows platform.

Added in version 3.30.

Python 3 interpreter. The release or debug version of the interpreter will be used, based on the context (platform, configuration). This target is defined only if the Interpreter component is found

Python 3 compiler. This target is defined only if the Compiler component is found.
Added in version 3.15.

Python 3 library for Python module. Target defined if component Development.Module is found.

Added in version 3.26.

Python 3 library for Python module using the Stable Application Binary Interface. Target defined if component Development.SABIModule is found.

Python 3 library for Python embedding. Target defined if component Development.Embed is found.
Added in version 3.14.

NumPy library for Python 3. Target defined if component NumPy is found.

Result Variables

This module will set the following variables in your project (see Standard Variable Names):

System has the Python 3 requested components.
System has the Python 3 interpreter.
Path to the Python 3 interpreter.
Added in version 3.30.

Path to the debug Python 3 interpreter. It is only defined on Windows platform.

Added in version 3.30.

Path to the Python 3 interpreter, defined as a generator expression selecting the Python3_EXECUTABLE or Python3_EXECUTABLE_DEBUG variable based on the context (platform, configuration).

  • Python
  • ActivePython
  • Anaconda
  • Canopy
  • IronPython
  • PyPy
Standard platform independent installation directory.

Information returned by sysconfig.get_path('stdlib').

Standard platform dependent installation directory.

Information returned by sysconfig.get_path('platstdlib').

Third-party platform independent installation directory.

Information returned by sysconfig.get_path('purelib').

Third-party platform dependent installation directory.

Information returned by sysconfig.get_path('platlib').