summaryrefslogtreecommitdiffstats
path: root/Help
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2022-09-23 12:52:02 (GMT)
committerKitware Robot <kwrobot@kitware.com>2022-09-23 12:52:13 (GMT)
commit98aef0929f4c5ce7bbf7ce9c2dfc5cad382f5a96 (patch)
treebfb6ee80bbd3e3e4ee81cd3c0aca30dca0cd747c /Help
parent14a0794b66d64e856d8b41afec086f1fb94f503d (diff)
parent611d80179006ba6670273fcfcad46b0bb64a36c2 (diff)
downloadCMake-98aef0929f4c5ce7bbf7ce9c2dfc5cad382f5a96.zip
CMake-98aef0929f4c5ce7bbf7ce9c2dfc5cad382f5a96.tar.gz
CMake-98aef0929f4c5ce7bbf7ce9c2dfc5cad382f5a96.tar.bz2
Merge topic 'try_compile-source-from'
611d801790 try_compile: Add SOURCE_FROM_FILE a04eaf6742 Tests: Clean up and simplify TryCompile tests cb14ae2b87 try_compile: Add SOURCE_FROM_{ARG,VAR} Acked-by: Kitware Robot <kwrobot@kitware.com> Acked-by: buildbot <buildbot@kitware.com> Merge-request: !7700
Diffstat (limited to 'Help')
-rw-r--r--Help/command/try_compile.rst47
-rw-r--r--Help/command/try_run.rst9
2 files changed, 50 insertions, 6 deletions
diff --git a/Help/command/try_compile.rst b/Help/command/try_compile.rst
index 97ad481..4632cd9 100644
--- a/Help/command/try_compile.rst
+++ b/Help/command/try_compile.rst
@@ -55,7 +55,11 @@ Try Compiling Source Files
.. code-block:: cmake
- try_compile(<resultVar> SOURCES <srcfile...>
+ try_compile(<resultVar>
+ <SOURCES <srcfile...>] |
+ SOURCE_FROM_ARG <name> <content>] |
+ SOURCE_FROM_VAR <name> <var>] |
+ SOURCE_FROM_FILE <name> <path> >...
[CMAKE_FLAGS <flags>...]
[COMPILE_DEFINITIONS <defs>...]
[LINK_OPTIONS <options>...]
@@ -74,10 +78,12 @@ Try building an executable or static library from one or more source files
variable). The success or failure of the ``try_compile``, i.e. ``TRUE`` or
``FALSE`` respectively, is returned in ``<resultVar>``.
-In this form, one or more source files must be provided. If
-:variable:`CMAKE_TRY_COMPILE_TARGET_TYPE` is unset or is set to ``EXECUTABLE``,
-the sources must include a definition for ``main`` and CMake will create a
-``CMakeLists.txt`` file to build the source(s) as an executable.
+In this form, one or more source files must be provided. Additionally, one of
+``SOURCES`` and/or ``SOURCE_FROM_*`` must precede other keywords.
+
+If :variable:`CMAKE_TRY_COMPILE_TARGET_TYPE` is unset or is set to
+``EXECUTABLE``, the sources must include a definition for ``main`` and CMake
+will create a ``CMakeLists.txt`` file to build the source(s) as an executable.
If :variable:`CMAKE_TRY_COMPILE_TARGET_TYPE` is set to ``STATIC_LIBRARY``,
a static library will be built instead and no definition for ``main`` is
required. For an executable, the generated ``CMakeLists.txt`` file would
@@ -163,6 +169,37 @@ The options are:
``OUTPUT_VARIABLE <var>``
Store the output from the build process in the given variable.
+``SOURCE_FROM_ARG <name> <content>``
+ .. versionadded:: 3.25
+
+ Write ``<content>`` to a file named ``<name>`` in the operation directory.
+ This can be used to bypass the need to separately write a source file when
+ the contents of the file are dynamically specified. The specified ``<name>``
+ is not allowed to contain path components.
+
+ ``SOURCE_FROM_ARG`` may be specified multiple times.
+
+``SOURCE_FROM_FILE <name> <path>``
+ .. versionadded:: 3.25
+
+ Copy ``<path>`` to a file named ``<name>`` in the operation directory. This
+ can be used to consolidate files into the operation directory, which may be
+ useful if a source which already exists (i.e. as a stand-alone file in a
+ project's source repository) needs to refer to other file(s) created by
+ ``SOURCE_FROM_*``. (Otherwise, ``SOURCES`` is usually more convenient.) The
+ specified ``<name>`` is not allowed to contain path components.
+
+``SOURCE_FROM_VAR <name> <content>``
+ .. versionadded:: 3.25
+
+ Write the contents of ``<var>`` to a file named ``<name>`` in the operation
+ directory. This is the same as ``SOURCE_FROM_ARG``, but takes the contents
+ from the specified CMake variable, rather than directly, which may be useful
+ when passing arguments through a function which wraps ``try_compile``. The
+ specified ``<name>`` is not allowed to contain path components.
+
+ ``SOURCE_FROM_VAR`` may be specified multiple times.
+
``<LANG>_STANDARD <std>``
.. versionadded:: 3.8
diff --git a/Help/command/try_run.rst b/Help/command/try_run.rst
index 1dc2355..efc10ec 100644
--- a/Help/command/try_run.rst
+++ b/Help/command/try_run.rst
@@ -12,7 +12,11 @@ Try Compiling and Running Source Files
.. code-block:: cmake
- try_run(<runResultVar> <compileResultVar> SOURCES <srcfile...>
+ try_run(<runResultVar> <compileResultVar>
+ <SOURCES <srcfile...>] |
+ SOURCE_FROM_ARG <name> <content>] |
+ SOURCE_FROM_VAR <name> <var>] |
+ SOURCE_FROM_FILE <name> <path> >...
[CMAKE_FLAGS <flags>...]
[COMPILE_DEFINITIONS <defs>...]
[LINK_OPTIONS <options>...]
@@ -40,6 +44,9 @@ set to ``FAILED_TO_RUN``. See the :command:`try_compile` command for
documentation of options common to both commands, and for information on how
the test project is constructed to build the source file.
+One or more source files must be provided. Additionally, one of ``SOURCES``
+and/or ``SOURCE_FROM_*`` must precede other keywords.
+
This command also supports an alternate signature
which was present in older versions of CMake: