diff options
author | Matthew Woehlke <matthew.woehlke@kitware.com> | 2022-09-21 17:34:02 (GMT) |
---|---|---|
committer | Matthew Woehlke <matthew.woehlke@kitware.com> | 2022-09-22 17:33:27 (GMT) |
commit | cb14ae2b870e9568d18990992882e0facacf22d4 (patch) | |
tree | b7c203b809fe854610a36b0d97b6299b9d9e18cc /Help/command | |
parent | 620cf9efa78c8862558ac321c043194d1cb6eb19 (diff) | |
download | CMake-cb14ae2b870e9568d18990992882e0facacf22d4.zip CMake-cb14ae2b870e9568d18990992882e0facacf22d4.tar.gz CMake-cb14ae2b870e9568d18990992882e0facacf22d4.tar.bz2 |
try_compile: Add SOURCE_FROM_{ARG,VAR}
Add ability to "feed" try_compile (and try_run) sources more directly,
either from literal content, or from a CMake variable which contains
literal content. This saves the user from needing a separate step to
write the content to a file, and allows for the sources to only exist in
the scratch directory.
Diffstat (limited to 'Help/command')
-rw-r--r-- | Help/command/try_compile.rst | 36 | ||||
-rw-r--r-- | Help/command/try_run.rst | 8 |
2 files changed, 38 insertions, 6 deletions
diff --git a/Help/command/try_compile.rst b/Help/command/try_compile.rst index 97ad481..ed61a2f 100644 --- a/Help/command/try_compile.rst +++ b/Help/command/try_compile.rst @@ -55,7 +55,10 @@ 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>] >... [CMAKE_FLAGS <flags>...] [COMPILE_DEFINITIONS <defs>...] [LINK_OPTIONS <options>...] @@ -74,10 +77,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 +168,27 @@ 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_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..5498344 100644 --- a/Help/command/try_run.rst +++ b/Help/command/try_run.rst @@ -12,7 +12,10 @@ 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>] >... [CMAKE_FLAGS <flags>...] [COMPILE_DEFINITIONS <defs>...] [LINK_OPTIONS <options>...] @@ -40,6 +43,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: |