|
|
@ -14,18 +14,20 @@ Try Compiling Whole Projects
|
|
|
|
|
|
|
|
|
|
|
|
.. code-block:: cmake
|
|
|
|
.. code-block:: cmake
|
|
|
|
|
|
|
|
|
|
|
|
try_compile(<resultVar> PROJECT <projectName>
|
|
|
|
try_compile(<compileResultVar> PROJECT <projectName>
|
|
|
|
SOURCE_DIR <srcdir>
|
|
|
|
SOURCE_DIR <srcdir>
|
|
|
|
[BINARY_DIR <bindir>]
|
|
|
|
[BINARY_DIR <bindir>]
|
|
|
|
[TARGET <targetName>]
|
|
|
|
[TARGET <targetName>]
|
|
|
|
|
|
|
|
[LOG_DESCRIPTION <text>]
|
|
|
|
[NO_CACHE]
|
|
|
|
[NO_CACHE]
|
|
|
|
|
|
|
|
[NO_LOG]
|
|
|
|
[CMAKE_FLAGS <flags>...]
|
|
|
|
[CMAKE_FLAGS <flags>...]
|
|
|
|
[OUTPUT_VARIABLE <var>])
|
|
|
|
[OUTPUT_VARIABLE <var>])
|
|
|
|
|
|
|
|
|
|
|
|
.. versionadded:: 3.25
|
|
|
|
.. versionadded:: 3.25
|
|
|
|
|
|
|
|
|
|
|
|
Try building a project. The success or failure of the ``try_compile``,
|
|
|
|
Try building a project. Build success returns ``TRUE`` and build failure
|
|
|
|
i.e. ``TRUE`` or ``FALSE`` respectively, is returned in ``<resultVar>``.
|
|
|
|
returns ``FALSE`` in ``<compileResultVar>``.
|
|
|
|
|
|
|
|
|
|
|
|
In this form, ``<srcdir>`` should contain a complete CMake project with a
|
|
|
|
In this form, ``<srcdir>`` should contain a complete CMake project with a
|
|
|
|
``CMakeLists.txt`` file and all sources. The ``<bindir>`` and ``<srcdir>``
|
|
|
|
``CMakeLists.txt`` file and all sources. The ``<bindir>`` and ``<srcdir>``
|
|
|
@ -40,14 +42,18 @@ below for the meaning of other options.
|
|
|
|
Previously this was only done by the
|
|
|
|
Previously this was only done by the
|
|
|
|
:ref:`source file <Try Compiling Source Files>` signature.
|
|
|
|
:ref:`source file <Try Compiling Source Files>` signature.
|
|
|
|
|
|
|
|
|
|
|
|
This command also supports an alternate signature
|
|
|
|
.. versionadded:: 3.26
|
|
|
|
which was present in older versions of CMake:
|
|
|
|
This command records a
|
|
|
|
|
|
|
|
:ref:`configure-log try_compile event <try_compile configure-log event>`
|
|
|
|
|
|
|
|
if the ``NO_LOG`` option is not specified.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
This command supports an alternate signature for CMake older than 3.25.
|
|
|
|
|
|
|
|
The signature above is recommended for clarity.
|
|
|
|
|
|
|
|
|
|
|
|
.. code-block:: cmake
|
|
|
|
.. code-block:: cmake
|
|
|
|
|
|
|
|
|
|
|
|
try_compile(<resultVar> <bindir> <srcdir>
|
|
|
|
try_compile(<compileResultVar> <bindir> <srcdir>
|
|
|
|
<projectName> [<targetName>]
|
|
|
|
<projectName> [<targetName>]
|
|
|
|
[NO_CACHE]
|
|
|
|
|
|
|
|
[CMAKE_FLAGS <flags>...]
|
|
|
|
[CMAKE_FLAGS <flags>...]
|
|
|
|
[OUTPUT_VARIABLE <var>])
|
|
|
|
[OUTPUT_VARIABLE <var>])
|
|
|
|
|
|
|
|
|
|
|
@ -58,12 +64,14 @@ Try Compiling Source Files
|
|
|
|
|
|
|
|
|
|
|
|
.. code-block:: cmake
|
|
|
|
.. code-block:: cmake
|
|
|
|
|
|
|
|
|
|
|
|
try_compile(<resultVar>
|
|
|
|
try_compile(<compileResultVar>
|
|
|
|
<SOURCES <srcfile...> |
|
|
|
|
<SOURCES <srcfile...> |
|
|
|
|
SOURCE_FROM_CONTENT <name> <content> |
|
|
|
|
SOURCE_FROM_CONTENT <name> <content> |
|
|
|
|
SOURCE_FROM_VAR <name> <var> |
|
|
|
|
SOURCE_FROM_VAR <name> <var> |
|
|
|
|
SOURCE_FROM_FILE <name> <path> >...
|
|
|
|
SOURCE_FROM_FILE <name> <path> >...
|
|
|
|
|
|
|
|
[LOG_DESCRIPTION <text>]
|
|
|
|
[NO_CACHE]
|
|
|
|
[NO_CACHE]
|
|
|
|
|
|
|
|
[NO_LOG]
|
|
|
|
[CMAKE_FLAGS <flags>...]
|
|
|
|
[CMAKE_FLAGS <flags>...]
|
|
|
|
[COMPILE_DEFINITIONS <defs>...]
|
|
|
|
[COMPILE_DEFINITIONS <defs>...]
|
|
|
|
[LINK_OPTIONS <options>...]
|
|
|
|
[LINK_OPTIONS <options>...]
|
|
|
@ -79,8 +87,8 @@ Try Compiling Source Files
|
|
|
|
|
|
|
|
|
|
|
|
Try building an executable or static library from one or more source files
|
|
|
|
Try building an executable or static library from one or more source files
|
|
|
|
(which one is determined by the :variable:`CMAKE_TRY_COMPILE_TARGET_TYPE`
|
|
|
|
(which one is determined by the :variable:`CMAKE_TRY_COMPILE_TARGET_TYPE`
|
|
|
|
variable). The success or failure of the ``try_compile``, i.e. ``TRUE`` or
|
|
|
|
variable). Build success returns ``TRUE`` and build failure returns ``FALSE``
|
|
|
|
``FALSE`` respectively, is returned in ``<resultVar>``.
|
|
|
|
in ``<compileResultVar>``.
|
|
|
|
|
|
|
|
|
|
|
|
In this form, one or more source files must be provided. Additionally, one of
|
|
|
|
In this form, one or more source files must be provided. Additionally, one of
|
|
|
|
``SOURCES`` and/or ``SOURCE_FROM_*`` must precede other keywords.
|
|
|
|
``SOURCES`` and/or ``SOURCE_FROM_*`` must precede other keywords.
|
|
|
@ -105,17 +113,16 @@ contain something like the following:
|
|
|
|
CMake automatically generates, for each ``try_compile`` operation, a
|
|
|
|
CMake automatically generates, for each ``try_compile`` operation, a
|
|
|
|
unique directory under ``${CMAKE_BINARY_DIR}/CMakeFiles/CMakeScratch``
|
|
|
|
unique directory under ``${CMAKE_BINARY_DIR}/CMakeFiles/CMakeScratch``
|
|
|
|
with an unspecified name. These directories are cleaned automatically unless
|
|
|
|
with an unspecified name. These directories are cleaned automatically unless
|
|
|
|
:option:`--debug-trycompile <cmake --debug-trycompile>` is passed to ``cmake``.
|
|
|
|
:option:`--debug-trycompile <cmake --debug-trycompile>` is passed to :program:`cmake`.
|
|
|
|
Such directories from previous runs are also unconditionally cleaned at the
|
|
|
|
Such directories from previous runs are also unconditionally cleaned at the
|
|
|
|
beginning of any ``cmake`` execution.
|
|
|
|
beginning of any :program:`cmake` execution.
|
|
|
|
|
|
|
|
|
|
|
|
This command also supports an alternate signature
|
|
|
|
This command supports an alternate signature for CMake older than 3.25.
|
|
|
|
which was present in older versions of CMake:
|
|
|
|
The signature above is recommended for clarity.
|
|
|
|
|
|
|
|
|
|
|
|
.. code-block:: cmake
|
|
|
|
.. code-block:: cmake
|
|
|
|
|
|
|
|
|
|
|
|
try_compile(<resultVar> <bindir> <srcfile|SOURCES srcfile...>
|
|
|
|
try_compile(<compileResultVar> <bindir> <srcfile|SOURCES srcfile...>
|
|
|
|
[NO_CACHE]
|
|
|
|
|
|
|
|
[CMAKE_FLAGS <flags>...]
|
|
|
|
[CMAKE_FLAGS <flags>...]
|
|
|
|
[COMPILE_DEFINITIONS <defs>...]
|
|
|
|
[COMPILE_DEFINITIONS <defs>...]
|
|
|
|
[LINK_OPTIONS <options>...]
|
|
|
|
[LINK_OPTIONS <options>...]
|
|
|
@ -130,7 +137,7 @@ which was present in older versions of CMake:
|
|
|
|
In this version, ``try_compile`` will use ``<bindir>/CMakeFiles/CMakeTmp`` for
|
|
|
|
In this version, ``try_compile`` will use ``<bindir>/CMakeFiles/CMakeTmp`` for
|
|
|
|
its operation, and all such files will be cleaned automatically.
|
|
|
|
its operation, and all such files will be cleaned automatically.
|
|
|
|
For debugging, :option:`--debug-trycompile <cmake --debug-trycompile>` can be
|
|
|
|
For debugging, :option:`--debug-trycompile <cmake --debug-trycompile>` can be
|
|
|
|
passed to ``cmake`` to avoid this clean. However, multiple sequential
|
|
|
|
passed to :program:`cmake` to avoid this clean. However, multiple sequential
|
|
|
|
``try_compile`` operations, if given the same ``<bindir>``, will reuse this
|
|
|
|
``try_compile`` operations, if given the same ``<bindir>``, will reuse this
|
|
|
|
single output directory, such that you can only debug one such ``try_compile``
|
|
|
|
single output directory, such that you can only debug one such ``try_compile``
|
|
|
|
call at a time. Use of the newer signature is recommended to simplify
|
|
|
|
call at a time. Use of the newer signature is recommended to simplify
|
|
|
@ -171,6 +178,12 @@ The options are:
|
|
|
|
set the :prop_tgt:`STATIC_LIBRARY_OPTIONS` target property in the generated
|
|
|
|
set the :prop_tgt:`STATIC_LIBRARY_OPTIONS` target property in the generated
|
|
|
|
project, depending on the :variable:`CMAKE_TRY_COMPILE_TARGET_TYPE` variable.
|
|
|
|
project, depending on the :variable:`CMAKE_TRY_COMPILE_TARGET_TYPE` variable.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
``LOG_DESCRIPTION <text>``
|
|
|
|
|
|
|
|
.. versionadded:: 3.26
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Specify a non-empty text description of the purpose of the check.
|
|
|
|
|
|
|
|
This is recorded in the :manual:`cmake-configure-log(7)` entry.
|
|
|
|
|
|
|
|
|
|
|
|
``NO_CACHE``
|
|
|
|
``NO_CACHE``
|
|
|
|
.. versionadded:: 3.25
|
|
|
|
.. versionadded:: 3.25
|
|
|
|
|
|
|
|
|
|
|
@ -191,6 +204,11 @@ The options are:
|
|
|
|
the test is part of a larger inspection), ``NO_CACHE`` may be useful to avoid
|
|
|
|
the test is part of a larger inspection), ``NO_CACHE`` may be useful to avoid
|
|
|
|
leaking the intermediate result variable into the cache.
|
|
|
|
leaking the intermediate result variable into the cache.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
``NO_LOG``
|
|
|
|
|
|
|
|
.. versionadded:: 3.26
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Do not record a :manual:`cmake-configure-log(7)` entry for this call.
|
|
|
|
|
|
|
|
|
|
|
|
``OUTPUT_VARIABLE <var>``
|
|
|
|
``OUTPUT_VARIABLE <var>``
|
|
|
|
Store the output from the build process in the given variable.
|
|
|
|
Store the output from the build process in the given variable.
|
|
|
|
|
|
|
|
|
|
|
@ -271,13 +289,18 @@ Other Behavior Settings
|
|
|
|
If :policy:`CMP0083` is set to ``NEW``, then in order to obtain correct
|
|
|
|
If :policy:`CMP0083` is set to ``NEW``, then in order to obtain correct
|
|
|
|
behavior at link time, the ``check_pie_supported()`` command from the
|
|
|
|
behavior at link time, the ``check_pie_supported()`` command from the
|
|
|
|
:module:`CheckPIESupported` module must be called before using the
|
|
|
|
:module:`CheckPIESupported` module must be called before using the
|
|
|
|
:command:`try_compile` command.
|
|
|
|
``try_compile`` command.
|
|
|
|
|
|
|
|
|
|
|
|
The current settings of :policy:`CMP0065` and :policy:`CMP0083` are propagated
|
|
|
|
The current settings of :policy:`CMP0065` and :policy:`CMP0083` are propagated
|
|
|
|
through to the generated test project.
|
|
|
|
through to the generated test project.
|
|
|
|
|
|
|
|
|
|
|
|
Set the :variable:`CMAKE_TRY_COMPILE_CONFIGURATION` variable to choose
|
|
|
|
Set variable :variable:`CMAKE_TRY_COMPILE_CONFIGURATION` to choose a build
|
|
|
|
a build configuration.
|
|
|
|
configuration:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
* For multi-config generators, this selects which configuration to build.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
* For single-config generators, this sets :variable:`CMAKE_BUILD_TYPE` in
|
|
|
|
|
|
|
|
the test project.
|
|
|
|
|
|
|
|
|
|
|
|
.. versionadded:: 3.6
|
|
|
|
.. versionadded:: 3.6
|
|
|
|
Set the :variable:`CMAKE_TRY_COMPILE_TARGET_TYPE` variable to specify
|
|
|
|
Set the :variable:`CMAKE_TRY_COMPILE_TARGET_TYPE` variable to specify
|
|
|
@ -327,3 +350,8 @@ a build configuration.
|
|
|
|
If :policy:`CMP0141` is set to ``NEW``, one can use
|
|
|
|
If :policy:`CMP0141` is set to ``NEW``, one can use
|
|
|
|
:variable:`CMAKE_MSVC_DEBUG_INFORMATION_FORMAT` to specify the MSVC debug
|
|
|
|
:variable:`CMAKE_MSVC_DEBUG_INFORMATION_FORMAT` to specify the MSVC debug
|
|
|
|
information format.
|
|
|
|
information format.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
See Also
|
|
|
|
|
|
|
|
^^^^^^^^
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
* :command:`try_run`
|
|
|
|