try_compile: Add NO_CACHE option (also try_run)

Add NO_CACHE option to try_compile and try_run, which places the results
in regular, rather than cache, variables.

Issue: #22799
This commit is contained in:
Matthew Woehlke
2022-09-28 13:41:11 -04:00
parent 164a156c7c
commit 09b3051524
7 changed files with 104 additions and 7 deletions
+26 -1
View File
@@ -18,6 +18,7 @@ Try Compiling Whole Projects
SOURCE_DIR <srcdir>
[BINARY_DIR <bindir>]
[TARGET <targetName>]
[NO_CACHE]
[CMAKE_FLAGS <flags>...]
[OUTPUT_VARIABLE <var>])
@@ -45,7 +46,9 @@ which was present in older versions of CMake:
.. code-block:: cmake
try_compile(<resultVar> <bindir> <srcdir>
<projectName> [<targetName>] [CMAKE_FLAGS <flags>...]
<projectName> [<targetName>]
[NO_CACHE]
[CMAKE_FLAGS <flags>...]
[OUTPUT_VARIABLE <var>])
.. _`Try Compiling Source Files`:
@@ -60,6 +63,7 @@ Try Compiling Source Files
SOURCE_FROM_ARG <name> <content>] |
SOURCE_FROM_VAR <name> <var>] |
SOURCE_FROM_FILE <name> <path> >...
[NO_CACHE]
[CMAKE_FLAGS <flags>...]
[COMPILE_DEFINITIONS <defs>...]
[LINK_OPTIONS <options>...]
@@ -111,6 +115,7 @@ which was present in older versions of CMake:
.. code-block:: cmake
try_compile(<resultVar> <bindir> <srcfile|SOURCES srcfile...>
[NO_CACHE]
[CMAKE_FLAGS <flags>...]
[COMPILE_DEFINITIONS <defs>...]
[LINK_OPTIONS <options>...]
@@ -166,6 +171,26 @@ The options are:
set the :prop_tgt:`STATIC_LIBRARY_OPTIONS` target property in the generated
project, depending on the :variable:`CMAKE_TRY_COMPILE_TARGET_TYPE` variable.
``NO_CACHE``
.. versionadded:: 3.25
The result will be stored in a normal variable rather than a cache entry.
The result variable is normally cached so that a simple pattern can be used
to avoid repeating the test on subsequent executions of CMake:
.. code-block:: cmake
if(NOT DEFINED RESULTVAR)
# ...(check-specific setup code)...
try_compile(RESULTVAR ...)
# ...(check-specific logging and cleanup code)...
endif()
If the guard variable and result variable are not the same (for example, if
the test is part of a larger inspection), ``NO_CACHE`` may be useful to avoid
leaking the intermediate result variable into the cache.
``OUTPUT_VARIABLE <var>``
Store the output from the build process in the given variable.
+2
View File
@@ -17,6 +17,7 @@ Try Compiling and Running Source Files
SOURCE_FROM_ARG <name> <content>] |
SOURCE_FROM_VAR <name> <var>] |
SOURCE_FROM_FILE <name> <path> >...
[NO_CACHE]
[CMAKE_FLAGS <flags>...]
[COMPILE_DEFINITIONS <defs>...]
[LINK_OPTIONS <options>...]
@@ -54,6 +55,7 @@ which was present in older versions of CMake:
try_run(<runResultVar> <compileResultVar>
<bindir> <srcfile|SOURCES srcfile...>
[NO_CACHE]
[CMAKE_FLAGS <flags>...]
[COMPILE_DEFINITIONS <defs>...]
[LINK_OPTIONS <options>...]