'\" t .\" Man page generated from reStructuredText .\" by the Docutils 0.22.3 manpage writer. . . .nr rst2man-indent-level 0 . .de1 rstReportMargin \\$1 \\n[an-margin] level \\n[rst2man-indent-level] level margin: \\n[rst2man-indent\\n[rst2man-indent-level]] - \\n[rst2man-indent0] \\n[rst2man-indent1] \\n[rst2man-indent2] .. .de1 INDENT .\" .rstReportMargin pre: . RS \\$1 . nr rst2man-indent\\n[rst2man-indent-level] \\n[an-margin] . nr rst2man-indent-level +1 .\" .rstReportMargin post: .. .de UNINDENT . RE .\" indent \\n[an-margin] .\" old: \\n[rst2man-indent\\n[rst2man-indent-level]] .nr rst2man-indent-level -1 .\" new: \\n[rst2man-indent\\n[rst2man-indent-level]] .in \\n[rst2man-indent\\n[rst2man-indent-level]]u .. .TH "CMAKE-MODULES" "7" "Jan 27, 2026" "4.2.3" "CMake" .SH NAME cmake-modules \- CMake Modules Reference .sp The modules listed here are part of the CMake distribution. Projects may provide further modules; their location(s) can be specified in the \fBCMAKE_MODULE_PATH\fP \%<#\:variable:CMAKE_MODULE_PATH> variable. .SH UTILITY MODULES .sp These modules are loaded using the \fBinclude()\fP \%<#\:command:include> command. .SS AndroidTestUtilities .sp Added in version 3.7. .sp This module provides a command to create a test that pushes data needed for testing an Android device behavior onto a connected Android device. .sp Load this module in a CMake project with: .INDENT 0.0 .INDENT 3.5 .sp .EX include(AndroidTestUtilities) .EE .UNINDENT .UNINDENT .SS Commands .sp This module provides the following command: .INDENT 0.0 .TP .B android_add_test_data Creates a test that automatically loads specified data onto an Android device: .INDENT 7.0 .INDENT 3.5 .sp .EX android_add_test_data( [FILES ...] [FILES_DEST ] [LIBS ...] [LIBS_DEST ] DEVICE_OBJECT_STORE DEVICE_TEST_DIR [NO_LINK_REGEX ...] ) .EE .UNINDENT .UNINDENT .sp This command accepts files and libraries needed to run project\-specific tests 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. .sp On the host operating system, files and libraries are copied at build time. For on\-device testing, the files are loaded onto the device by the manufactured test at run time. .sp This command accepts the following named parameters: .INDENT 7.0 .TP .B \fBFILES ...\fP Zero or more files needed for testing. .TP .B \fBFILES_DEST \fP Absolute path where the data files are expected to be. .TP .B \fBLIBS ...\fP Zero or more libraries needed for testing. .TP .B \fBLIBS_DEST \fP Absolute path where the libraries are expected to be. .TP .B \fBDEVICE_OBJECT_STORE \fP Absolute path to the on\-device location where the data files are initially stored. .TP .B \fBDEVICE_TEST_DIR \fP Absolute path to the root directory of the on\-device test location. .TP .B \fBNO_LINK_REGEX ...\fP A list of regular expression patterns matching file names to be copied from the object store to the test directory, instead of being symlinked. .UNINDENT .UNINDENT .SS Examples .sp The following example shows how to use this module to create a test named \fBexample_setup_test\fP that prepares data during the build phase. This test can then be run using \fBctest(1)\fP \%<#\:manual:ctest(1)> to load the data onto the Android device. .sp \fBCMakeLists.txt\fP .INDENT 0.0 .INDENT 3.5 .sp .EX include(AndroidTestUtilities) android_add_test_data( example_setup_test FILES data/protobuffer.p data/file.txt LIBS libs/library_1 libs/library_2 DEVICE_OBJECT_STORE \(dq/sdcard/.ExternalData/SHA\(dq DEVICE_TEST_DIR \(dq/data/local/tests/example\(dq ) .EE .UNINDENT .UNINDENT .SS BundleUtilities .sp This module provides utility commands for assembling standalone, bundle\-style applications with CMake, such as macOS \fB\&.app\fP bundles or similar directory\-based application bundles on other operating systems. .sp Load this module in a CMake installation with: .INDENT 0.0 .INDENT 3.5 .sp .EX include(BundleUtilities) .EE .UNINDENT .UNINDENT .sp \fBNote:\fP .INDENT 0.0 .INDENT 3.5 Do not use this module at configure time (from \fBCMakeLists.txt\fP). Instead, include it and invoke its commands from an \fBinstall(CODE)\fP \%<#\:code> or \fBinstall(SCRIPT)\fP \%<#\:script>\&. .UNINDENT .UNINDENT .SS Commands .sp This module provides the following commands: .INDENT 0.0 .IP \(bu 2 \fBfixup_bundle()\fP .IP \(bu 2 \fBcopy_and_fixup_bundle()\fP .IP \(bu 2 \fBverify_app()\fP .IP \(bu 2 \fBget_bundle_main_executable()\fP .IP \(bu 2 \fBget_dotapp_dir()\fP .IP \(bu 2 \fBget_bundle_and_executable()\fP .IP \(bu 2 \fBget_bundle_all_executables()\fP .IP \(bu 2 \fBget_item_key()\fP .IP \(bu 2 \fBget_item_rpaths()\fP .IP \(bu 2 \fBclear_bundle_keys()\fP .IP \(bu 2 \fBset_bundle_key_values()\fP .IP \(bu 2 \fBget_bundle_keys()\fP .IP \(bu 2 \fBcopy_resolved_item_into_bundle()\fP .IP \(bu 2 \fBcopy_resolved_framework_into_bundle()\fP .IP \(bu 2 \fBfixup_bundle_item()\fP .IP \(bu 2 \fBverify_bundle_prerequisites()\fP .IP \(bu 2 \fBverify_bundle_symlinks()\fP .UNINDENT .INDENT 0.0 .TP .B fixup_bundle Prepares a bundle for distribution by fixing up its internal dependencies: .INDENT 7.0 .INDENT 3.5 .sp .EX fixup_bundle( [IGNORE_ITEM ...]) .EE .UNINDENT .UNINDENT .sp This command modifies the \fB\fP bundle in\-place to make it self\-contained and portable, so that it can be drag\-n\-drop copied to another machine and run there, assuming all of the system libraries are compatible. .sp This command collects all dependencies (keys) for the executables and libraries in the bundle. For each dependency, it copies the required files into the bundle and adjusts them according to their own prerequisites. Once complete, it clears the collected keys and invokes the \fBverify_app()\fP command to ensure the final bundle is truly standalone. .sp The arguments are: .INDENT 7.0 .TP .B \fB\fP The path to the bundle to fix. This can be an \fB\&.app\fP directory or direct path to an executable. .TP .B \fB\fP A list of libraries that must be fixed up, but that cannot be automatically determined by the \fBotool\fP output analysis (i.e. \fBplugins\fP). If plugins are passed to this command as this parameter, they should be installed or copied into the bundle before calling this command. .TP .B \fB\fP A list of paths where libraries might be found. These paths are searched first when a target without any path info is given. Then standard system locations are also searched: \fBPATH\fP, Framework locations, \fB/usr/lib\fP, etc. .TP .B \fBIGNORE_ITEM ...\fP Added in version 3.6. .sp Optional list of file names to ignore (e.g. \fBIGNORE_ITEM \(dqvcredist_x86.exe;vcredist_x64.exe\(dq\fP). .UNINDENT .UNINDENT .INDENT 0.0 .TP .B copy_and_fixup_bundle Copies the bundle and fixes up the new copied bundle in\-place: .INDENT 7.0 .INDENT 3.5 .sp .EX copy_and_fixup_bundle( ) .EE .UNINDENT .UNINDENT .sp This command makes a copy of the bundle \fB\fP at location \fB\fP and then fixes up the new copied bundle in\-place at \fB\fP\&. .sp The arguments are: .INDENT 7.0 .TP .B \fB\fP The directory of the bundle being copied. .TP .B \fB\fP The destination directory of the bundle copy. .TP .B \fB\fP A list of libraries that must be fixed up, but that cannot be automatically determined by the \fBotool\fP output analysis (i.e. \fBplugins\fP). If plugins are passed to this command as this parameter, they should be installed or copied into the bundle before calling this command. .TP .B \fB\fP A list of paths where libraries might be found. These paths are searched first when a target without any path info is given. Then standard system locations are also searched: \fBPATH\fP, Framework locations, \fB/usr/lib\fP, etc. .UNINDENT .UNINDENT .INDENT 0.0 .TP .B verify_app Verifies that an application bundle appears valid based on running analysis tools on it: .INDENT 7.0 .INDENT 3.5 .sp .EX verify_app( [IGNORE_ITEM ...]) .EE .UNINDENT .UNINDENT .sp If the application fails verification, a \fBmessage(FATAL_ERROR)\fP \%<#\:command:message> is issued, halting the installation process. .sp The arguments are: .INDENT 7.0 .TP .B \fB\fP The path to the application to verify. This can be a \fB\&.app\fP directory or a standalone executable. .TP .B \fBIGNORE_ITEM ...\fP Added in version 3.6. .sp Optional list of file names to ignore (e.g. \fBIGNORE_ITEM \(dqvcredist_x86.exe;vcredist_x64.exe\(dq\fP). .UNINDENT .UNINDENT .INDENT 0.0 .TP .B get_bundle_main_executable Retrieves the main executable within a given application bundle: .INDENT 7.0 .INDENT 3.5 .sp .EX get_bundle_main_executable( ) .EE .UNINDENT .UNINDENT .sp The result is stored in a \fB\fP variable and will contain a full path name of the bundle\(aqs main executable file, or an \fBerror:\fP prefixed string if it could not be determined. .UNINDENT .INDENT 0.0 .TP .B get_dotapp_dir Locates the enclosing \fB\&.app\fP directory for the given executable: .INDENT 7.0 .INDENT 3.5 .sp .EX get_dotapp_dir( ) .EE .UNINDENT .UNINDENT .sp This command retrieves the nearest parent dir whose name ends with \fB\&.app\fP given the full path to an executable and stores it to the \fB\fP variable. If there is no such parent dir, then it simply retrieves the directory containing the executable. .sp The retrieved directory may or may not exist. .UNINDENT .INDENT 0.0 .TP .B get_bundle_and_executable Takes either a \fB\&.app\fP directory name or the name of an executable nested inside a \fB\&.app\fP directory and retrieves the path to the \fB\&.app\fP directory and the path to its main executable: .INDENT 7.0 .INDENT 3.5 .sp .EX get_bundle_and_executable( ) .EE .UNINDENT .UNINDENT .sp The arguments are: .INDENT 7.0 .TP .B \fB\fP The name of the application being processed. .TP .B \fB\fP Variable name in which to store the resulting path to the \fB\&.app\fP directory. In case of any error, this variable will contain an error message prefixed with string \fBerror:\fP\&. .TP .B \fB\fP Variable name in which to store the resulting main executable. In case of any error, this variable will contain an error message prefixed with string \fBerror:\fP\&. .TP .B \fB\fP Variable name in which the boolean result is stored whether this command was successful or not. .UNINDENT .UNINDENT .INDENT 0.0 .TP .B get_bundle_all_executables Gets all executables of a given bundle: .INDENT 7.0 .INDENT 3.5 .sp .EX get_bundle_all_executables( ) .EE .UNINDENT .UNINDENT .sp This command scans \fB\fP bundle recursively for all executable files and stores them into a variable \fB\fP\&. .UNINDENT .INDENT 0.0 .TP .B get_item_key Generates a unique key for the given item: .INDENT 7.0 .INDENT 3.5 .sp .EX get_item_key( ) .EE .UNINDENT .UNINDENT .sp Given \fB\fP file name, this command generates \fB\fP 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 \fB\&.\fP replaced by \fB_\fP\&. .sp This key is used as a prefix for CMake variables so that a set of variables can be associated with a given item based on its key. .UNINDENT .INDENT 0.0 .TP .B get_item_rpaths Gets RPATHS (run\-time search paths) for the given item: .INDENT 7.0 .INDENT 3.5 .sp .EX get_item_rpaths( ) .EE .UNINDENT .UNINDENT .sp This command gets RPATHS of the \fB\fP file name and stores them to the variable with provided name \fB\fP\&. .UNINDENT .INDENT 0.0 .TP .B clear_bundle_keys Clears all variables associated with keys: .INDENT 7.0 .INDENT 3.5 .sp .EX clear_bundle_keys() .EE .UNINDENT .UNINDENT .sp This command loops over the \fB\fP list of keys, clearing all the variables associated with each key. After the loop, it clears the list of keys itself. This command should be called after the \fBget_bundle_keys()\fP command, when done working with a list of keys. .UNINDENT .INDENT 0.0 .TP .B set_bundle_key_values Adds a key to the list of keys: .INDENT 7.0 .INDENT 3.5 .sp .EX set_bundle_key_values( [] ) .EE .UNINDENT .UNINDENT .sp This command adds the \fB\fP key to the list (if necessary) for the given item. If added, also set all the variables associated with that key. .sp The arguments are: .INDENT 7.0 .TP .B \fB\fP Variable name holding the name of the key to be added to the list for the given item. .TP .B \fB\fP The path to the top level loading path used for \fB@loader_path\fP replacement on Apple operating systems. When resolving item, \fB@loader_path\fP references will be resolved relative to the directory of the given context value (presumably another library). .TP .B \fB\fP The item for which to add the key. .TP .B \fB\fP The path to the top level executable used for \fB@executable_path\fP replacement on Apple operating systems. .TP .B \fB\fP A list of paths where libraries might be found. These paths are searched first when a target without any path info is given. Then standard system locations are also searched: \fBPATH\fP, Framework locations, \fB/usr/lib\fP, etc. .TP .B \fB\fP If set to \fB1\fP library symlink structure will be preserved. .TP .B \fB\fP Optional run\-time search paths for an executable file or library to help find files. .UNINDENT .UNINDENT .INDENT 0.0 .TP .B get_bundle_keys Gets bundle keys: .INDENT 7.0 .INDENT 3.5 .sp .EX get_bundle_keys( [IGNORE_ITEM ...]) .EE .UNINDENT .UNINDENT .sp This command loops over all the executable and library files within \fB\fP bundle (and given as extra \fB\fP) and accumulate a list of keys representing them. It sets values associated with each key such that they can be looped over all of them and copies prerequisite libs into the bundle and then does appropriate \fBinstall_name_tool\fP fixups. .sp The arguments are: .INDENT 7.0 .TP .B \fB\fP The path to the bundle to fix. This can be an \fB\&.app\fP directory or direct path to an executable. .TP .B \fB\fP A list of libraries that must be fixed up, but that cannot be automatically determined by the \fBotool\fP output analysis (i.e. \fBplugins\fP). If plugins are passed to this command as this parameter, they should be installed or copied into the bundle before calling this command. .TP .B \fB\fP A list of paths where libraries might be found. These paths are searched first when a target without any path info is given. Then standard system locations are also searched: \fBPATH\fP, Framework locations, \fB/usr/lib\fP, etc. .TP .B \fB\fP Variable name holding a list of keys that represent all executable and library files within the bundle. .TP .B \fBIGNORE_ITEM ...\fP Added in version 3.6. .sp Optional list of file names to ignore (e.g. \fBIGNORE_ITEM \(dqvcredist_x86.exe;vcredist_x64.exe\(dq\fP). .UNINDENT .UNINDENT .INDENT 0.0 .TP .B copy_resolved_item_into_bundle Copies a resolved item into the bundle if necessary: .INDENT 7.0 .INDENT 3.5 .sp .EX copy_resolved_item_into_bundle( ) .EE .UNINDENT .UNINDENT .sp Copy is not necessary, if the \fB\fP is \(dqthe same as\(dq the \fB\fP\&. .UNINDENT .INDENT 0.0 .TP .B copy_resolved_framework_into_bundle Copies a resolved framework into the bundle if necessary: .INDENT 7.0 .INDENT 3.5 .sp .EX copy_resolved_framework_into_bundle( ) .EE .UNINDENT .UNINDENT .sp Copy is not necessary, if the \fB\fP is \(dqthe same as\(dq the \fB\fP\&. .sp The following variables can be set before invoking this command: .INDENT 7.0 .TP .B \fBBU_COPY_FULL_FRAMEWORK_CONTENTS\fP By default, this variable is not set. If full frameworks should be embedded in the bundles, set this variable to boolean true before calling the \fBfixup_bundle()\fP command. By default, this command copies the framework dylib itself plus the framework \fBResources\fP directory. .UNINDENT .UNINDENT .INDENT 0.0 .TP .B fixup_bundle_item Fixes up bundle item: .INDENT 7.0 .INDENT 3.5 .sp .EX fixup_bundle_item( ) .EE .UNINDENT .UNINDENT .sp This command gets the direct/non\-system prerequisites of the \fB\fP and for each prerequisite, it changes the way it is referenced to the value of the \fB_EMBEDDED_ITEM\fP keyed variable for that prerequisite. Most likely changing to an \fB@executable_path\fP style reference. .sp This command requires that the \fB\fP be \fBinside\fP the bundle already. In other words, if plugins are passed to \fBfixup_bundle()\fP command as its \fB\fP parameter, they should be installed or copied into the bundle before calling the \fBfixup_bundle()\fP command. .sp Also, it changes the id of the item being fixed up to its own \fB_EMBEDDED_ITEM\fP value. .sp Changes are accumulated in a local variable and \fIone\fP call is made to \fBinstall_name_tool\fP command\-line tool at the end of this command with all the changes at once. .sp The arguments are: .INDENT 7.0 .TP .B \fB\fP The bundle item to be fixed up. .TP .B \fB\fP The path to the top level executable used for \fB@executable_path\fP replacement on Apple operating systems. .TP .B \fB\fP A list of paths where libraries might be found. These paths are searched first when a target without any path info is given. Then standard system locations are also searched: \fBPATH\fP, Framework locations, \fB/usr/lib\fP, etc. .UNINDENT .sp The following variables can be set before invoking this command: .INDENT 7.0 .TP .B \fBBU_CHMOD_BUNDLE_ITEMS\fP If this variable is set to boolean true value then bundle items will be marked writable before \fBinstall_name_tool\fP tool tries to change them. .UNINDENT .UNINDENT .INDENT 0.0 .TP .B verify_bundle_prerequisites Verifies that the sum of all prerequisites of all files inside the bundle are contained within the bundle or are \fBsystem\fP libraries, presumed to exist everywhere: .INDENT 7.0 .INDENT 3.5 .sp .EX verify_bundle_prerequisites( [IGNORE_ITEM ...] ) .EE .UNINDENT .UNINDENT .sp The arguments are: .INDENT 7.0 .TP .B \fB\fP Name of the bundle being verified. .TP .B \fB\fP Name of the variable in which to store a boolean result of whether a verification was successful. .TP .B \fB\fP Name of the variable holding any informational messages produced by the verification. .TP .B \fBIGNORE_ITEM ...\fP Added in version 3.6. .sp Optional list of file names to ignore (e.g. \fBIGNORE_ITEM \(dqvcredist_x86.exe;vcredist_x64.exe\(dq\fP). .UNINDENT .UNINDENT .INDENT 0.0 .TP .B verify_bundle_symlinks Verifies that any symlinks found in the specified bundle point to other files that are already also in the bundle: .INDENT 7.0 .INDENT 3.5 .sp .EX verify_bundle_symlinks( ) .EE .UNINDENT .UNINDENT .sp Anything that points to an external file causes this command to fail the verification. .sp The arguments are: .INDENT 7.0 .TP .B \fB\fP Name of the bundle being verified. .TP .B \fB\fP Name of the variable in which to store a boolean result of whether a verification was successful. .TP .B \fB\fP Name of the variable holding any informational messages produced by the verification. .UNINDENT .UNINDENT .SS Examples .sp Using this module inside the installation code that is executed at the installation phase: .sp \fBCMakeLists.txt\fP .INDENT 0.0 .INDENT 3.5 .sp .EX # ... install(CODE \(dq include(BundleUtilities) set(BU_CHMOD_BUNDLE_ITEMS TRUE) fixup_bundle( \e\(dq${fixup_exe}\e\(dq \e\(dq${plugins}\e\(dq \e\(dq${bin_dir};${library_dir};${binary_dir}\e\(dq ) \(dq) .EE .UNINDENT .UNINDENT .SS CheckCCompilerFlag .sp This module provides a command to check whether the C compiler supports a given flag. .sp Load this module in a CMake project with: .INDENT 0.0 .INDENT 3.5 .sp .EX include(CheckCCompilerFlag) .EE .UNINDENT .UNINDENT .SS Commands .sp This module provides the following command: .INDENT 0.0 .TP .B check_c_compiler_flag Checks once whether the C compiler supports a given flag: .INDENT 7.0 .INDENT 3.5 .sp .EX check_c_compiler_flag( ) .EE .UNINDENT .UNINDENT .sp This command checks once that the \fB\fP is accepted by the C compiler without producing a diagnostic message. Multiple flags can be specified in one argument as a string using a semicolon\-separated list \%<#\:cmake-language-lists>\&. .sp The result of the check is stored in the internal cache variable specified by \fB\fP, with boolean true for success and boolean false for failure. .sp A successful result only indicates that the compiler did not report an error when given the flag. Whether the flag has any effect, or the intended one, is outside the scope of this module. .sp \fBNote:\fP .INDENT 7.0 .INDENT 3.5 Since the underlying \fBtry_compile()\fP \%<#\:command:try_compile> command also uses flags from variables like \fBCMAKE__FLAGS\fP \%<#\:variable:CMAKE__FLAGS>, unknown or unsupported flags in those variables may result in a false negative for this check. .UNINDENT .UNINDENT .sp Variables Affecting the Check .sp The following variables may be set before calling this command to modify the way the check is run: .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_FLAGS\fP A space\-separated string of additional flags to pass to the compiler. A semicolon\-separated list \%<#\:cmake-language-lists> will not work. The contents of \fBCMAKE__FLAGS\fP \%<#\:variable:CMAKE__FLAGS> and its associated configuration\-specific \fBCMAKE__FLAGS_\fP \%<#\:variable:CMAKE__FLAGS_> variables are automatically prepended to the compiler command before the contents of this variable. .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_DEFINITIONS\fP A semicolon\-separated list \%<#\:cmake-language-lists> of compiler definitions, each of the form \fB\-DFOO\fP or \fB\-DFOO=bar\fP\&. A definition for the name specified by the result variable argument of the check command is also added automatically. .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_INCLUDES\fP A semicolon\-separated list \%<#\:cmake-language-lists> of header search paths to pass to the compiler. These will be the only header search paths used; the contents of the \fBINCLUDE_DIRECTORIES\fP \%<#\:prop_dir:INCLUDE_DIRECTORIES> directory property will be ignored. .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_LINK_OPTIONS\fP Added in version 3.14. .sp A semicolon\-separated list \%<#\:cmake-language-lists> of options to add to the link command (see \fBtry_compile()\fP \%<#\:command:try_compile> for further details). .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_LIBRARIES\fP A semicolon\-separated list \%<#\:cmake-language-lists> of libraries to add to the link command. These can be the names of system libraries, or they can be Imported Targets \%<#\:imported-targets> (see \fBtry_compile()\fP \%<#\:command:try_compile> for further details). .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_LINK_DIRECTORIES\fP Added in version 3.31. .sp A semicolon\-separated list \%<#\:cmake-language-lists> of library search paths to pass to the linker (see \fBtry_compile()\fP \%<#\:command:try_compile> for further details). .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_QUIET\fP Added in version 3.1. .sp If this variable evaluates to a boolean true value, all status messages associated with the check will be suppressed. .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_TRY_COMPILE_TARGET_TYPE\fP \%<#\:variable:CMAKE_TRY_COMPILE_TARGET_TYPE> Internally, the \fBtry_compile()\fP \%<#\:command:try_compile> command is used to perform the check, and this variable controls the type of target it creates. If this variable is set to \fBEXECUTABLE\fP (the default), the check compiles and links the test source code as an executable program. If set to \fBSTATIC_LIBRARY\fP, the test source code is compiled but not linked. .UNINDENT .UNINDENT .SS Examples .sp The following example demonstrates how to use this module to check support for the C compiler flag \fB\-fno\-optimize\-strlen\fP, which disables optimizations related to the \fBstrlen()\fP C function in GCC and Clang compilers. The result of the check is stored in the internal cache variable \fBHAVE_FNO_OPTIMIZE_STRLEN\fP, and the flag is conditionally enabled using the \fBtarget_compile_options()\fP \%<#\:command:target_compile_options> command. The \fB$\fP \%<#\:genex:COMPILE_LANGUAGE:languages> generator expression ensures that the flag is added only to \fBC\fP source files. .INDENT 0.0 .INDENT 3.5 .sp .EX include(CheckCCompilerFlag) check_c_compiler_flag(\-fno\-optimize\-strlen HAVE_FNO_OPTIMIZE_STRLEN) if(HAVE_FNO_OPTIMIZE_STRLEN) target_compile_options( example PRIVATE $<$:\-fno\-optimize\-strlen> ) endif() .EE .UNINDENT .UNINDENT .SS See Also .INDENT 0.0 .IP \(bu 2 The \fBCheckCompilerFlag\fP \%<#\:module:CheckCompilerFlag> module for a more general command to check whether a compiler flag is supported. .UNINDENT .SS CheckCompilerFlag .sp Added in version 3.19. .sp This module provides a command to check whether the compiler supports a given flag. .sp Load this module in a CMake project with: .INDENT 0.0 .INDENT 3.5 .sp .EX include(CheckCompilerFlag) .EE .UNINDENT .UNINDENT .SS Commands .sp This module provides the following command: .INDENT 0.0 .TP .B check_compiler_flag Checks once whether the compiler supports a given flag: .INDENT 7.0 .INDENT 3.5 .sp .EX check_compiler_flag( ) .EE .UNINDENT .UNINDENT .sp This command checks once that the \fB\fP is accepted by the \fB\fP compiler without producing a diagnostic message. The result of the check is stored in the internal cache variable specified by \fB\fP\&. .sp The arguments are: .INDENT 7.0 .TP .B \fB\fP The language of the compiler used for the check. Supported languages are: \fBC\fP, \fBCXX\fP, \fBCUDA\fP, \fBFortran\fP, \fBHIP\fP, \fBISPC\fP, \fBOBJC\fP, and \fBOBJCXX\fP, and \fBSwift\fP\&. .sp Added in version 3.21: Support for \fBHIP\fP language. .sp Added in version 3.26: Support for \fBSwift\fP language. .TP .B \fB\fP Compiler flag(s) to check. Multiple flags can be specified in one argument as a string using a semicolon\-separated list \%<#\:cmake-language-lists>\&. .TP .B \fB\fP Variable name of an internal cache variable to store the result of the check, with boolean true for success and boolean false for failure. .UNINDENT .sp A successful result only indicates that the compiler did not report an error when given the flag. Whether the flag has any effect, or the intended one, is outside the scope of this module. .sp \fBNote:\fP .INDENT 7.0 .INDENT 3.5 Since the underlying \fBtry_compile()\fP \%<#\:command:try_compile> command also uses flags from variables like \fBCMAKE__FLAGS\fP \%<#\:variable:CMAKE__FLAGS>, unknown or unsupported flags in those variables may result in a false negative for this check. .UNINDENT .UNINDENT .sp Variables Affecting the Check .sp The following variables may be set before calling this command to modify the way the check is run: .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_FLAGS\fP A space\-separated string of additional flags to pass to the compiler. A semicolon\-separated list \%<#\:cmake-language-lists> will not work. The contents of \fBCMAKE__FLAGS\fP \%<#\:variable:CMAKE__FLAGS> and its associated configuration\-specific \fBCMAKE__FLAGS_\fP \%<#\:variable:CMAKE__FLAGS_> variables are automatically prepended to the compiler command before the contents of this variable. .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_DEFINITIONS\fP A semicolon\-separated list \%<#\:cmake-language-lists> of compiler definitions, each of the form \fB\-DFOO\fP or \fB\-DFOO=bar\fP\&. A definition for the name specified by the result variable argument of the check command is also added automatically. .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_INCLUDES\fP A semicolon\-separated list \%<#\:cmake-language-lists> of header search paths to pass to the compiler. These will be the only header search paths used; the contents of the \fBINCLUDE_DIRECTORIES\fP \%<#\:prop_dir:INCLUDE_DIRECTORIES> directory property will be ignored. .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_LINK_OPTIONS\fP Added in version 3.14. .sp A semicolon\-separated list \%<#\:cmake-language-lists> of options to add to the link command (see \fBtry_compile()\fP \%<#\:command:try_compile> for further details). .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_LIBRARIES\fP A semicolon\-separated list \%<#\:cmake-language-lists> of libraries to add to the link command. These can be the names of system libraries, or they can be Imported Targets \%<#\:imported-targets> (see \fBtry_compile()\fP \%<#\:command:try_compile> for further details). .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_LINK_DIRECTORIES\fP Added in version 3.31. .sp A semicolon\-separated list \%<#\:cmake-language-lists> of library search paths to pass to the linker (see \fBtry_compile()\fP \%<#\:command:try_compile> for further details). .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_QUIET\fP Added in version 3.1. .sp If this variable evaluates to a boolean true value, all status messages associated with the check will be suppressed. .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_TRY_COMPILE_TARGET_TYPE\fP \%<#\:variable:CMAKE_TRY_COMPILE_TARGET_TYPE> Internally, the \fBtry_compile()\fP \%<#\:command:try_compile> command is used to perform the check, and this variable controls the type of target it creates. If this variable is set to \fBEXECUTABLE\fP (the default), the check compiles and links the test source code as an executable program. If set to \fBSTATIC_LIBRARY\fP, the test source code is compiled but not linked. .UNINDENT .UNINDENT .SS Examples .sp The following example demonstrates how to use this module to check support for the C compiler flag \fB\-fno\-optimize\-strlen\fP, which disables optimizations related to the \fBstrlen()\fP C function in GCC and Clang compilers. The result of the check is stored in the internal cache variable \fBHAVE_FNO_OPTIMIZE_STRLEN\fP, and the flag is conditionally enabled using the \fBtarget_compile_options()\fP \%<#\:command:target_compile_options> command. The \fB$\fP \%<#\:genex:COMPILE_LANGUAGE:languages> generator expression ensures that the flag is added only to \fBC\fP source files. .INDENT 0.0 .INDENT 3.5 .sp .EX include(CheckCompilerFlag) check_compiler_flag(C \-fno\-optimize\-strlen HAVE_FNO_OPTIMIZE_STRLEN) if(HAVE_FNO_OPTIMIZE_STRLEN) target_compile_options( example PRIVATE $<$:\-fno\-optimize\-strlen> ) endif() .EE .UNINDENT .UNINDENT .SS See Also .INDENT 0.0 .IP \(bu 2 The \fBCheckLinkerFlag\fP \%<#\:module:CheckLinkerFlag> module to check whether a linker flag is supported by the compiler. .UNINDENT .SS CheckCSourceCompiles .sp This module provides a command to check whether a C source can be built. .sp Load this module in a CMake project with: .INDENT 0.0 .INDENT 3.5 .sp .EX include(CheckCSourceCompiles) .EE .UNINDENT .UNINDENT .SS Commands .sp This module provides the following command: .INDENT 0.0 .TP .B check_c_source_compiles Checks once whether the given C source code can be built: .INDENT 7.0 .INDENT 3.5 .sp .EX check_c_source_compiles( [FAIL_REGEX ...]) .EE .UNINDENT .UNINDENT .sp This command checks once that the source supplied in \fB\fP can be compiled (and linked into an executable). The result of the check is stored in the internal cache variable specified by \fB\fP\&. .sp The arguments are: .INDENT 7.0 .TP .B \fB\fP C source code to check. This must be an entire program, as written in a file containing the body block. All symbols used in the source code are expected to be declared as usual in their corresponding headers. .TP .B \fB\fP Variable name of an internal cache variable to store the result of the check, with boolean true for success and boolean false for failure. .TP .B \fBFAIL_REGEX ...\fP If one or more regular expression patterns are provided, then failure is determined by checking if anything in the compiler output matches any of the specified regular expressions. .UNINDENT .sp Variables Affecting the Check .sp The following variables may be set before calling this command to modify the way the check is run: .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_FLAGS\fP A space\-separated string of additional flags to pass to the compiler. A semicolon\-separated list \%<#\:cmake-language-lists> will not work. The contents of \fBCMAKE__FLAGS\fP \%<#\:variable:CMAKE__FLAGS> and its associated configuration\-specific \fBCMAKE__FLAGS_\fP \%<#\:variable:CMAKE__FLAGS_> variables are automatically prepended to the compiler command before the contents of this variable. .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_DEFINITIONS\fP A semicolon\-separated list \%<#\:cmake-language-lists> of compiler definitions, each of the form \fB\-DFOO\fP or \fB\-DFOO=bar\fP\&. A definition for the name specified by the result variable argument of the check command is also added automatically. .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_INCLUDES\fP A semicolon\-separated list \%<#\:cmake-language-lists> of header search paths to pass to the compiler. These will be the only header search paths used; the contents of the \fBINCLUDE_DIRECTORIES\fP \%<#\:prop_dir:INCLUDE_DIRECTORIES> directory property will be ignored. .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_LINK_OPTIONS\fP Added in version 3.14. .sp A semicolon\-separated list \%<#\:cmake-language-lists> of options to add to the link command (see \fBtry_compile()\fP \%<#\:command:try_compile> for further details). .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_LIBRARIES\fP A semicolon\-separated list \%<#\:cmake-language-lists> of libraries to add to the link command. These can be the names of system libraries, or they can be Imported Targets \%<#\:imported-targets> (see \fBtry_compile()\fP \%<#\:command:try_compile> for further details). .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_LINK_DIRECTORIES\fP Added in version 3.31. .sp A semicolon\-separated list \%<#\:cmake-language-lists> of library search paths to pass to the linker (see \fBtry_compile()\fP \%<#\:command:try_compile> for further details). .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_QUIET\fP Added in version 3.1. .sp If this variable evaluates to a boolean true value, all status messages associated with the check will be suppressed. .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_TRY_COMPILE_TARGET_TYPE\fP \%<#\:variable:CMAKE_TRY_COMPILE_TARGET_TYPE> Internally, the \fBtry_compile()\fP \%<#\:command:try_compile> command is used to perform the check, and this variable controls the type of target it creates. If this variable is set to \fBEXECUTABLE\fP (the default), the check compiles and links the test source code as an executable program. If set to \fBSTATIC_LIBRARY\fP, the test source code is compiled but not linked. .UNINDENT .UNINDENT .SS Examples .sp Checking whether C source code containing SSE2 intrinsic can be compiled and linked: .INDENT 0.0 .INDENT 3.5 .sp .EX include(CheckCSourceCompiles) check_c_source_compiles(\(dq #include int main(void) { __m128d a = _mm_setzero_pd(); (void)a; return 0; } \(dq PROJECT_HAVE_SSE2_INTRINSICS) .EE .UNINDENT .UNINDENT .SS See Also .INDENT 0.0 .IP \(bu 2 The \fBCheckSourceCompiles\fP \%<#\:module:CheckSourceCompiles> module for a more general command to check whether source can be built. .IP \(bu 2 The \fBCheckSourceRuns\fP \%<#\:module:CheckSourceRuns> module to check whether source can be built and run. .UNINDENT .SS CheckCSourceRuns .sp This module provides a command to check whether a C source can be built and run. .sp Load this module in a CMake project with: .INDENT 0.0 .INDENT 3.5 .sp .EX include(CheckCSourceRuns) .EE .UNINDENT .UNINDENT .SS Commands .sp This module provides the following command: .INDENT 0.0 .TP .B check_c_source_runs Checks once whether the given C source code compiles and links into an executable that can subsequently be run: .INDENT 7.0 .INDENT 3.5 .sp .EX check_c_source_runs( ) .EE .UNINDENT .UNINDENT .sp The C source supplied in \fB\fP must contain at least a \fBmain()\fP function. The result of the check is stored in the internal cache variable specified by \fB\fP\&. If the code builds and runs with exit code \fB0\fP, success is indicated by a boolean true value. Failure to build or run is indicated by a boolean false value, such as an empty string or an error message. .sp Variables Affecting the Check .sp The following variables may be set before calling this command to modify the way the check is run: .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_FLAGS\fP A space\-separated string of additional flags to pass to the compiler. A semicolon\-separated list \%<#\:cmake-language-lists> will not work. The contents of \fBCMAKE__FLAGS\fP \%<#\:variable:CMAKE__FLAGS> and its associated configuration\-specific \fBCMAKE__FLAGS_\fP \%<#\:variable:CMAKE__FLAGS_> variables are automatically prepended to the compiler command before the contents of this variable. .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_DEFINITIONS\fP A semicolon\-separated list \%<#\:cmake-language-lists> of compiler definitions, each of the form \fB\-DFOO\fP or \fB\-DFOO=bar\fP\&. A definition for the name specified by the result variable argument of the check command is also added automatically. .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_INCLUDES\fP A semicolon\-separated list \%<#\:cmake-language-lists> of header search paths to pass to the compiler. These will be the only header search paths used; the contents of the \fBINCLUDE_DIRECTORIES\fP \%<#\:prop_dir:INCLUDE_DIRECTORIES> directory property will be ignored. .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_LINK_OPTIONS\fP Added in version 3.14. .sp A semicolon\-separated list \%<#\:cmake-language-lists> of options to add to the link command (see \fBtry_compile()\fP \%<#\:command:try_compile> for further details). .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_LIBRARIES\fP A semicolon\-separated list \%<#\:cmake-language-lists> of libraries to add to the link command. These can be the names of system libraries, or they can be Imported Targets \%<#\:imported-targets> (see \fBtry_compile()\fP \%<#\:command:try_compile> for further details). .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_LINK_DIRECTORIES\fP Added in version 3.31. .sp A semicolon\-separated list \%<#\:cmake-language-lists> of library search paths to pass to the linker (see \fBtry_compile()\fP \%<#\:command:try_compile> for further details). .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_QUIET\fP Added in version 3.1. .sp If this variable evaluates to a boolean true value, all status messages associated with the check will be suppressed. .UNINDENT .UNINDENT .SS Examples .sp The following example demonstrates how to use this module to check whether the C source code is supported and operational at runtime. The result of the check is stored in the internal cache variable \fBHAVE_NORETURN\fP\&. .INDENT 0.0 .INDENT 3.5 .sp .EX include(CheckCSourceRuns) check_c_source_runs(\(dq #include #include noreturn void f(){ exit(0); } int main(void) { f(); return 1; } \(dq HAVE_NORETURN) .EE .UNINDENT .UNINDENT .SS See Also .INDENT 0.0 .IP \(bu 2 The \fBCheckSourceRuns\fP \%<#\:module:CheckSourceRuns> module for a more general command syntax. .IP \(bu 2 The \fBCheckSourceCompiles\fP \%<#\:module:CheckSourceCompiles> module to check whether a source code can be built. .UNINDENT .SS CheckCXXCompilerFlag .sp This module provides a command to check whether the C++ compiler supports a given flag. .sp Load this module in a CMake project with: .INDENT 0.0 .INDENT 3.5 .sp .EX include(CheckCXXCompilerFlag) .EE .UNINDENT .UNINDENT .SS Commands .sp This module provides the following command: .INDENT 0.0 .TP .B check_cxx_compiler_flag Checks once whether the C++ compiler supports a given flag: .INDENT 7.0 .INDENT 3.5 .sp .EX check_cxx_compiler_flag( ) .EE .UNINDENT .UNINDENT .sp This command checks once that the \fB\fP is accepted by the \fBCXX\fP compiler without producing a diagnostic message. Multiple flags can be specified in one argument as a string using a semicolon\-separated list \%<#\:cmake-language-lists>\&. .sp The result of the check is stored in the internal cache variable specified by \fB\fP, with boolean true for success and boolean false for failure. .sp A successful result only indicates that the compiler did not report an error when given the flag. Whether the flag has any effect, or the intended one, is outside the scope of this module. .sp \fBNote:\fP .INDENT 7.0 .INDENT 3.5 Since the underlying \fBtry_compile()\fP \%<#\:command:try_compile> command also uses flags from variables like \fBCMAKE__FLAGS\fP \%<#\:variable:CMAKE__FLAGS>, unknown or unsupported flags in those variables may result in a false negative for this check. .UNINDENT .UNINDENT .sp Variables Affecting the Check .sp The following variables may be set before calling this command to modify the way the check is run: .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_FLAGS\fP A space\-separated string of additional flags to pass to the compiler. A semicolon\-separated list \%<#\:cmake-language-lists> will not work. The contents of \fBCMAKE__FLAGS\fP \%<#\:variable:CMAKE__FLAGS> and its associated configuration\-specific \fBCMAKE__FLAGS_\fP \%<#\:variable:CMAKE__FLAGS_> variables are automatically prepended to the compiler command before the contents of this variable. .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_DEFINITIONS\fP A semicolon\-separated list \%<#\:cmake-language-lists> of compiler definitions, each of the form \fB\-DFOO\fP or \fB\-DFOO=bar\fP\&. A definition for the name specified by the result variable argument of the check command is also added automatically. .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_INCLUDES\fP A semicolon\-separated list \%<#\:cmake-language-lists> of header search paths to pass to the compiler. These will be the only header search paths used; the contents of the \fBINCLUDE_DIRECTORIES\fP \%<#\:prop_dir:INCLUDE_DIRECTORIES> directory property will be ignored. .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_LINK_OPTIONS\fP Added in version 3.14. .sp A semicolon\-separated list \%<#\:cmake-language-lists> of options to add to the link command (see \fBtry_compile()\fP \%<#\:command:try_compile> for further details). .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_LIBRARIES\fP A semicolon\-separated list \%<#\:cmake-language-lists> of libraries to add to the link command. These can be the names of system libraries, or they can be Imported Targets \%<#\:imported-targets> (see \fBtry_compile()\fP \%<#\:command:try_compile> for further details). .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_LINK_DIRECTORIES\fP Added in version 3.31. .sp A semicolon\-separated list \%<#\:cmake-language-lists> of library search paths to pass to the linker (see \fBtry_compile()\fP \%<#\:command:try_compile> for further details). .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_QUIET\fP Added in version 3.1. .sp If this variable evaluates to a boolean true value, all status messages associated with the check will be suppressed. .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_TRY_COMPILE_TARGET_TYPE\fP \%<#\:variable:CMAKE_TRY_COMPILE_TARGET_TYPE> Internally, the \fBtry_compile()\fP \%<#\:command:try_compile> command is used to perform the check, and this variable controls the type of target it creates. If this variable is set to \fBEXECUTABLE\fP (the default), the check compiles and links the test source code as an executable program. If set to \fBSTATIC_LIBRARY\fP, the test source code is compiled but not linked. .UNINDENT .UNINDENT .SS Examples .sp The following example demonstrates how to use this module to check the C++ compiler flag \fB\-fsycl\fP\&. The result of the check is stored in the internal cache variable \fBHAVE_FSYCL_FLAG\fP, and the flag is conditionally enabled using the \fBtarget_compile_options()\fP \%<#\:command:target_compile_options> command. The \fB$\fP \%<#\:genex:COMPILE_LANGUAGE:languages> generator expression ensures that the flag is added only to \fBCXX\fP source files. .INDENT 0.0 .INDENT 3.5 .sp .EX include(CheckCXXCompilerFlag) check_cxx_compiler_flag(\-fsycl HAVE_FSYCL_FLAG) if(HAVE_FSYCL_FLAG) target_compile_options( example PRIVATE $<$:\-fsycl> ) endif() .EE .UNINDENT .UNINDENT .SS See Also .INDENT 0.0 .IP \(bu 2 The \fBCheckCompilerFlag\fP \%<#\:module:CheckCompilerFlag> module for a more general command to check whether a compiler flag is supported. .UNINDENT .SS CheckCXXSourceCompiles .sp This module provides a command to check whether a C++ source can be built. .sp Load this module in a CMake project with: .INDENT 0.0 .INDENT 3.5 .sp .EX include(CheckCXXSourceCompiles) .EE .UNINDENT .UNINDENT .SS Commands .sp This module provides the following command: .INDENT 0.0 .TP .B check_cxx_source_compiles Checks once whether the given C++ source code can be built: .INDENT 7.0 .INDENT 3.5 .sp .EX check_cxx_source_compiles( [FAIL_REGEX ...]) .EE .UNINDENT .UNINDENT .sp This command checks once that the source supplied in \fB\fP can be compiled (and linked into an executable). The result of the check is stored in the internal cache variable specified by \fB\fP\&. .sp The arguments are: .INDENT 7.0 .TP .B \fB\fP C++ source code to check. This must be an entire program, as written in a file containing the body block. All symbols used in the source code are expected to be declared as usual in their corresponding headers. .TP .B \fB\fP Variable name of an internal cache variable to store the result of the check, with boolean true for success and boolean false for failure. .TP .B \fBFAIL_REGEX ...\fP If one or more regular expression patterns are provided, then failure is determined by checking if anything in the compiler output matches any of the specified regular expressions. .UNINDENT .sp Variables Affecting the Check .sp The following variables may be set before calling this command to modify the way the check is run: .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_FLAGS\fP A space\-separated string of additional flags to pass to the compiler. A semicolon\-separated list \%<#\:cmake-language-lists> will not work. The contents of \fBCMAKE__FLAGS\fP \%<#\:variable:CMAKE__FLAGS> and its associated configuration\-specific \fBCMAKE__FLAGS_\fP \%<#\:variable:CMAKE__FLAGS_> variables are automatically prepended to the compiler command before the contents of this variable. .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_DEFINITIONS\fP A semicolon\-separated list \%<#\:cmake-language-lists> of compiler definitions, each of the form \fB\-DFOO\fP or \fB\-DFOO=bar\fP\&. A definition for the name specified by the result variable argument of the check command is also added automatically. .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_INCLUDES\fP A semicolon\-separated list \%<#\:cmake-language-lists> of header search paths to pass to the compiler. These will be the only header search paths used; the contents of the \fBINCLUDE_DIRECTORIES\fP \%<#\:prop_dir:INCLUDE_DIRECTORIES> directory property will be ignored. .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_LINK_OPTIONS\fP Added in version 3.14. .sp A semicolon\-separated list \%<#\:cmake-language-lists> of options to add to the link command (see \fBtry_compile()\fP \%<#\:command:try_compile> for further details). .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_LIBRARIES\fP A semicolon\-separated list \%<#\:cmake-language-lists> of libraries to add to the link command. These can be the names of system libraries, or they can be Imported Targets \%<#\:imported-targets> (see \fBtry_compile()\fP \%<#\:command:try_compile> for further details). .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_LINK_DIRECTORIES\fP Added in version 3.31. .sp A semicolon\-separated list \%<#\:cmake-language-lists> of library search paths to pass to the linker (see \fBtry_compile()\fP \%<#\:command:try_compile> for further details). .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_QUIET\fP Added in version 3.1. .sp If this variable evaluates to a boolean true value, all status messages associated with the check will be suppressed. .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_TRY_COMPILE_TARGET_TYPE\fP \%<#\:variable:CMAKE_TRY_COMPILE_TARGET_TYPE> Internally, the \fBtry_compile()\fP \%<#\:command:try_compile> command is used to perform the check, and this variable controls the type of target it creates. If this variable is set to \fBEXECUTABLE\fP (the default), the check compiles and links the test source code as an executable program. If set to \fBSTATIC_LIBRARY\fP, the test source code is compiled but not linked. .UNINDENT .UNINDENT .SS Examples .sp The following example demonstrates how to check whether the C++ compiler supports a specific language feature. In this case, the check verifies if the compiler supports \fBC++11\fP lambda expressions. The result is stored in the internal cache variable \fBHAVE_CXX11_LAMBDAS\fP: .INDENT 0.0 .INDENT 3.5 .sp .EX include(CheckCXXSourceCompiles) check_cxx_source_compiles(\(dq int main() { auto lambda = []() { return 42; }; return lambda(); } \(dq HAVE_CXX11_LAMBDAS) .EE .UNINDENT .UNINDENT .SS See Also .INDENT 0.0 .IP \(bu 2 The \fBCheckSourceCompiles\fP \%<#\:module:CheckSourceCompiles> module for a more general command to check whether source can be built. .IP \(bu 2 The \fBCheckSourceRuns\fP \%<#\:module:CheckSourceRuns> module to check whether source can be built and run. .UNINDENT .SS CheckCXXSourceRuns .sp This module provides a command to check whether a C++ source can be built and run. .sp Load this module in a CMake project with: .INDENT 0.0 .INDENT 3.5 .sp .EX include(CheckCXXSourceRuns) .EE .UNINDENT .UNINDENT .SS Commands .sp This module provides the following command: .INDENT 0.0 .TP .B check_cxx_source_runs Checks once whether the given C++ source code compiles and links into an executable that can subsequently be run: .INDENT 7.0 .INDENT 3.5 .sp .EX check_cxx_source_runs( ) .EE .UNINDENT .UNINDENT .sp The C++ source supplied in \fB\fP must contain at least a \fBmain()\fP function. The result of the check is stored in the internal cache variable specified by \fB\fP\&. If the code builds and runs with exit code \fB0\fP, success is indicated by a boolean true value. Failure to build or run is indicated by a boolean false value, such as an empty string or an error message. .sp Variables Affecting the Check .sp The following variables may be set before calling this command to modify the way the check is run: .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_FLAGS\fP A space\-separated string of additional flags to pass to the compiler. A semicolon\-separated list \%<#\:cmake-language-lists> will not work. The contents of \fBCMAKE__FLAGS\fP \%<#\:variable:CMAKE__FLAGS> and its associated configuration\-specific \fBCMAKE__FLAGS_\fP \%<#\:variable:CMAKE__FLAGS_> variables are automatically prepended to the compiler command before the contents of this variable. .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_DEFINITIONS\fP A semicolon\-separated list \%<#\:cmake-language-lists> of compiler definitions, each of the form \fB\-DFOO\fP or \fB\-DFOO=bar\fP\&. A definition for the name specified by the result variable argument of the check command is also added automatically. .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_INCLUDES\fP A semicolon\-separated list \%<#\:cmake-language-lists> of header search paths to pass to the compiler. These will be the only header search paths used; the contents of the \fBINCLUDE_DIRECTORIES\fP \%<#\:prop_dir:INCLUDE_DIRECTORIES> directory property will be ignored. .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_LINK_OPTIONS\fP Added in version 3.14. .sp A semicolon\-separated list \%<#\:cmake-language-lists> of options to add to the link command (see \fBtry_compile()\fP \%<#\:command:try_compile> for further details). .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_LIBRARIES\fP A semicolon\-separated list \%<#\:cmake-language-lists> of libraries to add to the link command. These can be the names of system libraries, or they can be Imported Targets \%<#\:imported-targets> (see \fBtry_compile()\fP \%<#\:command:try_compile> for further details). .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_LINK_DIRECTORIES\fP Added in version 3.31. .sp A semicolon\-separated list \%<#\:cmake-language-lists> of library search paths to pass to the linker (see \fBtry_compile()\fP \%<#\:command:try_compile> for further details). .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_QUIET\fP Added in version 3.1. .sp If this variable evaluates to a boolean true value, all status messages associated with the check will be suppressed. .UNINDENT .UNINDENT .SS Examples .sp The following example demonstrates how to check whether the C++ standard library is functional and \fBstd::vector\fP works at runtime. If the source compiles, links, and runs successfully, internal cache variable \fBHAVE_WORKING_STD_VECTOR\fP will be set to boolean true value. Code is supplied using Bracket Argument \%<#\:bracket-argument> for easier embedded quotes handling: .INDENT 0.0 .INDENT 3.5 .sp .EX include(CheckCXXSourceRuns) check_cxx_source_runs([[ #include #include int main() { std::vector v = {1, 2, 3}; if (v.size() != 3) return 1; std::cout << \(dqVector works correctly.\(dq << std::endl; return 0; } ]] HAVE_WORKING_STD_VECTOR) .EE .UNINDENT .UNINDENT .SS See Also .INDENT 0.0 .IP \(bu 2 The \fBCheckSourceRuns\fP \%<#\:module:CheckSourceRuns> module for a more general command syntax. .IP \(bu 2 The \fBCheckSourceCompiles\fP \%<#\:module:CheckSourceCompiles> module to check whether a source code can be built. .UNINDENT .SS CheckCXXSymbolExists .sp This module provides a command to check whether a C++ symbol exists. .sp Load this module in a CMake project with: .INDENT 0.0 .INDENT 3.5 .sp .EX include(CheckCXXSymbolExists) .EE .UNINDENT .UNINDENT .SS Commands .sp This module provides the following command: .INDENT 0.0 .TP .B check_cxx_symbol_exists Checks once whether a symbol exists as a function, variable, or preprocessor macro in C++: .INDENT 7.0 .INDENT 3.5 .sp .EX check_cxx_symbol_exists( ) .EE .UNINDENT .UNINDENT .sp This command checks whether the \fB\fP is available after including the specified header file(s) \fB\fP, and stores the result in the internal cache variable \fB\fP\&. Multiple header files can be specified in one argument as a string using a semicolon\-separated list \%<#\:cmake-language-lists>\&. .sp If the header files define the symbol as a macro, it is considered available and assumed to work. If the symbol is declared as a function or variable, the check also ensures that it links successfully (i.e., the symbol must exist in a linked library or object file). .sp Symbols that are types, enum values, or C++ templates are not recognized. For those, consider using the \fBCheckTypeSize\fP \%<#\:module:CheckTypeSize> or \fBCheckSourceCompiles\fP \%<#\:module:CheckSourceCompiles> module instead. .sp This command is intended to check symbols as they appear in C++. For C symbols, use the \fBCheckSymbolExists\fP \%<#\:module:CheckSymbolExists> module instead. .sp \fBNote:\fP .INDENT 7.0 .INDENT 3.5 This command is unreliable for symbols that are (potentially) overloaded functions. 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 \fBCheckSourceCompiles\fP \%<#\:module:CheckSourceCompiles> module for checking any function symbol (unless it is certain the checked function is not overloaded on other systems or will not be so in the future). .UNINDENT .UNINDENT .sp Variables Affecting the Check .sp The following variables may be set before calling this command to modify the way the check is run: .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_FLAGS\fP A space\-separated string of additional flags to pass to the compiler. A semicolon\-separated list \%<#\:cmake-language-lists> will not work. The contents of \fBCMAKE__FLAGS\fP \%<#\:variable:CMAKE__FLAGS> and its associated configuration\-specific \fBCMAKE__FLAGS_\fP \%<#\:variable:CMAKE__FLAGS_> variables are automatically prepended to the compiler command before the contents of this variable. .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_DEFINITIONS\fP A semicolon\-separated list \%<#\:cmake-language-lists> of compiler definitions, each of the form \fB\-DFOO\fP or \fB\-DFOO=bar\fP\&. A definition for the name specified by the result variable argument of the check command is also added automatically. .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_INCLUDES\fP A semicolon\-separated list \%<#\:cmake-language-lists> of header search paths to pass to the compiler. These will be the only header search paths used; the contents of the \fBINCLUDE_DIRECTORIES\fP \%<#\:prop_dir:INCLUDE_DIRECTORIES> directory property will be ignored. .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_LINK_OPTIONS\fP Added in version 3.14. .sp A semicolon\-separated list \%<#\:cmake-language-lists> of options to add to the link command (see \fBtry_compile()\fP \%<#\:command:try_compile> for further details). .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_LIBRARIES\fP A semicolon\-separated list \%<#\:cmake-language-lists> of libraries to add to the link command. These can be the names of system libraries, or they can be Imported Targets \%<#\:imported-targets> (see \fBtry_compile()\fP \%<#\:command:try_compile> for further details). .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_LINK_DIRECTORIES\fP Added in version 3.31. .sp A semicolon\-separated list \%<#\:cmake-language-lists> of library search paths to pass to the linker (see \fBtry_compile()\fP \%<#\:command:try_compile> for further details). .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_QUIET\fP Added in version 3.1. .sp If this variable evaluates to a boolean true value, all status messages associated with the check will be suppressed. .UNINDENT .UNINDENT .SS Examples .sp The following example demonstrates how to check for the presence of a preprocessor macro \fBSEEK_SET\fP and the C++ function \fBstd::fopen()\fP from the \fB\fP header using this module: .INDENT 0.0 .INDENT 3.5 .sp .EX include(CheckCXXSymbolExists) # Check for macro SEEK_SET check_cxx_symbol_exists(SEEK_SET \(dqcstdio\(dq HAVE_SEEK_SET) # Check for function std::fopen check_cxx_symbol_exists(std::fopen \(dqcstdio\(dq HAVE_STD_FOPEN) .EE .UNINDENT .UNINDENT .SS See Also .INDENT 0.0 .IP \(bu 2 The \fBCheckSymbolExists\fP \%<#\:module:CheckSymbolExists> module to check whether a C symbol exists. .UNINDENT .SS CheckFortranCompilerFlag .sp Added in version 3.3. .sp This module provides a command to check whether the Fortran compiler supports a given flag. .sp Load this module in a CMake project with: .INDENT 0.0 .INDENT 3.5 .sp .EX include(CheckFortranCompilerFlag) .EE .UNINDENT .UNINDENT .SS Commands .sp This module provides the following command: .INDENT 0.0 .TP .B check_fortran_compiler_flag Checks once whether the Fortran compiler supports a given flag: .INDENT 7.0 .INDENT 3.5 .sp .EX check_fortran_compiler_flag( ) .EE .UNINDENT .UNINDENT .sp This command checks once that the \fB\fP is accepted by the Fortran compiler without producing a diagnostic message. Multiple flags can be specified in one argument as a string using a semicolon\-separated list \%<#\:cmake-language-lists>\&. .sp The result of the check is stored in the internal cache variable specified by \fB\fP, with boolean true for success and boolean false for failure. .sp A successful result only indicates that the compiler did not report an error when given the flag. Whether the flag has any effect, or the intended one, is outside the scope of this module. .sp \fBNote:\fP .INDENT 7.0 .INDENT 3.5 Since the underlying \fBtry_compile()\fP \%<#\:command:try_compile> command also uses flags from variables like \fBCMAKE__FLAGS\fP \%<#\:variable:CMAKE__FLAGS>, unknown or unsupported flags in those variables may result in a false negative for this check. .UNINDENT .UNINDENT .sp Variables Affecting the Check .sp The following variables may be set before calling this command to modify the way the check is run: .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_FLAGS\fP A space\-separated string of additional flags to pass to the compiler. A semicolon\-separated list \%<#\:cmake-language-lists> will not work. The contents of \fBCMAKE__FLAGS\fP \%<#\:variable:CMAKE__FLAGS> and its associated configuration\-specific \fBCMAKE__FLAGS_\fP \%<#\:variable:CMAKE__FLAGS_> variables are automatically prepended to the compiler command before the contents of this variable. .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_DEFINITIONS\fP A semicolon\-separated list \%<#\:cmake-language-lists> of compiler definitions, each of the form \fB\-DFOO\fP or \fB\-DFOO=bar\fP\&. A definition for the name specified by the result variable argument of the check command is also added automatically. .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_INCLUDES\fP A semicolon\-separated list \%<#\:cmake-language-lists> of header search paths to pass to the compiler. These will be the only header search paths used; the contents of the \fBINCLUDE_DIRECTORIES\fP \%<#\:prop_dir:INCLUDE_DIRECTORIES> directory property will be ignored. .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_LINK_OPTIONS\fP Added in version 3.14. .sp A semicolon\-separated list \%<#\:cmake-language-lists> of options to add to the link command (see \fBtry_compile()\fP \%<#\:command:try_compile> for further details). .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_LIBRARIES\fP A semicolon\-separated list \%<#\:cmake-language-lists> of libraries to add to the link command. These can be the names of system libraries, or they can be Imported Targets \%<#\:imported-targets> (see \fBtry_compile()\fP \%<#\:command:try_compile> for further details). .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_LINK_DIRECTORIES\fP Added in version 3.31. .sp A semicolon\-separated list \%<#\:cmake-language-lists> of library search paths to pass to the linker (see \fBtry_compile()\fP \%<#\:command:try_compile> for further details). .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_QUIET\fP Added in version 3.1. .sp If this variable evaluates to a boolean true value, all status messages associated with the check will be suppressed. .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_TRY_COMPILE_TARGET_TYPE\fP \%<#\:variable:CMAKE_TRY_COMPILE_TARGET_TYPE> Internally, the \fBtry_compile()\fP \%<#\:command:try_compile> command is used to perform the check, and this variable controls the type of target it creates. If this variable is set to \fBEXECUTABLE\fP (the default), the check compiles and links the test source code as an executable program. If set to \fBSTATIC_LIBRARY\fP, the test source code is compiled but not linked. .UNINDENT .UNINDENT .SS Examples .sp The following example demonstrates how to use this module to check the Fortran compiler flag \fB\-fallow\-argument\-mismatch\fP\&. The result of the check is stored in the internal cache variable \fBHAVE_FORTRAN_FLAG\fP, and the flag is conditionally enabled using the \fBtarget_compile_options()\fP \%<#\:command:target_compile_options> command. The \fB$\fP \%<#\:genex:COMPILE_LANGUAGE:languages> generator expression ensures that the flag is added only to \fBFortran\fP source files. .INDENT 0.0 .INDENT 3.5 .sp .EX include(CheckFortranCompilerFlag) check_fortran_compiler_flag(\-fallow\-argument\-mismatch HAVE_FORTRAN_FLAG) if(HAVE_FORTRAN_FLAG) target_compile_options( example PRIVATE $<$:\-fallow\-argument\-mismatch> ) endif() .EE .UNINDENT .UNINDENT .SS See Also .INDENT 0.0 .IP \(bu 2 The \fBCheckCompilerFlag\fP \%<#\:module:CheckCompilerFlag> module for a more general command to check whether a compiler flag is supported. .UNINDENT .SS CheckFortranFunctionExists .sp This module provides a command to check whether a Fortran function exists. .sp Load this module in a CMake project with: .INDENT 0.0 .INDENT 3.5 .sp .EX include(CheckFortranFunctionExists) .EE .UNINDENT .UNINDENT .SS Commands .sp This module provides the following command: .INDENT 0.0 .TP .B check_fortran_function_exists Checks once whether a Fortran function exists: .INDENT 7.0 .INDENT 3.5 .sp .EX check_fortran_function_exists( ) .EE .UNINDENT .UNINDENT .INDENT 7.0 .TP .B \fB\fP The name of the Fortran function. .TP .B \fB\fP The name of the variable in which to store the check result. This variable will be created as an internal cache variable. .UNINDENT .sp \fBNote:\fP .INDENT 7.0 .INDENT 3.5 This command does not detect functions provided by Fortran modules. In general, it is recommended to use \fBCheckSourceCompiles\fP \%<#\:module:CheckSourceCompiles> instead to determine whether a Fortran function or subroutine is available. .UNINDENT .UNINDENT .sp Variables Affecting the Check .sp The following variables may be set before calling this command to modify the way the check is run: .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_LINK_OPTIONS\fP Added in version 3.14. .sp A semicolon\-separated list \%<#\:cmake-language-lists> of options to add to the link command (see \fBtry_compile()\fP \%<#\:command:try_compile> for further details). .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_LIBRARIES\fP A semicolon\-separated list \%<#\:cmake-language-lists> of libraries to add to the link command. These can be the names of system libraries, or they can be Imported Targets \%<#\:imported-targets> (see \fBtry_compile()\fP \%<#\:command:try_compile> for further details). .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_LINK_DIRECTORIES\fP Added in version 3.31. .sp A semicolon\-separated list \%<#\:cmake-language-lists> of library search paths to pass to the linker (see \fBtry_compile()\fP \%<#\:command:try_compile> for further details). .UNINDENT .UNINDENT .SS Examples .SS Example: Isolated Check With Linked Libraries .sp In the following example, this module is used in combination with the \fBCMakePushCheckState\fP \%<#\:module:CMakePushCheckState> module to temporarily modify the required linked libraries (via \fBCMAKE_REQUIRED_LIBRARIES\fP) and verify whether the Fortran function \fBdgesv\fP is available for linking. The result is stored in the internal cache variable \fBPROJECT_HAVE_DGESV\fP: .INDENT 0.0 .INDENT 3.5 .sp .EX include(CheckFortranFunctionExists) include(CMakePushCheckState) find_package(LAPACK) if(TARGET LAPACK::LAPACK) cmake_push_check_state(RESET) set(CMAKE_REQUIRED_LIBRARIES LAPACK::LAPACK) check_fortran_function_exists(dgesv PROJECT_HAVE_DGESV) cmake_pop_check_state() endif() .EE .UNINDENT .UNINDENT .SS See Also .INDENT 0.0 .IP \(bu 2 The \fBCheckFunctionExists\fP \%<#\:module:CheckFunctionExists> module to check whether a C function exists. .IP \(bu 2 The \fBCheckSourceCompiles\fP \%<#\:module:CheckSourceCompiles> module to check whether source code can be compiled. .UNINDENT .SS CheckFortranSourceCompiles .sp Added in version 3.1. .sp This module provides a command to check whether a Fortran source can be built. .sp Load this module in a CMake project with: .INDENT 0.0 .INDENT 3.5 .sp .EX include(CheckFortranSourceCompiles) .EE .UNINDENT .UNINDENT .SS Commands .sp This module provides the following command: .INDENT 0.0 .TP .B check_fortran_source_compiles Checks once whether the given Fortran source code can be built: .INDENT 7.0 .INDENT 3.5 .sp .EX check_fortran_source_compiles( [FAIL_REGEX ...] [SRC_EXT ] ) .EE .UNINDENT .UNINDENT .sp This command checks once that the source supplied in \fB\fP can be compiled (and linked into an executable). The result of the check is stored in the internal cache variable specified by \fB\fP\&. .sp The arguments are: .INDENT 7.0 .TP .B \fB\fP Fortran source code to check. This must be an entire program, as written in a file containing the body block. All symbols used in the source code are expected to be declared as usual in their corresponding headers. .TP .B \fB\fP Variable name of an internal cache variable to store the result of the check, with boolean true for success and boolean false for failure. .TP .B \fBFAIL_REGEX ...\fP If this option is provided with one or more regular expressions, then failure is determined by checking if anything in the compiler output matches any of the specified regular expressions. .TP .B \fBSRC_EXT \fP Added in version 3.7. .sp By default, the test source file used for the check will be given a \fB\&.F\fP file extension. This option can be used to override this with \fB\&.\fP instead \- \fB\&.F90\fP is a typical choice. .UNINDENT .sp Variables Affecting the Check .sp The following variables may be set before calling this command to modify the way the check is run: .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_FLAGS\fP A space\-separated string of additional flags to pass to the compiler. A semicolon\-separated list \%<#\:cmake-language-lists> will not work. The contents of \fBCMAKE__FLAGS\fP \%<#\:variable:CMAKE__FLAGS> and its associated configuration\-specific \fBCMAKE__FLAGS_\fP \%<#\:variable:CMAKE__FLAGS_> variables are automatically prepended to the compiler command before the contents of this variable. .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_DEFINITIONS\fP A semicolon\-separated list \%<#\:cmake-language-lists> of compiler definitions, each of the form \fB\-DFOO\fP or \fB\-DFOO=bar\fP\&. A definition for the name specified by the result variable argument of the check command is also added automatically. .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_INCLUDES\fP A semicolon\-separated list \%<#\:cmake-language-lists> of header search paths to pass to the compiler. These will be the only header search paths used; the contents of the \fBINCLUDE_DIRECTORIES\fP \%<#\:prop_dir:INCLUDE_DIRECTORIES> directory property will be ignored. .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_LINK_OPTIONS\fP Added in version 3.14. .sp A semicolon\-separated list \%<#\:cmake-language-lists> of options to add to the link command (see \fBtry_compile()\fP \%<#\:command:try_compile> for further details). .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_LIBRARIES\fP A semicolon\-separated list \%<#\:cmake-language-lists> of libraries to add to the link command. These can be the names of system libraries, or they can be Imported Targets \%<#\:imported-targets> (see \fBtry_compile()\fP \%<#\:command:try_compile> for further details). .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_LINK_DIRECTORIES\fP Added in version 3.31. .sp A semicolon\-separated list \%<#\:cmake-language-lists> of library search paths to pass to the linker (see \fBtry_compile()\fP \%<#\:command:try_compile> for further details). .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_QUIET\fP Added in version 3.1. .sp If this variable evaluates to a boolean true value, all status messages associated with the check will be suppressed. .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_TRY_COMPILE_TARGET_TYPE\fP \%<#\:variable:CMAKE_TRY_COMPILE_TARGET_TYPE> Internally, the \fBtry_compile()\fP \%<#\:command:try_compile> command is used to perform the check, and this variable controls the type of target it creates. If this variable is set to \fBEXECUTABLE\fP (the default), the check compiles and links the test source code as an executable program. If set to \fBSTATIC_LIBRARY\fP, the test source code is compiled but not linked. .UNINDENT .UNINDENT .SS Examples .sp Checking whether the Fortran compiler supports the \fBpure\fP procedure attribute: .INDENT 0.0 .INDENT 3.5 .sp .EX include(CheckFortranSourceCompiles) check_fortran_source_compiles(\(dq pure subroutine foo() end subroutine program test call foo() end \(dq HAVE_PURE SRC_EXT \(dqF90\(dq) .EE .UNINDENT .UNINDENT .SS See Also .INDENT 0.0 .IP \(bu 2 The \fBCheckSourceCompiles\fP \%<#\:module:CheckSourceCompiles> module for a more general command to check whether source can be built. .IP \(bu 2 The \fBCheckSourceRuns\fP \%<#\:module:CheckSourceRuns> module to check whether source can be built and run. .UNINDENT .SS CheckFortranSourceRuns .sp Added in version 3.14. .sp This module provides a command to check whether a Fortran source can be built and run. .sp Load this module in a CMake project with: .INDENT 0.0 .INDENT 3.5 .sp .EX include(CheckFortranSourceRuns) .EE .UNINDENT .UNINDENT .SS Commands .sp This module provides the following command: .INDENT 0.0 .TP .B check_fortran_source_runs Checks once whether the given Fortran source compiles and links into an executable that can subsequently be run. .INDENT 7.0 .INDENT 3.5 .sp .EX check_fortran_source_runs( [SRC_EXT ]) .EE .UNINDENT .UNINDENT .sp The Fortran source supplied in \fB\fP must contain a Fortran \fBprogram\fP unit. The result of the check is stored in the internal cache variable specified by \fB\fP\&. If the code builds and runs with exit code \fB0\fP, success is indicated by a boolean true value. Failure to build or run is indicated by a boolean false value, such as an empty string or an error message. .sp The options are: .INDENT 7.0 .TP .B \fBSRC_EXT \fP By default, the internal test source file used for the check will be given a \fB\&.F90\fP file extension. This option can be used to change the extension to \fB\&.\fP instead. .UNINDENT .sp Variables Affecting the Check .sp The following variables may be set before calling this command to modify the way the check is run: .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_FLAGS\fP A space\-separated string of additional flags to pass to the compiler. A semicolon\-separated list \%<#\:cmake-language-lists> will not work. The contents of \fBCMAKE__FLAGS\fP \%<#\:variable:CMAKE__FLAGS> and its associated configuration\-specific \fBCMAKE__FLAGS_\fP \%<#\:variable:CMAKE__FLAGS_> variables are automatically prepended to the compiler command before the contents of this variable. .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_DEFINITIONS\fP A semicolon\-separated list \%<#\:cmake-language-lists> of compiler definitions, each of the form \fB\-DFOO\fP or \fB\-DFOO=bar\fP\&. A definition for the name specified by the result variable argument of the check command is also added automatically. .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_INCLUDES\fP A semicolon\-separated list \%<#\:cmake-language-lists> of header search paths to pass to the compiler. These will be the only header search paths used; the contents of the \fBINCLUDE_DIRECTORIES\fP \%<#\:prop_dir:INCLUDE_DIRECTORIES> directory property will be ignored. .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_LINK_OPTIONS\fP Added in version 3.14. .sp A semicolon\-separated list \%<#\:cmake-language-lists> of options to add to the link command (see \fBtry_compile()\fP \%<#\:command:try_compile> for further details). .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_LIBRARIES\fP A semicolon\-separated list \%<#\:cmake-language-lists> of libraries to add to the link command. These can be the names of system libraries, or they can be Imported Targets \%<#\:imported-targets> (see \fBtry_compile()\fP \%<#\:command:try_compile> for further details). .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_LINK_DIRECTORIES\fP Added in version 3.31. .sp A semicolon\-separated list \%<#\:cmake-language-lists> of library search paths to pass to the linker (see \fBtry_compile()\fP \%<#\:command:try_compile> for further details). .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_QUIET\fP Added in version 3.1. .sp If this variable evaluates to a boolean true value, all status messages associated with the check will be suppressed. .UNINDENT .UNINDENT .SS Examples .sp The following example shows how to use this module to check whether a Fortran source code runs and store the result of the check in an internal cache variable \fBHAVE_COARRAY\fP: .INDENT 0.0 .INDENT 3.5 .sp .EX include(CheckFortranSourceRuns) check_fortran_source_runs([[ program test real :: x[*] call co_sum(x) end program ]] HAVE_COARRAY) .EE .UNINDENT .UNINDENT .SS See Also .INDENT 0.0 .IP \(bu 2 The \fBCheckSourceRuns\fP \%<#\:module:CheckSourceRuns> module for a more general command syntax. .IP \(bu 2 The \fBCheckSourceCompiles\fP \%<#\:module:CheckSourceCompiles> module to check whether a source code can be built. .UNINDENT .SS CheckFunctionExists .sp This module provides a command to check whether a C function exists. .sp Load this module in a CMake project with: .INDENT 0.0 .INDENT 3.5 .sp .EX include(CheckFunctionExists) .EE .UNINDENT .UNINDENT .SS Commands .sp This module provides the following command: .INDENT 0.0 .TP .B check_function_exists Checks once whether a C function can be linked from system libraries: .INDENT 7.0 .INDENT 3.5 .sp .EX check_function_exists( ) .EE .UNINDENT .UNINDENT .sp This command checks whether the \fB\fP is provided by libraries on the system, and stores the result in an internal cache variable \fB\fP\&. .sp \fBNote:\fP .INDENT 7.0 .INDENT 3.5 Prefer using \fBCheckSymbolExists\fP \%<#\:module:CheckSymbolExists> or \fBCheckSourceCompiles\fP \%<#\:module:CheckSourceCompiles> instead of this command, for the following reasons: .INDENT 0.0 .IP \(bu 2 \fBcheck_function_exists()\fP can\(aqt detect functions that are inlined in headers or defined as preprocessor macros. .IP \(bu 2 \fBcheck_function_exists()\fP can\(aqt detect anything in the 32\-bit versions of the Win32 API, because of a mismatch in calling conventions. .IP \(bu 2 \fBcheck_function_exists()\fP only verifies linking, it does not verify that the function is declared in system headers. .UNINDENT .UNINDENT .UNINDENT .sp Variables Affecting the Check .sp The following variables may be set before calling this command to modify the way the check is run: .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_FLAGS\fP A space\-separated string of additional flags to pass to the compiler. A semicolon\-separated list \%<#\:cmake-language-lists> will not work. The contents of \fBCMAKE__FLAGS\fP \%<#\:variable:CMAKE__FLAGS> and its associated configuration\-specific \fBCMAKE__FLAGS_\fP \%<#\:variable:CMAKE__FLAGS_> variables are automatically prepended to the compiler command before the contents of this variable. .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_DEFINITIONS\fP A semicolon\-separated list \%<#\:cmake-language-lists> of compiler definitions, each of the form \fB\-DFOO\fP or \fB\-DFOO=bar\fP\&. A definition for the name specified by the result variable argument of the check command is also added automatically. .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_INCLUDES\fP A semicolon\-separated list \%<#\:cmake-language-lists> of header search paths to pass to the compiler. These will be the only header search paths used; the contents of the \fBINCLUDE_DIRECTORIES\fP \%<#\:prop_dir:INCLUDE_DIRECTORIES> directory property will be ignored. .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_LINK_OPTIONS\fP Added in version 3.14. .sp A semicolon\-separated list \%<#\:cmake-language-lists> of options to add to the link command (see \fBtry_compile()\fP \%<#\:command:try_compile> for further details). .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_LIBRARIES\fP A semicolon\-separated list \%<#\:cmake-language-lists> of libraries to add to the link command. These can be the names of system libraries, or they can be Imported Targets \%<#\:imported-targets> (see \fBtry_compile()\fP \%<#\:command:try_compile> for further details). .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_LINK_DIRECTORIES\fP Added in version 3.31. .sp A semicolon\-separated list \%<#\:cmake-language-lists> of library search paths to pass to the linker (see \fBtry_compile()\fP \%<#\:command:try_compile> for further details). .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_QUIET\fP Added in version 3.1. .sp If this variable evaluates to a boolean true value, all status messages associated with the check will be suppressed. .UNINDENT .UNINDENT .SS Examples .SS Example: Basic Usage .sp In the following example, a check is performed to determine whether the linker sees the C function \fBfopen()\fP, and the result is stored in the \fBHAVE_FOPEN\fP internal cache variable: .INDENT 0.0 .INDENT 3.5 .sp .EX include(CheckFunctionExists) check_function_exists(fopen HAVE_FOPEN) .EE .UNINDENT .UNINDENT .SS Example: Missing Declaration .sp As noted above, the \fBCheckSymbolExists\fP \%<#\:module:CheckSymbolExists> module is preferred for checking C functions, since it also verifies whether the function is declared or defined as a macro. In the following example, this module is used to check an edge case where a function may not be declared in system headers. For instance, on macOS, the \fBfdatasync()\fP function may be available in the C library, but its declaration is not provided in the \fBunistd.h\fP system header. .sp \fBCMakeLists.txt\fP .INDENT 0.0 .INDENT 3.5 .sp .EX include(CheckFunctionExists) include(CheckSymbolExists) check_symbol_exists(fdatasync \(dqunistd.h\(dq HAVE_FDATASYNC) # Check if fdatasync() is available in the C library. if(NOT HAVE_FDATASYNC) check_function_exists(fdatasync HAVE_FDATASYNC_WITHOUT_DECL) endif() .EE .UNINDENT .UNINDENT .sp In such a case, the project can provide its own declaration if missing: .sp \fBexample.c\fP .INDENT 0.0 .INDENT 3.5 .sp .EX #ifdef HAVE_FDATASYNC_WITHOUT_DECL extern int fdatasync(int); #endif .EE .UNINDENT .UNINDENT .SS See Also .INDENT 0.0 .IP \(bu 2 The \fBCheckSymbolExists\fP \%<#\:module:CheckSymbolExists> module to check whether a C symbol exists. .IP \(bu 2 The \fBCheckSourceCompiles\fP \%<#\:module:CheckSourceCompiles> module to check whether a source code can be compiled. .IP \(bu 2 The \fBCheckFortranFunctionExists\fP \%<#\:module:CheckFortranFunctionExists> module to check whether a Fortran function exists. .UNINDENT .SS CheckIncludeFile .sp This module provides a command to check C header file. .sp Load this module in a CMake project with: .INDENT 0.0 .INDENT 3.5 .sp .EX include(CheckIncludeFile) .EE .UNINDENT .UNINDENT .SS Commands .sp This module provides the following command: .INDENT 0.0 .TP .B check_include_file Checks once whether a header file exists and can be included in C code: .INDENT 7.0 .INDENT 3.5 .sp .EX check_include_file( []) .EE .UNINDENT .UNINDENT .sp The arguments are: .INDENT 7.0 .TP .B \fB\fP A header file to be checked. .TP .B \fB\fP The name of the variable to store the result of the check. This variable will be created as an internal cache variable. .TP .B \fB\fP (Optional) A semicolon\-separated list \%<#\:cmake-language-lists> of additional compilation flags to be added to the check. Alternatively, flags can be also specified with the \fBCMAKE_REQUIRED_FLAGS\fP variable below. .UNINDENT .sp Variables Affecting the Check .sp The following variables may be set before calling this command to modify the way the check is run: .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_FLAGS\fP A space\-separated string of additional flags to pass to the compiler. A semicolon\-separated list \%<#\:cmake-language-lists> will not work. The contents of \fBCMAKE__FLAGS\fP \%<#\:variable:CMAKE__FLAGS> and its associated configuration\-specific \fBCMAKE__FLAGS_\fP \%<#\:variable:CMAKE__FLAGS_> variables are automatically prepended to the compiler command before the contents of this variable. .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_DEFINITIONS\fP A semicolon\-separated list \%<#\:cmake-language-lists> of compiler definitions, each of the form \fB\-DFOO\fP or \fB\-DFOO=bar\fP\&. A definition for the name specified by the result variable argument of the check command is also added automatically. .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_INCLUDES\fP A semicolon\-separated list \%<#\:cmake-language-lists> of header search paths to pass to the compiler. These will be the only header search paths used; the contents of the \fBINCLUDE_DIRECTORIES\fP \%<#\:prop_dir:INCLUDE_DIRECTORIES> directory property will be ignored. .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_LINK_OPTIONS\fP Added in version 3.14. .sp A semicolon\-separated list \%<#\:cmake-language-lists> of options to add to the link command (see \fBtry_compile()\fP \%<#\:command:try_compile> for further details). .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_LIBRARIES\fP A semicolon\-separated list \%<#\:cmake-language-lists> of libraries to add to the link command. These can be the names of system libraries, or they can be Imported Targets \%<#\:imported-targets> (see \fBtry_compile()\fP \%<#\:command:try_compile> for further details). .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_LINK_DIRECTORIES\fP Added in version 3.31. .sp A semicolon\-separated list \%<#\:cmake-language-lists> of library search paths to pass to the linker (see \fBtry_compile()\fP \%<#\:command:try_compile> for further details). .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_QUIET\fP Added in version 3.1. .sp If this variable evaluates to a boolean true value, all status messages associated with the check will be suppressed. .UNINDENT .sp Added in version 3.12: The \fBCMAKE_REQUIRED_LIBRARIES\fP variable, if policy \fBCMP0075\fP \%<#\:policy:CMP0075> is set to \fBNEW\fP\&. .UNINDENT .SS Examples .SS Example: Checking C Header .sp Checking whether the C header \fB\fP exists and storing the check result in the \fBHAVE_UNISTD_H\fP cache variable: .INDENT 0.0 .INDENT 3.5 .sp .EX include(CheckIncludeFile) check_include_file(unistd.h HAVE_UNISTD_H) .EE .UNINDENT .UNINDENT .SS Example: Isolated Check .sp In the following example, this module is used in combination with the \fBCMakePushCheckState\fP \%<#\:module:CMakePushCheckState> module to temporarily modify the required compile definitions (via \fBCMAKE_REQUIRED_DEFINITIONS\fP) and verify whether the C header \fB\fP is available. The result is stored in the internal cache variable \fBHAVE_UCONTEXT_H\fP\&. .sp For example, on macOS, the \fBucontext\fP API is deprecated, and headers may be hidden unless certain feature macros are defined. In particular, defining \fB_XOPEN_SOURCE\fP (without a value) can expose the necessary symbols without enabling broader POSIX or SUS (Single Unix Specification) features (values 500 or greater). .INDENT 0.0 .INDENT 3.5 .sp .EX include(CheckIncludeFile) include(CMakePushCheckState) cmake_push_check_state(RESET) if(CMAKE_SYSTEM_NAME STREQUAL \(dqDarwin\(dq) set(CMAKE_REQUIRED_DEFINITIONS \-D_XOPEN_SOURCE) endif() check_include_file(ucontext.h HAVE_UCONTEXT_H) cmake_pop_check_state() .EE .UNINDENT .UNINDENT .SS See Also .INDENT 0.0 .IP \(bu 2 The \fBCheckIncludeFileCXX\fP \%<#\:module:CheckIncludeFileCXX> module to check for single C++ header. .IP \(bu 2 The \fBCheckIncludeFiles\fP \%<#\:module:CheckIncludeFiles> module to check for one or more C or C++ headers at once. .UNINDENT .SS CheckIncludeFileCXX .sp This module provides a command to check a C++ header file. .sp Load this module in a CMake project with: .INDENT 0.0 .INDENT 3.5 .sp .EX include(CheckIncludeFileCXX) .EE .UNINDENT .UNINDENT .SS Commands .sp This module provides the following command: .INDENT 0.0 .TP .B check_include_file_cxx Checks once whether a header file exists and can be included in C++ code: .INDENT 7.0 .INDENT 3.5 .sp .EX check_include_file_cxx( []) .EE .UNINDENT .UNINDENT .sp The arguments are: .INDENT 7.0 .TP .B \fB\fP A header file to be checked. .TP .B \fB\fP The name of the variable to store the result of the check. This variable will be created as an internal cache variable. .TP .B \fB\fP (Optional) A semicolon\-separated list \%<#\:cmake-language-lists> of additional compilation flags to be added to the check. Alternatively, flags can be also specified with the \fBCMAKE_REQUIRED_FLAGS\fP variable below. .UNINDENT .sp Variables Affecting the Check .sp The following variables may be set before calling this command to modify the way the check is run: .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_FLAGS\fP A space\-separated string of additional flags to pass to the compiler. A semicolon\-separated list \%<#\:cmake-language-lists> will not work. The contents of \fBCMAKE__FLAGS\fP \%<#\:variable:CMAKE__FLAGS> and its associated configuration\-specific \fBCMAKE__FLAGS_\fP \%<#\:variable:CMAKE__FLAGS_> variables are automatically prepended to the compiler command before the contents of this variable. .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_DEFINITIONS\fP A semicolon\-separated list \%<#\:cmake-language-lists> of compiler definitions, each of the form \fB\-DFOO\fP or \fB\-DFOO=bar\fP\&. A definition for the name specified by the result variable argument of the check command is also added automatically. .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_INCLUDES\fP A semicolon\-separated list \%<#\:cmake-language-lists> of header search paths to pass to the compiler. These will be the only header search paths used; the contents of the \fBINCLUDE_DIRECTORIES\fP \%<#\:prop_dir:INCLUDE_DIRECTORIES> directory property will be ignored. .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_LINK_OPTIONS\fP Added in version 3.14. .sp A semicolon\-separated list \%<#\:cmake-language-lists> of options to add to the link command (see \fBtry_compile()\fP \%<#\:command:try_compile> for further details). .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_LIBRARIES\fP A semicolon\-separated list \%<#\:cmake-language-lists> of libraries to add to the link command. These can be the names of system libraries, or they can be Imported Targets \%<#\:imported-targets> (see \fBtry_compile()\fP \%<#\:command:try_compile> for further details). .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_LINK_DIRECTORIES\fP Added in version 3.31. .sp A semicolon\-separated list \%<#\:cmake-language-lists> of library search paths to pass to the linker (see \fBtry_compile()\fP \%<#\:command:try_compile> for further details). .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_QUIET\fP Added in version 3.1. .sp If this variable evaluates to a boolean true value, all status messages associated with the check will be suppressed. .UNINDENT .sp Added in version 3.12: The \fBCMAKE_REQUIRED_LIBRARIES\fP variable, if policy \fBCMP0075\fP \%<#\:policy:CMP0075> is set to \fBNEW\fP\&. .UNINDENT .SS Examples .sp Checking whether the \fBC++23\fP header \fB\fP exists and storing the check result in the \fBHAVE_STDFLOAT_HEADER\fP cache variable: .INDENT 0.0 .INDENT 3.5 .sp .EX include(CheckIncludeFileCXX) check_include_file_cxx(stdfloat HAVE_STDFLOAT_HEADER) .EE .UNINDENT .UNINDENT .SS See Also .INDENT 0.0 .IP \(bu 2 The \fBCheckIncludeFile\fP \%<#\:module:CheckIncludeFile> module to check for single C header. .IP \(bu 2 The \fBCheckIncludeFiles\fP \%<#\:module:CheckIncludeFiles> module to check for one or more C or C++ headers at once. .UNINDENT .SS CheckIncludeFiles .sp This module provides a command to check one or more C/C++ header files. .sp Load this module in a CMake project with: .INDENT 0.0 .INDENT 3.5 .sp .EX include(CheckIncludeFiles) .EE .UNINDENT .UNINDENT .SS Commands .sp This module provides the following command: .INDENT 0.0 .TP .B check_include_files Checks once whether one or more header files exist and can be included together in C or C++ code: .INDENT 7.0 .INDENT 3.5 .sp .EX check_include_files( [LANGUAGE ]) .EE .UNINDENT .UNINDENT .sp The arguments are: .INDENT 7.0 .TP .B \fB\fP A semicolon\-separated list \%<#\:cmake-language-lists> of header files to be checked. .TP .B \fB\fP The name of the variable to store the result of the check. This variable will be created as an internal cache variable. .TP .B \fBLANGUAGE \fP Added in version 3.11. .sp If set, the specified \fB\fP compiler will be used to perform the check. Acceptable values are \fBC\fP and \fBCXX\fP\&. If this option is not given, the C compiler will be used if enabled. If the C compiler is not enabled, the C++ compiler will be used if enabled. .UNINDENT .sp Variables Affecting the Check .sp The following variables may be set before calling this command to modify the way the check is run: .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_FLAGS\fP A space\-separated string of additional flags to pass to the compiler. A semicolon\-separated list \%<#\:cmake-language-lists> will not work. The contents of \fBCMAKE__FLAGS\fP \%<#\:variable:CMAKE__FLAGS> and its associated configuration\-specific \fBCMAKE__FLAGS_\fP \%<#\:variable:CMAKE__FLAGS_> variables are automatically prepended to the compiler command before the contents of this variable. .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_DEFINITIONS\fP A semicolon\-separated list \%<#\:cmake-language-lists> of compiler definitions, each of the form \fB\-DFOO\fP or \fB\-DFOO=bar\fP\&. A definition for the name specified by the result variable argument of the check command is also added automatically. .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_INCLUDES\fP A semicolon\-separated list \%<#\:cmake-language-lists> of header search paths to pass to the compiler. These will be the only header search paths used; the contents of the \fBINCLUDE_DIRECTORIES\fP \%<#\:prop_dir:INCLUDE_DIRECTORIES> directory property will be ignored. .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_LINK_OPTIONS\fP Added in version 3.14. .sp A semicolon\-separated list \%<#\:cmake-language-lists> of options to add to the link command (see \fBtry_compile()\fP \%<#\:command:try_compile> for further details). .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_LIBRARIES\fP A semicolon\-separated list \%<#\:cmake-language-lists> of libraries to add to the link command. These can be the names of system libraries, or they can be Imported Targets \%<#\:imported-targets> (see \fBtry_compile()\fP \%<#\:command:try_compile> for further details). .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_LINK_DIRECTORIES\fP Added in version 3.31. .sp A semicolon\-separated list \%<#\:cmake-language-lists> of library search paths to pass to the linker (see \fBtry_compile()\fP \%<#\:command:try_compile> for further details). .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_QUIET\fP Added in version 3.1. .sp If this variable evaluates to a boolean true value, all status messages associated with the check will be suppressed. .UNINDENT .sp Added in version 3.12: The \fBCMAKE_REQUIRED_LIBRARIES\fP variable, if policy \fBCMP0075\fP \%<#\:policy:CMP0075> is set to \fBNEW\fP\&. .UNINDENT .SS Examples .sp Checking one or more C headers and storing the check result in cache variables: .INDENT 0.0 .INDENT 3.5 .sp .EX include(CheckIncludeFiles) check_include_files(sys/socket.h HAVE_SYS_SOCKET_H) if(HAVE_SYS_SOCKET_H) # The header on Darwin and BSD\-like systems is not self\-contained # and also requires check_include_files(\(dqsys/socket.h;net/if.h\(dq HAVE_NET_IF_H) else() check_include_files(net/if.h HAVE_NET_IF_H) endif() .EE .UNINDENT .UNINDENT .sp The \fBLANGUAGE\fP option can be used to specify which compiler to use. For example, checking multiple \fBC++\fP headers, when both \fBC\fP and \fBCXX\fP languages are enabled in the project: .INDENT 0.0 .INDENT 3.5 .sp .EX include(CheckIncludeFiles) check_include_files(\(dqheader_1.hpp;header_2.hpp\(dq HAVE_HEADERS LANGUAGE CXX) .EE .UNINDENT .UNINDENT .SS See Also .INDENT 0.0 .IP \(bu 2 The \fBCheckIncludeFile\fP \%<#\:module:CheckIncludeFile> module to check for a single C header. .IP \(bu 2 The \fBCheckIncludeFileCXX\fP \%<#\:module:CheckIncludeFileCXX> module to check for a single C++ header. .UNINDENT .SS CheckIPOSupported .sp Added in version 3.9. .sp This module provides a command to check whether the compiler supports interprocedural optimization (IPO/LTO). .sp Load this module in a CMake project with: .INDENT 0.0 .INDENT 3.5 .sp .EX include(CheckIPOSupported) .EE .UNINDENT .UNINDENT .sp Interprocedural optimization is a compiler technique that performs optimizations across translation units (i.e., across source files), allowing the compiler to analyze and optimize the entire program as a whole rather than file\-by\-file. This can improve performance by enabling more aggressive inlining and dead code elimination. When these optimizations are applied at link time, the process is typically referred to as link\-time optimization (LTO), which is a common form of IPO. .sp In CMake, interprocedural optimization can be enabled on a per\-target basis using the \fBINTERPROCEDURAL_OPTIMIZATION\fP \%<#\:prop_tgt:INTERPROCEDURAL_OPTIMIZATION> target property, or for all targets in the current scope using the \fBCMAKE_INTERPROCEDURAL_OPTIMIZATION\fP \%<#\:variable:CMAKE_INTERPROCEDURAL_OPTIMIZATION> variable. .sp Use this module before enabling the interprocedural optimization on targets to ensure the compiler supports IPO/LTO. .SS Commands .sp This module provides the following command: .INDENT 0.0 .TP .B check_ipo_supported Checks whether the compiler supports interprocedural optimization (IPO/LTO): .INDENT 7.0 .INDENT 3.5 .sp .EX check_ipo_supported( [RESULT ] [OUTPUT ] [LANGUAGES ...] ) .EE .UNINDENT .UNINDENT .sp Options are: .INDENT 7.0 .TP .B \fBRESULT \fP Set \fB\fP variable to \fBYES\fP if IPO is supported by the compiler and \fBNO\fP otherwise. If this option is not given then the command will issue a fatal error if IPO is not supported. .TP .B \fBOUTPUT \fP Set \fB\fP variable with details about any error. .TP .B \fBLANGUAGES ...\fP Specify languages whose compilers to check. .sp The following languages are supported: .INDENT 7.0 .IP \(bu 2 \fBC\fP .IP \(bu 2 \fBCXX\fP .IP \(bu 2 \fBCUDA\fP .sp Added in version 3.25. .IP \(bu 2 \fBFortran\fP .UNINDENT .sp If this option is not given, the default languages are picked from the current \fBENABLED_LANGUAGES\fP \%<#\:prop_gbl:ENABLED_LANGUAGES> global property. .UNINDENT .sp \fBNote:\fP .INDENT 7.0 .INDENT 3.5 To use \fBcheck_ipo_supported()\fP, policy \fBCMP0069\fP \%<#\:policy:CMP0069> must be set to \fBNEW\fP; otherwise, a fatal error will occur. .UNINDENT .UNINDENT .sp Added in version 3.13: Support for Visual Studio Generators \%<#\:visual-studio-generators>\&. .sp Added in version 3.24: The check uses the caller\(aqs \fBCMAKE__FLAGS\fP \%<#\:variable:CMAKE__FLAGS> and \fBCMAKE__FLAGS_\fP \%<#\:variable:CMAKE__FLAGS_> values. See policy \fBCMP0138\fP \%<#\:policy:CMP0138>\&. .UNINDENT .SS Examples .sp Checking whether the compiler supports IPO and emitting a fatal error if it is not supported: .INDENT 0.0 .INDENT 3.5 .sp .EX include(CheckIPOSupported) check_ipo_supported() # fatal error if IPO is not supported set_property(TARGET foo PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE) .EE .UNINDENT .UNINDENT .sp The following example demonstrates how to use this module to enable IPO for the target only when supported by the compiler and to issue a warning if it is not. Additionally, projects may want to provide a configuration option to control when IPO is enabled. For example: .INDENT 0.0 .INDENT 3.5 .sp .EX option(FOO_ENABLE_IPO \(dqEnable IPO/LTO\(dq) if(FOO_ENABLE_IPO) include(CheckIPOSupported) check_ipo_supported(RESULT result OUTPUT output) if(result) set_property(TARGET foo PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE) else() message(WARNING \(dqIPO is not supported: ${output}\(dq) endif() endif() .EE .UNINDENT .UNINDENT .SS CheckLanguage .sp This module provides a command to check whether a language can be enabled using the \fBenable_language()\fP \%<#\:command:enable_language> or \fBproject()\fP \%<#\:command:project> commands. .sp Load this module in a CMake project with: .INDENT 0.0 .INDENT 3.5 .sp .EX include(CheckLanguage) .EE .UNINDENT .UNINDENT .sp This module is useful when a project does not always require a specific language but may need to enable it for certain parts. .SS Commands .sp This module provides the following command: .INDENT 0.0 .TP .B check_language Checks whether a language can be enabled in a CMake project: .INDENT 7.0 .INDENT 3.5 .sp .EX check_language() .EE .UNINDENT .UNINDENT .sp This command attempts to enable the language \fB\fP in a test project and records the results in the following cache variables: .INDENT 7.0 .TP .B \fBCMAKE__COMPILER\fP \%<#\:variable:CMAKE__COMPILER> 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 \fBNOTFOUND\fP\&. .sp If this variable is already set, either explicitly or cached by a previous call, the check is skipped. .TP .B \fBCMAKE__HOST_COMPILER\fP \%<#\:variable:CMAKE__HOST_COMPILER> This variable is set when \fB\fP is \fBCUDA\fP or \fBHIP\fP\&. .sp 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. .sp If this variable is already set, its value is preserved only if \fBCMAKE__COMPILER\fP \%<#\:variable:CMAKE__COMPILER> is also set. Otherwise, the check runs and overwrites \fBCMAKE__HOST_COMPILER\fP \%<#\:variable:CMAKE__HOST_COMPILER> with a new result. Note that \fBCMAKE__HOST_COMPILER\fP \%<#\:variable:CMAKE__HOST_COMPILER> documents it should not be set without also setting \fBCMAKE__COMPILER\fP \%<#\:variable:CMAKE__COMPILER> to a NVCC compiler. .TP .B \fBCMAKE__PLATFORM\fP \%<#\:variable:CMAKE_HIP_PLATFORM> This variable is set to the detected GPU platform when \fB\fP is \fBHIP\fP\&. .sp If this variable is already set, its value is always preserved. Only compatible values will be considered for \fBCMAKE__COMPILER\fP \%<#\:variable:CMAKE__COMPILER>\&. .UNINDENT .UNINDENT .SS Examples .sp The following example checks for the availability of the \fBFortran\fP language and enables it if possible: .INDENT 0.0 .INDENT 3.5 .sp .EX include(CheckLanguage) check_language(Fortran) if(CMAKE_Fortran_COMPILER) enable_language(Fortran) else() message(STATUS \(dqNo Fortran support\(dq) endif() .EE .UNINDENT .UNINDENT .SS CheckLibraryExists .sp This module provides a command to check whether a C library exists. .sp Load this module in a CMake project with: .INDENT 0.0 .INDENT 3.5 .sp .EX include(CheckLibraryExists) .EE .UNINDENT .UNINDENT .SS Commands .sp This module provides the following command: .INDENT 0.0 .TP .B check_library_exists Checks once whether a specified library exists and a given C function is available: .INDENT 7.0 .INDENT 3.5 .sp .EX check_library_exists( ) .EE .UNINDENT .UNINDENT .sp This command attempts to link a test executable that uses the specified C \fB\fP to verify that it is provided by either a system or user\-provided \fB\fP\&. .sp The arguments are: .INDENT 7.0 .TP .B \fB\fP The name of the library, a full path to a library file, or an Imported Target \%<#\:imported-targets>\&. .TP .B \fB\fP The name of a function that should be available in the system or user\-provided library \fB\fP\&. .TP .B \fB\fP The directory containing the library file. It is added to the link search path during the check. If this is an empty string, only the default library search paths are used. .TP .B \fB\fP The name of the variable in which to store the check result. This variable will be created as an internal cache variable. .UNINDENT .sp \fBNote:\fP .INDENT 7.0 .INDENT 3.5 This command is intended for performing basic sanity checks to verify that a library provides the expected functionality, or that the correct library is being located. However, it only verifies that a function symbol can be linked successfully \- it does not ensure that the function is declared in library headers, nor can it detect functions that are inlined or defined as preprocessor macros. For more robust detection of function availability, prefer using \fBCheckSymbolExists\fP \%<#\:module:CheckSymbolExists> or \fBCheckSourceCompiles\fP \%<#\:module:CheckSourceCompiles>\&. .UNINDENT .UNINDENT .sp Variables Affecting the Check .sp The following variables may be set before calling this command to modify the way the check is run: .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_FLAGS\fP A space\-separated string of additional flags to pass to the compiler. A semicolon\-separated list \%<#\:cmake-language-lists> will not work. The contents of \fBCMAKE__FLAGS\fP \%<#\:variable:CMAKE__FLAGS> and its associated configuration\-specific \fBCMAKE__FLAGS_\fP \%<#\:variable:CMAKE__FLAGS_> variables are automatically prepended to the compiler command before the contents of this variable. .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_DEFINITIONS\fP A semicolon\-separated list \%<#\:cmake-language-lists> of compiler definitions, each of the form \fB\-DFOO\fP or \fB\-DFOO=bar\fP\&. A definition for the name specified by the result variable argument of the check command is also added automatically. .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_LINK_OPTIONS\fP Added in version 3.14. .sp A semicolon\-separated list \%<#\:cmake-language-lists> of options to add to the link command (see \fBtry_compile()\fP \%<#\:command:try_compile> for further details). .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_LIBRARIES\fP A semicolon\-separated list \%<#\:cmake-language-lists> of libraries to add to the link command. These can be the names of system libraries, or they can be Imported Targets \%<#\:imported-targets> (see \fBtry_compile()\fP \%<#\:command:try_compile> for further details). .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_LINK_DIRECTORIES\fP Added in version 3.31. .sp A semicolon\-separated list \%<#\:cmake-language-lists> of library search paths to pass to the linker (see \fBtry_compile()\fP \%<#\:command:try_compile> for further details). .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_QUIET\fP Added in version 3.1. .sp If this variable evaluates to a boolean true value, all status messages associated with the check will be suppressed. .UNINDENT .UNINDENT .SS Examples .sp Checking if the \fBcurl\fP library exists in the default paths and has the \fBcurl_easy_perform()\fP function: .INDENT 0.0 .INDENT 3.5 .sp .EX include(CheckLibraryExists) check_library_exists(curl curl_easy_perform \(dq\(dq HAVE_LIBRARY_CURL) .EE .UNINDENT .UNINDENT .sp To check if library exists in specific non\-standard location and has a specified function: .INDENT 0.0 .INDENT 3.5 .sp .EX include(CheckLibraryExists) check_library_exists(curl curl_easy_perform \(dq/opt/curl/lib\(dq HAVE_LIBRARY_CURL) .EE .UNINDENT .UNINDENT .sp Also Imported Targets \%<#\:imported-targets> (for example, from the \fBfind_package()\fP call) can be used: .INDENT 0.0 .INDENT 3.5 .sp .EX find_package(CURL) # ... if(TARGET CURL::libcurl) include(CheckLibraryExists) check_library_exists(CURL::libcurl curl_easy_perform \(dq\(dq HAVE_LIBRARY_CURL) endif() .EE .UNINDENT .UNINDENT .SS See Also .INDENT 0.0 .IP \(bu 2 The \fBCheckSymbolExists\fP \%<#\:module:CheckSymbolExists> module to check whether a C symbol exists. .UNINDENT .SS CheckLinkerFlag .sp Added in version 3.18. .sp This module provides a command to check whether a given link flag is supported by the compiler. .sp Load this module in a CMake project with: .INDENT 0.0 .INDENT 3.5 .sp .EX include(CheckLinkerFlag) .EE .UNINDENT .UNINDENT .SS Commands .sp This module provides the following command: .INDENT 0.0 .TP .B check_linker_flag Checks once whether the compiler supports a given link flag: .INDENT 7.0 .INDENT 3.5 .sp .EX check_linker_flag( ) .EE .UNINDENT .UNINDENT .sp This command checks once whether the linker flag \fB\fP is accepted by the \fB\fP compiler without producing a diagnostic message. .sp The arguments are: .INDENT 7.0 .TP .B \fB\fP The language of the compiler used for the check. Supported languages are \fBC\fP, \fBCXX\fP, \fBCUDA\fP, \fBFortran\fP, \fBHIP\fP, \fBOBJC\fP, \fBOBJCXX\fP, and \fBSwift\fP\&. .sp Added in version 3.19: Support for \fBCUDA\fP language. .sp Added in version 3.21: Support for \fBHIP\fP language. .sp Added in version 3.26: Support for \fBSwift\fP language. .TP .B \fB\fP Linker flag(s) to check. Multiple flags can be specified in one argument as a string using a semicolon\-separated list \%<#\:cmake-language-lists>\&. .sp The underlying implementation uses the \fBLINK_OPTIONS\fP \%<#\:prop_tgt:LINK_OPTIONS> target property to test the specified flag. The \fBLINKER:\fP (and \fBSHELL:\fP) prefixes may be used, as described in the Handling Compiler Driver Differences section. .TP .B \fB\fP The name of the variable to store the check result. This variable will be created as an internal cache variable. .UNINDENT .sp This command temporarily sets the \fBCMAKE_REQUIRED_LINK_OPTIONS\fP variable and calls the \fBcheck_source_compiles()\fP \%<#\:command:check_source_compiles> command from the \fBCheckSourceCompiles\fP \%<#\:module:CheckSourceCompiles> module. .sp A successful result only indicates that the compiler did not report an error when given the link flag. Whether the flag has any effect, or the intended one, is outside the scope of this module. .sp \fBNote:\fP .INDENT 7.0 .INDENT 3.5 Since the underlying \fBtry_compile()\fP \%<#\:command:try_compile> command also uses flags from variables like \fBCMAKE__FLAGS\fP \%<#\:variable:CMAKE__FLAGS>, unknown or unsupported flags in those variables may result in a false negative for this check. .UNINDENT .UNINDENT .sp Variables Affecting the Check .sp The following variables may be set before calling this command to modify the way the check is run: .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_FLAGS\fP A space\-separated string of additional flags to pass to the compiler. A semicolon\-separated list \%<#\:cmake-language-lists> will not work. The contents of \fBCMAKE__FLAGS\fP \%<#\:variable:CMAKE__FLAGS> and its associated configuration\-specific \fBCMAKE__FLAGS_\fP \%<#\:variable:CMAKE__FLAGS_> variables are automatically prepended to the compiler command before the contents of this variable. .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_DEFINITIONS\fP A semicolon\-separated list \%<#\:cmake-language-lists> of compiler definitions, each of the form \fB\-DFOO\fP or \fB\-DFOO=bar\fP\&. A definition for the name specified by the result variable argument of the check command is also added automatically. .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_INCLUDES\fP A semicolon\-separated list \%<#\:cmake-language-lists> of header search paths to pass to the compiler. These will be the only header search paths used; the contents of the \fBINCLUDE_DIRECTORIES\fP \%<#\:prop_dir:INCLUDE_DIRECTORIES> directory property will be ignored. .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_LIBRARIES\fP A semicolon\-separated list \%<#\:cmake-language-lists> of libraries to add to the link command. These can be the names of system libraries, or they can be Imported Targets \%<#\:imported-targets> (see \fBtry_compile()\fP \%<#\:command:try_compile> for further details). .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_LINK_DIRECTORIES\fP Added in version 3.31. .sp A semicolon\-separated list \%<#\:cmake-language-lists> of library search paths to pass to the linker (see \fBtry_compile()\fP \%<#\:command:try_compile> for further details). .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_QUIET\fP Added in version 3.1. .sp If this variable evaluates to a boolean true value, all status messages associated with the check will be suppressed. .UNINDENT .UNINDENT .SS Handling Compiler Driver Differences .sp To pass options to the linker tool, each compiler driver has its own syntax. The \fBLINKER:\fP prefix and \fB,\fP separator can be used to specify, in a portable way, options to pass to the linker tool. \fBLINKER:\fP is replaced by the appropriate driver option and \fB,\fP by the appropriate driver separator. The driver prefix and driver separator are given by the values of the \fBCMAKE__LINKER_WRAPPER_FLAG\fP \%<#\:variable:CMAKE__LINKER_WRAPPER_FLAG> and \fBCMAKE__LINKER_WRAPPER_FLAG_SEP\fP \%<#\:variable:CMAKE__LINKER_WRAPPER_FLAG_SEP> variables. .sp For example, \fB\(dqLINKER:\-z,defs\(dq\fP becomes \fB\-Xlinker \-z \-Xlinker defs\fP for \fBClang\fP and \fB\-Wl,\-z,defs\fP for \fBGNU GCC\fP\&. .sp The \fBLINKER:\fP prefix can be specified as part of a \fBSHELL:\fP prefix expression. .sp The \fBLINKER:\fP prefix supports, as an alternative syntax, specification of arguments using the \fBSHELL:\fP prefix and space as separator. The previous example then becomes \fB\(dqLINKER:SHELL:\-z defs\(dq\fP\&. .sp \fBNote:\fP .INDENT 0.0 .INDENT 3.5 Specifying the \fBSHELL:\fP prefix anywhere other than at the beginning of the \fBLINKER:\fP prefix is not supported. .UNINDENT .UNINDENT .SS Examples .SS Example: Checking Linker Flag .sp The following example shows how to use this module to check the \fB\-z relro\fP linker flag, which is supported on many Unix\-like systems to enable read\-only relocations for improved binary security. If the flag is supported by the linker, it is conditionally added to the executable target using the \fBtarget_link_options()\fP \%<#\:command:target_link_options>\&. The \fBLINKER:\fP prefix is used to pass the flag to the linker in a portable and compiler\-independent way. .INDENT 0.0 .INDENT 3.5 .sp .EX include(CheckLinkerFlag) check_linker_flag(C \(dqLINKER:\-z,relro\(dq HAVE_Z_RELRO) add_executable(example main.c) if(HAVE_Z_RELRO) target_link_options(example PRIVATE \(dqLINKER:\-z,relro\(dq) endif() .EE .UNINDENT .UNINDENT .SS Example: Checking Multiple Flags .sp In the following example, multiple linker flags are checked simultaneously: .INDENT 0.0 .INDENT 3.5 .sp .EX include(CheckLinkerFlag) check_linker_flag(C \(dqLINKER:\-z,relro;LINKER:\-z,now\(dq HAVE_FLAGS) add_executable(example main.c) if(HAVE_FLAGS) target_link_options(example PRIVATE LINKER:\-z,relro LINKER:\-z,now) endif() .EE .UNINDENT .UNINDENT .SS See Also .INDENT 0.0 .IP \(bu 2 The \fBCMAKE_LINKER_TYPE\fP \%<#\:variable:CMAKE_LINKER_TYPE> variable to specify the linker, which will be used also by this module. .IP \(bu 2 The \fBCheckCompilerFlag\fP \%<#\:module:CheckCompilerFlag> module to check whether a compiler flag is supported. .UNINDENT .SS CheckOBJCCompilerFlag .sp Added in version 3.16. .sp This module provides a command to check whether the Objective\-C compiler supports a given flag. .sp Load this module in a CMake project with: .INDENT 0.0 .INDENT 3.5 .sp .EX include(CheckOBJCCompilerFlag) .EE .UNINDENT .UNINDENT .SS Commands .sp This module provides the following command: .INDENT 0.0 .TP .B check_objc_compiler_flag Checks once whether the Objective\-C compiler supports a given flag: .INDENT 7.0 .INDENT 3.5 .sp .EX check_objc_compiler_flag( ) .EE .UNINDENT .UNINDENT .sp This command checks once that the \fB\fP is accepted by the \fBOBJC\fP compiler without producing a diagnostic message. Multiple flags can be specified in one argument as a string using a semicolon\-separated list \%<#\:cmake-language-lists>\&. .sp The result of the check is stored in the internal cache variable specified by \fB\fP, with boolean true for success and boolean false for failure. .sp A successful result only indicates that the compiler did not report an error when given the flag. Whether the flag has any effect, or the intended one, is outside the scope of this module. .sp \fBNote:\fP .INDENT 7.0 .INDENT 3.5 Since the underlying \fBtry_compile()\fP \%<#\:command:try_compile> command also uses flags from variables like \fBCMAKE__FLAGS\fP \%<#\:variable:CMAKE__FLAGS>, unknown or unsupported flags in those variables may result in a false negative for this check. .UNINDENT .UNINDENT .sp Variables Affecting the Check .sp The following variables may be set before calling this command to modify the way the check is run: .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_FLAGS\fP A space\-separated string of additional flags to pass to the compiler. A semicolon\-separated list \%<#\:cmake-language-lists> will not work. The contents of \fBCMAKE__FLAGS\fP \%<#\:variable:CMAKE__FLAGS> and its associated configuration\-specific \fBCMAKE__FLAGS_\fP \%<#\:variable:CMAKE__FLAGS_> variables are automatically prepended to the compiler command before the contents of this variable. .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_DEFINITIONS\fP A semicolon\-separated list \%<#\:cmake-language-lists> of compiler definitions, each of the form \fB\-DFOO\fP or \fB\-DFOO=bar\fP\&. A definition for the name specified by the result variable argument of the check command is also added automatically. .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_INCLUDES\fP A semicolon\-separated list \%<#\:cmake-language-lists> of header search paths to pass to the compiler. These will be the only header search paths used; the contents of the \fBINCLUDE_DIRECTORIES\fP \%<#\:prop_dir:INCLUDE_DIRECTORIES> directory property will be ignored. .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_LINK_OPTIONS\fP Added in version 3.14. .sp A semicolon\-separated list \%<#\:cmake-language-lists> of options to add to the link command (see \fBtry_compile()\fP \%<#\:command:try_compile> for further details). .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_LIBRARIES\fP A semicolon\-separated list \%<#\:cmake-language-lists> of libraries to add to the link command. These can be the names of system libraries, or they can be Imported Targets \%<#\:imported-targets> (see \fBtry_compile()\fP \%<#\:command:try_compile> for further details). .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_LINK_DIRECTORIES\fP Added in version 3.31. .sp A semicolon\-separated list \%<#\:cmake-language-lists> of library search paths to pass to the linker (see \fBtry_compile()\fP \%<#\:command:try_compile> for further details). .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_QUIET\fP Added in version 3.1. .sp If this variable evaluates to a boolean true value, all status messages associated with the check will be suppressed. .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_TRY_COMPILE_TARGET_TYPE\fP \%<#\:variable:CMAKE_TRY_COMPILE_TARGET_TYPE> Internally, the \fBtry_compile()\fP \%<#\:command:try_compile> command is used to perform the check, and this variable controls the type of target it creates. If this variable is set to \fBEXECUTABLE\fP (the default), the check compiles and links the test source code as an executable program. If set to \fBSTATIC_LIBRARY\fP, the test source code is compiled but not linked. .UNINDENT .UNINDENT .SS Examples .sp The following example demonstrates how to use this module to check the Objective\-C compiler flag \fB\-fobjc\-arc\fP\&. The result of the check is stored in the internal cache variable \fBHAVE_OBJC_ARC\fP, and the flag is conditionally enabled using the \fBtarget_compile_options()\fP \%<#\:command:target_compile_options> command. The \fB$\fP \%<#\:genex:COMPILE_LANGUAGE:languages> generator expression ensures that the flag is added only to \fBOBJC\fP source files. .INDENT 0.0 .INDENT 3.5 .sp .EX include(CheckOBJCCompilerFlag) check_objc_compiler_flag(\-fobjc\-arc HAVE_OBJC_ARC) if(HAVE_OBJC_ARC) target_compile_options( example PRIVATE $<$:\-fobjc\-arc> ) endif() .EE .UNINDENT .UNINDENT .SS See Also .INDENT 0.0 .IP \(bu 2 The \fBCheckCompilerFlag\fP \%<#\:module:CheckCompilerFlag> module for a more general command to check whether a compiler flag is supported. .UNINDENT .SS CheckOBJCSourceCompiles .sp Added in version 3.16. .sp This module provides a command to check whether an Objective\-C source can be built. .sp Load this module in a CMake project with: .INDENT 0.0 .INDENT 3.5 .sp .EX include(CheckOBJCSourceCompiles) .EE .UNINDENT .UNINDENT .SS Commands .sp This module provides the following command: .INDENT 0.0 .TP .B check_objc_source_compiles Checks once whether the given Objective\-C source code can be built: .INDENT 7.0 .INDENT 3.5 .sp .EX check_objc_source_compiles( [FAIL_REGEX ...]) .EE .UNINDENT .UNINDENT .sp This command checks once that the source supplied in \fB\fP can be compiled (and linked into an executable). The result of the check is stored in the internal cache variable specified by \fB\fP\&. .sp The arguments are: .INDENT 7.0 .TP .B \fB\fP Source code to check. This must be an entire program, as written in a file containing the body block. All symbols used in the source code are expected to be declared as usual in their corresponding headers. .TP .B \fB\fP Variable name of an internal cache variable to store the result of the check, with boolean true for success and boolean false for failure. .TP .B \fBFAIL_REGEX ...\fP If this option is provided with one or more regular expressions, then failure is determined by checking if anything in the compiler output matches any of the specified regular expressions. .UNINDENT .sp Variables Affecting the Check .sp The following variables may be set before calling this command to modify the way the check is run: .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_FLAGS\fP A space\-separated string of additional flags to pass to the compiler. A semicolon\-separated list \%<#\:cmake-language-lists> will not work. The contents of \fBCMAKE__FLAGS\fP \%<#\:variable:CMAKE__FLAGS> and its associated configuration\-specific \fBCMAKE__FLAGS_\fP \%<#\:variable:CMAKE__FLAGS_> variables are automatically prepended to the compiler command before the contents of this variable. .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_DEFINITIONS\fP A semicolon\-separated list \%<#\:cmake-language-lists> of compiler definitions, each of the form \fB\-DFOO\fP or \fB\-DFOO=bar\fP\&. A definition for the name specified by the result variable argument of the check command is also added automatically. .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_INCLUDES\fP A semicolon\-separated list \%<#\:cmake-language-lists> of header search paths to pass to the compiler. These will be the only header search paths used; the contents of the \fBINCLUDE_DIRECTORIES\fP \%<#\:prop_dir:INCLUDE_DIRECTORIES> directory property will be ignored. .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_LINK_OPTIONS\fP Added in version 3.14. .sp A semicolon\-separated list \%<#\:cmake-language-lists> of options to add to the link command (see \fBtry_compile()\fP \%<#\:command:try_compile> for further details). .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_LIBRARIES\fP A semicolon\-separated list \%<#\:cmake-language-lists> of libraries to add to the link command. These can be the names of system libraries, or they can be Imported Targets \%<#\:imported-targets> (see \fBtry_compile()\fP \%<#\:command:try_compile> for further details). .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_LINK_DIRECTORIES\fP Added in version 3.31. .sp A semicolon\-separated list \%<#\:cmake-language-lists> of library search paths to pass to the linker (see \fBtry_compile()\fP \%<#\:command:try_compile> for further details). .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_QUIET\fP Added in version 3.1. .sp If this variable evaluates to a boolean true value, all status messages associated with the check will be suppressed. .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_TRY_COMPILE_TARGET_TYPE\fP \%<#\:variable:CMAKE_TRY_COMPILE_TARGET_TYPE> Internally, the \fBtry_compile()\fP \%<#\:command:try_compile> command is used to perform the check, and this variable controls the type of target it creates. If this variable is set to \fBEXECUTABLE\fP (the default), the check compiles and links the test source code as an executable program. If set to \fBSTATIC_LIBRARY\fP, the test source code is compiled but not linked. .UNINDENT .UNINDENT .SS Examples .sp In the following example, this module is used to check whether the provided Objective\-C source code compiles and links. Result of the check is stored in the internal cache variable \fBHAVE_WORKING_CODE\fP\&. .INDENT 0.0 .INDENT 3.5 .sp .EX include(CheckOBJCSourceCompiles) check_objc_source_compiles(\(dq #import int main() { NSObject *foo; return 0; } \(dq HAVE_WORKING_CODE) .EE .UNINDENT .UNINDENT .SS See Also .INDENT 0.0 .IP \(bu 2 The \fBCheckSourceCompiles\fP \%<#\:module:CheckSourceCompiles> module for a more general command to check whether source can be built. .IP \(bu 2 The \fBCheckSourceRuns\fP \%<#\:module:CheckSourceRuns> module to check whether source can be built and run. .UNINDENT .SS CheckOBJCSourceRuns .sp Added in version 3.16. .sp This module provides a command to check whether an Objective\-C source can be built and run. .sp Load this module in a CMake project with: .INDENT 0.0 .INDENT 3.5 .sp .EX include(CheckOBJCSourceRuns) .EE .UNINDENT .UNINDENT .SS Commands .sp This module provides the following command: .INDENT 0.0 .TP .B check_objc_source_runs Checks once whether the given Objective\-C source code compiles and links into an executable that can subsequently be run: .INDENT 7.0 .INDENT 3.5 .sp .EX check_objc_source_runs( ) .EE .UNINDENT .UNINDENT .sp The Objective\-C source supplied in \fB\fP must contain at least a \fBmain()\fP function. The result of the check is stored in the internal cache variable specified by \fB\fP\&. If the code builds and runs with exit code \fB0\fP, success is indicated by a boolean true value. Failure to build or run is indicated by a boolean false value, such as an empty string or an error message. .sp Variables Affecting the Check .sp The following variables may be set before calling this command to modify the way the check is run: .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_FLAGS\fP A space\-separated string of additional flags to pass to the compiler. A semicolon\-separated list \%<#\:cmake-language-lists> will not work. The contents of \fBCMAKE__FLAGS\fP \%<#\:variable:CMAKE__FLAGS> and its associated configuration\-specific \fBCMAKE__FLAGS_\fP \%<#\:variable:CMAKE__FLAGS_> variables are automatically prepended to the compiler command before the contents of this variable. .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_DEFINITIONS\fP A semicolon\-separated list \%<#\:cmake-language-lists> of compiler definitions, each of the form \fB\-DFOO\fP or \fB\-DFOO=bar\fP\&. A definition for the name specified by the result variable argument of the check command is also added automatically. .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_INCLUDES\fP A semicolon\-separated list \%<#\:cmake-language-lists> of header search paths to pass to the compiler. These will be the only header search paths used; the contents of the \fBINCLUDE_DIRECTORIES\fP \%<#\:prop_dir:INCLUDE_DIRECTORIES> directory property will be ignored. .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_LINK_OPTIONS\fP Added in version 3.14. .sp A semicolon\-separated list \%<#\:cmake-language-lists> of options to add to the link command (see \fBtry_compile()\fP \%<#\:command:try_compile> for further details). .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_LIBRARIES\fP A semicolon\-separated list \%<#\:cmake-language-lists> of libraries to add to the link command. These can be the names of system libraries, or they can be Imported Targets \%<#\:imported-targets> (see \fBtry_compile()\fP \%<#\:command:try_compile> for further details). .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_LINK_DIRECTORIES\fP Added in version 3.31. .sp A semicolon\-separated list \%<#\:cmake-language-lists> of library search paths to pass to the linker (see \fBtry_compile()\fP \%<#\:command:try_compile> for further details). .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_QUIET\fP Added in version 3.1. .sp If this variable evaluates to a boolean true value, all status messages associated with the check will be suppressed. .UNINDENT .UNINDENT .SS Examples .sp In the following example, this module is used to check whether the provided Objective\-C source code builds and runs. Result of the check is stored in an internal cache variable \fBHAVE_WORKING_CODE\fP\&. .INDENT 0.0 .INDENT 3.5 .sp .EX include(CheckOBJCSourceRuns) check_objc_source_runs(\(dq #import int main() { NSObject *foo; return 0; } \(dq HAVE_WORKING_CODE) .EE .UNINDENT .UNINDENT .SS See Also .INDENT 0.0 .IP \(bu 2 The \fBCheckSourceRuns\fP \%<#\:module:CheckSourceRuns> module for a more general command syntax. .IP \(bu 2 The \fBCheckSourceCompiles\fP \%<#\:module:CheckSourceCompiles> module to check whether a source code can be built. .UNINDENT .SS CheckOBJCXXCompilerFlag .sp Added in version 3.16. .sp This module provides a command to check whether the Objective\-C++ compiler supports a given flag. .sp Load this module in a CMake project with: .INDENT 0.0 .INDENT 3.5 .sp .EX include(CheckOBJCXXCompilerFlag) .EE .UNINDENT .UNINDENT .SS Commands .sp This module provides the following command: .INDENT 0.0 .TP .B check_objcxx_compiler_flag Checks once whether the Objective\-C++ compiler supports a given flag: .INDENT 7.0 .INDENT 3.5 .sp .EX check_objcxx_compiler_flag( ) .EE .UNINDENT .UNINDENT .sp This command checks once that the \fB\fP is accepted by the \fBOBJCXX\fP compiler without producing a diagnostic message. Multiple flags can be specified in one argument as a string using a semicolon\-separated list \%<#\:cmake-language-lists>\&. .sp The result of the check is stored in the internal cache variable specified by \fB\fP, with boolean true for success and boolean false for failure. .sp A successful result only indicates that the compiler did not report an error when given the flag. Whether the flag has any effect, or the intended one, is outside the scope of this module. .sp \fBNote:\fP .INDENT 7.0 .INDENT 3.5 Since the underlying \fBtry_compile()\fP \%<#\:command:try_compile> command also uses flags from variables like \fBCMAKE__FLAGS\fP \%<#\:variable:CMAKE__FLAGS>, unknown or unsupported flags in those variables may result in a false negative for this check. .UNINDENT .UNINDENT .sp Variables Affecting the Check .sp The following variables may be set before calling this command to modify the way the check is run: .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_FLAGS\fP A space\-separated string of additional flags to pass to the compiler. A semicolon\-separated list \%<#\:cmake-language-lists> will not work. The contents of \fBCMAKE__FLAGS\fP \%<#\:variable:CMAKE__FLAGS> and its associated configuration\-specific \fBCMAKE__FLAGS_\fP \%<#\:variable:CMAKE__FLAGS_> variables are automatically prepended to the compiler command before the contents of this variable. .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_DEFINITIONS\fP A semicolon\-separated list \%<#\:cmake-language-lists> of compiler definitions, each of the form \fB\-DFOO\fP or \fB\-DFOO=bar\fP\&. A definition for the name specified by the result variable argument of the check command is also added automatically. .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_INCLUDES\fP A semicolon\-separated list \%<#\:cmake-language-lists> of header search paths to pass to the compiler. These will be the only header search paths used; the contents of the \fBINCLUDE_DIRECTORIES\fP \%<#\:prop_dir:INCLUDE_DIRECTORIES> directory property will be ignored. .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_LINK_OPTIONS\fP Added in version 3.14. .sp A semicolon\-separated list \%<#\:cmake-language-lists> of options to add to the link command (see \fBtry_compile()\fP \%<#\:command:try_compile> for further details). .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_LIBRARIES\fP A semicolon\-separated list \%<#\:cmake-language-lists> of libraries to add to the link command. These can be the names of system libraries, or they can be Imported Targets \%<#\:imported-targets> (see \fBtry_compile()\fP \%<#\:command:try_compile> for further details). .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_LINK_DIRECTORIES\fP Added in version 3.31. .sp A semicolon\-separated list \%<#\:cmake-language-lists> of library search paths to pass to the linker (see \fBtry_compile()\fP \%<#\:command:try_compile> for further details). .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_QUIET\fP Added in version 3.1. .sp If this variable evaluates to a boolean true value, all status messages associated with the check will be suppressed. .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_TRY_COMPILE_TARGET_TYPE\fP \%<#\:variable:CMAKE_TRY_COMPILE_TARGET_TYPE> Internally, the \fBtry_compile()\fP \%<#\:command:try_compile> command is used to perform the check, and this variable controls the type of target it creates. If this variable is set to \fBEXECUTABLE\fP (the default), the check compiles and links the test source code as an executable program. If set to \fBSTATIC_LIBRARY\fP, the test source code is compiled but not linked. .UNINDENT .UNINDENT .SS Examples .sp The following example demonstrates how to use this module to check the Objective\-C++ compiler flag \fB\-fobjc\-arc\fP\&. The result of the check is stored in the internal cache variable \fBHAVE_OBJC_ARC\fP, and the flag is conditionally enabled using the \fBtarget_compile_options()\fP \%<#\:command:target_compile_options> command. The \fB$\fP \%<#\:genex:COMPILE_LANGUAGE:languages> generator expression ensures that the flag is added only to \fBOBJCXX\fP source files. .INDENT 0.0 .INDENT 3.5 .sp .EX include(CheckOBJCXXCompilerFlag) check_objcxx_compiler_flag(\-fobjc\-arc HAVE_OBJC_ARC) if(HAVE_OBJC_ARC) target_compile_options( example PRIVATE $<$:\-fobjc\-arc> ) endif() .EE .UNINDENT .UNINDENT .SS See Also .INDENT 0.0 .IP \(bu 2 The \fBCheckCompilerFlag\fP \%<#\:module:CheckCompilerFlag> module for a more general command to check whether a compiler flag is supported. .UNINDENT .SS CheckOBJCXXSourceCompiles .sp Added in version 3.16. .sp This module provides a command to check whether an Objective\-C++ source can be built. .sp Load this module in a CMake project with: .INDENT 0.0 .INDENT 3.5 .sp .EX include(CheckOBJCXXSourceCompiles) .EE .UNINDENT .UNINDENT .SS Commands .sp This module provides the following command: .INDENT 0.0 .TP .B check_objcxx_source_compiles Checks once whether the given Objective\-C++ source code can be built: .INDENT 7.0 .INDENT 3.5 .sp .EX check_objcxx_source_compiles( [FAIL_REGEX ...]) .EE .UNINDENT .UNINDENT .sp This command checks once that the source supplied in \fB\fP can be compiled (and linked into an executable). The result of the check is stored in the internal cache variable specified by \fB\fP\&. .sp The arguments are: .INDENT 7.0 .TP .B \fB\fP Objective\-C++ source code to check. This must be an entire program, as written in a file containing the body block. All symbols used in the source code are expected to be declared as usual in their corresponding headers. .TP .B \fB\fP Variable name of an internal cache variable to store the result of the check, with boolean true for success and boolean false for failure. .TP .B \fBFAIL_REGEX ...\fP If this option is provided with one or more regular expressions, then failure is determined by checking if anything in the compiler output matches any of the specified regular expressions. .UNINDENT .sp Variables Affecting the Check .sp The following variables may be set before calling this command to modify the way the check is run: .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_FLAGS\fP A space\-separated string of additional flags to pass to the compiler. A semicolon\-separated list \%<#\:cmake-language-lists> will not work. The contents of \fBCMAKE__FLAGS\fP \%<#\:variable:CMAKE__FLAGS> and its associated configuration\-specific \fBCMAKE__FLAGS_\fP \%<#\:variable:CMAKE__FLAGS_> variables are automatically prepended to the compiler command before the contents of this variable. .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_DEFINITIONS\fP A semicolon\-separated list \%<#\:cmake-language-lists> of compiler definitions, each of the form \fB\-DFOO\fP or \fB\-DFOO=bar\fP\&. A definition for the name specified by the result variable argument of the check command is also added automatically. .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_INCLUDES\fP A semicolon\-separated list \%<#\:cmake-language-lists> of header search paths to pass to the compiler. These will be the only header search paths used; the contents of the \fBINCLUDE_DIRECTORIES\fP \%<#\:prop_dir:INCLUDE_DIRECTORIES> directory property will be ignored. .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_LINK_OPTIONS\fP Added in version 3.14. .sp A semicolon\-separated list \%<#\:cmake-language-lists> of options to add to the link command (see \fBtry_compile()\fP \%<#\:command:try_compile> for further details). .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_LIBRARIES\fP A semicolon\-separated list \%<#\:cmake-language-lists> of libraries to add to the link command. These can be the names of system libraries, or they can be Imported Targets \%<#\:imported-targets> (see \fBtry_compile()\fP \%<#\:command:try_compile> for further details). .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_LINK_DIRECTORIES\fP Added in version 3.31. .sp A semicolon\-separated list \%<#\:cmake-language-lists> of library search paths to pass to the linker (see \fBtry_compile()\fP \%<#\:command:try_compile> for further details). .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_QUIET\fP Added in version 3.1. .sp If this variable evaluates to a boolean true value, all status messages associated with the check will be suppressed. .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_TRY_COMPILE_TARGET_TYPE\fP \%<#\:variable:CMAKE_TRY_COMPILE_TARGET_TYPE> Internally, the \fBtry_compile()\fP \%<#\:command:try_compile> command is used to perform the check, and this variable controls the type of target it creates. If this variable is set to \fBEXECUTABLE\fP (the default), the check compiles and links the test source code as an executable program. If set to \fBSTATIC_LIBRARY\fP, the test source code is compiled but not linked. .UNINDENT .UNINDENT .SS Examples .sp In the following example, this module is used to check whether the provided Objective\-C++ source code can be compiled and linked. Result of the check is stored in the internal cache variable \fBHAVE_WORKING_CODE\fP\&. .INDENT 0.0 .INDENT 3.5 .sp .EX include(CheckOBJCXXSourceCompiles) check_objcxx_source_compiles(\(dq #include #import int main() { std::vector v; NSObject *foo; return 0; } \(dq HAVE_WORKING_CODE) .EE .UNINDENT .UNINDENT .SS See Also .INDENT 0.0 .IP \(bu 2 The \fBCheckSourceCompiles\fP \%<#\:module:CheckSourceCompiles> module for a more general command to check whether source can be built. .IP \(bu 2 The \fBCheckSourceRuns\fP \%<#\:module:CheckSourceRuns> module to check whether source can be built and run. .UNINDENT .SS CheckOBJCXXSourceRuns .sp Added in version 3.16. .sp This module provides a command to check whether an Objective\-C++ source can be built and run. .sp Load this module in a CMake project with: .INDENT 0.0 .INDENT 3.5 .sp .EX include(CheckOBJCXXSourceRuns) .EE .UNINDENT .UNINDENT .SS Commands .sp This module provides the following command: .INDENT 0.0 .TP .B check_objcxx_source_runs Checks once whether the given Objective\-C++ source code compiles and links into an executable that can subsequently be run: .INDENT 7.0 .INDENT 3.5 .sp .EX check_objcxx_source_runs( ) .EE .UNINDENT .UNINDENT .sp The Objective\-C++ source supplied in \fB\fP must contain at least a \fBmain()\fP function. The result of the check is stored in the internal cache variable specified by \fB\fP\&. If the code builds and runs with exit code \fB0\fP, success is indicated by a boolean true value. Failure to build or run is indicated by a boolean false value, such as an empty string or an error message. .sp Variables Affecting the Check .sp The following variables may be set before calling this command to modify the way the check is run: .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_FLAGS\fP A space\-separated string of additional flags to pass to the compiler. A semicolon\-separated list \%<#\:cmake-language-lists> will not work. The contents of \fBCMAKE__FLAGS\fP \%<#\:variable:CMAKE__FLAGS> and its associated configuration\-specific \fBCMAKE__FLAGS_\fP \%<#\:variable:CMAKE__FLAGS_> variables are automatically prepended to the compiler command before the contents of this variable. .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_DEFINITIONS\fP A semicolon\-separated list \%<#\:cmake-language-lists> of compiler definitions, each of the form \fB\-DFOO\fP or \fB\-DFOO=bar\fP\&. A definition for the name specified by the result variable argument of the check command is also added automatically. .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_INCLUDES\fP A semicolon\-separated list \%<#\:cmake-language-lists> of header search paths to pass to the compiler. These will be the only header search paths used; the contents of the \fBINCLUDE_DIRECTORIES\fP \%<#\:prop_dir:INCLUDE_DIRECTORIES> directory property will be ignored. .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_LINK_OPTIONS\fP Added in version 3.14. .sp A semicolon\-separated list \%<#\:cmake-language-lists> of options to add to the link command (see \fBtry_compile()\fP \%<#\:command:try_compile> for further details). .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_LIBRARIES\fP A semicolon\-separated list \%<#\:cmake-language-lists> of libraries to add to the link command. These can be the names of system libraries, or they can be Imported Targets \%<#\:imported-targets> (see \fBtry_compile()\fP \%<#\:command:try_compile> for further details). .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_LINK_DIRECTORIES\fP Added in version 3.31. .sp A semicolon\-separated list \%<#\:cmake-language-lists> of library search paths to pass to the linker (see \fBtry_compile()\fP \%<#\:command:try_compile> for further details). .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_QUIET\fP Added in version 3.1. .sp If this variable evaluates to a boolean true value, all status messages associated with the check will be suppressed. .UNINDENT .UNINDENT .SS Examples .sp In the following example, this module is used to check whether the provided Objective\-C++ source code builds and runs. Result of the check is stored in an internal cache variable \fBHAVE_WORKING_CODE\fP\&. .INDENT 0.0 .INDENT 3.5 .sp .EX include(CheckOBJCXXSourceRuns) check_objcxx_source_runs(\(dq #include #import int main() { std::vector v; NSObject *foo; return 0; } \(dq HAVE_WORKING_CODE) .EE .UNINDENT .UNINDENT .SS See Also .INDENT 0.0 .IP \(bu 2 The \fBCheckSourceRuns\fP \%<#\:module:CheckSourceRuns> module for a more general command syntax. .IP \(bu 2 The \fBCheckSourceCompiles\fP \%<#\:module:CheckSourceCompiles> module to check whether a source code can be built. .UNINDENT .SS CheckPIESupported .sp Added in version 3.14. .sp This module provides a command to check whether the linker supports Position Independent Code (PIE) or No Position Independent Code (NO_PIE) for executables. .sp Load this module in a CMake project with: .INDENT 0.0 .INDENT 3.5 .sp .EX include(CheckPIESupported) .EE .UNINDENT .UNINDENT .sp When setting the \fBPOSITION_INDEPENDENT_CODE\fP \%<#\:prop_tgt:POSITION_INDEPENDENT_CODE> target property, PIC\-related compile and link options are added when building library objects, and PIE\-related compile options are added when building objects of executable targets, regardless of this module. Use this module to ensure that the \fBPOSITION_INDEPENDENT_CODE\fP target property for executables is also honored at link time. .SS Commands .sp This module provides the following command: .INDENT 0.0 .TP .B check_pie_supported Checks for PIE/NO_PIE support and prepares all executables to have link time PIE options enabled: .INDENT 7.0 .INDENT 3.5 .sp .EX check_pie_supported([OUTPUT_VARIABLE ] [LANGUAGES ...]) .EE .UNINDENT .UNINDENT .sp Options are: .INDENT 7.0 .TP .B \fBOUTPUT_VARIABLE \fP Set \fB\fP 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. .TP .B \fBLANGUAGES ...\fP Check the linkers used for each of the specified languages. If this option is not provided, the command checks all enabled languages. .sp \fBC\fP, \fBCXX\fP, \fBFortran\fP are supported. .sp Added in version 3.23: \fBOBJC\fP, \fBOBJCXX\fP, \fBCUDA\fP, and \fBHIP\fP are supported. .UNINDENT .sp \fBNote:\fP .INDENT 7.0 .INDENT 3.5 To use \fBcheck_pie_supported()\fP, policy \fBCMP0083\fP \%<#\:policy:CMP0083> must be set to \fBNEW\fP; otherwise, a fatal error will occur. .UNINDENT .UNINDENT .UNINDENT .SS Variables .sp For each language checked, the \fBcheck_pie_supported()\fP command defines two boolean cache variables: .INDENT 0.0 .TP .B \fBCMAKE__LINK_PIE_SUPPORTED\fP Set to true if \fBPIE\fP is supported by the linker and false otherwise. .TP .B \fBCMAKE__LINK_NO_PIE_SUPPORTED\fP Set to true if \fBNO_PIE\fP is supported by the linker and false otherwise. .UNINDENT .SS Examples .sp To enable PIE on an executable target at link time as well, include this module and call \fBcheck_pie_supported()\fP before setting the \fBPOSITION_INDEPENDENT_CODE\fP target property. This will determine whether the linker for each checked language supports PIE\-related link options. For example: .INDENT 0.0 .INDENT 3.5 .sp .EX add_executable(foo ...) include(CheckPIESupported) check_pie_supported() set_property(TARGET foo PROPERTY POSITION_INDEPENDENT_CODE TRUE) .EE .UNINDENT .UNINDENT .sp Since not all linkers require or support PIE\-related link options (for example, \fBMSVC\fP), retrieving any error messages might be useful for logging purposes: .INDENT 0.0 .INDENT 3.5 .sp .EX add_executable(foo ...) message(CHECK_START \(dqChecking for C linker PIE support\(dq) include(CheckPIESupported) check_pie_supported(OUTPUT_VARIABLE output LANGUAGES C) set_property(TARGET foo PROPERTY POSITION_INDEPENDENT_CODE TRUE) if(CMAKE_C_LINK_PIE_SUPPORTED) message(CHECK_PASS \(dqyes\(dq) else() message(CHECK_FAIL \(dqno\(dq) message(VERBOSE \(dqPIE is not supported at link time:\en${output}\(dq \(dqPIE link options will not be passed to linker.\(dq) endif() .EE .UNINDENT .UNINDENT .sp Setting the \fBPOSITION_INDEPENDENT_CODE\fP target property on an executable without this module will set PIE\-related compile options but not PIE\-related link options, which might not be sufficient in certain cases: .INDENT 0.0 .INDENT 3.5 .sp .EX add_executable(foo ...) set_property(TARGET foo PROPERTY POSITION_INDEPENDENT_CODE TRUE) .EE .UNINDENT .UNINDENT .SS CheckPrototypeDefinition .sp This module provides a command to check if a C function has the expected prototype. .sp Load this module in a CMake project with: .INDENT 0.0 .INDENT 3.5 .sp .EX include(CheckPrototypeDefinition) .EE .UNINDENT .UNINDENT .SS Commands .sp This module provides the following command: .INDENT 0.0 .TP .B check_prototype_definition Checks if a C function has the expected prototype: .INDENT 7.0 .INDENT 3.5 .sp .EX check_prototype_definition( ) .EE .UNINDENT .UNINDENT .INDENT 7.0 .TP .B \fB\fP The name of the function whose prototype is being checked. .TP .B \fB\fP The expected prototype of the function, provided as a string. .TP .B \fB\fP The return value of the function. This will be used as a return value in the function definition body of the generated test program to verify that the function\(aqs return type matches the expected type. .TP .B \fB\fP A semicolon\-separated list \%<#\:cmake-language-lists> of header file names required for checking the function prototype. .TP .B \fB\fP The name of the variable to store the check result. This variable will be created as an internal cache variable. .UNINDENT .sp This command generates a test program and verifies that it builds without errors. The generated test program includes specified \fB\fP, defines a function with given literal \fB\fP and \fB\fP value and then uses the specified \fB\fP\&. The simplified test program can be illustrated as: .INDENT 7.0 .INDENT 3.5 .sp .EX #include // ... { return ; } int main(...) { ...()... } .EE .UNINDENT .UNINDENT .sp Variables Affecting the Check .sp The following variables may be set before calling this command to modify the way the check is run: .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_FLAGS\fP A space\-separated string of additional flags to pass to the compiler. A semicolon\-separated list \%<#\:cmake-language-lists> will not work. The contents of \fBCMAKE__FLAGS\fP \%<#\:variable:CMAKE__FLAGS> and its associated configuration\-specific \fBCMAKE__FLAGS_\fP \%<#\:variable:CMAKE__FLAGS_> variables are automatically prepended to the compiler command before the contents of this variable. .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_DEFINITIONS\fP A semicolon\-separated list \%<#\:cmake-language-lists> of compiler definitions, each of the form \fB\-DFOO\fP or \fB\-DFOO=bar\fP\&. A definition for the name specified by the result variable argument of the check command is also added automatically. .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_INCLUDES\fP A semicolon\-separated list \%<#\:cmake-language-lists> of header search paths to pass to the compiler. These will be the only header search paths used; the contents of the \fBINCLUDE_DIRECTORIES\fP \%<#\:prop_dir:INCLUDE_DIRECTORIES> directory property will be ignored. .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_LINK_OPTIONS\fP Added in version 3.14. .sp A semicolon\-separated list \%<#\:cmake-language-lists> of options to add to the link command (see \fBtry_compile()\fP \%<#\:command:try_compile> for further details). .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_LIBRARIES\fP A semicolon\-separated list \%<#\:cmake-language-lists> of libraries to add to the link command. These can be the names of system libraries, or they can be Imported Targets \%<#\:imported-targets> (see \fBtry_compile()\fP \%<#\:command:try_compile> for further details). .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_LINK_DIRECTORIES\fP Added in version 3.31. .sp A semicolon\-separated list \%<#\:cmake-language-lists> of library search paths to pass to the linker (see \fBtry_compile()\fP \%<#\:command:try_compile> for further details). .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_QUIET\fP Added in version 3.1. .sp If this variable evaluates to a boolean true value, all status messages associated with the check will be suppressed. .UNINDENT .UNINDENT .SS Examples .sp Checking if the \fBgetpwent_r()\fP function on Solaris/illumos systems has the expected prototype: .INDENT 0.0 .INDENT 3.5 .sp .EX include(CheckPrototypeDefinition) check_prototype_definition( getpwent_r \(dqstruct passwd *getpwent_r(struct passwd *src, char *buf, int buflen)\(dq \(dqNULL\(dq \(dqunistd.h;pwd.h\(dq HAVE_SOLARIS_GETPWENT_R ) .EE .UNINDENT .UNINDENT .SS CheckSourceCompiles .sp Added in version 3.19. .sp This module provides a command that checks whether a source code can be built for a given language. .sp Load this module in a CMake project with: .INDENT 0.0 .INDENT 3.5 .sp .EX include(CheckSourceCompiles) .EE .UNINDENT .UNINDENT .SS Commands .sp This module provides the following command: .INDENT 0.0 .TP .B check_source_compiles Checks once whether the given source code can be built for the given language: .INDENT 7.0 .INDENT 3.5 .sp .EX check_source_compiles( [FAIL_REGEX ...] [SRC_EXT ] ) .EE .UNINDENT .UNINDENT .sp This command checks once that the source supplied in \fB\fP can be compiled (and linked into an executable) for code language \fB\fP\&. The result of the check is stored in the internal cache variable specified by \fB\fP\&. .sp The arguments are: .INDENT 7.0 .TP .B \fB\fP Language of the source code to check. Supported languages are: \fBC\fP, \fBCXX\fP, \fBCUDA\fP, \fBFortran\fP, \fBHIP\fP, \fBISPC\fP, \fBOBJC\fP, \fBOBJCXX\fP, and \fBSwift\fP\&. .sp Added in version 3.21: Support for \fBHIP\fP language. .sp Added in version 3.26: Support for \fBSwift\fP language. .TP .B \fB\fP The source code to check. This must be an entire program, as written in a file containing the body block. All symbols used in the source code are expected to be declared as usual in their corresponding headers. .TP .B \fB\fP Variable name of an internal cache variable to store the result of the check, with boolean true for success and boolean false for failure. .TP .B \fBFAIL_REGEX ...\fP If one or more regular expression patterns are provided, then failure is determined by checking if anything in the compiler output matches any of the specified regular expressions. .TP .B \fBSRC_EXT \fP By default, the internal test source file used for the check will be given a file extension that matches the requested language (e.g., \fB\&.c\fP for C, \fB\&.cxx\fP for C++, \fB\&.F90\fP for Fortran, etc.). This option can be used to override this with the \fB\&.\fP instead. .UNINDENT .sp Variables Affecting the Check .sp The following variables may be set before calling this command to modify the way the check is run: .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_FLAGS\fP A space\-separated string of additional flags to pass to the compiler. A semicolon\-separated list \%<#\:cmake-language-lists> will not work. The contents of \fBCMAKE__FLAGS\fP \%<#\:variable:CMAKE__FLAGS> and its associated configuration\-specific \fBCMAKE__FLAGS_\fP \%<#\:variable:CMAKE__FLAGS_> variables are automatically prepended to the compiler command before the contents of this variable. .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_DEFINITIONS\fP A semicolon\-separated list \%<#\:cmake-language-lists> of compiler definitions, each of the form \fB\-DFOO\fP or \fB\-DFOO=bar\fP\&. A definition for the name specified by the result variable argument of the check command is also added automatically. .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_INCLUDES\fP A semicolon\-separated list \%<#\:cmake-language-lists> of header search paths to pass to the compiler. These will be the only header search paths used; the contents of the \fBINCLUDE_DIRECTORIES\fP \%<#\:prop_dir:INCLUDE_DIRECTORIES> directory property will be ignored. .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_LINK_OPTIONS\fP Added in version 3.14. .sp A semicolon\-separated list \%<#\:cmake-language-lists> of options to add to the link command (see \fBtry_compile()\fP \%<#\:command:try_compile> for further details). .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_LIBRARIES\fP A semicolon\-separated list \%<#\:cmake-language-lists> of libraries to add to the link command. These can be the names of system libraries, or they can be Imported Targets \%<#\:imported-targets> (see \fBtry_compile()\fP \%<#\:command:try_compile> for further details). .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_LINK_DIRECTORIES\fP Added in version 3.31. .sp A semicolon\-separated list \%<#\:cmake-language-lists> of library search paths to pass to the linker (see \fBtry_compile()\fP \%<#\:command:try_compile> for further details). .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_QUIET\fP Added in version 3.1. .sp If this variable evaluates to a boolean true value, all status messages associated with the check will be suppressed. .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_TRY_COMPILE_TARGET_TYPE\fP \%<#\:variable:CMAKE_TRY_COMPILE_TARGET_TYPE> Internally, the \fBtry_compile()\fP \%<#\:command:try_compile> command is used to perform the check, and this variable controls the type of target it creates. If this variable is set to \fBEXECUTABLE\fP (the default), the check compiles and links the test source code as an executable program. If set to \fBSTATIC_LIBRARY\fP, the test source code is compiled but not linked. .UNINDENT .UNINDENT .SS Examples .SS Example: Basic Usage .sp The following example demonstrates how to check whether the C++ compiler supports a specific language feature using this module. In this case, the check verifies if the compiler supports \fBC++11\fP lambda expressions. The result is stored in the internal cache variable \fBHAVE_CXX11_LAMBDAS\fP: .INDENT 0.0 .INDENT 3.5 .sp .EX include(CheckSourceCompiles) check_source_compiles(CXX \(dq int main() { auto lambda = []() { return 42; }; return lambda(); } \(dq HAVE_CXX11_LAMBDAS) .EE .UNINDENT .UNINDENT .SS Example: Checking Code With Bracket Argument .sp The following example shows how to check whether the C compiler supports the \fBnoreturn\fP attribute. Code is supplied using the Bracket Argument \%<#\:bracket-argument> for easier embedded quotes handling: .INDENT 0.0 .INDENT 3.5 .sp .EX include(CheckSourceCompiles) check_source_compiles(C [[ #if !__has_c_attribute(noreturn) # error \(dqNo noreturn attribute\(dq #endif int main(void) { return 0; } ]] HAVE_NORETURN) .EE .UNINDENT .UNINDENT .SS Example: Performing a Check Without Linking .sp In the following example, this module is used to perform a compile\-only check of Fortran source code, whether the compiler supports the \fBpure\fP procedure attribute: .INDENT 0.0 .INDENT 3.5 .sp .EX include(CheckSourceCompiles) block() set(CMAKE_TRY_COMPILE_TARGET_TYPE \(dqSTATIC_LIBRARY\(dq) check_source_compiles( Fortran \(dqpure subroutine foo() end subroutine\(dq HAVE_PURE ) endblock() .EE .UNINDENT .UNINDENT .SS Example: Isolated Check .sp In the following example, this module is used in combination with the \fBCMakePushCheckState\fP \%<#\:module:CMakePushCheckState> module to modify required libraries when checking whether the PostgreSQL \fBPGVerbosity\fP enum contains \fBPQERRORS_SQLSTATE\fP (available as of PostgreSQL version 12): .INDENT 0.0 .INDENT 3.5 .sp .EX include(CheckSourceCompiles) include(CMakePushCheckState) find_package(PostgreSQL) if(TARGET PostgreSQL::PostgreSQL) cmake_push_check_state(RESET) set(CMAKE_REQUIRED_LIBRARIES PostgreSQL::PostgreSQL) check_source_compiles(C \(dq #include int main(void) { PGVerbosity e = PQERRORS_SQLSTATE; (void)e; return 0; } \(dq HAVE_PQERRORS_SQLSTATE) cmake_pop_check_state() endif() .EE .UNINDENT .UNINDENT .SS See Also .INDENT 0.0 .IP \(bu 2 The \fBCheckSourceRuns\fP \%<#\:module:CheckSourceRuns> module to check whether the source code can be built and also run. .UNINDENT .SS CheckSourceRuns .sp Added in version 3.19. .sp This module provides a command to check whether a source code can be built and run. .sp Load this module in a CMake project with: .INDENT 0.0 .INDENT 3.5 .sp .EX include(CheckSourceRuns) .EE .UNINDENT .UNINDENT .SS Commands .sp This module provides the following command: .INDENT 0.0 .TP .B check_source_runs Checks once whether the given source code compiles and links into an executable that can subsequently be run: .INDENT 7.0 .INDENT 3.5 .sp .EX check_source_runs( [SRC_EXT ]) .EE .UNINDENT .UNINDENT .sp This command checks once that the \fB\fP source code supplied in \fB\fP can be built, linked as an executable, and then run. The result of the check is stored in the internal cache variable specified by \fB\fP\&. .sp The arguments are: .INDENT 7.0 .TP .B \fB\fP The programming language of the source \fB\fP to check. Supported languages are: \fBC\fP, \fBCXX\fP, \fBCUDA\fP, \fBFortran\fP, \fBHIP\fP, \fBOBJC\fP, and \fBOBJCXX\fP\&. .sp Added in version 3.21: Support for \fBHIP\fP language. .TP .B \fB\fP The source code to be tested. It must contain a valid source program. For example, it must contain at least a \fBmain()\fP function (in C/C++), or a \fBprogram\fP unit (in Fortran). .TP .B \fB\fP Name of the internal cache variable with the result of the check. If the code builds and runs with exit code \fB0\fP, success is indicated by a boolean true value. Failure to build or run is indicated by a boolean false value, such as an empty string or an error message. .TP .B \fBSRC_EXT \fP By default, the internal test source file used for the check will be given a file extension that matches the requested language (e.g., \fB\&.c\fP for C, \fB\&.cxx\fP for C++, \fB\&.F90\fP for Fortran, etc.). This option can be used to override this with the \fB\&.\fP instead. .UNINDENT .sp Variables Affecting the Check .sp The following variables may be set before calling this command to modify the way the check is run: .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_FLAGS\fP A space\-separated string of additional flags to pass to the compiler. A semicolon\-separated list \%<#\:cmake-language-lists> will not work. The contents of \fBCMAKE__FLAGS\fP \%<#\:variable:CMAKE__FLAGS> and its associated configuration\-specific \fBCMAKE__FLAGS_\fP \%<#\:variable:CMAKE__FLAGS_> variables are automatically prepended to the compiler command before the contents of this variable. .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_DEFINITIONS\fP A semicolon\-separated list \%<#\:cmake-language-lists> of compiler definitions, each of the form \fB\-DFOO\fP or \fB\-DFOO=bar\fP\&. A definition for the name specified by the result variable argument of the check command is also added automatically. .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_INCLUDES\fP A semicolon\-separated list \%<#\:cmake-language-lists> of header search paths to pass to the compiler. These will be the only header search paths used; the contents of the \fBINCLUDE_DIRECTORIES\fP \%<#\:prop_dir:INCLUDE_DIRECTORIES> directory property will be ignored. .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_LINK_OPTIONS\fP Added in version 3.14. .sp A semicolon\-separated list \%<#\:cmake-language-lists> of options to add to the link command (see \fBtry_compile()\fP \%<#\:command:try_compile> for further details). .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_LIBRARIES\fP A semicolon\-separated list \%<#\:cmake-language-lists> of libraries to add to the link command. These can be the names of system libraries, or they can be Imported Targets \%<#\:imported-targets> (see \fBtry_compile()\fP \%<#\:command:try_compile> for further details). .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_LINK_DIRECTORIES\fP Added in version 3.31. .sp A semicolon\-separated list \%<#\:cmake-language-lists> of library search paths to pass to the linker (see \fBtry_compile()\fP \%<#\:command:try_compile> for further details). .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_QUIET\fP Added in version 3.1. .sp If this variable evaluates to a boolean true value, all status messages associated with the check will be suppressed. .UNINDENT .UNINDENT .SS Examples .SS Example: Basic Usage .sp The following example demonstrates how to use this module to check whether the C source code is supported and operational at runtime. The result of the check is stored in the internal cache variable \fBHAVE_NORETURN\fP\&. .INDENT 0.0 .INDENT 3.5 .sp .EX include(CheckSourceRuns) check_source_runs(C \(dq #include #include noreturn void f(){ exit(0); } int main(void) { f(); return 1; } \(dq HAVE_NORETURN) .EE .UNINDENT .UNINDENT .SS Example: Checking Fortran Code .sp Checking if Fortran source code runs successfully: .INDENT 0.0 .INDENT 3.5 .sp .EX include(CheckSourceRuns) check_source_runs(Fortran \(dq program test real :: x[*] call co_sum(x) end program \(dq HAVE_COARRAY) .EE .UNINDENT .UNINDENT .SS Example: Checking C++ Code With Bracket Argument .sp The following example demonstrates how to check whether the C++ standard library is functional and \fBstd::vector\fP works at runtime. If the source compiles, links, and runs successfully, internal cache variable \fBHAVE_WORKING_STD_VECTOR\fP will be set to boolean true value. Code is supplied using Bracket Argument \%<#\:bracket-argument> for easier embedded quotes handling: .INDENT 0.0 .INDENT 3.5 .sp .EX include(CheckSourceRuns) check_source_runs(CXX [[ #include #include int main() { std::vector v = {1, 2, 3}; if (v.size() != 3) return 1; std::cout << \(dqVector works correctly.\(dq << std::endl; return 0; } ]] HAVE_WORKING_STD_VECTOR) .EE .UNINDENT .UNINDENT .SS Example: Isolated Check .sp In the following example, this module is used in combination with the \fBCMakePushCheckState\fP \%<#\:module:CMakePushCheckState> module to modify required compile definitions and libraries when checking whether the C function \fBsched_getcpu()\fP is supported and operational at runtime. For example, on some systems, the \fBsched_getcpu()\fP function may be available at compile time but not actually implemented by the kernel. In such cases, it returns \fB\-1\fP and sets \fBerrno\fP to \fBENOSYS\fP\&. This check verifies that \fBsched_getcpu()\fP runs successfully and stores a boolean result in the internal cache variable \fBHAVE_SCHED_GETCPU\fP\&. .INDENT 0.0 .INDENT 3.5 .sp .EX include(CheckSourceRuns) include(CMakePushCheckState) cmake_push_check_state(RESET) set(CMAKE_REQUIRED_DEFINITIONS \-D_GNU_SOURCE) if(CMAKE_SYSTEM_NAME STREQUAL \(dqHaiku\(dq) set(CMAKE_REQUIRED_LIBRARIES gnu) endif() check_source_runs(C \(dq #include int main(void) { if (sched_getcpu() == \-1) { return 1; } return 0; } \(dq HAVE_SCHED_GETCPU) cmake_pop_check_state() .EE .UNINDENT .UNINDENT .SS See Also .INDENT 0.0 .IP \(bu 2 The \fBCheckSourceCompiles\fP \%<#\:module:CheckSourceCompiles> module to check whether a source code can be built. .UNINDENT .SS CheckStructHasMember .sp This module provides a command to check whether a struct or class has a specified member variable. .sp Load this module in a CMake project with: .INDENT 0.0 .INDENT 3.5 .sp .EX include(CheckStructHasMember) .EE .UNINDENT .UNINDENT .SS Commands .sp This module provides the following command: .INDENT 0.0 .TP .B check_struct_has_member Checks once if the given struct or class has the specified member variable: .INDENT 7.0 .INDENT 3.5 .sp .EX check_struct_has_member( [LANGUAGE ] ) .EE .UNINDENT .UNINDENT .sp This command checks once whether the struct or class \fB\fP contains the specified \fB\fP after including the given header(s) \fB\fP where the prototype should be declared. Multiple header files can be specified in one argument as a string using a semicolon\-separated list \%<#\:cmake-language-lists>\&. The result is stored in an internal cache variable \fB\fP\&. .sp The options are: .INDENT 7.0 .TP .B \fBLANGUAGE \fP Use the \fB\fP compiler to perform the check. Acceptable values are \fBC\fP and \fBCXX\fP\&. If not specified, it defaults to \fBC\fP\&. .UNINDENT .sp Variables Affecting the Check .sp The following variables may be set before calling this command to modify the way the check is run: .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_FLAGS\fP A space\-separated string of additional flags to pass to the compiler. A semicolon\-separated list \%<#\:cmake-language-lists> will not work. The contents of \fBCMAKE__FLAGS\fP \%<#\:variable:CMAKE__FLAGS> and its associated configuration\-specific \fBCMAKE__FLAGS_\fP \%<#\:variable:CMAKE__FLAGS_> variables are automatically prepended to the compiler command before the contents of this variable. .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_DEFINITIONS\fP A semicolon\-separated list \%<#\:cmake-language-lists> of compiler definitions, each of the form \fB\-DFOO\fP or \fB\-DFOO=bar\fP\&. A definition for the name specified by the result variable argument of the check command is also added automatically. .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_INCLUDES\fP A semicolon\-separated list \%<#\:cmake-language-lists> of header search paths to pass to the compiler. These will be the only header search paths used; the contents of the \fBINCLUDE_DIRECTORIES\fP \%<#\:prop_dir:INCLUDE_DIRECTORIES> directory property will be ignored. .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_LINK_OPTIONS\fP Added in version 3.14. .sp A semicolon\-separated list \%<#\:cmake-language-lists> of options to add to the link command (see \fBtry_compile()\fP \%<#\:command:try_compile> for further details). .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_LIBRARIES\fP A semicolon\-separated list \%<#\:cmake-language-lists> of libraries to add to the link command. These can be the names of system libraries, or they can be Imported Targets \%<#\:imported-targets> (see \fBtry_compile()\fP \%<#\:command:try_compile> for further details). .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_LINK_DIRECTORIES\fP Added in version 3.31. .sp A semicolon\-separated list \%<#\:cmake-language-lists> of library search paths to pass to the linker (see \fBtry_compile()\fP \%<#\:command:try_compile> for further details). .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_QUIET\fP Added in version 3.1. .sp If this variable evaluates to a boolean true value, all status messages associated with the check will be suppressed. .UNINDENT .UNINDENT .SS Examples .SS Example: Checking C Struct Member .sp In the following example, this module checks if the C struct \fBtimeval\fP has a member variable \fBtv_sec\fP after including the \fB\fP header. The result of the check is stored in the internal cache variable \fBHAVE_TIMEVAL_TV_SEC\fP\&. .INDENT 0.0 .INDENT 3.5 .sp .EX include(CheckStructHasMember) check_struct_has_member( \(dqstruct timeval\(dq tv_sec sys/select.h HAVE_TIMEVAL_TV_SEC ) .EE .UNINDENT .UNINDENT .SS Example: Checking C++ Struct Member .sp In the following example, this module checks if the C++ struct \fBstd::tm\fP has a member variable \fBtm_gmtoff\fP after including the \fB\fP header. The result of the check is stored in the internal cache variable \fBHAVE_TM_GMTOFF\fP\&. .INDENT 0.0 .INDENT 3.5 .sp .EX include(CheckStructHasMember) check_struct_has_member( std::tm tm_gmtoff ctime HAVE_TM_GMTOFF LANGUAGE CXX ) .EE .UNINDENT .UNINDENT .SS Example: Isolated Check With Compile Definitions .sp In the following example, the check is performed with temporarily modified compile definitions using the \fBCMakePushCheckState\fP \%<#\:module:CMakePushCheckState> module: .INDENT 0.0 .INDENT 3.5 .sp .EX include(CheckStructHasMember) include(CMakePushCheckState) cmake_push_check_state(RESET) set(CMAKE_REQUIRED_DEFINITIONS \-D_GNU_SOURCE) check_struct_has_member( \(dqstruct utsname\(dq domainname sys/utsname.h HAVE_UTSNAME_DOMAINNAME ) cmake_pop_check_state() .EE .UNINDENT .UNINDENT .SS CheckSymbolExists .sp This module provides a command to check whether a C symbol exists. .sp Load this module in a CMake project with: .INDENT 0.0 .INDENT 3.5 .sp .EX include(CheckSymbolExists) .EE .UNINDENT .UNINDENT .SS Commands .sp This module provides the following command: .INDENT 0.0 .TP .B check_symbol_exists Checks once whether a symbol exists as a function, variable, or preprocessor macro in C: .INDENT 7.0 .INDENT 3.5 .sp .EX check_symbol_exists( ) .EE .UNINDENT .UNINDENT .sp This command checks whether the \fB\fP is available after including the specified header file(s) \fB\fP, and stores the result in the internal cache variable \fB\fP\&. Multiple header files can be specified in one argument as a string using a semicolon\-separated list \%<#\:cmake-language-lists>\&. .sp If the header files define the symbol as a macro, it is considered available and assumed to work. If the symbol is declared as a function or variable, the check also ensures that it links successfully (i.e., the symbol must exist in a linked library or object file). Compiler intrinsics may not be detected, as they are not always linkable or explicitly declared in headers. .sp Symbols that are types, enum values, or compiler intrinsics are not recognized. For those, consider using the \fBCheckTypeSize\fP \%<#\:module:CheckTypeSize> or \fBCheckSourceCompiles\fP \%<#\:module:CheckSourceCompiles> module instead. .sp This command is intended to check symbols as they appear in C. For C++ symbols, use the \fBCheckCXXSymbolExists\fP \%<#\:module:CheckCXXSymbolExists> module instead. .sp Variables Affecting the Check .sp The following variables may be set before calling this command to modify the way the check is run: .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_FLAGS\fP A space\-separated string of additional flags to pass to the compiler. A semicolon\-separated list \%<#\:cmake-language-lists> will not work. The contents of \fBCMAKE__FLAGS\fP \%<#\:variable:CMAKE__FLAGS> and its associated configuration\-specific \fBCMAKE__FLAGS_\fP \%<#\:variable:CMAKE__FLAGS_> variables are automatically prepended to the compiler command before the contents of this variable. .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_DEFINITIONS\fP A semicolon\-separated list \%<#\:cmake-language-lists> of compiler definitions, each of the form \fB\-DFOO\fP or \fB\-DFOO=bar\fP\&. A definition for the name specified by the result variable argument of the check command is also added automatically. .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_INCLUDES\fP A semicolon\-separated list \%<#\:cmake-language-lists> of header search paths to pass to the compiler. These will be the only header search paths used; the contents of the \fBINCLUDE_DIRECTORIES\fP \%<#\:prop_dir:INCLUDE_DIRECTORIES> directory property will be ignored. .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_LINK_OPTIONS\fP Added in version 3.14. .sp A semicolon\-separated list \%<#\:cmake-language-lists> of options to add to the link command (see \fBtry_compile()\fP \%<#\:command:try_compile> for further details). .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_LIBRARIES\fP A semicolon\-separated list \%<#\:cmake-language-lists> of libraries to add to the link command. These can be the names of system libraries, or they can be Imported Targets \%<#\:imported-targets> (see \fBtry_compile()\fP \%<#\:command:try_compile> for further details). .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_LINK_DIRECTORIES\fP Added in version 3.31. .sp A semicolon\-separated list \%<#\:cmake-language-lists> of library search paths to pass to the linker (see \fBtry_compile()\fP \%<#\:command:try_compile> for further details). .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_QUIET\fP Added in version 3.1. .sp If this variable evaluates to a boolean true value, all status messages associated with the check will be suppressed. .UNINDENT .UNINDENT .SS Examples .sp The following example demonstrates how to check for the presence of a preprocessor macro \fBSEEK_SET\fP and the C function \fBfopen()\fP from the \fB\fP header using this module: .INDENT 0.0 .INDENT 3.5 .sp .EX include(CheckSymbolExists) # Check for macro SEEK_SET check_symbol_exists(SEEK_SET \(dqstdio.h\(dq HAVE_SEEK_SET) # Check for function fopen check_symbol_exists(fopen \(dqstdio.h\(dq HAVE_FOPEN) .EE .UNINDENT .UNINDENT .SS See Also .INDENT 0.0 .IP \(bu 2 The \fBCheckCXXSymbolExists\fP \%<#\:module:CheckCXXSymbolExists> module to check whether a C++ symbol exists. .UNINDENT .SS CheckTypeSize .sp This module provides a command to check the size of a C/C++ type or expression. .sp Load this module in a CMake project with: .INDENT 0.0 .INDENT 3.5 .sp .EX include(CheckTypeSize) .EE .UNINDENT .UNINDENT .SS Commands .sp This module provides the following command: .INDENT 0.0 .TP .B check_type_size Checks once whether the C/C++ type or expression exists and determines its size: .INDENT 7.0 .INDENT 3.5 .sp .EX check_type_size( [RESULT_VARIABLE ] [BUILTIN_TYPES_ONLY] [LANGUAGE ] ) .EE .UNINDENT .UNINDENT .sp The arguments are: .INDENT 7.0 .TP .B \fB\fP The type or expression being checked. .TP .B \fB\fP The name of the internal cache variable for storing the size of the type or expression \fB\fP\&. This name is also used as a prefix as explained below. .TP .B \fBRESULT_VARIABLE \fP Added in version 4.2. .sp The name of the internal cache variable that holds a boolean value indicating whether the type or expression \fB\fP exists. If \fInot\fP given, the command will by default define an internal cache variable named \fBHAVE_\fP instead. .TP .B \fBBUILTIN_TYPES_ONLY\fP If given, only compiler\-builtin types will be supported in the check. If \fInot\fP given, the command checks for common headers \fB\fP, \fB\fP, and \fB\fP, and saves results in \fBHAVE_SYS_TYPES_H\fP, \fBHAVE_STDINT_H\fP, and \fBHAVE_STDDEF_H\fP internal cache variables. For C++ \fBstd::\fP types, \fB\fP and \fB\fP are also checked with \fBHAVE_CSTDINT\fP and \fBHAVE_CSTDDEF\fP defined respectively. The command automatically includes the available headers in the type size check, thus supporting checks of types defined in the headers. .TP .B \fBLANGUAGE \fP Uses the \fB\fP compiler to perform the check. Acceptable values are \fBC\fP and \fBCXX\fP\&. If not specified, it defaults to \fBC\fP\&. .UNINDENT .sp Result Variables .sp Results are reported in the following variables: .INDENT 7.0 .TP .B \fB\fP Internal cache variable that holds one of the following values: .INDENT 7.0 .TP .B \fB\fP If the type or expression \fB\fP exists, it will have a non\-zero size \fB\fP in bytes. .TP .B \fB0\fP When the type has an architecture\-dependent size; This may occur when \fBCMAKE_OSX_ARCHITECTURES\fP \%<#\:variable:CMAKE_OSX_ARCHITECTURES> has multiple architectures. In this case also the \fB_KEYS\fP variable is defined and the \fB_CODE\fP variable contains preprocessor tests mapping as explained below. .TP .B \(dq\(dq (empty string) When the type or expression \fB\fP does not exist. .UNINDENT .TP .B \fBHAVE_\fP Internal cache variable that holds a boolean value indicating whether the type or expression \fB\fP exists. This variable is defined when the \fBRESULT_VARIABLE\fP argument is not used. .TP .B \fB\fP Added in version 4.2. .sp Internal cache variable defined when the \fBRESULT_VARIABLE\fP argument is used. It holds a boolean value indicating whether the type or expression \fB\fP exists (same value as \fBHAVE_\fP). In this case, the \fBHAVE_\fP variable is not defined. .TP .B \fB_CODE\fP CMake variable that holds preprocessor code to define the macro \fB\fP to the size of the type, or to leave the macro undefined if the type does not exist. .sp When the type has an architecture\-dependent size (\fB\fP value is \fB0\fP) this variable contains preprocessor tests mapping from each architecture macro to the corresponding type size. .TP .B \fB_KEYS\fP CMake variable that is defined only when the type has an architecture\-dependent size (\fB\fP value is \fB0\fP) and contains a list of architecture macros. The value for each key is stored in \fB\-\fP variables. .UNINDENT .sp Variables Affecting the Check .sp The following variables may be set before calling this command to modify the way the check is run: .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_FLAGS\fP A space\-separated string of additional flags to pass to the compiler. A semicolon\-separated list \%<#\:cmake-language-lists> will not work. The contents of \fBCMAKE__FLAGS\fP \%<#\:variable:CMAKE__FLAGS> and its associated configuration\-specific \fBCMAKE__FLAGS_\fP \%<#\:variable:CMAKE__FLAGS_> variables are automatically prepended to the compiler command before the contents of this variable. .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_DEFINITIONS\fP A semicolon\-separated list \%<#\:cmake-language-lists> of compiler definitions, each of the form \fB\-DFOO\fP or \fB\-DFOO=bar\fP\&. A definition for the name specified by the result variable argument of the check command is also added automatically. .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_INCLUDES\fP A semicolon\-separated list \%<#\:cmake-language-lists> of header search paths to pass to the compiler. These will be the only header search paths used; the contents of the \fBINCLUDE_DIRECTORIES\fP \%<#\:prop_dir:INCLUDE_DIRECTORIES> directory property will be ignored. .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_LINK_OPTIONS\fP Added in version 3.14. .sp A semicolon\-separated list \%<#\:cmake-language-lists> of options to add to the link command (see \fBtry_compile()\fP \%<#\:command:try_compile> for further details). .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_LIBRARIES\fP A semicolon\-separated list \%<#\:cmake-language-lists> of libraries to add to the link command. These can be the names of system libraries, or they can be Imported Targets \%<#\:imported-targets> (see \fBtry_compile()\fP \%<#\:command:try_compile> for further details). .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_LINK_DIRECTORIES\fP Added in version 3.31. .sp A semicolon\-separated list \%<#\:cmake-language-lists> of library search paths to pass to the linker (see \fBtry_compile()\fP \%<#\:command:try_compile> for further details). .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_QUIET\fP Added in version 3.1. .sp If this variable evaluates to a boolean true value, all status messages associated with the check will be suppressed. .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_EXTRA_INCLUDE_FILES\fP A semicolon\-separated list \%<#\:cmake-language-lists> of extra header files to include when performing the check. .UNINDENT .UNINDENT .SS Examples .sp Consider the code: .INDENT 0.0 .INDENT 3.5 .sp .EX include(CheckTypeSize) # Check for size of long. check_type_size(long SIZEOF_LONG) message(\(dqHAVE_SIZEOF_LONG: ${HAVE_SIZEOF_LONG}\(dq) message(\(dqSIZEOF_LONG: ${SIZEOF_LONG}\(dq) message(\(dqSIZEOF_LONG_CODE: ${SIZEOF_LONG_CODE}\(dq) .EE .UNINDENT .UNINDENT .sp On a 64\-bit architecture, the output may look something like this: .INDENT 0.0 .INDENT 3.5 .sp .EX HAVE_SIZEOF_LONG: TRUE SIZEOF_LONG: 8 SIZEOF_LONG_CODE: #define SIZEOF_LONG 8 .EE .UNINDENT .UNINDENT .sp On Apple platforms, when \fBCMAKE_OSX_ARCHITECTURES\fP \%<#\:variable:CMAKE_OSX_ARCHITECTURES> has multiple architectures, types may have architecture\-dependent sizes. For example, with the code: .INDENT 0.0 .INDENT 3.5 .sp .EX include(CheckTypeSize) check_type_size(long SIZEOF_LONG) message(\(dqHAVE_SIZEOF_LONG: ${HAVE_SIZEOF_LONG}\(dq) message(\(dqSIZEOF_LONG: ${SIZEOF_LONG}\(dq) foreach(key IN LISTS SIZEOF_LONG_KEYS) message(\(dqkey: ${key}\(dq) message(\(dqvalue: ${SIZEOF_LONG\-${key}}\(dq) endforeach() message(\(dqSIZEOF_LONG_CODE:\en${SIZEOF_LONG_CODE}\(dq) .EE .UNINDENT .UNINDENT .sp the result may be: .INDENT 0.0 .INDENT 3.5 .sp .EX HAVE_SIZEOF_LONG: TRUE SIZEOF_LONG: 0 key: __i386 value: 4 key: __x86_64 value: 8 SIZEOF_LONG_CODE: #if defined(__i386) # define SIZEOF_LONG 4 #elif defined(__x86_64) # define SIZEOF_LONG 8 #else # error SIZEOF_LONG unknown #endif .EE .UNINDENT .UNINDENT .SS Example: Configuration Header .sp The next example demonstrates how the result variables can be used in a configuration header: .INDENT 0.0 .INDENT 3.5 .sp .EX include(CheckTypeSize) check_type_size(long SIZEOF_LONG) configure_file(config.h.in config.h @ONLY) .EE .UNINDENT .UNINDENT .sp \fBconfig.h.in\fP .INDENT 0.0 .INDENT 3.5 .sp .EX /* Define whether the type \(aqlong\(aq exists. */ #cmakedefine HAVE_SIZEOF_LONG /* The size of \(aqlong\(aq, as computed by sizeof. */ @SIZEOF_LONG_CODE@ .EE .UNINDENT .UNINDENT .SS Example: Checking Complex Expressions .sp Despite the name of this module, it may also be used to determine the size of more complex expressions. For example, to check the size of a struct member: .INDENT 0.0 .INDENT 3.5 .sp .EX include(CheckTypeSize) check_type_size(\(dq((struct something*)0)\->member\(dq SIZEOF_MEMBER) .EE .UNINDENT .UNINDENT .SS Example: Isolated Check .sp In the following example, the check is performed with temporarily modified additional headers using the \fBCMAKE_EXTRA_INCLUDE_FILES\fP variable and \fBCMakePushCheckState\fP \%<#\:module:CMakePushCheckState> module. The result of the check is stored in \fBHAVE_SIZEOF_UNION_SEMUN\fP, and size is stored in \fBSIZEOF_UNION_SEMUN\fP internal cache variables. .INDENT 0.0 .INDENT 3.5 .sp .EX include(CheckTypeSize) include(CMakePushCheckState) cmake_push_check_state(RESET) set(CMAKE_EXTRA_INCLUDE_FILES sys/types.h sys/ipc.h sys/sem.h) check_type_size(\(dqunion semun\(dq SIZEOF_UNION_SEMUN) cmake_pop_check_state() .EE .UNINDENT .UNINDENT .SS Example: Customizing Result Variable .sp Since CMake 4.2, the \fBHAVE_\fP variable name can be customized using the \fBRESULT_VARIABLE\fP argument. In the following example, this module is used to check whether the \fBstruct flock\fP exists, and the result is stored in the \fBMyProj_HAVE_STRUCT_FLOCK\fP internal cache variable: .INDENT 0.0 .INDENT 3.5 .sp .EX cmake_minimum_required(VERSION 4.2) # ... include(CheckTypeSize) include(CMakePushCheckState) cmake_push_check_state(RESET) set(CMAKE_EXTRA_INCLUDE_FILES \(dqfcntl.h\(dq) check_type_size( \(dqstruct flock\(dq MyProj_SIZEOF_STRUCT_FLOCK RESULT_VARIABLE MyProj_HAVE_STRUCT_FLOCK ) cmake_pop_check_state() .EE .UNINDENT .UNINDENT .SS CheckVariableExists .sp This module provides a command to check whether a C variable exists. .sp Load this module in a CMake project with: .INDENT 0.0 .INDENT 3.5 .sp .EX include(CheckVariableExists) .EE .UNINDENT .UNINDENT .SS Commands .sp This module provides the following command: .INDENT 0.0 .TP .B check_variable_exists Checks once if a C variable exists: .INDENT 7.0 .INDENT 3.5 .sp .EX check_variable_exists( ) .EE .UNINDENT .UNINDENT .sp This command attempts to compile and link a test C program that references the specified C variable \fB\fP\&. A boolean result of whether the check was successful is stored in an internal cache variable \fB\fP\&. .sp \fBNote:\fP .INDENT 7.0 .INDENT 3.5 Prefer using \fBCheckSymbolExists\fP \%<#\:module:CheckSymbolExists> or \fBCheckSourceCompiles\fP \%<#\:module:CheckSourceCompiles> instead of this command for more robust detection. This command performs a link\-only check and doesn\(aqt detect whether a variable is also declared in system or library headers. Neither can it detect variables that might be defined as preprocessor macros. .UNINDENT .UNINDENT .sp Variables Affecting the Check .sp The following variables may be set before calling this command to modify the way the check is run: .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_FLAGS\fP A space\-separated string of additional flags to pass to the compiler. A semicolon\-separated list \%<#\:cmake-language-lists> will not work. The contents of \fBCMAKE__FLAGS\fP \%<#\:variable:CMAKE__FLAGS> and its associated configuration\-specific \fBCMAKE__FLAGS_\fP \%<#\:variable:CMAKE__FLAGS_> variables are automatically prepended to the compiler command before the contents of this variable. .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_DEFINITIONS\fP A semicolon\-separated list \%<#\:cmake-language-lists> of compiler definitions, each of the form \fB\-DFOO\fP or \fB\-DFOO=bar\fP\&. A definition for the name specified by the result variable argument of the check command is also added automatically. .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_LINK_OPTIONS\fP Added in version 3.14. .sp A semicolon\-separated list \%<#\:cmake-language-lists> of options to add to the link command (see \fBtry_compile()\fP \%<#\:command:try_compile> for further details). .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_LIBRARIES\fP A semicolon\-separated list \%<#\:cmake-language-lists> of libraries to add to the link command. These can be the names of system libraries, or they can be Imported Targets \%<#\:imported-targets> (see \fBtry_compile()\fP \%<#\:command:try_compile> for further details). .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_LINK_DIRECTORIES\fP Added in version 3.31. .sp A semicolon\-separated list \%<#\:cmake-language-lists> of library search paths to pass to the linker (see \fBtry_compile()\fP \%<#\:command:try_compile> for further details). .UNINDENT .INDENT 7.0 .TP .B \fBCMAKE_REQUIRED_QUIET\fP Added in version 3.1. .sp If this variable evaluates to a boolean true value, all status messages associated with the check will be suppressed. .UNINDENT .UNINDENT .SS Examples .SS Example: Basic Usage .sp In the following example, a check is performed whether the linker sees the C variable \fBtzname\fP and stores the check result in the \fBPROJECT_HAVE_TZNAME\fP internal cache variable: .INDENT 0.0 .INDENT 3.5 .sp .EX include(CheckVariableExists) check_variable_exists(tzname PROJECT_HAVE_TZNAME) .EE .UNINDENT .UNINDENT .SS Example: Isolated Check With Linked Libraries .sp In the following example, this module is used in combination with the \fBCMakePushCheckState\fP \%<#\:module:CMakePushCheckState> module to link additional required library using the \fBCMAKE_REQUIRED_LIBRARIES\fP variable. For example, in a find module, to check whether the Net\-SNMP library has the \fBusmHMAC192SHA256AuthProtocol\fP array: .INDENT 0.0 .INDENT 3.5 .sp .EX include(CheckVariableExists) include(CMakePushCheckState) find_library(SNMP_LIBRARY NAMES netsnmp) if(SNMP_LIBRARY) cmake_push_check_state(RESET) set(CMAKE_REQUIRED_LIBRARIES ${SNMP_LIBRARY}) check_variable_exists(usmHMAC192SHA256AuthProtocol SNMP_HAVE_SHA256) cmake_pop_check_state() endif() .EE .UNINDENT .UNINDENT .SS See Also .INDENT 0.0 .IP \(bu 2 The \fBCheckSymbolExists\fP \%<#\:module:CheckSymbolExists> module to check whether a C symbol exists. .UNINDENT .SS CMakeAddFortranSubdirectory .sp This module provides a command to add a Fortran project located in a subdirectory. .sp Load this module in a CMake project with: .INDENT 0.0 .INDENT 3.5 .sp .EX include(CMakeAddFortranSubdirectory) .EE .UNINDENT .UNINDENT .SS Commands .sp This module provides the following command: .INDENT 0.0 .TP .B cmake_add_fortran_subdirectory Adds a Fortran\-only subproject from subdirectory to the current project: .INDENT 7.0 .INDENT 3.5 .sp .EX cmake_add_fortran_subdirectory( PROJECT ARCHIVE_DIR RUNTIME_DIR LIBRARIES ... LINK_LIBRARIES [LINK_LIBS ...]... [CMAKE_COMMAND_LINE ...] NO_EXTERNAL_INSTALL ) .EE .UNINDENT .UNINDENT .sp This command checks whether the current compiler supports Fortran or attempts to locate a Fortran compiler. If a compatible Fortran compiler is found, the Fortran project located in \fB\fP is added as a subdirectory to the current project. .sp If no Fortran compiler is found and the compiler is \fBMSVC\fP, it searches for the MinGW \fBgfortran\fP compiler. In this case, the Fortran project is built as an external project using MinGW tools, and Fortran\-related imported targets are created. This setup works only if the Fortran code is built as a shared DLL library, so the \fBBUILD_SHARED_LIBS\fP \%<#\:variable:BUILD_SHARED_LIBS> variable is enabled in the external project. Additionally, the \fBCMAKE_GNUtoMS\fP \%<#\:variable:CMAKE_GNUtoMS> variable is set to \fBON\fP to ensure that Microsoft\-compatible \fB\&.lib\fP files are created. .sp The options are: .INDENT 7.0 .TP .B \fBPROJECT\fP The name of the Fortran project as defined in the top\-level \fBCMakeLists.txt\fP located in \fB\fP\&. .TP .B \fBARCHIVE_DIR\fP Directory where the project places \fB\&.lib\fP archive files. A relative path is interpreted as relative to \fBCMAKE_CURRENT_BINARY_DIR\fP \%<#\:variable:CMAKE_CURRENT_BINARY_DIR>\&. .TP .B \fBRUNTIME_DIR\fP Directory where the project places \fB\&.dll\fP runtime files. A relative path is interpreted as relative to \fBCMAKE_CURRENT_BINARY_DIR\fP \%<#\:variable:CMAKE_CURRENT_BINARY_DIR>\&. .TP .B \fBLIBRARIES\fP Names of library targets to create or import into the current project. .TP .B \fBLINK_LIBRARIES\fP Specifies link interface libraries for \fBLIBRARIES\fP\&. This option expects a list of \fBLINK_LIBS ...\fP items, where: .INDENT 7.0 .IP \(bu 2 \fBLINK_LIBS\fP marks the start of a new pair .IP \(bu 2 \fB\fP is a library target. .IP \(bu 2 \fB...\fP represents one or more dependencies required by \fB\fP\&. .UNINDENT .TP .B \fBCMAKE_COMMAND_LINE\fP Additional command\-line flags passed to \fBcmake(1)\fP \%<#\:manual:cmake(1)> command when configuring the Fortran subproject. .TP .B \fBNO_EXTERNAL_INSTALL\fP Prevents installation of the external project. .sp \fBNote:\fP .INDENT 7.0 .INDENT 3.5 The \fBNO_EXTERNAL_INSTALL\fP option is required for forward compatibility with a future version that supports installation of the external project binaries during \fBmake install\fP\&. .UNINDENT .UNINDENT .UNINDENT .UNINDENT .SS Examples .sp Adding a Fortran subdirectory to a project can be done by including this module and calling the \fBcmake_add_fortran_subdirectory()\fP command. In the following example, a Fortran project provides the \fBhello\fP library and its dependent \fBworld\fP library: .INDENT 0.0 .INDENT 3.5 .sp .EX include(CMakeAddFortranSubdirectory) cmake_add_fortran_subdirectory( fortran\-subdir PROJECT FortranHelloWorld ARCHIVE_DIR lib RUNTIME_DIR bin LIBRARIES hello world LINK_LIBRARIES LINK_LIBS hello world # hello library depends on the world library NO_EXTERNAL_INSTALL ) # The Fortran target can be then linked to the main project target. add_executable(main main.c) target_link_libraries(main PRIVATE hello) .EE .UNINDENT .UNINDENT .SS See Also .sp There are multiple ways to integrate Fortran libraries. Alternative approaches include: .INDENT 0.0 .IP \(bu 2 The \fBadd_subdirectory()\fP \%<#\:command:add_subdirectory> command to add the subdirectory directly to the build. .IP \(bu 2 The \fBexport()\fP \%<#\:command:export> command can be used in the subproject to provide Imported Targets \%<#\:imported-targets> or similar for integration with other projects. .IP \(bu 2 The \fBFetchContent\fP \%<#\:module:FetchContent> or \fBExternalProject\fP \%<#\:module:ExternalProject> modules when working with external dependencies. .UNINDENT .SS CMakeBackwardCompatibilityCXX .sp This module defines several backward compatibility cache variables for the \fBCXX\fP language to support early C++ (pre\-C++98, ANSI C++). .sp Load this module in a CMake project with: .INDENT 0.0 .INDENT 3.5 .sp .EX include(CMakeBackwardCompatibilityCXX) .EE .UNINDENT .UNINDENT .sp The following modules are included by this module: .INDENT 0.0 .IP \(bu 2 \fBTestForANSIForScope\fP \%<#\:module:TestForANSIForScope> .IP \(bu 2 \fBTestForANSIStreamHeaders\fP \%<#\:module:TestForANSIStreamHeaders> .IP \(bu 2 \fBTestForSSTREAM\fP \%<#\:module:TestForSSTREAM> .IP \(bu 2 \fBTestForSTDNamespace\fP \%<#\:module:TestForSTDNamespace> .UNINDENT .sp Additionally, the following cache variable may be defined: .INDENT 0.0 .TP .B \fBCMAKE_ANSI_CXXFLAGS\fP A space\-separated string of compiler options for enabling ANSI C++ mode, if available. .UNINDENT .sp \fBNote:\fP .INDENT 0.0 .INDENT 3.5 This module is intended for C++ code written before \fBC++ 98\fP\&. As of the \fBC++ 98\fP standard, these issues have been formally addressed, making such checks obsolete. .UNINDENT .UNINDENT .SS Examples .sp Including this module provides backward compatibility cache variables, which can be used in C++. For example: .sp \fBCMakeLists.txt\fP .INDENT 0.0 .INDENT 3.5 .sp .EX include(CMakeBackwardCompatibilityCXX) file( CONFIGURE OUTPUT config.h CONTENT [[ #cmakedefine CMAKE_NO_ANSI_FOR_SCOPE #cmakedefine CMAKE_NO_ANSI_STRING_STREAM #cmakedefine CMAKE_NO_ANSI_STREAM_HEADERS #cmakedefine CMAKE_NO_STD_NAMESPACE ]] ) .EE .UNINDENT .UNINDENT .SS CMakeDependentOption .sp This module provides a command to define boolean options whose availability and default values depend on specified conditions or other options. This helps maintain a clean configuration interface by only displaying options that are relevant to the current settings. .sp Load this module in CMake with: .INDENT 0.0 .INDENT 3.5 .sp .EX include(CMakeDependentOption) .EE .UNINDENT .UNINDENT .SS Commands .sp This module provides the following command: .INDENT 0.0 .TP .B cmake_dependent_option Provides a boolean option that depends on a set of conditions: .INDENT 7.0 .INDENT 3.5 .sp .EX cmake_dependent_option( ) .EE .UNINDENT .UNINDENT .sp This command creates a boolean \fB\fP and makes it available to the user in the GUI (such as \fBcmake\-gui(1)\fP \%<#\:manual:cmake-gui(1)> or \fBccmake(1)\fP \%<#\:manual:ccmake(1)>), if a set of conditions evaluates to boolean true. .sp The arguments are: .INDENT 7.0 .TP .B \fB\fP The name of a variable that stores the option value. .TP .B \fB\fP A brief description of the option. This string is typically a short line of text and is displayed in the GUI. .TP .B \fB\fP Boolean value for the \fB\fP, when \fB\fP evaluates to boolean true. .TP .B \fB\fP Specifies the conditions that determine whether \fB\fP is set and visible in the GUI. .INDENT 7.0 .IP \(bu 2 If \fB\fP evaluates to boolean false, option is hidden from the user in the GUI, and a local variable \fB\fP is set to \fB\fP\&. .IP \(bu 2 If \fB\fP evaluates to boolean true, a boolean cache variable named \fB\fP is created with default \fB\fP, and option is shown in the GUI, allowing the user to enable or disable it. .IP \(bu 2 If \fB\fP later evaluates to boolean false (on consecutive configuration run), option is hidden from the user in the GUI and the \fB\fP type is changed to an internal cache variable. In that case a local variable of the same name is set to \fB\fP\&. .IP \(bu 2 If \fB\fP becomes true again in consecutive configuration runs, the user\(aqs previously set value is preserved. .UNINDENT .sp The \fB\fP argument can be: .INDENT 7.0 .IP \(bu 2 A single condition (such as a variable name). .IP \(bu 2 A semicolon\-separated list \%<#\:cmake-language-lists> of multiple conditions. .IP \(bu 2 Added in version 3.22: A full Condition Syntax \%<#\:condition-syntax> as used in an \fBif()\fP clause. See policy \fBCMP0127\fP \%<#\:policy:CMP0127>\&. This enables using entire condition syntax (such as grouping conditions with parens and similar). .UNINDENT .TP .B \fB\fP The value assigned to a local variable named \fB\fP, when \fB\fP evaluates to boolean false. .UNINDENT .sp In CMake project mode, boolean cache variables are created as explained above. In CMake script mode, boolean variables are set instead. .UNINDENT .SS Examples .SS Example: Basic Usage .sp Using this module in a project to conditionally set an option: .sp \fBCMakeLists.txt\fP .INDENT 0.0 .INDENT 3.5 .sp .EX include(CMakeDependentOption) cmake_dependent_option(USE_SSL_GNUTLS \(dqUse GnuTLS for SSL\(dq ON USE_SSL OFF) .EE .UNINDENT .UNINDENT .SS Example: Enabling/Disabling Dependent Option .sp Extending the previous example, this demonstrates how the module allows user\-configurable options based on a condition during the configuration phase: .sp \fBCMakeLists.txt\fP .INDENT 0.0 .INDENT 3.5 .sp .EX include(CMakeDependentOption) option(USE_SSL \(dqEnable SSL in the project\(dq OFF) cmake_dependent_option(USE_SSL_GNUTLS \(dqUse GnuTLS for SSL\(dq ON USE_SSL OFF) message(STATUS \(dqUSE_SSL: ${USE_SSL}\(dq) message(STATUS \(dqUSE_SSL_GNUTLS: ${USE_SSL_GNUTLS}\(dq) .EE .UNINDENT .UNINDENT .sp On the first configuration run, a boolean cache variable \fBUSE_SSL\fP is set to OFF, and a local variable \fBUSE_SSL_GNUTLS\fP is set to OFF: .INDENT 0.0 .INDENT 3.5 .sp .EX $ cmake \-B build\-dir \-\- USE_SSL: OFF \-\- USE_SSL_GNUTLS: OFF .EE .UNINDENT .UNINDENT .sp Running CMake with \fBUSE_SSL=ON\fP sets both \fBUSE_SSL\fP and \fBUSE_SSL_GNUTLS\fP boolean cache variables to ON: .INDENT 0.0 .INDENT 3.5 .sp .EX $ cmake \-B build\-dir \-D USE_SSL=ON \-\- USE_SSL: ON \-\- USE_SSL_GNUTLS: ON .EE .UNINDENT .UNINDENT .sp On a subsequent configuration run with \fBUSE_SSL=OFF\fP, \fBUSE_SSL_GNUTLS\fP follows suit. However, its value is preserved in the internal cache while being overridden locally: .INDENT 0.0 .INDENT 3.5 .sp .EX $ cmake \-B build\-dir \-D USE_SSL=OFF \-\- USE_SSL: OFF \-\- USE_SSL_GNUTLS: OFF .EE .UNINDENT .UNINDENT .SS Example: Semicolon\-separated List of Conditions .sp The \fB\fP argument can also be a semicolon\-separated list of conditions. In the following example, if the variable \fBUSE_BAR\fP is ON and variable \fBUSE_ZOT\fP is OFF, the option \fBUSE_FOO\fP is available and defaults to ON. Otherwise, \fBUSE_FOO\fP is set to OFF and hidden from the user. .sp If the values of \fBUSE_BAR\fP or \fBUSE_ZOT\fP change in the future configuration runs, the previous value of \fBUSE_FOO\fP is preserved so that when it becomes available again, it retains its last set value. .sp \fBCMakeLists.txt\fP .INDENT 0.0 .INDENT 3.5 .sp .EX include(CMakeDependentOption) cmake_dependent_option(USE_FOO \(dqUse Foo\(dq ON \(dqUSE_BAR;NOT USE_ZOT\(dq OFF) .EE .UNINDENT .UNINDENT .SS Example: Full Condition Syntax .sp As of CMake 3.22, \fBcmake_dependent_option()\fP supports full condition syntax. .sp In fhe following example, if the condition evaluates to true, the option \fBUSE_FOO\fP is available and set to ON. Otherwise, it is set to OFF and hidden in the GUI. The value of \fBUSE_FOO\fP is preserved across configuration runs, similar to the previous example. .sp \fBCMakeLists.txt\fP .INDENT 0.0 .INDENT 3.5 .sp .EX include(CMakeDependentOption) cmake_dependent_option(USE_FOO \(dqUse Foo\(dq ON \(dqUSE_A AND (USE_B OR USE_C)\(dq OFF) .EE .UNINDENT .UNINDENT .sp Another example demonstrates how an option can be conditionally available based on the target system: .sp \fBCMakeLists.txt\fP .INDENT 0.0 .INDENT 3.5 .sp .EX include(CMakeDependentOption) cmake_dependent_option( ENABLE_FOO \(dqEnable feature Foo (this option is available when building for Windows)\(dq ON [[CMAKE_SYSTEM_NAME STREQUAL \(dqWindows\(dq]] OFF ) .EE .UNINDENT .UNINDENT .SS See Also .INDENT 0.0 .IP \(bu 2 The \fBoption()\fP \%<#\:command:option> command to provide a boolean option that the user can optionally select. .UNINDENT .SS CMakeFindDependencyMacro .sp This module provides a command implemented as a macro that finds dependency for a package. .sp Load this module in a CMake package configuration file with: .sp \fBFooConfig.cmake\fP or \fBfoo\-config.cmake\fP: .INDENT 0.0 .INDENT 3.5 .sp .EX include(CMakeFindDependencyMacro) .EE .UNINDENT .UNINDENT .sp \fBNote:\fP .INDENT 0.0 .INDENT 3.5 This module is designed to be used in a Package Configuration File \%<#\:config-file-packages> (\fBConfig.cmake\fP). .UNINDENT .UNINDENT .SS Commands .sp This module provides the following command: .INDENT 0.0 .TP .B find_dependency The \fBfind_dependency()\fP macro wraps a \fBfind_package()\fP \%<#\:command:find_package> call for a package dependency: .INDENT 7.0 .INDENT 3.5 .sp .EX find_dependency( [...]) .EE .UNINDENT .UNINDENT .sp It is designed to be used in a Package Configuration File \%<#\:config-file-packages> (\fBConfig.cmake\fP). \fBfind_dependency\fP forwards the correct parameters for \fBQUIET\fP and \fBREQUIRED\fP which were passed to the original \fBfind_package()\fP \%<#\:command:find_package> call. Any additional arguments specified are forwarded to \fBfind_package()\fP \%<#\:command:find_package>\&. .sp If the dependency could not be found it sets an informative diagnostic message and calls \fBreturn()\fP \%<#\:command:return> to end processing of the calling package configuration file and return to the \fBfind_package()\fP \%<#\:command:find_package> command that loaded it. .sp \fBNote:\fP .INDENT 7.0 .INDENT 3.5 The call to \fBreturn()\fP \%<#\:command:return> makes this macro unsuitable to call from Find Modules \%<#\:find-modules>\&. .UNINDENT .UNINDENT .UNINDENT .SS Package Dependency Search Optimizations .sp If \fBfind_dependency\fP is called with arguments identical to a previous call in the same directory, perhaps due to diamond\-shaped package dependencies, the underlying call to \fBfind_package()\fP \%<#\:command: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 \fB_USE_STATIC_LIBS\fP, offered by some packages. Therefore package configuration files should avoid setting such variables before their calls to \fBfind_dependency\fP\&. .sp Changed in version 3.15: Previously, the underlying call to \fBfind_package()\fP \%<#\:command:find_package> was always optimized out if the package had already been found. CMake 3.15 removed the optimization to support cases in which \fBfind_dependency\fP call arguments request different components. .sp Changed in version 3.26: The pre\-3.15 optimization was restored, but with the above\-described heuristic to account for varying \fBfind_dependency\fP call arguments. .SS CMakePackageConfigHelpers .sp This module provides helper commands for creating config files \%<#\:libraries-providing-config-file-packages> that can be included by other projects to find and use a package. .sp Load this module in a CMake project with: .INDENT 0.0 .INDENT 3.5 .sp .EX include(CMakePackageConfigHelpers) .EE .UNINDENT .UNINDENT .SS Generating a Package Configuration File .INDENT 0.0 .TP .B configure_package_config_file Create a config file for a project: .INDENT 7.0 .INDENT 3.5 .sp .EX configure_package_config_file( INSTALL_DESTINATION [PATH_VARS ... ] [NO_SET_AND_CHECK_MACRO] [NO_CHECK_REQUIRED_COMPONENTS_MACRO] [INSTALL_PREFIX ] ) .EE .UNINDENT .UNINDENT .UNINDENT .sp \fBconfigure_package_config_file()\fP should be used instead of the plain \fBconfigure_file()\fP \%<#\:command:configure_file> command when creating the \fBConfig.cmake\fP or \fB\-config.cmake\fP file for installing a project or library. It helps make the resulting package relocatable by avoiding hardcoded paths in the installed \fBConfig.cmake\fP file. .sp In a \fBFooConfig.cmake\fP file there may be code like this to make the install destinations known to the using project: .INDENT 0.0 .INDENT 3.5 .sp .EX set(FOO_INCLUDE_DIR \(dq@CMAKE_INSTALL_FULL_INCLUDEDIR@\(dq ) set(FOO_DATA_DIR \(dq@CMAKE_INSTALL_PREFIX@/@RELATIVE_DATA_INSTALL_DIR@\(dq ) set(FOO_ICONS_DIR \(dq@CMAKE_INSTALL_PREFIX@/share/icons\(dq ) #...logic to determine installedPrefix from the own location... set(FOO_CONFIG_DIR \(dq${installedPrefix}/@CONFIG_INSTALL_DIR@\(dq ) .EE .UNINDENT .UNINDENT .sp 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 \fBinstalledPrefix\fP is correct, and if \fBCONFIG_INSTALL_DIR\fP contains a relative path, which in general cannot be guaranteed. This has the effect that the resulting \fBFooConfig.cmake\fP 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 \fBCMAKE_INSTALL_PREFIX\fP \%<#\:variable:CMAKE_INSTALL_PREFIX> was set at build/cmake time. .sp Using \fBconfigure_package_config_file()\fP helps. If used correctly, it makes the resulting \fBFooConfig.cmake\fP file relocatable. Usage: .INDENT 0.0 .IP 1. 3 Write a \fBFooConfig.cmake.in\fP file as you are used to. .IP 2. 3 Insert a line at the top containing only the string \fB@PACKAGE_INIT@\fP\&. .IP 3. 3 Instead of \fBset(FOO_DIR \(dq@SOME_INSTALL_DIR@\(dq)\fP, use \fBset(FOO_DIR \(dq@PACKAGE_SOME_INSTALL_DIR@\(dq)\fP (this must be after the \fB@PACKAGE_INIT@\fP line). .IP 4. 3 Instead of using the normal \fBconfigure_file()\fP \%<#\:command:configure_file> command, use \fBconfigure_package_config_file()\fP\&. .UNINDENT .sp The \fB\fP and \fB\fP arguments are the input and output file, the same way as in \fBconfigure_file()\fP \%<#\:command:configure_file>\&. .sp The \fB\fP given to \fBINSTALL_DESTINATION\fP must be the destination where the \fBFooConfig.cmake\fP file will be installed to. This path can either be absolute, or relative to the \fBINSTALL_PREFIX\fP path. .sp The variables \fB\fP to \fB\fP given as \fBPATH_VARS\fP are the variables which contain install destinations. For each of them, the macro will create a helper variable \fBPACKAGE_\fP\&. These helper variables must be used in the \fBFooConfig.cmake.in\fP file for setting the installed location. They are calculated by \fBconfigure_package_config_file()\fP 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 \fBINSTALL_PREFIX\fP\&. .sp Added in version 3.30: The variable \fBPACKAGE_PREFIX_DIR\fP will always be defined after the \fB@PACKAGE_INIT@\fP line. It will hold the value of the base install location. In general, variables defined via the \fBPATH_VARS\fP mechanism should be used instead, but \fBPACKAGE_PREFIX_DIR\fP can be used for those cases not easily handled by \fBPATH_VARS\fP, such as for files installed directly to the base install location rather than a subdirectory of it. .sp \fBNote:\fP .INDENT 0.0 .INDENT 3.5 When consumers of the generated file use CMake 3.29 or older, the value of \fBPACKAGE_PREFIX_DIR\fP can be changed by a call to \fBfind_dependency()\fP \%<#\:command:find_dependency> or \fBfind_package()\fP \%<#\:command:find_package>\&. If a project relies on \fBPACKAGE_PREFIX_DIR\fP, it is the project\(aqs responsibility to ensure that the value of \fBPACKAGE_PREFIX_DIR\fP is preserved across any such calls, or any other calls which might include another file generated by \fBconfigure_package_config_file()\fP\&. .UNINDENT .UNINDENT .sp Added in version 3.1: If the \fBINSTALL_PREFIX\fP argument is passed, this is used as the base path to calculate all the relative paths. The \fB\fP argument must be an absolute path. If this argument is not passed, the \fBCMAKE_INSTALL_PREFIX\fP \%<#\:variable:CMAKE_INSTALL_PREFIX> variable will be used instead. The default value is good when generating a \fBFooConfig.cmake\fP file to use your package from the install tree. When generating a \fBFooConfig.cmake\fP file to use your package from the build tree, this option should be used. .sp By default, \fBconfigure_package_config_file()\fP also generates two helper macros, \fBset_and_check()\fP and \fBcheck_required_components()\fP, into the \fBFooConfig.cmake\fP file. .sp \fBset_and_check()\fP should be used instead of the normal \fBset()\fP \%<#\:command: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\(aqt. This ensures that the generated \fBFooConfig.cmake\fP file does not contain wrong references. Add the \fBNO_SET_AND_CHECK_MACRO\fP option to prevent the generation of the \fBset_and_check()\fP macro in the \fBFooConfig.cmake\fP file. .sp \fBcheck_required_components()\fP should be called at the end of the \fBFooConfig.cmake\fP file. This macro checks whether all requested, non\-optional components have been found, and if this is not the case, it sets the \fBFoo_FOUND\fP variable to \fBFALSE\fP so that the package is considered to be not found. It does that by testing the \fBFoo__FOUND\fP variables for all requested required components. This macro should be called even if the package doesn\(aqt provide any components to make sure users are not specifying components erroneously. Add the \fBNO_CHECK_REQUIRED_COMPONENTS_MACRO\fP option to prevent the generation of the \fBcheck_required_components()\fP macro in the \fBFooConfig.cmake\fP file. .sp See also Example Generating Package Files\&. .SS Generating a Package Version File .INDENT 0.0 .TP .B write_basic_package_version_file Create a version file for a project: .INDENT 7.0 .INDENT 3.5 .sp .EX write_basic_package_version_file( [VERSION ] COMPATIBILITY [ARCH_INDEPENDENT] ) .EE .UNINDENT .UNINDENT .UNINDENT .sp Writes a file for use as a \fBConfigVersion.cmake\fP file to \fB\fP\&. See the documentation of \fBfind_package()\fP \%<#\:command:find_package> for details on such files. .sp \fB\fP is the output filename, which should be in the build tree. \fB\fP is the version number of the project to be installed. .sp If no \fBVERSION\fP is given, the \fBPROJECT_VERSION\fP \%<#\:variable:PROJECT_VERSION> variable is used. If this hasn\(aqt been set, it errors out. .sp The \fBCOMPATIBILITY\fP mode \fBAnyNewerVersion\fP 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 \fBSameMajorVersion\fP is used instead, then the behavior differs from \fBAnyNewerVersion\fP 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 \fBSameMinorVersion\fP is used, the behavior is the same as \fBSameMajorVersion\fP, 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 \fBExactVersion\fP 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 \fBConfigVersion.cmake\fP file instead of using this macro. .sp Added in version 3.11: The \fBSameMinorVersion\fP compatibility mode. .sp Added in version 3.14: If \fBARCH_INDEPENDENT\fP 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 \fBARCH_INDEPENDENT\fP is given, in which case the package is considered compatible on any architecture. .sp \fBNote:\fP .INDENT 0.0 .INDENT 3.5 \fBARCH_INDEPENDENT\fP is intended for header\-only libraries or similar packages with no binaries. .UNINDENT .UNINDENT .sp Added in version 3.19: The version file generated by \fBAnyNewerVersion\fP, \fBSameMajorVersion\fP and \fBSameMinorVersion\fP arguments of \fBCOMPATIBILITY\fP handle the version range, if one is specified (see \fBfind_package()\fP \%<#\:command:find_package> command for the details). \fBExactVersion\fP mode is incompatible with version ranges and will display an author warning if one is specified. .sp Internally, this macro executes \fBconfigure_file()\fP \%<#\:command:configure_file> to create the resulting version file. Depending on the \fBCOMPATIBILITY\fP, the corresponding \fBBasicConfigVersion\-.cmake.in\fP file is used. Please note that these files are internal to CMake and you should not call \fBconfigure_file()\fP \%<#\:command:configure_file> on them yourself, but they can be used as a starting point to create more sophisticated custom \fBConfigVersion.cmake\fP files. .SS Generating an Apple Platform Selection File .INDENT 0.0 .TP .B generate_apple_platform_selection_file Added in version 3.29. .sp Create an Apple platform selection file: .INDENT 7.0 .INDENT 3.5 .sp .EX generate_apple_platform_selection_file( INSTALL_DESTINATION [INSTALL_PREFIX ] [MACOS_INCLUDE_FILE ] [IOS_INCLUDE_FILE ] [IOS_SIMULATOR_INCLUDE_FILE ] [IOS_CATALYST_INCLUDE_FILE ] [TVOS_INCLUDE_FILE ] [TVOS_SIMULATOR_INCLUDE_FILE ] [WATCHOS_INCLUDE_FILE ] [WATCHOS_SIMULATOR_INCLUDE_FILE ] [VISIONOS_INCLUDE_FILE ] [VISIONOS_SIMULATOR_INCLUDE_FILE ] [ERROR_VARIABLE ] ) .EE .UNINDENT .UNINDENT .sp Write a file that includes an Apple\-platform\-specific \fB\&.cmake\fP file, e.g., for use as \fBConfig.cmake\fP\&. This can be used in conjunction with the \fBXCFRAMEWORK_LOCATION\fP argument of \fBexport(SETUP)\fP \%<#\:setup> to export packages in a way that a project built for any Apple platform can use them. .INDENT 7.0 .TP .B \fBINSTALL_DESTINATION \fP Path to which the generated file will be installed by the caller, e.g., via \fBinstall(FILES)\fP \%<#\:files>\&. The path may be either relative to the \fBINSTALL_PREFIX\fP or absolute. .TP .B \fBINSTALL_PREFIX \fP Path prefix to which the package will be installed by the caller. The \fB\fP argument must be an absolute path. If this argument is not passed, the \fBCMAKE_INSTALL_PREFIX\fP \%<#\:variable:CMAKE_INSTALL_PREFIX> variable will be used instead. .TP .B \fBMACOS_INCLUDE_FILE \fP File to include if the platform is macOS. .TP .B \fBIOS_INCLUDE_FILE \fP File to include if the platform is iOS. .TP .B \fBIOS_SIMULATOR_INCLUDE_FILE \fP File to include if the platform is iOS Simulator. .TP .B \fBIOS_CATALYST_INCLUDE_FILE \fP Added in version 3.31. .sp File to include if the platform is iOS Catalyst. .TP .B \fBTVOS_INCLUDE_FILE \fP File to include if the platform is tvOS. .TP .B \fBTVOS_SIMULATOR_INCLUDE_FILE \fP File to include if the platform is tvOS Simulator. .TP .B \fBWATCHOS_INCLUDE_FILE \fP File to include if the platform is watchOS. .TP .B \fBWATCHOS_SIMULATOR_INCLUDE_FILE \fP File to include if the platform is watchOS Simulator. .TP .B \fBVISIONOS_INCLUDE_FILE \fP File to include if the platform is visionOS. .TP .B \fBVISIONOS_SIMULATOR_INCLUDE_FILE \fP File to include if the platform is visionOS Simulator. .TP .B \fBERROR_VARIABLE \fP If the consuming project is built for an unsupported platform, set \fB\fP 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. .UNINDENT .sp 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 \fBERROR_VARIABLE\fP option. .UNINDENT .SS Generating an Apple Architecture Selection File .INDENT 0.0 .TP .B generate_apple_architecture_selection_file Added in version 3.29. .sp Create an Apple architecture selection file: .INDENT 7.0 .INDENT 3.5 .sp .EX generate_apple_architecture_selection_file( INSTALL_DESTINATION [INSTALL_PREFIX ] [SINGLE_ARCHITECTURES ... SINGLE_ARCHITECTURE_INCLUDE_FILES ...] [UNIVERSAL_ARCHITECTURES ... UNIVERSAL_INCLUDE_FILE ] [ERROR_VARIABLE ] ) .EE .UNINDENT .UNINDENT .sp Write a file that includes an Apple\-architecture\-specific \fB\&.cmake\fP file based on \fBCMAKE_OSX_ARCHITECTURES\fP \%<#\:variable:CMAKE_OSX_ARCHITECTURES>, e.g., for inclusion from an Apple\-specific \fBConfig.cmake\fP file. .INDENT 7.0 .TP .B \fBINSTALL_DESTINATION \fP Path to which the generated file will be installed by the caller, e.g., via \fBinstall(FILES)\fP \%<#\:files>\&. The path may be either relative to the \fBINSTALL_PREFIX\fP or absolute. .TP .B \fBINSTALL_PREFIX \fP Path prefix to which the package will be installed by the caller. The \fB\fP argument must be an absolute path. If this argument is not passed, the \fBCMAKE_INSTALL_PREFIX\fP \%<#\:variable:CMAKE_INSTALL_PREFIX> variable will be used instead. .TP .B \fBSINGLE_ARCHITECTURES ...\fP Architectures provided by entries of \fBSINGLE_ARCHITECTURE_INCLUDE_FILES\fP\&. .TP .B \fBSINGLE_ARCHITECTURE_INCLUDE_FILES ...\fP Architecture\-specific files. One of them will be loaded when \fBCMAKE_OSX_ARCHITECTURES\fP \%<#\:variable:CMAKE_OSX_ARCHITECTURES> contains a single architecture matching the corresponding entry of \fBSINGLE_ARCHITECTURES\fP\&. .TP .B \fBUNIVERSAL_ARCHITECTURES ...\fP Architectures provided by the \fBUNIVERSAL_INCLUDE_FILE\fP\&. .sp The list may include \fB$(ARCHS_STANDARD)\fP to support consumption using the \fBXcode\fP \%<#\:generator:Xcode> generator, but the architectures should always be listed individually too. .TP .B \fBUNIVERSAL_INCLUDE_FILE \fP A file to load when \fBCMAKE_OSX_ARCHITECTURES\fP \%<#\:variable:CMAKE_OSX_ARCHITECTURES> contains a (non\-strict) subset of the \fBUNIVERSAL_ARCHITECTURES\fP and does not match any one of the \fBSINGLE_ARCHITECTURES\fP\&. .TP .B \fBERROR_VARIABLE \fP If the consuming project is built for an unsupported architecture, set \fB\fP 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. .UNINDENT .UNINDENT .SS Example Generating Package Files .sp Example using both the \fBconfigure_package_config_file()\fP and \fBwrite_basic_package_version_file()\fP commands: .sp \fBCMakeLists.txt\fP .INDENT 0.0 .INDENT 3.5 .sp .EX include(GNUInstallDirs) set(INCLUDE_INSTALL_DIR ${CMAKE_INSTALL_INCLUDEDIR}/Foo CACHE PATH \(dqLocation of header files\(dq ) set(SYSCONFIG_INSTALL_DIR ${CMAKE_INSTALL_SYSCONFDIR}/foo CACHE PATH \(dqLocation of configuration files\(dq ) #... 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 ) .EE .UNINDENT .UNINDENT .sp \fBFooConfig.cmake.in\fP .INDENT 0.0 .INDENT 3.5 .sp .EX set(FOO_VERSION x.y.z) \&... @PACKAGE_INIT@ \&... set_and_check(FOO_INCLUDE_DIR \(dq@PACKAGE_INCLUDE_INSTALL_DIR@\(dq) set_and_check(FOO_SYSCONFIG_DIR \(dq@PACKAGE_SYSCONFIG_INSTALL_DIR@\(dq) check_required_components(Foo) .EE .UNINDENT .UNINDENT .SS CMakePrintHelpers .sp This module provides convenience commands, primarily intended for debugging, to print the values of properties and variables. .sp Load this module in CMake with: .INDENT 0.0 .INDENT 3.5 .sp .EX include(CMakePrintHelpers) .EE .UNINDENT .UNINDENT .SS Commands .sp This module provides the following commands: .INDENT 0.0 .TP .B cmake_print_properties Prints the values of properties for the specified targets, source files, directories, tests, or cache entries: .INDENT 7.0 .INDENT 3.5 .sp .EX cmake_print_properties( ...] | SOURCES [...] | DIRECTORIES [...] | TESTS [...] | CACHE_ENTRIES [...] > PROPERTIES [...] ) .EE .UNINDENT .UNINDENT .sp Exactly one of the scope keywords must be specified. The scope keyword and its arguments must appear before the \fBPROPERTIES\fP keyword in the argument list. .UNINDENT .INDENT 0.0 .TP .B cmake_print_variables Prints each variable name followed by its value: .INDENT 7.0 .INDENT 3.5 .sp .EX cmake_print_variables([...]) .EE .UNINDENT .UNINDENT .UNINDENT .SS Examples .sp Printing the \fBLOCATION\fP and \fBINTERFACE_INCLUDE_DIRECTORIES\fP properties for both targets \fBfoo\fP and \fBbar\fP: .INDENT 0.0 .INDENT 3.5 .sp .EX include(CMakePrintHelpers) cmake_print_properties( TARGETS foo bar PROPERTIES LOCATION INTERFACE_INCLUDE_DIRECTORIES ) .EE .UNINDENT .UNINDENT .sp Gives: .INDENT 0.0 .INDENT 3.5 .sp .EX \-\- Properties for TARGET foo: foo.LOCATION = \(dq/usr/lib/libfoo.so\(dq foo.INTERFACE_INCLUDE_DIRECTORIES = \(dq/usr/include;/usr/include/foo\(dq Properties for TARGET bar: bar.LOCATION = \(dq/usr/lib/libbar.so\(dq bar.INTERFACE_INCLUDE_DIRECTORIES = \(dq/usr/include;/usr/include/bar\(dq .EE .UNINDENT .UNINDENT .sp Printing given variables: .INDENT 0.0 .INDENT 3.5 .sp .EX include(CMakePrintHelpers) cmake_print_variables(CMAKE_C_COMPILER CMAKE_MAJOR_VERSION NOT_EXISTS) .EE .UNINDENT .UNINDENT .sp Gives: .INDENT 0.0 .INDENT 3.5 .sp .EX \-\- CMAKE_C_COMPILER=\(dq/usr/bin/cc\(dq ; CMAKE_MAJOR_VERSION=\(dq3\(dq ; NOT_EXISTS=\(dq\(dq .EE .UNINDENT .UNINDENT .SS CMakePrintSystemInformation .sp This module can be used for diagnostics to print system information. .sp Load this module in a CMake project with: .INDENT 0.0 .INDENT 3.5 .sp .EX include(CMakePrintSystemInformation) .EE .UNINDENT .UNINDENT .SS Examples .sp For example, including this module in a project: .sp \fBCMakeLists.txt\fP .INDENT 0.0 .INDENT 3.5 .sp .EX project(Example) # ... include(CMakePrintSystemInformation) .EE .UNINDENT .UNINDENT .sp prints various CMake variables: .INDENT 0.0 .INDENT 3.5 .sp .EX CMAKE_SYSTEM is Linux\-6.11.0\-17\-generic Linux 6.11.0\-17\-generic x86_64 CMAKE_SYSTEM file is Platform/Linux CMAKE_C_COMPILER is /usr/bin/cc CMAKE_CXX_COMPILER is /usr/bin/c++ CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS is \-shared CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS is \-shared \&... .EE .UNINDENT .UNINDENT .SS CMakePushCheckState .sp This module provides commands for managing the state of variables that influence how various CMake check commands (e.g., \fBcheck_symbol_exists()\fP \%<#\:command:check_symbol_exists>, etc.) are performed. .sp Load this module in a CMake project with: .INDENT 0.0 .INDENT 3.5 .sp .EX include(CMakePushCheckState) .EE .UNINDENT .UNINDENT .sp This module provides the following commands, which are useful for scoped configuration, for example, in CMake modules or when performing checks in a controlled environment, ensuring that temporary modifications are isolated to the scope of the check and do not propagate into other parts of the build system: .INDENT 0.0 .IP \(bu 2 \fBcmake_push_check_state()\fP .IP \(bu 2 \fBcmake_reset_check_state()\fP .IP \(bu 2 \fBcmake_pop_check_state()\fP .UNINDENT .SS Affected Variables .sp The following CMake variables are saved, reset, and restored by this module\(aqs commands: .INDENT 0.0 .TP .B \fBCMAKE_REQUIRED_FLAGS\fP A space\-separated string of additional flags to pass to the compiler. A semicolon\-separated list \%<#\:cmake-language-lists> will not work. The contents of \fBCMAKE__FLAGS\fP \%<#\:variable:CMAKE__FLAGS> and its associated configuration\-specific \fBCMAKE__FLAGS_\fP \%<#\:variable:CMAKE__FLAGS_> variables are automatically prepended to the compiler command before the contents of this variable. .UNINDENT .INDENT 0.0 .TP .B \fBCMAKE_REQUIRED_DEFINITIONS\fP A semicolon\-separated list \%<#\:cmake-language-lists> of compiler definitions, each of the form \fB\-DFOO\fP or \fB\-DFOO=bar\fP\&. A definition for the name specified by the result variable argument of the check command is also added automatically. .UNINDENT .INDENT 0.0 .TP .B \fBCMAKE_REQUIRED_INCLUDES\fP A semicolon\-separated list \%<#\:cmake-language-lists> of header search paths to pass to the compiler. These will be the only header search paths used; the contents of the \fBINCLUDE_DIRECTORIES\fP \%<#\:prop_dir:INCLUDE_DIRECTORIES> directory property will be ignored. .UNINDENT .INDENT 0.0 .TP .B \fBCMAKE_REQUIRED_LINK_OPTIONS\fP Added in version 3.14. .sp A semicolon\-separated list \%<#\:cmake-language-lists> of options to add to the link command (see \fBtry_compile()\fP \%<#\:command:try_compile> for further details). .UNINDENT .INDENT 0.0 .TP .B \fBCMAKE_REQUIRED_LIBRARIES\fP A semicolon\-separated list \%<#\:cmake-language-lists> of libraries to add to the link command. These can be the names of system libraries, or they can be Imported Targets \%<#\:imported-targets> (see \fBtry_compile()\fP \%<#\:command:try_compile> for further details). .UNINDENT .INDENT 0.0 .TP .B \fBCMAKE_REQUIRED_LINK_DIRECTORIES\fP Added in version 3.31. .sp A semicolon\-separated list \%<#\:cmake-language-lists> of library search paths to pass to the linker (see \fBtry_compile()\fP \%<#\:command:try_compile> for further details). .UNINDENT .INDENT 0.0 .TP .B \fBCMAKE_REQUIRED_QUIET\fP Added in version 3.1. .sp If this variable evaluates to a boolean true value, all status messages associated with the check will be suppressed. .UNINDENT .INDENT 0.0 .TP .B \fBCMAKE_EXTRA_INCLUDE_FILES\fP Added in version 3.6: Previously used already by the \fBcheck_type_size()\fP \%<#\:command:check_type_size> command; now also supported by this module. .sp A semicolon\-separated list \%<#\:cmake-language-lists> of extra header files to include when performing the check. .UNINDENT .sp \fBNote:\fP .INDENT 0.0 .INDENT 3.5 Other CMake variables, such as \fBCMAKE__FLAGS\fP \%<#\:variable:CMAKE__FLAGS>, propagate to all checks regardless of commands provided by this module, as those fundamental variables are designed to influence the global state of the build system. .UNINDENT .UNINDENT .SS Commands .INDENT 0.0 .TP .B cmake_push_check_state Pushes (saves) the current states of the above variables onto a stack: .INDENT 7.0 .INDENT 3.5 .sp .EX cmake_push_check_state([RESET]) .EE .UNINDENT .UNINDENT .sp Use this command to preserve the current configuration before making temporary modifications for specific checks. .INDENT 7.0 .TP .B \fBRESET\fP When this option is specified, the command not only saves the current states of the listed variables but also resets them to empty, allowing them to be reconfigured from a clean state. .UNINDENT .UNINDENT .INDENT 0.0 .TP .B cmake_reset_check_state Resets (clears) the contents of the variables listed above to empty states: .INDENT 7.0 .INDENT 3.5 .sp .EX cmake_reset_check_state() .EE .UNINDENT .UNINDENT .sp Use this command when performing multiple sequential checks that require entirely new configurations, ensuring no previous configuration unintentionally carries over. .UNINDENT .INDENT 0.0 .TP .B cmake_pop_check_state Restores the states of the variables listed above to their values at the time of the most recent \fBcmake_push_check_state()\fP call: .INDENT 7.0 .INDENT 3.5 .sp .EX cmake_pop_check_state() .EE .UNINDENT .UNINDENT .sp Use this command to revert temporary changes made during a check. To prevent unexpected behavior, pair each \fBcmake_push_check_state()\fP with a corresponding \fBcmake_pop_check_state()\fP\&. .UNINDENT .SS Examples .SS Example: Isolated Check With Compile Definitions .sp In the following example, a check for the C symbol \fBmemfd_create()\fP is performed with an additional \fB_GNU_SOURCE\fP compile definition, without affecting global compile flags. The \fBRESET\fP option is used to ensure that any prior values of the check\-related variables are explicitly cleared before the check. .INDENT 0.0 .INDENT 3.5 .sp .EX include(CMakePushCheckState) # Save and reset the current state cmake_push_check_state(RESET) # Perform check with specific compile definitions set(CMAKE_REQUIRED_DEFINITIONS \-D_GNU_SOURCE) include(CheckSymbolExists) check_symbol_exists(memfd_create \(dqsys/mman.h\(dq HAVE_MEMFD_CREATE) # Restore the original state cmake_pop_check_state() .EE .UNINDENT .UNINDENT .SS Example: Nested Configuration Scopes .sp In the following example, variable states are pushed onto the stack multiple times, allowing for sequential or nested checks. Each \fBcmake_pop_check_state()\fP restores the most recent pushed states. .INDENT 0.0 .INDENT 3.5 .sp .EX include(CMakePushCheckState) # Save and reset the current state cmake_push_check_state(RESET) # Perform the first check with additional libraries set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_DL_LIBS}) include(CheckSymbolExists) check_symbol_exists(dlopen \(dqdlfcn.h\(dq HAVE_DLOPEN) # Save current state cmake_push_check_state() # Perform the second check with libraries and additional compile definitions set(CMAKE_REQUIRED_DEFINITIONS \-D_GNU_SOURCE) check_symbol_exists(dladdr \(dqdlfcn.h\(dq HAVE_DLADDR) message(STATUS \(dq${CMAKE_REQUIRED_DEFINITIONS}\(dq) # Output: \-D_GNU_SOURCE # Restore the previous state cmake_pop_check_state() message(STATUS \(dq${CMAKE_REQUIRED_DEFINITIONS}\(dq) # Output here is empty # Reset variables to prepare for the next check cmake_reset_check_state() # Perform the next check only with additional compile definitions set(CMAKE_REQUIRED_DEFINITIONS \-D_GNU_SOURCE) check_symbol_exists(dl_iterate_phdr \(dqlink.h\(dq HAVE_DL_ITERATE_PHDR) # Restore the original state cmake_pop_check_state() .EE .UNINDENT .UNINDENT .SS CMakeVerifyManifest .sp This module is intended to be used in command\-line mode using the cmake \-P \%<#\:script-processing-mode> to verify that embedded manifests and side\-by\-side manifests for a project match. .sp Load this module in a CMake script with: .INDENT 0.0 .INDENT 3.5 .sp .EX include(CMakeVerifyManifest) .EE .UNINDENT .UNINDENT .sp This module first recursively globs \fB*.manifest\fP files from the current source directory and creates a list of allowed versions. .sp Next, the script globs all \fB*.exe\fP and \fB*.dll\fP files. Each \fB\&.exe\fP and \fB\&.dll\fP file is scanned for embedded manifests and the versions of CRT are checked to be in the list of allowed versions. .SS Input Variables .sp This module accepts the following variables: .INDENT 0.0 .TP .B \fBallow_versions\fP Additional versions can be passed by setting the \fBallow_versions\fP variable from the invocation command. This enables using additional embedded manifest versions in a project, even if that version was not found in a \fB\&.manifest\fP file. .UNINDENT .SS Examples .sp To use this module in the project, create a local command\-line script (for example, in the project\(aqs subdirectory \fBcmake/scripts\fP) and include the module: .sp \fBcmake/scripts/verify\-manifest.cmake\fP .INDENT 0.0 .INDENT 3.5 .sp .EX include(CMakeVerifyManifest) .EE .UNINDENT .UNINDENT .sp Then run the local script in command\-line and, for example, specify additional embedded manifest of \fB8.0.50608.0\fP to be used in a project: .INDENT 0.0 .INDENT 3.5 .sp .EX cmake \-Dallow_versions=8.0.50608.0 \-Pcmake/scripts/verify\-manifest.cmake .EE .UNINDENT .UNINDENT .SS CPack .sp This module configures generators for binary installers and source packages. .sp Load this module in a CMake project with: .INDENT 0.0 .INDENT 3.5 .sp .EX include(CPack) .EE .UNINDENT .UNINDENT .SS Introduction .sp The CPack module generates the configuration files \fBCPackConfig.cmake\fP and \fBCPackSourceConfig.cmake\fP\&. They are intended for use in a subsequent run of the \fBcpack\fP \%<#\:manual:cpack(1)> program where they steer the generation of installers or/and source packages. .sp Depending on the CMake generator, the CPack module may also add two new build targets, \fBpackage\fP and \fBpackage_source\fP\&. See the packaging targets section below for details. .sp The generated binary installers will contain all files that have been installed via CMake\(aqs \fBinstall()\fP \%<#\:command:install> command (and the deprecated commands \fBinstall_files()\fP \%<#\:command:install_files>, \fBinstall_programs()\fP \%<#\:command:install_programs>, and \fBinstall_targets()\fP \%<#\:command:install_targets>). Note that the \fBDESTINATION\fP option of the \fBinstall()\fP \%<#\:command:install> command must be a relative path; otherwise installed files are ignored by CPack. .sp Certain kinds of binary installers can be configured such that users can select individual application components to install. See the \fBCPackComponent\fP \%<#\:module:CPackComponent> module for further details. .sp Source packages (configured through \fBCPackSourceConfig.cmake\fP and generated by the \fBCPack Archive Generator\fP \%<#\:cpack_gen:CPack Archive Generator>) will contain all source files in the project directory except those specified in \fBCPACK_SOURCE_IGNORE_FILES\fP\&. .SS CPack Generators .sp The \fBCPACK_GENERATOR\fP variable has different meanings in different contexts. In a \fBCMakeLists.txt\fP file, \fBCPACK_GENERATOR\fP is a \fIlist of generators\fP: and when \fBcpack\fP \%<#\:manual:cpack(1)> is run with no other arguments, it will iterate over that list and produce one package for each generator. In a \fBCPACK_PROJECT_CONFIG_FILE\fP, \fBCPACK_GENERATOR\fP is a \fIstring naming a single generator\fP\&. If you need per\-cpack\-generator logic to control \fIother\fP cpack settings, then you need a \fBCPACK_PROJECT_CONFIG_FILE\fP\&. If set, the \fBCPACK_PROJECT_CONFIG_FILE\fP is included automatically on a per\-generator basis. It only need contain overrides. .sp Here\(aqs how it works: .INDENT 0.0 .IP \(bu 2 \fBcpack\fP \%<#\:manual:cpack(1)> runs .IP \(bu 2 it includes \fBCPackConfig.cmake\fP .IP \(bu 2 it iterates over the generators given by the \fB\-G\fP \%<#\:cmdoption-cpack-G> command line option, or if no such option was specified, over the list of generators given by the \fBCPACK_GENERATOR\fP variable set in the \fBCPackConfig.cmake\fP input file. .IP \(bu 2 foreach generator, it then .INDENT 2.0 .IP \(bu 2 sets \fBCPACK_GENERATOR\fP to the one currently being iterated .IP \(bu 2 includes the \fBCPACK_PROJECT_CONFIG_FILE\fP .IP \(bu 2 produces the package for that generator .UNINDENT .UNINDENT .sp This is the key: For each generator listed in \fBCPACK_GENERATOR\fP in \fBCPackConfig.cmake\fP, cpack will \fIreset\fP \fBCPACK_GENERATOR\fP internally to \fIthe one currently being used\fP and then include the \fBCPACK_PROJECT_CONFIG_FILE\fP\&. .sp For a list of available generators, see \fBcpack\-generators(7)\fP \%<#\:manual:cpack-generators(7)>\&. .SS Targets package and package_source .sp If CMake is run with the Makefile, Ninja, or Xcode generator, then \fBinclude(CPack)\fP generates a target \fBpackage\fP\&. This makes it possible to build a binary installer from CMake, Make, or Ninja: Instead of \fBcpack\fP, one may call \fBcmake \-\-build . \-\-target package\fP or \fBmake package\fP or \fBninja package\fP\&. The VS generator creates an uppercase target \fBPACKAGE\fP\&. .sp If CMake is run with the Makefile or Ninja generator, then \fBinclude(CPack)\fP also generates a target \fBpackage_source\fP\&. To build a source package, instead of \fBcpack \-G TGZ \-\-config CPackSourceConfig.cmake\fP one may call \fBcmake \-\-build . \-\-target package_source\fP, \fBmake package_source\fP, or \fBninja package_source\fP\&. .SS Variables common to all CPack Generators .sp Before including this CPack module in your \fBCMakeLists.txt\fP file, there are a variety of variables that can be set to customize the resulting installers. The most commonly\-used variables are: .INDENT 0.0 .TP .B CPACK_PACKAGE_NAME The name of the package (or application). If not specified, it defaults to the project name. .UNINDENT .INDENT 0.0 .TP .B CPACK_PACKAGE_VENDOR The name of the package vendor. (e.g., \(dqKitware\(dq). The default is \(dqHumanity\(dq. .UNINDENT .INDENT 0.0 .TP .B CPACK_PACKAGE_DIRECTORY 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 \fBcpack\fP \%<#\:manual:cpack(1)> command line option \fB\-B\fP\&. If set, the command line option overrides the value found in the config file. .UNINDENT .INDENT 0.0 .TP .B CPACK_PACKAGE_VERSION_MAJOR Package major version. This variable will always be set, but its default value depends on whether or not version details were given to the \fBproject()\fP \%<#\:command:project> command in the top level CMakeLists.txt file. If version details were given, the default value will be \fBCMAKE_PROJECT_VERSION_MAJOR\fP \%<#\:variable:CMAKE_PROJECT_VERSION_MAJOR>\&. If no version details were given, a default version of 0.1.1 will be assumed, leading to \fBCPACK_PACKAGE_VERSION_MAJOR\fP having a default value of 0. .UNINDENT .INDENT 0.0 .TP .B CPACK_PACKAGE_VERSION_MINOR Package minor version. The default value is determined based on whether or not version details were given to the \fBproject()\fP \%<#\:command:project> command in the top level CMakeLists.txt file. If version details were given, the default value will be \fBCMAKE_PROJECT_VERSION_MINOR\fP \%<#\:variable:CMAKE_PROJECT_VERSION_MINOR>, but if no minor version component was specified then \fBCPACK_PACKAGE_VERSION_MINOR\fP will be left unset. If no project version was given at all, a default version of 0.1.1 will be assumed, leading to \fBCPACK_PACKAGE_VERSION_MINOR\fP having a default value of 1. .UNINDENT .INDENT 0.0 .TP .B CPACK_PACKAGE_VERSION_PATCH Package patch version. The default value is determined based on whether or not version details were given to the \fBproject()\fP \%<#\:command:project> command in the top level CMakeLists.txt file. If version details were given, the default value will be \fBCMAKE_PROJECT_VERSION_PATCH\fP \%<#\:variable:CMAKE_PROJECT_VERSION_PATCH>, but if no patch version component was specified then \fBCPACK_PACKAGE_VERSION_PATCH\fP will be left unset. If no project version was given at all, a default version of 0.1.1 will be assumed, leading to \fBCPACK_PACKAGE_VERSION_PATCH\fP having a default value of 1. .UNINDENT .INDENT 0.0 .TP .B CPACK_PACKAGE_DESCRIPTION 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 \fBCPACK_PACKAGE_DESCRIPTION_FILE\fP\&. .UNINDENT .INDENT 0.0 .TP .B CPACK_PACKAGE_DESCRIPTION_FILE A text file used to describe the project when \fBCPACK_PACKAGE_DESCRIPTION\fP is not explicitly set. The default value for \fBCPACK_PACKAGE_DESCRIPTION_FILE\fP points to a built\-in template file \fBTemplates/CPack.GenericDescription.txt\fP\&. .UNINDENT .INDENT 0.0 .TP .B CPACK_PACKAGE_DESCRIPTION_SUMMARY Short description of the project (only a few words). If the \fBCMAKE_PROJECT_DESCRIPTION\fP \%<#\:variable: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 \fBCMAKE_PROJECT_NAME\fP \%<#\:variable:CMAKE_PROJECT_NAME>\&. .UNINDENT .INDENT 0.0 .TP .B CPACK_PACKAGE_HOMEPAGE_URL Project homepage URL. The default value is taken from the \fBCMAKE_PROJECT_HOMEPAGE_URL\fP \%<#\:variable:CMAKE_PROJECT_HOMEPAGE_URL> variable, which is set by the top level \fBproject()\fP \%<#\:command:project> command, or else the default will be empty if no URL was provided to \fBproject()\fP \%<#\:command:project>\&. .UNINDENT .INDENT 0.0 .TP .B CPACK_PACKAGE_FILE_NAME The name of the package file to generate, not including the extension. For example, \fBcmake\-2.6.1\-Linux\-i686\fP\&. The default value is: .INDENT 7.0 .INDENT 3.5 .sp .EX ${CPACK_PACKAGE_NAME}\-${CPACK_PACKAGE_VERSION}\-${CPACK_SYSTEM_NAME} .EE .UNINDENT .UNINDENT .UNINDENT .INDENT 0.0 .TP .B CPACK_PACKAGE_INSTALL_DIRECTORY Installation directory on the target system. This may be used by some CPack generators like NSIS to create an installation directory e.g., \(dqCMake 2.5\(dq below the installation prefix. All installed elements will be put inside this directory. .UNINDENT .INDENT 0.0 .TP .B CPACK_PACKAGE_ICON A branding image that will be displayed inside the installer (used by GUI installers). .UNINDENT .INDENT 0.0 .TP .B CPACK_PACKAGE_CHECKSUM Added in version 3.7. .sp One or multiple algorithms that will be used to generate additional files with the checksum of the package. The output file names will be: .INDENT 7.0 .INDENT 3.5 .sp .EX ${CPACK_PACKAGE_FILE_NAME}.${CPACK_PACKAGE_CHECKSUM} .EE .UNINDENT .UNINDENT .sp Supported algorithms are those listed by the string() \%<#\:supported-hash-algorithms> command. .sp Changed in version 4.2: The variable accepts a list of algorithms. .UNINDENT .INDENT 0.0 .TP .B CPACK_PROJECT_CONFIG_FILE CPack\-time project CPack configuration file. This file is included at cpack time, once per generator after CPack has set \fBCPACK_GENERATOR\fP to the actual generator being used. It allows per\-generator setting of \fBCPACK_*\fP variables at cpack time. .UNINDENT .INDENT 0.0 .TP .B CPACK_RESOURCE_FILE_LICENSE License to be embedded in the installer. It will typically be displayed to the user by the produced installer (often with an explicit \(dqAccept\(dq 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 \fBinstall()\fP \%<#\:command:install> command in your \fBCMakeLists.txt\fP\&. .UNINDENT .INDENT 0.0 .TP .B CPACK_RESOURCE_FILE_README 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. .UNINDENT .INDENT 0.0 .TP .B CPACK_RESOURCE_FILE_WELCOME 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. .UNINDENT .INDENT 0.0 .TP .B CPACK_MONOLITHIC_INSTALL Disables the component\-based installation mechanism. When set, the component specification is ignored and all installed items are put in a single \(dqMONOLITHIC\(dq package. Some CPack generators do monolithic packaging by default and may be asked to do component packaging by setting \fBCPACK__COMPONENT_INSTALL\fP to \fBTRUE\fP\&. .UNINDENT .INDENT 0.0 .TP .B CPACK_GENERATOR List of CPack generators to use. If not specified, CPack will create a set of options following the naming pattern \fBCPACK_BINARY_\fP (e.g. \fBCPACK_BINARY_NSIS\fP) allowing the user to enable/disable individual generators. If the \fB\-G\fP \%<#\:cmdoption-cpack-G> option is given on the \fBcpack\fP \%<#\:manual:cpack(1)> command line, it will override this variable and any \fBCPACK_BINARY_\fP options. .UNINDENT .INDENT 0.0 .TP .B CPACK_OUTPUT_CONFIG_FILE The name of the CPack binary configuration file. This file is the CPack configuration generated by the CPack module for binary installers. Defaults to \fBCPackConfig.cmake\fP\&. .UNINDENT .INDENT 0.0 .TP .B CPACK_PACKAGE_EXECUTABLES Lists each of the executables and associated text label to be used to create Start Menu shortcuts. For example, setting this to the list \fBccmake;CMake\fP will create a shortcut named \(dqCMake\(dq that will execute the installed executable \fBccmake\fP\&. Not all CPack generators use it (at least NSIS, Inno Setup and WIX do). .UNINDENT .INDENT 0.0 .TP .B CPACK_STRIP_FILES List of files to be stripped. Starting with CMake 2.6.0, \fBCPACK_STRIP_FILES\fP will be a boolean variable which enables stripping of all files (a list of files evaluates to \fBTRUE\fP in CMake, so this change is compatible). .UNINDENT .INDENT 0.0 .TP .B CPACK_VERBATIM_VARIABLES Added in version 3.4. .sp If set to \fBTRUE\fP, values of variables prefixed with \fBCPACK_\fP 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 \fBFALSE\fP for backwards compatibility. .UNINDENT .INDENT 0.0 .TP .B CPACK_THREADS Added in version 3.20. .sp Number of threads to use when performing parallelized operations, such as compressing the installer package. .sp Some compression methods used by CPack generators such as Debian or Archive may take advantage of multiple CPU cores to speed up compression. \fBCPACK_THREADS\fP can be set to specify how many threads will be used for compression. .sp A positive integer can be used to specify an exact desired thread count. .sp 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. .sp Given 0 CPack will try to use all available CPU cores. .sp By default \fBCPACK_THREADS\fP is set to \fB1\fP\&. .sp The following compression methods may take advantage of multiple cores: .INDENT 7.0 .TP .B \fBxz\fP Supported if CMake is built with a \fBliblzma\fP that supports parallel compression. .sp Added in version 3.21: Official CMake binaries available on \fBcmake.org\fP now ship with a \fBliblzma\fP that supports parallel compression. Older versions did not. .TP .B \fBzstd\fP Added in version 3.24. .sp Supported if CMake is built with libarchive 3.6 or higher. Official CMake binaries available on \fBcmake.org\fP support it. .UNINDENT .sp Other compression methods ignore this value and use only one thread. .UNINDENT .SS Variables for Source Package Generators .sp The following CPack variables are specific to source packages, and will not affect binary packages: .INDENT 0.0 .TP .B CPACK_SOURCE_PACKAGE_FILE_NAME The name of the source package. For example \fBcmake\-2.6.1\fP\&. .UNINDENT .INDENT 0.0 .TP .B CPACK_SOURCE_STRIP_FILES List of files in the source tree that will be stripped. Starting with CMake 2.6.0, \fBCPACK_SOURCE_STRIP_FILES\fP will be a boolean variable which enables stripping of all files (a list of files evaluates to \fBTRUE\fP in CMake, so this change is compatible). .UNINDENT .INDENT 0.0 .TP .B CPACK_SOURCE_GENERATOR List of generators used for the source packages. As with \fBCPACK_GENERATOR\fP, if this is not specified then CPack will create a set of options (e.g. \fBCPACK_SOURCE_ZIP\fP) allowing users to select which packages will be generated. .UNINDENT .INDENT 0.0 .TP .B CPACK_SOURCE_OUTPUT_CONFIG_FILE The name of the CPack source configuration file. This file is the CPack configuration generated by the CPack module for source installers. Defaults to \fBCPackSourceConfig.cmake\fP\&. .UNINDENT .INDENT 0.0 .TP .B CPACK_SOURCE_IGNORE_FILES Pattern of files in the source tree that won\(aqt be packaged when building a source package. This is a list of regular expression patterns (that must be properly escaped), e.g., \fB/CVS/;/\e\e.svn/;\e\e.swp$;\e\e.#;/#;.*~;cscope.*\fP .UNINDENT .SS Variables for Advanced Use .sp The following variables are for advanced uses of CPack: .INDENT 0.0 .TP .B CPACK_CMAKE_GENERATOR What CMake generator should be used if the project is a CMake project. Defaults to the value of \fBCMAKE_GENERATOR\fP \%<#\:variable:CMAKE_GENERATOR>\&. Few users will want to change this setting. .UNINDENT .INDENT 0.0 .TP .B CPACK_INSTALL_CMAKE_PROJECTS 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. .UNINDENT .INDENT 0.0 .TP .B CPACK_SYSTEM_NAME System name, defaults to the value of \fBCMAKE_SYSTEM_NAME\fP \%<#\:variable:CMAKE_SYSTEM_NAME>, except on Windows where it will be \fBwin32\fP or \fBwin64\fP\&. .UNINDENT .INDENT 0.0 .TP .B CPACK_PACKAGE_VERSION Package full version, used internally. By default, this is built from \fBCPACK_PACKAGE_VERSION_MAJOR\fP, \fBCPACK_PACKAGE_VERSION_MINOR\fP, and \fBCPACK_PACKAGE_VERSION_PATCH\fP\&. .UNINDENT .INDENT 0.0 .TP .B CPACK_TOPLEVEL_TAG Directory for the installed files. .UNINDENT .INDENT 0.0 .TP .B CPACK_INSTALL_COMMANDS Extra commands to install components. The environment variable \fBCMAKE_INSTALL_PREFIX\fP is set to the temporary install directory during execution. .UNINDENT .INDENT 0.0 .TP .B CPACK_INSTALL_SCRIPTS Added in version 3.16. .sp 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.: \fBmake install\fP). For every script, the following variables will be set: \fBCMAKE_CURRENT_SOURCE_DIR\fP \%<#\:variable:CMAKE_CURRENT_SOURCE_DIR>, \fBCMAKE_CURRENT_BINARY_DIR\fP \%<#\:variable:CMAKE_CURRENT_BINARY_DIR> and \fBCMAKE_INSTALL_PREFIX\fP \%<#\:variable:CMAKE_INSTALL_PREFIX> (which is set to the staging install directory). The singular form \fBCMAKE_INSTALL_SCRIPT\fP is supported as an alternative variable for historical reasons, but its value is ignored if \fBCMAKE_INSTALL_SCRIPTS\fP is set and a warning will be issued. .sp See also \fBCPACK_PRE_BUILD_SCRIPTS\fP and \fBCPACK_POST_BUILD_SCRIPTS\fP which can be used to specify scripts to be executed later in the packaging process. .UNINDENT .INDENT 0.0 .TP .B CPACK_PRE_BUILD_SCRIPTS Added in version 3.19. .sp 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 \fBCPACK_INSTALL_SCRIPTS\fP and \fBCPACK_POST_BUILD_SCRIPTS\fP\&. .UNINDENT .INDENT 0.0 .TP .B CPACK_POST_BUILD_SCRIPTS Added in version 3.19. .sp List of CMake scripts to execute after CPack has produced the resultant packages and before copying them back to the build directory. See also \fBCPACK_INSTALL_SCRIPTS\fP, \fBCPACK_PRE_BUILD_SCRIPTS\fP and \fBCPACK_PACKAGE_FILES\fP\&. .UNINDENT .INDENT 0.0 .TP .B CPACK_PACKAGE_FILES Added in version 3.19. .sp 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 \fBCPACK_POST_BUILD_SCRIPTS\fP\&. 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. .UNINDENT .INDENT 0.0 .TP .B CPACK_INSTALLED_DIRECTORIES Extra directories to install. .UNINDENT .INDENT 0.0 .TP .B CPACK_PACKAGE_INSTALL_REGISTRY_KEY Registry key used when installing this project. This is only used by installers for Windows. The default value is based on the installation directory. .UNINDENT .INDENT 0.0 .TP .B CPACK_CREATE_DESKTOP_LINKS List of desktop links to create. Each desktop link requires a corresponding start menu shortcut as created by \fBCPACK_PACKAGE_EXECUTABLES\fP\&. .UNINDENT .INDENT 0.0 .TP .B CPACK_BINARY_ CPack generated options for binary generators. The \fBCPack.cmake\fP module generates (when \fBCPACK_GENERATOR\fP is not set) a set of CMake options (see CMake \fBoption()\fP \%<#\:command:option> command) which may then be used to select the CPack generator(s) to be used when building the \fBpackage\fP target or when running \fBcpack\fP \%<#\:manual:cpack(1)> without the \fB\-G\fP \%<#\:cmdoption-cpack-G> option. .UNINDENT .INDENT 0.0 .TP .B CPACK_READELF_EXECUTABLE Added in version 3.25. .sp Specify the \fBreadelf\fP executable path used by CPack. The default value will be taken from the \fBCMAKE_READELF\fP variable, if set, which may be populated CMake when enabling languages. If \fBCMAKE_READELF\fP is not set, CPack will use \fBfind_program()\fP \%<#\:command:find_program> to determine the \fBreadelf\fP path when needed. .UNINDENT .INDENT 0.0 .TP .B CPACK_OBJCOPY_EXECUTABLE Added in version 3.25. .sp Specify the \fBobjcopy\fP executable path used by CPack. The default value will be taken from the \fBCMAKE_OBJCOPY\fP variable, if set, which may be populated by CMake when enabling languages. If \fBCMAKE_OBJCOPY\fP is not set, CPack will use \fBfind_program()\fP \%<#\:command:find_program> to determine the \fBobjcopy\fP path when needed. .UNINDENT .INDENT 0.0 .TP .B CPACK_OBJDUMP_EXECUTABLE Added in version 3.25. .sp Specify the \fBobjdump\fP executable path used by CPack. The default value will be taken from the \fBCMAKE_OBJDUMP\fP \%<#\:variable:CMAKE_OBJDUMP> variable, which may be populated by CMake when enabling languages. If \fBCMAKE_OBJDUMP\fP is not set, CPack will use \fBfind_program()\fP \%<#\:command:find_program> to determine the \fBobjdump\fP path when needed. .UNINDENT .SS CPackComponent .sp This module provides commands to configure components for binary installers and source packages. .sp Load this module in a CMake project with: .INDENT 0.0 .INDENT 3.5 .sp .EX include(CPackComponent) .EE .UNINDENT .UNINDENT .SS Introduction .sp This module is also automatically included by \fBCPack\fP \%<#\:module:CPack>\&. .sp Certain binary installers (especially the graphical installers) generated by CPack allow users to select individual application \fIcomponents\fP to install. This module allows developers to configure the packaging of such components. .sp Contents is assigned to components by the \fBCOMPONENT\fP argument of CMake\(aqs \fBinstall()\fP \%<#\:command: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. .sp To specify different groupings for different CPack generators use a CPACK_PROJECT_CONFIG_FILE. .SS Variables .sp The following variables influence the component\-specific packaging: .INDENT 0.0 .TP .B CPACK_COMPONENTS_ALL The list of component to install. .sp 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. .sp 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 \fBget_cmake_property()\fP \%<#\:command:get_cmake_property> command can be used to obtain the \fBCOMPONENTS\fP property, then the \fBlist(REMOVE_ITEM)\fP \%<#\:remove-item> command can be used to remove the unwanted ones. For example, to use all defined components except \fBfoo\fP and \fBbar\fP: .INDENT 7.0 .INDENT 3.5 .sp .EX get_cmake_property(CPACK_COMPONENTS_ALL COMPONENTS) list(REMOVE_ITEM CPACK_COMPONENTS_ALL \(dqfoo\(dq \(dqbar\(dq) .EE .UNINDENT .UNINDENT .UNINDENT .INDENT 0.0 .TP .B CPACK__COMPONENT_INSTALL Enable/Disable component install for CPack generator . .sp 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. .UNINDENT .INDENT 0.0 .TP .B CPACK_COMPONENTS_GROUPING Specify how components are grouped for multi\-package component\-aware CPack generators. .sp Some generators like RPM or ARCHIVE (TGZ, ZIP, ...) may generate several packages files when there are components, depending on the value of this variable: .INDENT 7.0 .IP \(bu 2 ONE_PER_GROUP (default): create one package per component group .IP \(bu 2 IGNORE : create one package per component (ignore the groups) .IP \(bu 2 ALL_COMPONENTS_IN_ONE : create a single package with all requested components .UNINDENT .UNINDENT .INDENT 0.0 .TP .B CPACK_COMPONENT__DISPLAY_NAME The name to be displayed for a component. .UNINDENT .INDENT 0.0 .TP .B CPACK_COMPONENT__DESCRIPTION The description of a component. .UNINDENT .INDENT 0.0 .TP .B CPACK_COMPONENT__GROUP The group of a component. .UNINDENT .INDENT 0.0 .TP .B CPACK_COMPONENT__DEPENDS The dependencies (list of components) on which this component depends. .UNINDENT .INDENT 0.0 .TP .B CPACK_COMPONENT__HIDDEN True if this component is hidden from the user. .UNINDENT .INDENT 0.0 .TP .B CPACK_COMPONENT__REQUIRED True if this component is required. .UNINDENT .INDENT 0.0 .TP .B CPACK_COMPONENT__DISABLED True if this component is not selected to be installed by default. .UNINDENT .SS Commands .SS Add component .INDENT 0.0 .TP .B cpack_add_component .UNINDENT .sp Describe an installation component. .INDENT 0.0 .INDENT 3.5 .sp .EX 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]) .EE .UNINDENT .UNINDENT .sp \fBcompname\fP is the name of an installation component, as defined by the \fBCOMPONENT\fP argument of one or more CMake \fBinstall()\fP \%<#\:command:install> commands. With the \fBcpack_add_component\fP 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. .sp DISPLAY_NAME is the displayed name of the component, used in graphical installers to display the component name. This value can be any string. .sp 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 \fB\en\fP as the line separator. Typically, these descriptions should be no more than a few lines long. .sp 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. .sp 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). .sp 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. .sp 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. .sp 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. .sp 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. .sp 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. .sp 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. .sp PLIST gives a filename that is passed to pkgbuild with the \fB\-\-component\-plist\fP argument when using the productbuild generator. .SS Add component group .INDENT 0.0 .TP .B cpack_add_component_group .UNINDENT .sp Describes a group of related CPack installation components. .INDENT 0.0 .INDENT 3.5 .sp .EX cpack_add_component_group(groupname [DISPLAY_NAME name] [DESCRIPTION description] [PARENT_GROUP parent] [EXPANDED] [BOLD_TITLE]) .EE .UNINDENT .UNINDENT .sp 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. .sp 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. .sp 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 \fB\en\fP as the line separator. Typically, these descriptions should be no more than a few lines long. .sp 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. .sp EXPANDED indicates that, by default, the group should show up as \(dqexpanded\(dq, so that the user immediately sees all of the components within the group. Otherwise, the group will initially show up as a single entry. .sp BOLD_TITLE indicates that the group title should appear in bold, to call the user\(aqs attention to the group. .SS Add installation type .INDENT 0.0 .TP .B cpack_add_install_type .UNINDENT .sp Add a new installation type containing a set of predefined component selections to the graphical installer. .INDENT 0.0 .INDENT 3.5 .sp .EX cpack_add_install_type(typename [DISPLAY_NAME name]) .EE .UNINDENT .UNINDENT .sp The cpack_add_install_type command identifies a set of preselected components that represents a common use case for an application. For example, a \(dqDeveloper\(dq install type might include an application along with its header and library files, while an \(dqEnd user\(dq install type might just include the application\(aqs executable. Each component identifies itself with one or more install types via the INSTALL_TYPES argument to cpack_add_component. .sp 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. .SS Configure downloads .INDENT 0.0 .TP .B cpack_configure_downloads .UNINDENT .sp Configure CPack to download selected components on\-the\-fly as part of the installation process. .INDENT 0.0 .INDENT 3.5 .sp .EX cpack_configure_downloads(site [UPLOAD_DIRECTORY dirname] [ALL] [ADD_REMOVE|NO_ADD_REMOVE]) .EE .UNINDENT .UNINDENT .sp 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 \(dqChange\(dq 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: .INDENT 0.0 .INDENT 3.5 .sp .EX http://nsis.sourceforge.net/ZipDLL_plug\-in .EE .UNINDENT .UNINDENT .sp On macOS, installers that download components on\-the\-fly can only be built and installed on system using macOS 10.5 or later. .sp The site argument is a URL where the archives for downloadable components will reside, e.g., \% All of the archives produced by CPack should be uploaded to that location. .sp 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. .sp 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). .sp ADD_REMOVE indicates that CPack should install a copy of the installer that can be called from Windows\(aq Add/Remove Programs dialog (via the \(dqModify\(dq button) to change the set of installed components. NO_ADD_REMOVE turns off this behavior. This option is ignored on Mac OS X. .SS CPackIFW .sp Added in version 3.1. .sp This module looks for the location of the command\-line utilities supplied with the Qt Installer Framework \% (QtIFW). .sp Load this module in a CMake project with: .INDENT 0.0 .INDENT 3.5 .sp .EX include(CPackIFW) .EE .UNINDENT .UNINDENT .sp The module also defines several commands to control the behavior of the \fBCPack IFW Generator\fP \%<#\:cpack_gen:CPack IFW Generator>\&. .SS Commands .sp The module defines the following commands: .INDENT 0.0 .TP .B cpack_ifw_configure_component Sets the arguments specific to the CPack IFW generator. .INDENT 7.0 .INDENT 3.5 .sp .EX cpack_ifw_configure_component( [COMMON] [ESSENTIAL] [VIRTUAL] [FORCED_INSTALLATION] [REQUIRES_ADMIN_RIGHTS] [NAME ] [DISPLAY_NAME ] # Note: Internationalization supported [DESCRIPTION ] # Note: Internationalization supported [UPDATE_TEXT ] [VERSION ] [RELEASE_DATE ] [SCRIPT