summaryrefslogtreecommitdiff
path: root/Modules/CheckSourceCompiles.cmake
diff options
context:
space:
mode:
authorscivision <scivision@users.noreply.github.com>2023-02-04 20:25:58 -0500
committerBrad King <brad.king@kitware.com>2023-02-06 09:55:23 -0500
commitb19036d8b38aaebd892ef8bff1fe5eb0a37fc6a3 (patch)
treeffc97617a0eacf5b1ea285efa17e79f576ce7b0e /Modules/CheckSourceCompiles.cmake
parent2a0c105cf08190284b288057c693eeddef5066fc (diff)
downloadcmake-b19036d8b38aaebd892ef8bff1fe5eb0a37fc6a3.tar.gz
Help: CheckSource{Compiles,Runs}: fix typo and clarify
Diffstat (limited to 'Modules/CheckSourceCompiles.cmake')
-rw-r--r--Modules/CheckSourceCompiles.cmake30
1 files changed, 23 insertions, 7 deletions
diff --git a/Modules/CheckSourceCompiles.cmake b/Modules/CheckSourceCompiles.cmake
index ad74c3cad0..978879815d 100644
--- a/Modules/CheckSourceCompiles.cmake
+++ b/Modules/CheckSourceCompiles.cmake
@@ -19,17 +19,34 @@ Check if given source compiles and links into an executable.
[SRC_EXT <extension>])
Check that the source supplied in ``<code>`` can be compiled as a source
- file for the requested language 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 ``<resultVar>``, 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.
+ file for the requested language and linked as an executable. The result
+ will be stored in the internal cache variable specified by ``<resultVar>``,
+ 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 ``.<extension>`` instead.
+ The ``<code>`` must contain a valid main program. For example:
+
+ .. code-block:: cmake
+
+ check_source_compiles(C
+ "#include <stdlib.h>
+ #include <stdnoreturn.h>
+ 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 underlying check is performed by the :command:`try_compile` command. The
compile and link commands can be influenced by setting any of the following
variables prior to calling ``check_source_compiles()``:
@@ -73,7 +90,6 @@ Check if given source compiles and links into an executable.
#]=======================================================================]
-
include_guard(GLOBAL)
include(Internal/CheckSourceCompiles)