CMAKE-MODULES(7) CMake CMAKE-MODULES(7) NAME cmake-modules - CMake Modules Reference The modules listed here are part of the CMake distribution. Projects may provide further modules; their location(s) can be specified in the CMAKE_MODULE_PATH variable. UTILITY MODULES These modules are loaded using the include() command. AndroidTestUtilities New in version 3.7. Create a test that automatically loads specified data onto an Android device. Introduction Use this module to push data needed for testing an Android device behavior onto a connected Android device. The module will accept files and libraries as well as separate destinations for each. It will create a test that loads the files into a device object store and link to them from the specified destination. The files are only uploaded if they are not already in the object store. For example: include(AndroidTestUtilities) android_add_test_data( example_setup_test FILES ... LIBS ... DEVICE_TEST_DIR "/data/local/tests/example" DEVICE_OBJECT_STORE "/sdcard/.ExternalData/SHA" ) At build time a test named "example_setup_test" will be created. Run this test on the command line with ctest(1) to load the data onto the Android device. Module Functions android_add_test_data android_add_test_data( [FILES ...] [FILES_DEST ] [LIBS ...] [LIBS_DEST ] [DEVICE_OBJECT_STORE ] [DEVICE_TEST_DIR ] [NO_LINK_REGEX ...] ) The android_add_test_data function is used to copy files and libraries needed to run project-specific tests. On the host operating system, this is done at build time. For on-device testing, the files are loaded onto the device by the manufactured test at run time. This function accepts the following named parameters: FILES ... zero or more files needed for testing LIBS ... zero or more libraries needed for testing FILES_DEST absolute path where the data files are expected to be LIBS_DEST absolute path where the libraries are expected to be DEVICE_OBJECT_STORE absolute path to the location where the data is stored on-device DEVICE_TEST_DIR absolute path to the root directory of the on-device test location NO_LINK_REGEX ... list of regex strings matching the names of files that should be copied from the object store to the testing directory BundleUtilities Functions to help assemble a standalone bundle application. A collection of CMake utility functions useful for dealing with .app bundles on the Mac and bundle-like directories on any OS. The following functions are provided by this module: fixup_bundle copy_and_fixup_bundle verify_app get_bundle_main_executable get_dotapp_dir get_bundle_and_executable get_bundle_all_executables get_item_key get_item_rpaths clear_bundle_keys set_bundle_key_values get_bundle_keys copy_resolved_item_into_bundle copy_resolved_framework_into_bundle fixup_bundle_item verify_bundle_prerequisites verify_bundle_symlinks Requires CMake 2.6 or greater because it uses function, break and PARENT_SCOPE. Also depends on GetPrerequisites.cmake. DO NOT USE THESE FUNCTIONS AT CONFIGURE TIME (from CMakeLists.txt)! Instead, invoke them from an install(CODE) or install(SCRIPT) rule. fixup_bundle( ) Fix up bundle in-place and make it standalone, such that it can be drag-n-drop copied to another machine and run on that machine as long as all of the system libraries are compatible. If you pass plugins to fixup_bundle as the libs parameter, you should install them or copy them into the bundle before calling fixup_bundle. The parameter is a list of libraries that must be fixed up, but that cannot be determined by otool output analysis (i.e. plugins). Gather all the keys for all the executables and libraries in a bundle, and then, for each key, copy each prerequisite into the bundle. Then fix each one up according to its own list of prerequisites. Then clear all the keys and call verify_app on the final bundle to ensure that it is truly standalone. New in version 3.6: As an optional parameter (IGNORE_ITEM) a list of file names can be passed, which are then ignored (e.g. IGNORE_ITEM "vcredist_x86.exe;vcredist_x64.exe"). copy_and_fixup_bundle( ) Makes a copy of the bundle at location and then fixes up the new copied bundle in-place at . verify_app() Verifies that an application appears valid based on running analysis tools on it. Calls message(FATAL_ERROR) if the application is not verified. New in version 3.6: As an optional parameter (IGNORE_ITEM) a list of file names can be passed, which are then ignored (e.g. IGNORE_ITEM "vcredist_x86.exe;vcredist_x64.exe") get_bundle_main_executable( ) The result will be the full path name of the bundle's main executable file or an error: prefixed string if it could not be determined. get_dotapp_dir( ) Returns the nearest parent dir whose name ends with .app given the full path to an executable. If there is no such parent dir, then simply return the dir containing the executable. The returned directory may or may not exist. get_bundle_and_executable( ) Takes either a .app directory name or the name of an executable nested inside a .app directory and returns the path to the .app directory in and the path to its main executable in . get_bundle_all_executables( ) Scans bundle recursively for all executable files and accumulates them into a variable. get_item_key( ) Given file name, generate key that should be unique considering the set of libraries that need copying or fixing up to make a bundle standalone. This is essentially the file name including extension with . replaced by _ This key is used as a prefix for CMake variables so that we can associate a set of variables with a given item based on its key. clear_bundle_keys() Loop over the list of keys, clearing all the variables associated with each key. After the loop, clear the list of keys itself. Caller of get_bundle_keys should call clear_bundle_keys when done with list of keys. set_bundle_key_values( []) Add key to the list (if necessary) for the given item. If added, also set all the variables associated with that key. get_bundle_keys( ) Loop over all the executable and library files within bundle (and given as extra ) and accumulate a list of keys representing them. Set values associated with each key such that we can loop over all of them and copy prerequisite libs into the bundle and then do appropriate install_name_tool fixups. New in version 3.6: As an optional parameter (IGNORE_ITEM) a list of file names can be passed, which are then ignored (e.g. IGNORE_ITEM "vcredist_x86.exe;vcredist_x64.exe") copy_resolved_item_into_bundle( ) Copy a resolved item into the bundle if necessary. Copy is not necessary, if the is "the same as" the . copy_resolved_framework_into_bundle( ) Copy a resolved framework into the bundle if necessary. Copy is not necessary, if the is "the same as" the . By default, BU_COPY_FULL_FRAMEWORK_CONTENTS is not set. If you want full frameworks embedded in your bundles, set BU_COPY_FULL_FRAMEWORK_CONTENTS to ON before calling fixup_bundle. By default, COPY_RESOLVED_FRAMEWORK_INTO_BUNDLE copies the framework dylib itself plus the framework Resources directory. fixup_bundle_item( ) Get the direct/non-system prerequisites of the . For each prerequisite, change the way it is referenced to the value of the _EMBEDDED_ITEM keyed variable for that prerequisite. (Most likely changing to an @executable_path style reference.) This function requires that the be inside the bundle already. In other words, if you pass plugins to fixup_bundle as the libs parameter, you should install them or copy them into the bundle before calling fixup_bundle. The libs parameter is a list of libraries that must be fixed up, but that cannot be determined by otool output analysis. (i.e., plugins) Also, change the id of the item being fixed up to its own _EMBEDDED_ITEM value. Accumulate changes in a local variable and make one call to install_name_tool at the end of the function with all the changes at once. If the BU_CHMOD_BUNDLE_ITEMS variable is set then bundle items will be marked writable before install_name_tool tries to change them. verify_bundle_prerequisites( ) Verifies that the sum of all prerequisites of all files inside the bundle are contained within the bundle or are system libraries, presumed to exist everywhere. New in version 3.6: As an optional parameter (IGNORE_ITEM) a list of file names can be passed, which are then ignored (e.g. IGNORE_ITEM "vcredist_x86.exe;vcredist_x64.exe") verify_bundle_symlinks( ) Verifies that any symlinks found in the bundle point to other files that are already also in the bundle... Anything that points to an external file causes this function to fail the verification. CheckCCompilerFlag Check whether the C compiler supports a given flag. check_c_compiler_flag check_c_compiler_flag( ) Check that the is accepted by the compiler without a diagnostic. Stores the result in an internal cache entry named . A positive result from this check indicates only that the compiler did not issue a diagnostic message when given the flag. Whether the flag has any effect or even a specific one is beyond the scope of this module. The check is only performed once, with the result cached in the variable named by . Every subsequent CMake run will reuse this cached value rather than performing the check again, even if the changes. In order to force the check to be re-evaluated, the variable named by must be manually removed from the cache. The compile and link commands can be influenced by setting any of the following variables prior to calling check_c_compiler_flag() CMAKE_REQUIRED_FLAGS String of additional flags to pass to the compiler. The string must be space-delimited--a ;-list will not work. The contents of CMAKE__FLAGS and its associated configuration-specific variable are automatically added to the compiler command before the contents of CMAKE_REQUIRED_FLAGS. CMAKE_REQUIRED_DEFINITIONS A ;-list of compiler definitions of the form -DFOO or -DFOO=bar. A definition for the name specified by will also be added automatically. CMAKE_REQUIRED_INCLUDES A ;-list of header search paths to pass to the compiler. These will be the only header search paths used--the contents of the INCLUDE_DIRECTORIES directory property will be ignored. CMAKE_REQUIRED_LINK_OPTIONS New in version 3.14. A ;-list of options to add to the link command (see try_compile() for further details). CMAKE_REQUIRED_LIBRARIES A ;-list of libraries to add to the link command. These can be the name of system libraries or they can be Imported Targets (see try_compile() for further details). CMAKE_REQUIRED_QUIET New in version 3.1. If this variable evaluates to a boolean true value, all status messages associated with the check will be suppressed. CheckCompilerFlag New in version 3.19. Check whether the compiler supports a given flag. check_compiler_flag check_compiler_flag( ) Check that the is accepted by the compiler without a diagnostic. Stores the result in an internal cache entry named . A positive result from this check indicates only that the compiler did not issue a diagnostic message when given the flag. Whether the flag has any effect or even a specific one is beyond the scope of this module. The check is only performed once, with the result cached in the variable named by . Every subsequent CMake run will reuse this cached value rather than performing the check again, even if the changes. In order to force the check to be re-evaluated, the variable named by must be manually removed from the cache. The compile and link commands can be influenced by setting any of the following variables prior to calling check_compiler_flag() CMAKE_REQUIRED_FLAGS String of additional flags to pass to the compiler. The string must be space-delimited--a ;-list will not work. The contents of CMAKE__FLAGS and its associated configuration-specific variable are automatically added to the compiler command before the contents of CMAKE_REQUIRED_FLAGS. CMAKE_REQUIRED_DEFINITIONS A ;-list of compiler definitions of the form -DFOO or -DFOO=bar. A definition for the name specified by will also be added automatically. CMAKE_REQUIRED_INCLUDES A ;-list of header search paths to pass to the compiler. These will be the only header search paths used--the contents of the INCLUDE_DIRECTORIES directory property will be ignored. CMAKE_REQUIRED_LINK_OPTIONS New in version 3.14. A ;-list of options to add to the link command (see try_compile() for further details). CMAKE_REQUIRED_LIBRARIES A ;-list of libraries to add to the link command. These can be the name of system libraries or they can be Imported Targets (see try_compile() for further details). CMAKE_REQUIRED_QUIET New in version 3.1. If this variable evaluates to a boolean true value, all status messages associated with the check will be suppressed. CheckCSourceCompiles Check if given C source compiles and links into an executable. check_c_source_compiles check_c_source_compiles( [FAIL_REGEX [...]]) Check that the source supplied in can be compiled as a C source file and linked as an executable (so it must contain at least a main() function). The result will be stored in the internal cache variable specified by , with a boolean true value for success and boolean false for failure. If FAIL_REGEX is provided, then failure is determined by checking if anything in the output matches any of the specified regular expressions. The check is only performed once, with the result cached in the variable named by . Every subsequent CMake run will reuse this cached value rather than performing the check again, even if the changes. In order to force the check to be re-evaluated, the variable named by must be manually removed from the cache. The compile and link commands can be influenced by setting any of the following variables prior to calling check_c_source_compiles(): CMAKE_REQUIRED_FLAGS String of additional flags to pass to the compiler. The string must be space-delimited--a ;-list will not work. The contents of CMAKE__FLAGS and its associated configuration-specific variable are automatically added to the compiler command before the contents of CMAKE_REQUIRED_FLAGS. CMAKE_REQUIRED_DEFINITIONS A ;-list of compiler definitions of the form -DFOO or -DFOO=bar. A definition for the name specified by will also be added automatically. CMAKE_REQUIRED_INCLUDES A ;-list of header search paths to pass to the compiler. These will be the only header search paths used--the contents of the INCLUDE_DIRECTORIES directory property will be ignored. CMAKE_REQUIRED_LINK_OPTIONS New in version 3.14. A ;-list of options to add to the link command (see try_compile() for further details). CMAKE_REQUIRED_LIBRARIES A ;-list of libraries to add to the link command. These can be the name of system libraries or they can be Imported Targets (see try_compile() for further details). CMAKE_REQUIRED_QUIET New in version 3.1. If this variable evaluates to a boolean true value, all status messages associated with the check will be suppressed. CheckCSourceRuns Check if given C source compiles and links into an executable and can subsequently be run. check_c_source_runs check_c_source_runs( ) Check that the source supplied in can be compiled as a C source file, linked as an executable and then run. The must contain at least a main() function. If the could be built and run successfully, the internal cache variable specified by will be set to 1, otherwise it will be set to an value that evaluates to boolean false (e.g. an empty string or an error message). The check is only performed once, with the result cached in the variable named by . Every subsequent CMake run will reuse this cached value rather than performing the check again, even if the changes. In order to force the check to be re-evaluated, the variable named by must be manually removed from the cache. The compile and link commands can be influenced by setting any of the following variables prior to calling check_c_source_runs(): CMAKE_REQUIRED_FLAGS String of additional flags to pass to the compiler. The string must be space-delimited--a ;-list will not work. The contents of CMAKE__FLAGS and its associated configuration-specific variable are automatically added to the compiler command before the contents of CMAKE_REQUIRED_FLAGS. CMAKE_REQUIRED_DEFINITIONS A ;-list of compiler definitions of the form -DFOO or -DFOO=bar. A definition for the name specified by will also be added automatically. CMAKE_REQUIRED_INCLUDES A ;-list of header search paths to pass to the compiler. These will be the only header search paths used--the contents of the INCLUDE_DIRECTORIES directory property will be ignored. CMAKE_REQUIRED_LINK_OPTIONS New in version 3.14. A ;-list of options to add to the link command (see try_compile() for further details). CMAKE_REQUIRED_LIBRARIES A ;-list of libraries to add to the link command. These can be the name of system libraries or they can be Imported Targets (see try_compile() for further details). CMAKE_REQUIRED_QUIET New in version 3.1. If this variable evaluates to a boolean true value, all status messages associated with the check will be suppressed. CheckCXXCompilerFlag Check whether the CXX compiler supports a given flag. check_cxx_compiler_flag check_cxx_compiler_flag( ) Check that the is accepted by the compiler without a diagnostic. Stores the result in an internal cache entry named . A positive result from this check indicates only that the compiler did not issue a diagnostic message when given the flag. Whether the flag has any effect or even a specific one is beyond the scope of this module. NOTE: Since the try_compile() command forwards flags from variables like CMAKE_CXX_FLAGS, unknown flags in such variables may cause a false negative for this check. CheckCXXSourceCompiles Check if given C++ source compiles and links into an executable. check_cxx_source_compiles check_cxx_source_compiles( [FAIL_REGEX [...]]) Check that the source supplied in can be compiled as a C++ source file and linked as an executable (so it must contain at least a main() function). The result will be stored in the internal cache variable specified by , with a boolean true value for success and boolean false for failure. If FAIL_REGEX is provided, then failure is determined by checking if anything in the output matches any of the specified regular expressions. The check is only performed once, with the result cached in the variable named by . Every subsequent CMake run will reuse this cached value rather than performing the check again, even if the changes. In order to force the check to be re-evaluated, the variable named by must be manually removed from the cache. The compile and link commands can be influenced by setting any of the following variables prior to calling check_cxx_source_compiles(): CMAKE_REQUIRED_FLAGS String of additional flags to pass to the compiler. The string must be space-delimited--a ;-list will not work. The contents of CMAKE__FLAGS and its associated configuration-specific variable are automatically added to the compiler command before the contents of CMAKE_REQUIRED_FLAGS. CMAKE_REQUIRED_DEFINITIONS A ;-list of compiler definitions of the form -DFOO or -DFOO=bar. A definition for the name specified by will also be added automatically. CMAKE_REQUIRED_INCLUDES A ;-list of header search paths to pass to the compiler. These will be the only header search paths used--the contents of the INCLUDE_DIRECTORIES directory property will be ignored. CMAKE_REQUIRED_LINK_OPTIONS New in version 3.14. A ;-list of options to add to the link command (see try_compile() for further details). CMAKE_REQUIRED_LIBRARIES A ;-list of libraries to add to the link command. These can be the name of system libraries or they can be Imported Targets (see try_compile() for further details). CMAKE_REQUIRED_QUIET New in version 3.1. If this variable evaluates to a boolean true value, all status messages associated with the check will be suppressed. CheckCXXSourceRuns Check if given C++ source compiles and links into an executable and can subsequently be run. check_cxx_source_runs check_cxx_source_runs( ) Check that the source supplied in can be compiled as a C++ source file, linked as an executable and then run. The must contain at least a main() function. If the could be built and run successfully, the internal cache variable specified by will be set to 1, otherwise it will be set to an value that evaluates to boolean false (e.g. an empty string or an error message). The check is only performed once, with the result cached in the variable named by . Every subsequent CMake run will reuse this cached value rather than performing the check again, even if the changes. In order to force the check to be re-evaluated, the variable named by must be manually removed from the cache. The compile and link commands can be influenced by setting any of the following variables prior to calling check_cxx_source_runs(): CMAKE_REQUIRED_FLAGS String of additional flags to pass to the compiler. The string must be space-delimited--a ;-list will not work. The contents of CMAKE__FLAGS and its associated configuration-specific variable are automatically added to the compiler command before the contents of CMAKE_REQUIRED_FLAGS. CMAKE_REQUIRED_DEFINITIONS A ;-list of compiler definitions of the form -DFOO or -DFOO=bar. A definition for the name specified by will also be added automatically. CMAKE_REQUIRED_INCLUDES A ;-list of header search paths to pass to the compiler. These will be the only header search paths used--the contents of the INCLUDE_DIRECTORIES directory property will be ignored. CMAKE_REQUIRED_LINK_OPTIONS New in version 3.14. A ;-list of options to add to the link command (see try_compile() for further details). CMAKE_REQUIRED_LIBRARIES A ;-list of libraries to add to the link command. These can be the name of system libraries or they can be Imported Targets (see try_compile() for further details). CMAKE_REQUIRED_QUIET New in version 3.1. If this variable evaluates to a boolean true value, all status messages associated with the check will be suppressed. CheckCXXSymbolExists Check if a symbol exists as a function, variable, or macro in C++. check_cxx_symbol_exists check_cxx_symbol_exists( ) Check that the is available after including given header and store the result in a . Specify the list of files in one argument as a semicolon-separated list. check_cxx_symbol_exists() can be used to check for symbols as seen by the C++ compiler, as opposed to check_symbol_exists(), which always uses the C compiler. If the header files define the symbol as a macro it is considered available and assumed to work. If the header files declare the symbol as a function or variable then the symbol must also be available for linking. If the symbol is a type, enum value, or C++ template it will not be recognized: consider using the CheckTypeSize or CheckSourceCompiles module instead. NOTE: This command is unreliable when is (potentially) an overloaded function. Since there is no reliable way to predict whether a given function in the system environment may be defined as an overloaded function or may be an overloaded function on other systems or will become so in the future, it is generally advised to use the CheckSourceCompiles module for checking any function symbol (unless somehow you surely know the checked function is not overloaded on other systems or will not be so in the future). The following variables may be set before calling this macro to modify the way the check is run: CMAKE_REQUIRED_FLAGS String of additional flags to pass to the compiler. The string must be space-delimited--a ;-list will not work. The contents of CMAKE__FLAGS and its associated configuration-specific variable are automatically added to the compiler command before the contents of CMAKE_REQUIRED_FLAGS. CMAKE_REQUIRED_DEFINITIONS A ;-list of compiler definitions of the form -DFOO or -DFOO=bar. A definition for the name specified by will also be added automatically. CMAKE_REQUIRED_INCLUDES A ;-list of header search paths to pass to the compiler. These will be the only header search paths used--the contents of the INCLUDE_DIRECTORIES directory property will be ignored. CMAKE_REQUIRED_LINK_OPTIONS New in version 3.14. A ;-list of options to add to the link command (see try_compile() for further details). CMAKE_REQUIRED_LIBRARIES A ;-list of libraries to add to the link command. These can be the name of system libraries or they can be Imported Targets (see try_compile() for further details). CMAKE_REQUIRED_QUIET New in version 3.1. If this variable evaluates to a boolean true value, all status messages associated with the check will be suppressed. For example: include(CheckCXXSymbolExists) # Check for macro SEEK_SET check_cxx_symbol_exists(SEEK_SET "cstdio" HAVE_SEEK_SET) # Check for function std::fopen check_cxx_symbol_exists(std::fopen "cstdio" HAVE_STD_FOPEN) CheckFortranCompilerFlag New in version 3.3. Check whether the Fortran compiler supports a given flag. check_fortran_compiler_flag check_fortran_compiler_flag( ) Check that the is accepted by the compiler without a diagnostic. Stores the result in an internal cache entry named . A positive result from this check indicates only that the compiler did not issue a diagnostic message when given the flag. Whether the flag has any effect or even a specific one is beyond the scope of this module. The check is only performed once, with the result cached in the variable named by . Every subsequent CMake run will reuse this cached value rather than performing the check again, even if the changes. In order to force the check to be re-evaluated, the variable named by must be manually removed from the cache. The compile and link commands can be influenced by setting any of the following variables prior to calling check_fortran_compiler_flag() CMAKE_REQUIRED_FLAGS String of additional flags to pass to the compiler. The string must be space-delimited--a ;-list will not work. The contents of CMAKE__FLAGS and its associated configuration-specific variable are automatically added to the compiler command before the contents of CMAKE_REQUIRED_FLAGS. CMAKE_REQUIRED_DEFINITIONS A ;-list of compiler definitions of the form -DFOO or -DFOO=bar. A definition for the name specified by will also be added automatically. CMAKE_REQUIRED_INCLUDES A ;-list of header search paths to pass to the compiler. These will be the only header search paths used--the contents of the INCLUDE_DIRECTORIES directory property will be ignored. CMAKE_REQUIRED_LINK_OPTIONS New in version 3.14. A ;-list of options to add to the link command (see try_compile() for further details). CMAKE_REQUIRED_LIBRARIES A ;-list of libraries to add to the link command. These can be the name of system libraries or they can be Imported Targets (see try_compile() for further details). CMAKE_REQUIRED_QUIET New in version 3.1. If this variable evaluates to a boolean true value, all status messages associated with the check will be suppressed. CheckFortranFunctionExists Check if a Fortran function exists. CHECK_FORTRAN_FUNCTION_EXISTS CHECK_FORTRAN_FUNCTION_EXISTS( ) where the name of the Fortran function variable to store the result; will be created as an internal cache variable. NOTE: This command does not detect functions in Fortran modules. In general it is recommended to use CheckSourceCompiles instead to determine if a Fortran function or subroutine is available. The following variables may be set before calling this macro to modify the way the check is run: CMAKE_REQUIRED_LINK_OPTIONS New in version 3.14: A ;-list of options to add to the link command (see try_compile() for further details). CMAKE_REQUIRED_LIBRARIES A ;-list of libraries to add to the link command. These can be the name of system libraries or they can be Imported Targets (see try_compile() for further details). CheckFortranSourceCompiles New in version 3.1. Check if given Fortran source compiles and links into an executable. check_fortran_source_compiles check_fortran_source_compiles( [FAIL_REGEX ...] [SRC_EXT ] ) Checks that the source supplied in can be compiled as a Fortran source file and linked as an executable. The must be a Fortran program. check_fortran_source_compiles("program test error stop end program" HAVE_ERROR_STOP SRC_EXT .F90) This command can help avoid costly build processes when a compiler lacks support for a necessary feature, or a particular vendor library is not compatible with the Fortran compiler version being used. This generate-time check may advise the user of such before the main build process. See also the check_fortran_source_runs() command to run the compiled code. The result will be stored in the internal cache variable , with a boolean true value for success and boolean false for failure. If FAIL_REGEX is provided, then failure is determined by checking if anything in the output matches any of the specified regular expressions. By default, the test source file will be given a .F file extension. The SRC_EXT option can be used to override this with . instead-- .F90 is a typical choice. The check is only performed once, with the result cached in the variable named by . Every subsequent CMake run will reuse this cached value rather than performing the check again, even if the changes. In order to force the check to be re-evaluated, the variable named by must be manually removed from the cache. The compile and link commands can be influenced by setting any of the following variables prior to calling check_fortran_source_compiles(): CMAKE_REQUIRED_FLAGS String of additional flags to pass to the compiler. The string must be space-delimited--a ;-list will not work. The contents of CMAKE__FLAGS and its associated configuration-specific variable are automatically added to the compiler command before the contents of CMAKE_REQUIRED_FLAGS. CMAKE_REQUIRED_DEFINITIONS A ;-list of compiler definitions of the form -DFOO or -DFOO=bar. A definition for the name specified by will also be added automatically. CMAKE_REQUIRED_INCLUDES A ;-list of header search paths to pass to the compiler. These will be the only header search paths used--the contents of the INCLUDE_DIRECTORIES directory property will be ignored. CMAKE_REQUIRED_LINK_OPTIONS New in version 3.14. A ;-list of options to add to the link command (see try_compile() for further details). CMAKE_REQUIRED_LIBRARIES A ;-list of libraries to add to the link command. These can be the name of system libraries or they can be Imported Targets (see try_compile() for further details). CMAKE_REQUIRED_QUIET New in version 3.1. If this variable evaluates to a boolean true value, all status messages associated with the check will be suppressed. CheckFortranSourceRuns New in version 3.14. Check if given Fortran source compiles and links into an executable and can subsequently be run. check_fortran_source_runs check_fortran_source_runs( [SRC_EXT ]) Check that the source supplied in can be compiled as a Fortran source file, linked as an executable and then run. The must be a Fortran program. check_fortran_source_runs("program test real :: x[*] call co_sum(x) end program" HAVE_COARRAY) This command can help avoid costly build processes when a compiler lacks support for a necessary feature, or a particular vendor library is not compatible with the Fortran compiler version being used. Some of these failures only occur at runtime instead of linktime, and a trivial runtime example can catch the issue before the main build process. If the could be built and run successfully, the internal cache variable specified by will be set to 1, otherwise it will be set to an value that evaluates to boolean false (e.g. an empty string or an error message). By default, the test source file will be given a .F90 file extension. The SRC_EXT option can be used to override this with . instead. The check is only performed once, with the result cached in the variable named by . Every subsequent CMake run will reuse this cached value rather than performing the check again, even if the changes. In order to force the check to be re-evaluated, the variable named by must be manually removed from the cache. The compile and link commands can be influenced by setting any of the following variables prior to calling check_fortran_source_runs(): CMAKE_REQUIRED_FLAGS String of additional flags to pass to the compiler. The string must be space-delimited--a ;-list will not work. The contents of CMAKE__FLAGS and its associated configuration-specific variable are automatically added to the compiler command before the contents of CMAKE_REQUIRED_FLAGS. CMAKE_REQUIRED_DEFINITIONS A ;-list of compiler definitions of the form -DFOO or -DFOO=bar. A definition for the name specified by will also be added automatically. CMAKE_REQUIRED_INCLUDES A ;-list of header search paths to pass to the compiler. These will be the only header search paths used--the contents of the INCLUDE_DIRECTORIES directory property will be ignored. CMAKE_REQUIRED_LINK_OPTIONS New in version 3.14. A ;-list of options to add to the link command (see try_compile() for further details). CMAKE_REQUIRED_LIBRARIES A ;-list of libraries to add to the link command. These can be the name of system libraries or they can be Imported Targets (see try_compile() for further details). CMAKE_REQUIRED_QUIET New in version 3.1. If this variable evaluates to a boolean true value, all status messages associated with the check will be suppressed. CheckFunctionExists Check if a C function can be linked check_function_exists check_function_exists( ) Checks that the is provided by libraries on the system and store the result in a , which will be created as an internal cache variable. The following variables may be set before calling this macro to modify the way the check is run: CMAKE_REQUIRED_FLAGS String of additional flags to pass to the compiler. The string must be space-delimited--a ;-list will not work. The contents of CMAKE__FLAGS and its associated configuration-specific variable are automatically added to the compiler command before the contents of CMAKE_REQUIRED_FLAGS. CMAKE_REQUIRED_DEFINITIONS A ;-list of compiler definitions of the form -DFOO or -DFOO=bar. A definition for the name specified by will also be added automatically. CMAKE_REQUIRED_INCLUDES A ;-list of header search paths to pass to the compiler. These will be the only header search paths used--the contents of the INCLUDE_DIRECTORIES directory property will be ignored. CMAKE_REQUIRED_LINK_OPTIONS New in version 3.14. A ;-list of options to add to the link command (see try_compile() for further details). CMAKE_REQUIRED_LIBRARIES A ;-list of libraries to add to the link command. These can be the name of system libraries or they can be Imported Targets (see try_compile() for further details). CMAKE_REQUIRED_QUIET New in version 3.1. If this variable evaluates to a boolean true value, all status messages associated with the check will be suppressed. NOTE: Prefer using CheckSymbolExists instead of this module, for the following reasons: o check_function_exists() can't detect functions that are inlined in headers or specified as a macro. o check_function_exists() can't detect anything in the 32-bit versions of the Win32 API, because of a mismatch in calling conventions. o check_function_exists() only verifies linking, it does not verify that the function is declared in system headers. CheckIncludeFileCXX Provides a macro to check if a header file can be included in CXX. CHECK_INCLUDE_FILE_CXX CHECK_INCLUDE_FILE_CXX( []) Check if the given file may be included in a CXX source file and store the result in an internal cache entry named . The optional third argument may be used to add compilation flags to the check (or use CMAKE_REQUIRED_FLAGS below). The following variables may be set before calling this macro to modify the way the check is run: CMAKE_REQUIRED_FLAGS String of additional flags to pass to the compiler. The string must be space-delimited--a ;-list will not work. The contents of CMAKE__FLAGS and its associated configuration-specific variable are automatically added to the compiler command before the contents of CMAKE_REQUIRED_FLAGS. CMAKE_REQUIRED_DEFINITIONS A ;-list of compiler definitions of the form -DFOO or -DFOO=bar. A definition for the name specified by will also be added automatically. CMAKE_REQUIRED_INCLUDES A ;-list of header search paths to pass to the compiler. These will be the only header search paths used--the contents of the INCLUDE_DIRECTORIES directory property will be ignored. CMAKE_REQUIRED_LINK_OPTIONS New in version 3.14. A ;-list of options to add to the link command (see try_compile() for further details). CMAKE_REQUIRED_LIBRARIES A ;-list of libraries to add to the link command. These can be the name of system libraries or they can be Imported Targets (see try_compile() for further details). CMAKE_REQUIRED_QUIET New in version 3.1. If this variable evaluates to a boolean true value, all status messages associated with the check will be suppressed. See modules CheckIncludeFile and CheckIncludeFiles to check for one or more C headers. CheckIncludeFile Provides a macro to check if a header file can be included in C. CHECK_INCLUDE_FILE CHECK_INCLUDE_FILE( []) Check if the given file may be included in a C source file and store the result in an internal cache entry named . The optional third argument may be used to add compilation flags to the check (or use CMAKE_REQUIRED_FLAGS below). The following variables may be set before calling this macro to modify the way the check is run: CMAKE_REQUIRED_FLAGS String of additional flags to pass to the compiler. The string must be space-delimited--a ;-list will not work. The contents of CMAKE__FLAGS and its associated configuration-specific variable are automatically added to the compiler command before the contents of CMAKE_REQUIRED_FLAGS. CMAKE_REQUIRED_DEFINITIONS A ;-list of compiler definitions of the form -DFOO or -DFOO=bar. A definition for the name specified by will also be added automatically. CMAKE_REQUIRED_INCLUDES A ;-list of header search paths to pass to the compiler. These will be the only header search paths used--the contents of the INCLUDE_DIRECTORIES directory property will be ignored. CMAKE_REQUIRED_LINK_OPTIONS New in version 3.14. A ;-list of options to add to the link command (see try_compile() for further details). CMAKE_REQUIRED_LIBRARIES A ;-list of libraries to add to the link command. These can be the name of system libraries or they can be Imported Targets (see try_compile() for further details). CMAKE_REQUIRED_QUIET New in version 3.1. If this variable evaluates to a boolean true value, all status messages associated with the check will be suppressed. See the CheckIncludeFiles module to check for multiple headers at once. See the CheckIncludeFileCXX module to check for headers using the CXX language. CheckIncludeFiles Provides a macro to check if a list of one or more header files can be included together. CHECK_INCLUDE_FILES CHECK_INCLUDE_FILES("" [LANGUAGE ]) Check if the given list may be included together in a source file and store the result in an internal cache entry named . Specify the argument as a ;-list of header file names. If LANGUAGE is set, the specified compiler will be used to perform the check. Acceptable values are C and CXX. If not set, the C compiler will be used if enabled. If the C compiler is not enabled, the C++ compiler will be used if enabled. The following variables may be set before calling this macro to modify the way the check is run: CMAKE_REQUIRED_FLAGS String of additional flags to pass to the compiler. The string must be space-delimited--a ;-list will not work. The contents of CMAKE__FLAGS and its associated configuration-specific variable are automatically added to the compiler command before the contents of CMAKE_REQUIRED_FLAGS. CMAKE_REQUIRED_DEFINITIONS A ;-list of compiler definitions of the form -DFOO or -DFOO=bar. A definition for the name specified by will also be added automatically. CMAKE_REQUIRED_INCLUDES A ;-list of header search paths to pass to the compiler. These will be the only header search paths used--the contents of the INCLUDE_DIRECTORIES directory property will be ignored. CMAKE_REQUIRED_LINK_OPTIONS New in version 3.14. A ;-list of options to add to the link command (see try_compile() for further details). CMAKE_REQUIRED_LIBRARIES A ;-list of libraries to add to the link command. These can be the name of system libraries or they can be Imported Targets (see try_compile() for further details). CMAKE_REQUIRED_QUIET New in version 3.1. If this variable evaluates to a boolean true value, all status messages associated with the check will be suppressed. See modules CheckIncludeFile and CheckIncludeFileCXX to check for a single header file in C or CXX languages. CheckIPOSupported New in version 3.9. Check whether the compiler supports an interprocedural optimization (IPO/LTO). Use this before enabling the INTERPROCEDURAL_OPTIMIZATION target property. check_ipo_supported check_ipo_supported([RESULT ] [OUTPUT ] [LANGUAGES ...]) Options are: RESULT Set variable to YES if IPO is supported by the compiler and NO otherwise. If this option is not given then the command will issue a fatal error if IPO is not supported. OUTPUT Set variable with details about any error. LANGUAGES ... Specify languages whose compilers to check. Languages C, CXX, and Fortran are supported. It makes no sense to use this module when CMP0069 is set to OLD so module will return error in this case. See policy CMP0069 for details. New in version 3.13: Add support for Visual Studio generators. New in version 3.24: The check uses the caller's CMAKE__FLAGS and CMAKE__FLAGS_ values. See policy CMP0138. Examples check_ipo_supported() # fatal error if IPO is not supported set_property(TARGET foo PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE) # Optional IPO. Do not use IPO if it's not supported by compiler. check_ipo_supported(RESULT result OUTPUT output) if(result) set_property(TARGET foo PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE) else() message(WARNING "IPO is not supported: ${output}") endif() CheckLanguage Check whether a language can be enabled by the enable_language() or project() commands: check_language check_language() Try enabling language in a test project and record results in the cache: 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 NOTFOUND. If this variable is already set, either explicitly or cached by a previous call, the check is skipped. CMAKE__HOST_COMPILER This variable is set when is CUDA or HIP. If the check detects an explicit host compiler that is required for compilation, this variable will be set to that compiler. If the check detects that no explicit host compiler is needed, this variable will be cleared. If this variable is already set, its value is preserved only if CMAKE__COMPILER is also set. Otherwise, the check runs and overwrites CMAKE__HOST_COMPILER with a new result. Note that CMAKE__HOST_COMPILER documents it should not be set without also setting CMAKE__COMPILER to a NVCC compiler. CMAKE__PLATFORM This variable is set to the detected GPU platform when is HIP. If the variable is already set its value is always preserved. Only compatible values will be considered for CMAKE__COMPILER. For example: check_language(Fortran) if(CMAKE_Fortran_COMPILER) enable_language(Fortran) else() message(STATUS "No Fortran support") endif() CheckLibraryExists Check if the function exists. CHECK_LIBRARY_EXISTS CHECK_LIBRARY_EXISTS(LIBRARY FUNCTION LOCATION VARIABLE) LIBRARY - the name of the library you are looking for FUNCTION - the name of the function LOCATION - location where the library should be found VARIABLE - variable to store the result Will be created as an internal cache variable. The following variables may be set before calling this macro to modify the way the check is run: CMAKE_REQUIRED_FLAGS String of additional flags to pass to the compiler. The string must be space-delimited--a ;-list will not work. The contents of CMAKE__FLAGS and its associated configuration-specific variable are automatically added to the compiler command before the contents of CMAKE_REQUIRED_FLAGS. CMAKE_REQUIRED_DEFINITIONS A ;-list of compiler definitions of the form -DFOO or -DFOO=bar. A definition for the name specified by will also be added automatically. CMAKE_REQUIRED_LINK_OPTIONS New in version 3.14. A ;-list of options to add to the link command (see try_compile() for further details). CMAKE_REQUIRED_LIBRARIES A ;-list of libraries to add to the link command. These can be the name of system libraries or they can be Imported Targets (see try_compile() for further details). CMAKE_REQUIRED_QUIET New in version 3.1. If this variable evaluates to a boolean true value, all status messages associated with the check will be suppressed. CheckLinkerFlag New in version 3.18. Check whether the compiler supports a given link flag. check_linker_flag check_linker_flag( ) Check that the link is accepted by the compiler without a diagnostic. Stores the result in an internal cache entry named . This command temporarily sets the CMAKE_REQUIRED_LINK_OPTIONS variable and calls the check_source_compiles() command from the CheckSourceCompiles module. See that module's documentation for a listing of variables that can otherwise modify the build. The underlying implementation relies on the LINK_OPTIONS property to check the specified flag. The LINKER: prefix, as described in the target_link_options() command, can be used as well. A positive result from this check indicates only that the compiler did not issue a diagnostic message when given the link flag. Whether the flag has any effect or even a specific one is beyond the scope of this module. NOTE: Since the try_compile() command forwards flags from variables like CMAKE__FLAGS, unknown flags in such variables may cause a false negative for this check. CheckOBJCCompilerFlag New in version 3.16. Check whether the Objective-C compiler supports a given flag. check_objc_compiler_flag check_objc_compiler_flag( ) Check that the is accepted by the compiler without a diagnostic. Stores the result in an internal cache entry named . A positive result from this check indicates only that the compiler did not issue a diagnostic message when given the flag. Whether the flag has any effect or even a specific one is beyond the scope of this module. The check is only performed once, with the result cached in the variable named by . Every subsequent CMake run will reuse this cached value rather than performing the check again, even if the changes. In order to force the check to be re-evaluated, the variable named by must be manually removed from the cache. The compile and link commands can be influenced by setting any of the following variables prior to calling check_objc_compiler_flag() CMAKE_REQUIRED_FLAGS String of additional flags to pass to the compiler. The string must be space-delimited--a ;-list will not work. The contents of CMAKE__FLAGS and its associated configuration-specific variable are automatically added to the compiler command before the contents of CMAKE_REQUIRED_FLAGS. CMAKE_REQUIRED_DEFINITIONS A ;-list of compiler definitions of the form -DFOO or -DFOO=bar. A definition for the name specified by will also be added automatically. CMAKE_REQUIRED_INCLUDES A ;-list of header search paths to pass to the compiler. These will be the only header search paths used--the contents of the INCLUDE_DIRECTORIES directory property will be ignored. CMAKE_REQUIRED_LINK_OPTIONS New in version 3.14. A ;-list of options to add to the link command (see try_compile() for further details). CMAKE_REQUIRED_LIBRARIES A ;-list of libraries to add to the link command. These can be the name of system libraries or they can be Imported Targets (see try_compile() for further details). CMAKE_REQUIRED_QUIET New in version 3.1. If this variable evaluates to a boolean true value, all status messages associated with the check will be suppressed. CheckOBJCSourceCompiles New in version 3.16. Check if given Objective-C source compiles and links into an executable. check_objc_source_compiles check_objc_source_compiles( [FAIL_REGEX [...]]) Check that the source supplied in can be compiled as a Objectie-C source file and linked as an executable (so it must contain at least a main() function). The result will be stored in the internal cache variable specified by , with a boolean true value for success and boolean false for failure. If FAIL_REGEX is provided, then failure is determined by checking if anything in the output matches any of the specified regular expressions. The check is only performed once, with the result cached in the variable named by . Every subsequent CMake run will reuse this cached value rather than performing the check again, even if the changes. In order to force the check to be re-evaluated, the variable named by must be manually removed from the cache. The compile and link commands can be influenced by setting any of the following variables prior to calling check_objc_source_compiles() CMAKE_REQUIRED_FLAGS String of additional flags to pass to the compiler. The string must be space-delimited--a ;-list will not work. The contents of CMAKE__FLAGS and its associated configuration-specific variable are automatically added to the compiler command before the contents of CMAKE_REQUIRED_FLAGS. CMAKE_REQUIRED_DEFINITIONS A ;-list of compiler definitions of the form -DFOO or -DFOO=bar. A definition for the name specified by will also be added automatically. CMAKE_REQUIRED_INCLUDES A ;-list of header search paths to pass to the compiler. These will be the only header search paths used--the contents of the INCLUDE_DIRECTORIES directory property will be ignored. CMAKE_REQUIRED_LINK_OPTIONS New in version 3.14. A ;-list of options to add to the link command (see try_compile() for further details). CMAKE_REQUIRED_LIBRARIES A ;-list of libraries to add to the link command. These can be the name of system libraries or they can be Imported Targets (see try_compile() for further details). CMAKE_REQUIRED_QUIET New in version 3.1. If this variable evaluates to a boolean true value, all status messages associated with the check will be suppressed. CheckOBJCSourceRuns New in version 3.16. Check if given Objective-C source compiles and links into an executable and can subsequently be run. check_objc_source_runs check_objc_source_runs( ) Check that the source supplied in can be compiled as a Objective-C source file, linked as an executable and then run. The must contain at least a main() function. If the could be built and run successfully, the internal cache variable specified by will be set to 1, otherwise it will be set to an value that evaluates to boolean false (e.g. an empty string or an error message). The check is only performed once, with the result cached in the variable named by . Every subsequent CMake run will reuse this cached value rather than performing the check again, even if the changes. In order to force the check to be re-evaluated, the variable named by must be manually removed from the cache. The compile and link commands can be influenced by setting any of the following variables prior to calling check_objc_source_runs() CMAKE_REQUIRED_FLAGS String of additional flags to pass to the compiler. The string must be space-delimited--a ;-list will not work. The contents of CMAKE__FLAGS and its associated configuration-specific variable are automatically added to the compiler command before the contents of CMAKE_REQUIRED_FLAGS. CMAKE_REQUIRED_DEFINITIONS A ;-list of compiler definitions of the form -DFOO or -DFOO=bar. A definition for the name specified by will also be added automatically. CMAKE_REQUIRED_INCLUDES A ;-list of header search paths to pass to the compiler. These will be the only header search paths used--the contents of the INCLUDE_DIRECTORIES directory property will be ignored. CMAKE_REQUIRED_LINK_OPTIONS New in version 3.14. A ;-list of options to add to the link command (see try_compile() for further details). CMAKE_REQUIRED_LIBRARIES A ;-list of libraries to add to the link command. These can be the name of system libraries or they can be Imported Targets (see try_compile() for further details). CMAKE_REQUIRED_QUIET New in version 3.1. If this variable evaluates to a boolean true value, all status messages associated with the check will be suppressed. CheckOBJCXXCompilerFlag New in version 3.16. Check whether the Objective-C++ compiler supports a given flag. check_objcxx_compiler_flag check_objcxx_compiler_flag( ) Check that the is accepted by the compiler without a diagnostic. Stores the result in an internal cache entry named . A positive result from this check indicates only that the compiler did not issue a diagnostic message when given the flag. Whether the flag has any effect or even a specific one is beyond the scope of this module. The check is only performed once, with the result cached in the variable named by . Every subsequent CMake run will reuse this cached value rather than performing the check again, even if the changes. In order to force the check to be re-evaluated, the variable named by must be manually removed from the cache. The compile and link commands can be influenced by setting any of the following variables prior to calling check_objcxx_compiler_flag() CMAKE_REQUIRED_FLAGS String of additional flags to pass to the compiler. The string must be space-delimited--a ;-list will not work. The contents of CMAKE__FLAGS and its associated configuration-specific variable are automatically added to the compiler command before the contents of CMAKE_REQUIRED_FLAGS. CMAKE_REQUIRED_DEFINITIONS A ;-list of compiler definitions of the form -DFOO or -DFOO=bar. A definition for the name specified by will also be added automatically. CMAKE_REQUIRED_INCLUDES A ;-list of header search paths to pass to the compiler. These will be the only header search paths used--the contents of the INCLUDE_DIRECTORIES directory property will be ignored. CMAKE_REQUIRED_LINK_OPTIONS New in version 3.14. A ;-list of options to add to the link command (see try_compile() for further details). CMAKE_REQUIRED_LIBRARIES A ;-list of libraries to add to the link command. These can be the name of system libraries or they can be Imported Targets (see try_compile() for further details). CMAKE_REQUIRED_QUIET New in version 3.1. If this variable evaluates to a boolean true value, all status messages associated with the check will be suppressed. CheckOBJCXXSourceCompiles New in version 3.16. Check if given Objective-C++ source compiles and links into an executable. check_objcxx_source_compiles check_objcxx_source_compiles( [FAIL_REGEX [...]]) Check that the source supplied in can be compiled as a Objective-C++ source file and linked as an executable (so it must contain at least a main() function). The result will be stored in the internal cache variable specified by , with a boolean true value for success and boolean false for failure. If FAIL_REGEX is provided, then failure is determined by checking if anything in the output matches any of the specified regular expressions. The check is only performed once, with the result cached in the variable named by . Every subsequent CMake run will reuse this cached value rather than performing the check again, even if the changes. In order to force the check to be re-evaluated, the variable named by must be manually removed from the cache. The compile and link commands can be influenced by setting any of the following variables prior to calling check_objcxx_source_compiles() CMAKE_REQUIRED_FLAGS String of additional flags to pass to the compiler. The string must be space-delimited--a ;-list will not work. The contents of CMAKE__FLAGS and its associated configuration-specific variable are automatically added to the compiler command before the contents of CMAKE_REQUIRED_FLAGS. CMAKE_REQUIRED_DEFINITIONS A ;-list of compiler definitions of the form -DFOO or -DFOO=bar. A definition for the name specified by will also be added automatically. CMAKE_REQUIRED_INCLUDES A ;-list of header search paths to pass to the compiler. These will be the only header search paths used--the contents of the INCLUDE_DIRECTORIES directory property will be ignored. CMAKE_REQUIRED_LINK_OPTIONS New in version 3.14. A ;-list of options to add to the link command (see try_compile() for further details). CMAKE_REQUIRED_LIBRARIES A ;-list of libraries to add to the link command. These can be the name of system libraries or they can be Imported Targets (see try_compile() for further details). CMAKE_REQUIRED_QUIET New in version 3.1. If this variable evaluates to a boolean true value, all status messages associated with the check will be suppressed. CheckOBJCXXSourceRuns New in version 3.16. Check if given Objective-C++ source compiles and links into an executable and can subsequently be run. check_objcxx_source_runs check_objcxx_source_runs( ) Check that the source supplied in can be compiled as a Objective-C++ source file, linked as an executable and then run. The must contain at least a main() function. If the could be built and run successfully, the internal cache variable specified by will be set to 1, otherwise it will be set to an value that evaluates to boolean false (e.g. an empty string or an error message). The check is only performed once, with the result cached in the variable named by . Every subsequent CMake run will reuse this cached value rather than performing the check again, even if the changes. In order to force the check to be re-evaluated, the variable named by must be manually removed from the cache. The compile and link commands can be influenced by setting any of the following variables prior to calling check_objcxx_source_runs() CMAKE_REQUIRED_FLAGS String of additional flags to pass to the compiler. The string must be space-delimited--a ;-list will not work. The contents of CMAKE__FLAGS and its associated configuration-specific variable are automatically added to the compiler command before the contents of CMAKE_REQUIRED_FLAGS. CMAKE_REQUIRED_DEFINITIONS A ;-list of compiler definitions of the form -DFOO or -DFOO=bar. A definition for the name specified by will also be added automatically. CMAKE_REQUIRED_INCLUDES A ;-list of header search paths to pass to the compiler. These will be the only header search paths used--the contents of the INCLUDE_DIRECTORIES directory property will be ignored. CMAKE_REQUIRED_LINK_OPTIONS New in version 3.14. A ;-list of options to add to the link command (see try_compile() for further details). CMAKE_REQUIRED_LIBRARIES A ;-list of libraries to add to the link command. These can be the name of system libraries or they can be Imported Targets (see try_compile() for further details). CMAKE_REQUIRED_QUIET New in version 3.1. If this variable evaluates to a boolean true value, all status messages associated with the check will be suppressed. CheckPIESupported New in version 3.14. Check whether the linker supports Position Independent Code (PIE) or No Position Independent Code (NO_PIE) for executables. Use this to ensure that the POSITION_INDEPENDENT_CODE target property for executables will be honored at link time. check_pie_supported check_pie_supported([OUTPUT_VARIABLE ] [LANGUAGES ...]) Options are: OUTPUT_VARIABLE Set 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. LANGUAGES ... Check the linkers used for each of the specified languages. If this option is not provided, the command checks all enabled languages. C, CXX, Fortran are supported. New in version 3.23: OBJC, OBJCXX, CUDA, and HIP are supported. It makes no sense to use this module when CMP0083 is set to OLD, so the command will return an error in this case. See policy CMP0083 for details. Variables For each language checked, two boolean cache variables are defined. CMAKE__LINK_PIE_SUPPORTED Set to true if PIE is supported by the linker and false otherwise. CMAKE__LINK_NO_PIE_SUPPORTED Set to true if NO_PIE is supported by the linker and false otherwise. Examples check_pie_supported() set_property(TARGET foo PROPERTY POSITION_INDEPENDENT_CODE TRUE) # Retrieve any error message. check_pie_supported(OUTPUT_VARIABLE output LANGUAGES C) set_property(TARGET foo PROPERTY POSITION_INDEPENDENT_CODE TRUE) if(NOT CMAKE_C_LINK_PIE_SUPPORTED) message(WARNING "PIE is not supported at link time: ${output}.\n" "PIE link options will not be passed to linker.") endif() CheckPrototypeDefinition Check if the prototype we expect is correct. check_prototype_definition check_prototype_definition(FUNCTION PROTOTYPE RETURN HEADER VARIABLE) FUNCTION - The name of the function (used to check if prototype exists) PROTOTYPE- The prototype to check. RETURN - The return value of the function. HEADER - The header files required. VARIABLE - The variable to store the result. Will be created as an internal cache variable. Example: check_prototype_definition(getpwent_r "struct passwd *getpwent_r(struct passwd *src, char *buf, int buflen)" "NULL" "unistd.h;pwd.h" SOLARIS_GETPWENT_R) The following variables may be set before calling this function to modify the way the check is run: CMAKE_REQUIRED_FLAGS String of additional flags to pass to the compiler. The string must be space-delimited--a ;-list will not work. The contents of CMAKE__FLAGS and its associated configuration-specific variable are automatically added to the compiler command before the contents of CMAKE_REQUIRED_FLAGS. CMAKE_REQUIRED_DEFINITIONS A ;-list of compiler definitions of the form -DFOO or -DFOO=bar. A definition for the name specified by will also be added automatically. CMAKE_REQUIRED_INCLUDES A ;-list of header search paths to pass to the compiler. These will be the only header search paths used--the contents of the INCLUDE_DIRECTORIES directory property will be ignored. CMAKE_REQUIRED_LINK_OPTIONS New in version 3.14. A ;-list of options to add to the link command (see try_compile() for further details). CMAKE_REQUIRED_LIBRARIES A ;-list of libraries to add to the link command. These can be the name of system libraries or they can be Imported Targets (see try_compile() for further details). CMAKE_REQUIRED_QUIET New in version 3.1. If this variable evaluates to a boolean true value, all status messages associated with the check will be suppressed. CheckSourceCompiles New in version 3.19. Check if given source compiles and links into an executable. check_source_compiles check_source_compiles( [FAIL_REGEX [...]] [SRC_EXT ]) Check that the source supplied in can be compiled as a source file for the requested language and linked as an executable. The result will be stored in the internal cache variable specified by , with a boolean true value for success and boolean false for failure. If FAIL_REGEX is provided, then failure is determined by checking if anything in the compiler output matches any of the specified regular expressions. By default, the test source file will be given a file extension that matches the requested language. The SRC_EXT option can be used to override this with . instead. The must contain a valid main program. For example: check_source_compiles(C "#include #include noreturn void f(){ exit(0); } int main(void) { f(); return 1; }" HAVE_NORETURN) check_source_compiles(Fortran "program test error stop end program" HAVE_ERROR_STOP) The check is only performed once, with the result cached in the variable named by . Every subsequent CMake run will reuse this cached value rather than performing the check again, even if the changes. In order to force the check to be re-evaluated, the variable named by must be manually removed from the cache. The compile and link commands can be influenced by setting any of the following variables prior to calling check_source_compiles(): CMAKE_REQUIRED_FLAGS String of additional flags to pass to the compiler. The string must be space-delimited--a ;-list will not work. The contents of CMAKE__FLAGS and its associated configuration-specific variable are automatically added to the compiler command before the contents of CMAKE_REQUIRED_FLAGS. CMAKE_REQUIRED_DEFINITIONS A ;-list of compiler definitions of the form -DFOO or -DFOO=bar. A definition for the name specified by will also be added automatically. CMAKE_REQUIRED_INCLUDES A ;-list of header search paths to pass to the compiler. These will be the only header search paths used--the contents of the INCLUDE_DIRECTORIES directory property will be ignored. CMAKE_REQUIRED_LINK_OPTIONS New in version 3.14. A ;-list of options to add to the link command (see try_compile() for further details). CMAKE_REQUIRED_LIBRARIES A ;-list of libraries to add to the link command. These can be the name of system libraries or they can be Imported Targets (see try_compile() for further details). CMAKE_REQUIRED_QUIET New in version 3.1. If this variable evaluates to a boolean true value, all status messages associated with the check will be suppressed. CheckSourceRuns New in version 3.19. Check if given source compiles and links into an executable and can subsequently be run. check_source_runs check_source_runs( [SRC_EXT ]) Check that the source supplied in can be compiled as a source file for the requested language, linked as an executable and then run. If the could be built and run successfully, the internal cache variable specified by will be set to 1, otherwise it will be set to a value that evaluates to boolean false (e.g. an empty string or an error message). By default, the test source file will be given a file extension that matches the requested language. The SRC_EXT option can be used to override this with . instead. The must contain a valid main program. For example: check_source_runs(C "#include #include noreturn void f(){ exit(0); } int main(void) { f(); return 1; }" HAVE_NORETURN) check_source_runs(Fortran "program test real :: x[*] call co_sum(x) end program" HAVE_COARRAY) The check is only performed once, with the result cached in the variable named by . Every subsequent CMake run will reuse this cached value rather than performing the check again, even if the changes. In order to force the check to be re-evaluated, the variable named by must be manually removed from the cache. The compile and link commands can be influenced by setting any of the following variables prior to calling check_source_runs() CMAKE_REQUIRED_FLAGS String of additional flags to pass to the compiler. The string must be space-delimited--a ;-list will not work. The contents of CMAKE__FLAGS and its associated configuration-specific variable are automatically added to the compiler command before the contents of CMAKE_REQUIRED_FLAGS. CMAKE_REQUIRED_DEFINITIONS A ;-list of compiler definitions of the form -DFOO or -DFOO=bar. A definition for the name specified by will also be added automatically. CMAKE_REQUIRED_INCLUDES A ;-list of header search paths to pass to the compiler. These will be the only header search paths used--the contents of the INCLUDE_DIRECTORIES directory property will be ignored. CMAKE_REQUIRED_LINK_OPTIONS New in version 3.14. A ;-list of options to add to the link command (see try_compile() for further details). CMAKE_REQUIRED_LIBRARIES A ;-list of libraries to add to the link command. These can be the name of system libraries or they can be Imported Targets (see try_compile() for further details). CMAKE_REQUIRED_QUIET New in version 3.1. If this variable evaluates to a boolean true value, all status messages associated with the check will be suppressed. CheckStructHasMember Check if the given struct or class has the specified member variable CHECK_STRUCT_HAS_MEMBER CHECK_STRUCT_HAS_MEMBER(
[LANGUAGE ]) - the name of the struct or class you are interested in - the member which existence you want to check
- the header(s) where the prototype should be declared - variable to store the result - the compiler to use (C or CXX) The following variables may be set before calling this macro to modify the way the check is run: CMAKE_REQUIRED_FLAGS String of additional flags to pass to the compiler. The string must be space-delimited--a ;-list will not work. The contents of CMAKE__FLAGS and its associated configuration-specific variable are automatically added to the compiler command before the contents of CMAKE_REQUIRED_FLAGS. CMAKE_REQUIRED_DEFINITIONS A ;-list of compiler definitions of the form -DFOO or -DFOO=bar. A definition for the name specified by will also be added automatically. CMAKE_REQUIRED_INCLUDES A ;-list of header search paths to pass to the compiler. These will be the only header search paths used--the contents of the INCLUDE_DIRECTORIES directory property will be ignored. CMAKE_REQUIRED_LINK_OPTIONS New in version 3.14. A ;-list of options to add to the link command (see try_compile() for further details). CMAKE_REQUIRED_LIBRARIES A ;-list of libraries to add to the link command. These can be the name of system libraries or they can be Imported Targets (see try_compile() for further details). CMAKE_REQUIRED_QUIET New in version 3.1. If this variable evaluates to a boolean true value, all status messages associated with the check will be suppressed. Example: CHECK_STRUCT_HAS_MEMBER("struct timeval" tv_sec sys/select.h HAVE_TIMEVAL_TV_SEC LANGUAGE C) CheckSymbolExists Provides a macro to check if a symbol exists as a function, variable, or macro in C. check_symbol_exists check_symbol_exists( ) Check that the is available after including given header and store the result in a . Specify the list of files in one argument as a semicolon-separated list. will be created as an internal cache variable. If the header files define the symbol as a macro it is considered available and assumed to work. If the header files declare the symbol as a function or variable then the symbol must also be available for linking (so intrinsics may not be detected). If the symbol is a type, enum value, or intrinsic it will not be recognized (consider using CheckTypeSize or CheckSourceCompiles). If the check needs to be done in C++, consider using CheckCXXSymbolExists instead. The following variables may be set before calling this macro to modify the way the check is run: CMAKE_REQUIRED_FLAGS String of additional flags to pass to the compiler. The string must be space-delimited--a ;-list will not work. The contents of CMAKE__FLAGS and its associated configuration-specific variable are automatically added to the compiler command before the contents of CMAKE_REQUIRED_FLAGS. CMAKE_REQUIRED_DEFINITIONS A ;-list of compiler definitions of the form -DFOO or -DFOO=bar. A definition for the name specified by will also be added automatically. CMAKE_REQUIRED_INCLUDES A ;-list of header search paths to pass to the compiler. These will be the only header search paths used--the contents of the INCLUDE_DIRECTORIES directory property will be ignored. CMAKE_REQUIRED_LINK_OPTIONS New in version 3.14. A ;-list of options to add to the link command (see try_compile() for further details). CMAKE_REQUIRED_LIBRARIES A ;-list of libraries to add to the link command. These can be the name of system libraries or they can be Imported Targets (see try_compile() for further details). CMAKE_REQUIRED_QUIET New in version 3.1. If this variable evaluates to a boolean true value, all status messages associated with the check will be suppressed. For example: include(CheckSymbolExists) # Check for macro SEEK_SET check_symbol_exists(SEEK_SET "stdio.h" HAVE_SEEK_SET) # Check for function fopen check_symbol_exists(fopen "stdio.h" HAVE_FOPEN) CheckTypeSize Check sizeof a type check_type_size check_type_size( [BUILTIN_TYPES_ONLY] [LANGUAGE ]) Check if the type exists and determine its size. Results are reported in the following variables: HAVE_ Holds a true or false value indicating whether the type exists. Holds one of the following values: Type has non-zero size . 0 Type has architecture-dependent size. This may occur when CMAKE_OSX_ARCHITECTURES has multiple architectures. In this case _CODE contains C preprocessor tests mapping from each architecture macro to the corresponding type size. The list of architecture macros is stored in _KEYS, and the value for each key is stored in -. "" (empty string) Type does not exist. _CODE Holds C preprocessor code to define the macro to the size of the type, or to leave the macro undefined if the type does not exist. The options are: BUILTIN_TYPES_ONLY Support only compiler-builtin types. If not given, the macro checks for headers , , and , and saves results in HAVE_SYS_TYPES_H, HAVE_STDINT_H, and HAVE_STDDEF_H. The type size check automatically includes the available headers, thus supporting checks of types defined in the headers. LANGUAGE Use the compiler to perform the check. Acceptable values are C and CXX. Despite the name of the macro you may use it to check the size of more complex expressions, too. To check e.g. for the size of a struct member you can do something like this: check_type_size("((struct something*)0)->member" SIZEOF_MEMBER) The following variables may be set before calling this macro to modify the way the check is run: CMAKE_REQUIRED_FLAGS String of additional flags to pass to the compiler. The string must be space-delimited--a ;-list will not work. The contents of CMAKE__FLAGS and its associated configuration-specific variable are automatically added to the compiler command before the contents of CMAKE_REQUIRED_FLAGS. CMAKE_REQUIRED_DEFINITIONS A ;-list of compiler definitions of the form -DFOO or -DFOO=bar. A definition for the name specified by will also be added automatically. CMAKE_REQUIRED_INCLUDES A ;-list of header search paths to pass to the compiler. These will be the only header search paths used--the contents of the INCLUDE_DIRECTORIES directory property will be ignored. CMAKE_REQUIRED_LINK_OPTIONS New in version 3.14. A ;-list of options to add to the link command (see try_compile() for further details). CMAKE_REQUIRED_LIBRARIES A ;-list of libraries to add to the link command. These can be the name of system libraries or they can be Imported Targets (see try_compile() for further details). CMAKE_REQUIRED_QUIET New in version 3.1. If this variable evaluates to a boolean true value, all status messages associated with the check will be suppressed. CMAKE_EXTRA_INCLUDE_FILES list of extra headers to include. CheckVariableExists Check if the variable exists. CHECK_VARIABLE_EXISTS CHECK_VARIABLE_EXISTS(VAR VARIABLE) VAR - the name of the variable VARIABLE - variable to store the result Will be created as an internal cache variable. This macro is only for C variables. The following variables may be set before calling this macro to modify the way the check is run: CMAKE_REQUIRED_FLAGS String of additional flags to pass to the compiler. The string must be space-delimited--a ;-list will not work. The contents of CMAKE__FLAGS and its associated configuration-specific variable are automatically added to the compiler command before the contents of CMAKE_REQUIRED_FLAGS. CMAKE_REQUIRED_DEFINITIONS A ;-list of compiler definitions of the form -DFOO or -DFOO=bar. A definition for the name specified by will also be added automatically. CMAKE_REQUIRED_LINK_OPTIONS New in version 3.14. A ;-list of options to add to the link command (see try_compile() for further details). CMAKE_REQUIRED_LIBRARIES A ;-list of libraries to add to the link command. These can be the name of system libraries or they can be Imported Targets (see try_compile() for further details). CMAKE_REQUIRED_QUIET New in version 3.1. If this variable evaluates to a boolean true value, all status messages associated with the check will be suppressed. CMakeAddFortranSubdirectory Add a fortran-only subdirectory, find a fortran compiler, and build. The cmake_add_fortran_subdirectory function adds a subdirectory to a project that contains a fortran-only subproject. The module will check the current compiler and see if it can support fortran. If no fortran compiler is found and the compiler is MSVC, then this module will find the MinGW gfortran. It will then use an external project to build with the MinGW tools. It will also create imported targets for the libraries created. This will only work if the fortran code is built into a dll, so BUILD_SHARED_LIBS is turned on in the project. In addition the CMAKE_GNUtoMS option is set to on, so that Microsoft .lib files are created. Usage is as follows: cmake_add_fortran_subdirectory( # name of subdirectory PROJECT # project name in subdir top CMakeLists.txt ARCHIVE_DIR # dir where project places .lib files RUNTIME_DIR # dir where project places .dll files LIBRARIES ... # names of library targets to import LINK_LIBRARIES # link interface libraries for LIBRARIES [LINK_LIBS ...]... CMAKE_COMMAND_LINE ... # extra command line flags to pass to cmake NO_EXTERNAL_INSTALL # skip installation of external project ) Relative paths in ARCHIVE_DIR and RUNTIME_DIR are interpreted with respect to the build directory corresponding to the source directory in which the function is invoked. Limitations: NO_EXTERNAL_INSTALL is required for forward compatibility with a future version that supports installation of the external project binaries during make install. CMakeBackwardCompatibilityCXX define a bunch of backwards compatibility variables CMAKE_ANSI_CXXFLAGS - flag for ansi c++ CMAKE_HAS_ANSI_STRING_STREAM - has include(TestForANSIStreamHeaders) include(CheckIncludeFileCXX) include(TestForSTDNamespace) include(TestForANSIForScope) CMakeDependentOption Macro to provide an option dependent on other options. This macro presents an option to the user only if a set of other conditions are true. cmake_dependent_option cmake_dependent_option(