Bläddra i källkod

Merge topic 'try_compile-unique-bindir'

aa9220d3a0 try_compile: Add keyword-dispatched signature
d1befe5515 cmSystemTools: Add MakeTempDirectory

Acked-by: Kitware Robot <[email protected]>
Tested-by: buildbot <[email protected]>
Acked-by: Matthew Woehlke <[email protected]>
Merge-request: !7579
Brad King 3 år sedan
förälder
incheckning
ecfc63a9b0
80 ändrade filer med 903 tillägg och 473 borttagningar
  1. 36 13
      Help/command/try_compile.rst
  2. 43 33
      Help/command/try_run.rst
  3. 8 0
      Help/release/dev/try_compile-signatures.rst
  4. 83 20
      Source/cmCoreTryCompile.cxx
  5. 17 3
      Source/cmCoreTryCompile.h
  6. 92 1
      Source/cmSystemTools.cxx
  7. 25 0
      Source/cmSystemTools.h
  8. 3 0
      Source/cmake.cxx
  9. 1 1
      Tests/RunCMake/try_compile/BadLinkLibraries-stderr.txt
  10. 5 1
      Tests/RunCMake/try_compile/BadLinkLibraries.cmake
  11. 1 1
      Tests/RunCMake/try_compile/BadSources1-stderr.txt
  12. 3 1
      Tests/RunCMake/try_compile/BadSources1.cmake
  13. 1 1
      Tests/RunCMake/try_compile/BadSources2-stderr.txt
  14. 4 3
      Tests/RunCMake/try_compile/BadSources2.cmake
  15. 1 1
      Tests/RunCMake/try_compile/CStandard-stderr.txt
  16. 6 2
      Tests/RunCMake/try_compile/CStandard.cmake
  17. 11 4
      Tests/RunCMake/try_compile/CStandardGNU.cmake
  18. 6 2
      Tests/RunCMake/try_compile/CStandardNoDefault.cmake
  19. 1 1
      Tests/RunCMake/try_compile/CopyFileErrorNoCopyFile-stderr.txt
  20. 3 1
      Tests/RunCMake/try_compile/CopyFileErrorNoCopyFile.cmake
  21. 1 1
      Tests/RunCMake/try_compile/CudaStandard-stderr.txt
  22. 6 2
      Tests/RunCMake/try_compile/CudaStandard.cmake
  23. 3 3
      Tests/RunCMake/try_compile/CxxStandard-stderr.txt
  24. 6 2
      Tests/RunCMake/try_compile/CxxStandard.cmake
  25. 11 4
      Tests/RunCMake/try_compile/CxxStandardGNU.cmake
  26. 6 2
      Tests/RunCMake/try_compile/CxxStandardNoDefault.cmake
  27. 4 1
      Tests/RunCMake/try_compile/EmptyListArgs.cmake
  28. 5 2
      Tests/RunCMake/try_compile/EmptyValueArgs.cmake
  29. 4 2
      Tests/RunCMake/try_compile/EnvConfig.cmake
  30. 8 4
      Tests/RunCMake/try_compile/ISPCDuplicateTarget.cmake
  31. 9 4
      Tests/RunCMake/try_compile/ISPCDuplicateTargetNinja.cmake
  32. 7 2
      Tests/RunCMake/try_compile/ISPCInvalidTarget.cmake
  33. 7 2
      Tests/RunCMake/try_compile/ISPCTargets.cmake
  34. 1 1
      Tests/RunCMake/try_compile/NoArgs-stderr.txt
  35. 1 1
      Tests/RunCMake/try_compile/NoCStandard-stderr.txt
  36. 3 1
      Tests/RunCMake/try_compile/NoCStandard.cmake
  37. 1 1
      Tests/RunCMake/try_compile/NoCopyFile-stderr.txt
  38. 3 1
      Tests/RunCMake/try_compile/NoCopyFile.cmake
  39. 1 1
      Tests/RunCMake/try_compile/NoCopyFile2-stderr.txt
  40. 3 1
      Tests/RunCMake/try_compile/NoCopyFile2.cmake
  41. 1 1
      Tests/RunCMake/try_compile/NoCopyFileError-stderr.txt
  42. 3 1
      Tests/RunCMake/try_compile/NoCopyFileError.cmake
  43. 1 1
      Tests/RunCMake/try_compile/NoOutputVariable-stderr.txt
  44. 3 1
      Tests/RunCMake/try_compile/NoOutputVariable.cmake
  45. 1 1
      Tests/RunCMake/try_compile/NoOutputVariable2-stderr.txt
  46. 3 1
      Tests/RunCMake/try_compile/NoOutputVariable2.cmake
  47. 1 1
      Tests/RunCMake/try_compile/NoSources-stderr.txt
  48. 1 1
      Tests/RunCMake/try_compile/NonSourceCompileDefinitions-stderr.txt
  49. 1 1
      Tests/RunCMake/try_compile/NonSourceCopyFile-stderr.txt
  50. 1 1
      Tests/RunCMake/try_compile/ObjCStandard-stderr.txt
  51. 6 2
      Tests/RunCMake/try_compile/ObjCStandard.cmake
  52. 1 1
      Tests/RunCMake/try_compile/ObjCxxStandard-stderr.txt
  53. 6 2
      Tests/RunCMake/try_compile/ObjCxxStandard.cmake
  54. 1 1
      Tests/RunCMake/try_compile/OneArg-stderr.txt
  55. 10 55
      Tests/RunCMake/try_compile/RunCMakeTest.cmake
  56. 8 2
      Tests/RunCMake/try_compile/TargetTypeExe.cmake
  57. 1 1
      Tests/RunCMake/try_compile/TargetTypeInvalid-stderr.txt
  58. 5 1
      Tests/RunCMake/try_compile/TargetTypeInvalid.cmake
  59. 8 2
      Tests/RunCMake/try_compile/TargetTypeStatic.cmake
  60. 4 1
      Tests/RunCMake/try_compile/TryRunArgs.cmake
  61. 1 1
      Tests/RunCMake/try_compile/TwoArgs-stderr.txt
  62. 2 0
      Tests/RunCMake/try_compile/new_signature.cmake
  63. 54 0
      Tests/RunCMake/try_compile/old_and_new_signature_tests.cmake
  64. 2 0
      Tests/RunCMake/try_compile/old_signature.cmake
  65. 1 1
      Tests/RunCMake/try_run/BadLinkLibraries-stderr.txt
  66. 5 2
      Tests/RunCMake/try_run/BadLinkLibraries.cmake
  67. 4 2
      Tests/RunCMake/try_run/NoCompileOutputVariable.cmake
  68. 4 2
      Tests/RunCMake/try_run/NoRunOutputVariable.cmake
  69. 1 1
      Tests/RunCMake/try_run/NoRunStdErrVariable-stderr.txt
  70. 4 2
      Tests/RunCMake/try_run/NoRunStdErrVariable.cmake
  71. 1 1
      Tests/RunCMake/try_run/NoRunStdOutVariable-stderr.txt
  72. 4 2
      Tests/RunCMake/try_run/NoRunStdOutVariable.cmake
  73. 4 2
      Tests/RunCMake/try_run/NoWorkingDirectory.cmake
  74. 9 10
      Tests/RunCMake/try_run/RunCMakeTest.cmake
  75. 4 2
      Tests/RunCMake/try_run/WorkingDirArg.cmake
  76. 2 0
      Tests/RunCMake/try_run/new_signature.cmake
  77. 11 0
      Tests/RunCMake/try_run/old_and_new_signature_tests.cmake
  78. 2 0
      Tests/RunCMake/try_run/old_signature.cmake
  79. 37 240
      Tests/TryCompile/CMakeLists.txt
  80. 245 0
      Tests/TryCompile/old_and_new_signature_tests.cmake

+ 36 - 13
Help/command/try_compile.rst

@@ -41,7 +41,7 @@ Try Compiling Source Files
 
 
 .. code-block:: cmake
 .. code-block:: cmake
 
 
-  try_compile(<resultVar> <bindir> <srcfile|SOURCES srcfile...>
+  try_compile(<resultVar> SOURCES <srcfile...>
               [CMAKE_FLAGS <flags>...]
               [CMAKE_FLAGS <flags>...]
               [COMPILE_DEFINITIONS <defs>...]
               [COMPILE_DEFINITIONS <defs>...]
               [LINK_OPTIONS <options>...]
               [LINK_OPTIONS <options>...]
@@ -53,6 +53,8 @@ Try Compiling Source Files
               [<LANG>_EXTENSIONS <bool>]
               [<LANG>_EXTENSIONS <bool>]
               )
               )
 
 
+.. versionadded:: 3.25
+
 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).  The success or failure of the ``try_compile``, i.e. ``TRUE`` or
@@ -76,6 +78,39 @@ contain something like the following:
   target_link_options(cmTryCompileExec PRIVATE <LINK_OPTIONS from caller>)
   target_link_options(cmTryCompileExec PRIVATE <LINK_OPTIONS from caller>)
   target_link_libraries(cmTryCompileExec ${LINK_LIBRARIES})
   target_link_libraries(cmTryCompileExec ${LINK_LIBRARIES})
 
 
+CMake will automatically generate a unique directory for each ``try_compile``
+operation in an unspecified location within the project's binary directory.
+These directories will be cleaned automatically unless
+:option:`--debug-trycompile <cmake --debug-trycompile>` is passed to ``cmake``.
+Such directories from previous runs are also unconditionally cleaned at the
+beginning of any ``cmake`` execution.
+
+This command also supports an alternate signature
+which was present in older versions of CMake:
+
+.. code-block:: cmake
+
+  try_compile(<resultVar> <bindir> <srcfile|SOURCES srcfile...>
+              [CMAKE_FLAGS <flags>...]
+              [COMPILE_DEFINITIONS <defs>...]
+              [LINK_OPTIONS <options>...]
+              [LINK_LIBRARIES <libs>...]
+              [OUTPUT_VARIABLE <var>]
+              [COPY_FILE <fileName> [COPY_FILE_ERROR <var>]]
+              [<LANG>_STANDARD <std>]
+              [<LANG>_STANDARD_REQUIRED <bool>]
+              [<LANG>_EXTENSIONS <bool>]
+              )
+
+In this version, ``try_compile`` will use ``<bindir>/CMakeFiles/CMakeTmp`` for
+its operation, and all such files will be cleaned automatically.
+For debugging, :option:`--debug-trycompile <cmake --debug-trycompile>` can be
+passed to ``cmake`` to avoid this clean.  However, multiple sequential
+``try_compile`` operations, if given the same ``<bindir>``, will reuse this
+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
+debugging of multiple ``try_compile`` operations.
+
 The options are:
 The options are:
 
 
 ``CMAKE_FLAGS <flags>...``
 ``CMAKE_FLAGS <flags>...``
@@ -136,18 +171,6 @@ The options are:
   :prop_tgt:`OBJC_EXTENSIONS`, :prop_tgt:`OBJCXX_EXTENSIONS`,
   :prop_tgt:`OBJC_EXTENSIONS`, :prop_tgt:`OBJCXX_EXTENSIONS`,
   or :prop_tgt:`CUDA_EXTENSIONS` target property of the generated project.
   or :prop_tgt:`CUDA_EXTENSIONS` target property of the generated project.
 
 
-In this version all files in ``<bindir>/CMakeFiles/CMakeTmp`` will be
-cleaned automatically.  For debugging,
-:option:`--debug-trycompile <cmake --debug-trycompile>` can be
-passed to ``cmake`` to avoid this clean.  However, multiple sequential
-``try_compile`` operations reuse this single output directory.  If you use
-:option:`--debug-trycompile <cmake --debug-trycompile>`, you can only debug
-one ``try_compile`` call at a time.  The recommended procedure is to protect
-all ``try_compile`` calls in your project by ``if(NOT DEFINED <resultVar>)``
-logic, configure with cmake all the way through once, then delete the cache
-entry associated with the try_compile call of interest, and then re-run cmake
-again with :option:`--debug-trycompile <cmake --debug-trycompile>`.
-
 Other Behavior Settings
 Other Behavior Settings
 ^^^^^^^^^^^^^^^^^^^^^^^
 ^^^^^^^^^^^^^^^^^^^^^^^
 
 

+ 43 - 33
Help/command/try_run.rst

@@ -12,62 +12,68 @@ Try Compiling and Running Source Files
 
 
 .. code-block:: cmake
 .. code-block:: cmake
 
 
-  try_run(<runResultVar> <compileResultVar>
-          <bindir> <srcfile> [CMAKE_FLAGS <flags>...]
+  try_run(<runResultVar> <compileResultVar> SOURCES <srcfile...>
+          [CMAKE_FLAGS <flags>...]
           [COMPILE_DEFINITIONS <defs>...]
           [COMPILE_DEFINITIONS <defs>...]
           [LINK_OPTIONS <options>...]
           [LINK_OPTIONS <options>...]
           [LINK_LIBRARIES <libs>...]
           [LINK_LIBRARIES <libs>...]
           [COMPILE_OUTPUT_VARIABLE <var>]
           [COMPILE_OUTPUT_VARIABLE <var>]
+          [COPY_FILE <fileName> [COPY_FILE_ERROR <var>]]
+          [<LANG>_STANDARD <std>]
+          [<LANG>_STANDARD_REQUIRED <bool>]
+          [<LANG>_EXTENSIONS <bool>]
           [RUN_OUTPUT_VARIABLE <var>]
           [RUN_OUTPUT_VARIABLE <var>]
           [RUN_OUTPUT_STDOUT_VARIABLE <var>]
           [RUN_OUTPUT_STDOUT_VARIABLE <var>]
           [RUN_OUTPUT_STDERR_VARIABLE <var>]
           [RUN_OUTPUT_STDERR_VARIABLE <var>]
           [OUTPUT_VARIABLE <var>]
           [OUTPUT_VARIABLE <var>]
           [WORKING_DIRECTORY <var>]
           [WORKING_DIRECTORY <var>]
-          [ARGS <args>...])
+          [ARGS <args>...]
+          )
+
+.. versionadded:: 3.25
 
 
 Try compiling a ``<srcfile>``.  Returns ``TRUE`` or ``FALSE`` for success
 Try compiling a ``<srcfile>``.  Returns ``TRUE`` or ``FALSE`` for success
 or failure in ``<compileResultVar>``.  If the compile succeeded, runs the
 or failure in ``<compileResultVar>``.  If the compile succeeded, runs the
 executable and returns its exit code in ``<runResultVar>``.  If the
 executable and returns its exit code in ``<runResultVar>``.  If the
 executable was built, but failed to run, then ``<runResultVar>`` will be
 executable was built, but failed to run, then ``<runResultVar>`` will be
 set to ``FAILED_TO_RUN``.  See the :command:`try_compile` command for
 set to ``FAILED_TO_RUN``.  See the :command:`try_compile` command for
-information on how the test project is constructed to build the source file.
+documentation of options common to both commands, and for information on how
+the test project is constructed to build the source file.
 
 
-The options are:
+This command also supports an alternate signature
+which was present in older versions of CMake:
 
 
-``CMAKE_FLAGS <flags>...``
-  Specify flags of the form :option:`-DVAR:TYPE=VALUE <cmake -D>` to be passed
-  to the :manual:`cmake(1)` command-line used to drive the test build.
-  The example in :command:`try_compile` shows how values for variables
-  ``INCLUDE_DIRECTORIES``, ``LINK_DIRECTORIES``, and ``LINK_LIBRARIES``
-  are used.
+.. code-block:: cmake
+
+  try_run(<runResultVar> <compileResultVar>
+          <bindir> <srcfile|SOURCES srcfile...>
+          [CMAKE_FLAGS <flags>...]
+          [COMPILE_DEFINITIONS <defs>...]
+          [LINK_OPTIONS <options>...]
+          [LINK_LIBRARIES <libs>...]
+          [COMPILE_OUTPUT_VARIABLE <var>]
+          [COPY_FILE <fileName> [COPY_FILE_ERROR <var>]]
+          [<LANG>_STANDARD <std>]
+          [<LANG>_STANDARD_REQUIRED <bool>]
+          [<LANG>_EXTENSIONS <bool>]
+          [RUN_OUTPUT_VARIABLE <var>]
+          [RUN_OUTPUT_STDOUT_VARIABLE <var>]
+          [RUN_OUTPUT_STDERR_VARIABLE <var>]
+          [OUTPUT_VARIABLE <var>]
+          [WORKING_DIRECTORY <var>]
+          [ARGS <args>...]
+          )
 
 
-``COMPILE_DEFINITIONS <defs>...``
-  Specify ``-Ddefinition`` arguments to pass to :command:`add_definitions`
-  in the generated test project.
+The options specific to ``try_run`` are:
 
 
 ``COMPILE_OUTPUT_VARIABLE <var>``
 ``COMPILE_OUTPUT_VARIABLE <var>``
   Report the compile step build output in a given variable.
   Report the compile step build output in a given variable.
 
 
-``LINK_LIBRARIES <libs>...``
-  .. versionadded:: 3.2
-
-  Specify libraries to be linked in the generated project.
-  The list of libraries may refer to system libraries and to
-  :ref:`Imported Targets <Imported Targets>` from the calling project.
-
-  If this option is specified, any ``-DLINK_LIBRARIES=...`` value
-  given to the ``CMAKE_FLAGS`` option will be ignored.
-
-``LINK_OPTIONS <options>...``
-  .. versionadded:: 3.14
-
-  Specify link step options to pass to :command:`target_link_options` in the
-  generated project.
-
 ``OUTPUT_VARIABLE <var>``
 ``OUTPUT_VARIABLE <var>``
   Report the compile build output and the output from running the executable
   Report the compile build output and the output from running the executable
-  in the given variable.  This option exists for legacy reasons.  Prefer
-  ``COMPILE_OUTPUT_VARIABLE`` and ``RUN_OUTPUT_VARIABLE`` instead.
+  in the given variable.  This option exists for legacy reasons and is only
+  supported by the old ``try_run`` signature.
+  Prefer ``COMPILE_OUTPUT_VARIABLE`` and ``RUN_OUTPUT_VARIABLE`` instead.
 
 
 ``RUN_OUTPUT_VARIABLE <var>``
 ``RUN_OUTPUT_VARIABLE <var>``
   Report the output from running the executable in a given variable.
   Report the output from running the executable in a given variable.
@@ -86,7 +92,11 @@ The options are:
   .. versionadded:: 3.20
   .. versionadded:: 3.20
 
 
   Run the executable in the given directory. If no ``WORKING_DIRECTORY`` is
   Run the executable in the given directory. If no ``WORKING_DIRECTORY`` is
-  specified, the executable will run in ``<bindir>``.
+  specified, the executable will run in ``<bindir>`` or the current build
+  directory.
+
+``ARGS <args>...``
+  Additional arguments to pass to the executable when running it.
 
 
 Other Behavior Settings
 Other Behavior Settings
 ^^^^^^^^^^^^^^^^^^^^^^^
 ^^^^^^^^^^^^^^^^^^^^^^^

+ 8 - 0
Help/release/dev/try_compile-signatures.rst

@@ -0,0 +1,8 @@
+try_compile-signatures
+----------------------
+
+* The :command:`try_compile` and :command:`try_run` commands gained new
+  signatures that more consistently use keyword dispatch and do not require a
+  binary directory to be specified.  Additionally, these signatures use a
+  unique directory for each invocation, which allows multiple outputs to be
+  preserved when using ``--debug-trycompile``.

+ 83 - 20
Source/cmCoreTryCompile.cxx

@@ -31,6 +31,7 @@
 #include "cmake.h"
 #include "cmake.h"
 
 
 namespace {
 namespace {
+constexpr const char* unique_binary_directory = "CMAKE_BINARY_DIR_USE_MKDTEMP";
 constexpr size_t lang_property_start = 0;
 constexpr size_t lang_property_start = 0;
 constexpr size_t lang_property_size = 4;
 constexpr size_t lang_property_size = 4;
 constexpr size_t pie_property_start = 4;
 constexpr size_t pie_property_start = 4;
@@ -122,13 +123,9 @@ ArgumentParser::Continue TryCompileCompileDefs(Arguments& args,
     .Bind(#lang "_STANDARD_REQUIRED"_s, TryCompileLangProp)                   \
     .Bind(#lang "_STANDARD_REQUIRED"_s, TryCompileLangProp)                   \
     .Bind(#lang "_EXTENSIONS"_s, TryCompileLangProp)
     .Bind(#lang "_EXTENSIONS"_s, TryCompileLangProp)
 
 
-auto const TryCompileArgParser =
+auto const TryCompileBaseArgParser =
   cmArgumentParser<Arguments>{}
   cmArgumentParser<Arguments>{}
     .Bind(0, &Arguments::CompileResultVariable)
     .Bind(0, &Arguments::CompileResultVariable)
-    .Bind(1, &Arguments::BinaryDirectory)
-    .Bind(2, &Arguments::SourceDirectoryOrFile)
-    .Bind(3, &Arguments::ProjectName)
-    .Bind(4, &Arguments::TargetName)
     .Bind("SOURCES"_s, &Arguments::Sources)
     .Bind("SOURCES"_s, &Arguments::Sources)
     .Bind("CMAKE_FLAGS"_s, &Arguments::CMakeFlags)
     .Bind("CMAKE_FLAGS"_s, &Arguments::CMakeFlags)
     .Bind("COMPILE_DEFINITIONS"_s, TryCompileCompileDefs,
     .Bind("COMPILE_DEFINITIONS"_s, TryCompileCompileDefs,
@@ -136,7 +133,6 @@ auto const TryCompileArgParser =
     .Bind("LINK_LIBRARIES"_s, &Arguments::LinkLibraries)
     .Bind("LINK_LIBRARIES"_s, &Arguments::LinkLibraries)
     .Bind("LINK_OPTIONS"_s, &Arguments::LinkOptions)
     .Bind("LINK_OPTIONS"_s, &Arguments::LinkOptions)
     .Bind("__CMAKE_INTERNAL"_s, &Arguments::CMakeInternal)
     .Bind("__CMAKE_INTERNAL"_s, &Arguments::CMakeInternal)
-    .Bind("OUTPUT_VARIABLE"_s, &Arguments::OutputVariable)
     .Bind("COPY_FILE"_s, &Arguments::CopyFileTo)
     .Bind("COPY_FILE"_s, &Arguments::CopyFileTo)
     .Bind("COPY_FILE_ERROR"_s, &Arguments::CopyFileError)
     .Bind("COPY_FILE_ERROR"_s, &Arguments::CopyFileError)
     .BIND_LANG_PROPS(C)
     .BIND_LANG_PROPS(C)
@@ -147,8 +143,31 @@ auto const TryCompileArgParser =
     .BIND_LANG_PROPS(OBJCXX)
     .BIND_LANG_PROPS(OBJCXX)
   /* keep semicolon on own line */;
   /* keep semicolon on own line */;
 
 
-auto const TryRunArgParser =
+auto const TryCompileArgParser =
+  cmArgumentParser<Arguments>{ TryCompileBaseArgParser }.Bind(
+    "OUTPUT_VARIABLE"_s, &Arguments::OutputVariable)
+  /* keep semicolon on own line */;
+
+auto const TryCompileOldArgParser =
   cmArgumentParser<Arguments>{ TryCompileArgParser }
   cmArgumentParser<Arguments>{ TryCompileArgParser }
+    .Bind(1, &Arguments::BinaryDirectory)
+    .Bind(2, &Arguments::SourceDirectoryOrFile)
+    .Bind(3, &Arguments::ProjectName)
+    .Bind(4, &Arguments::TargetName)
+  /* keep semicolon on own line */;
+
+auto const TryRunArgParser =
+  cmArgumentParser<Arguments>{ TryCompileBaseArgParser }
+    .Bind("COMPILE_OUTPUT_VARIABLE"_s, &Arguments::CompileOutputVariable)
+    .Bind("RUN_OUTPUT_VARIABLE"_s, &Arguments::RunOutputVariable)
+    .Bind("RUN_OUTPUT_STDOUT_VARIABLE"_s, &Arguments::RunOutputStdOutVariable)
+    .Bind("RUN_OUTPUT_STDERR_VARIABLE"_s, &Arguments::RunOutputStdErrVariable)
+    .Bind("WORKING_DIRECTORY"_s, &Arguments::RunWorkingDirectory)
+    .Bind("ARGS"_s, &Arguments::RunArgs)
+  /* keep semicolon on own line */;
+
+auto const TryRunOldArgParser =
+  cmArgumentParser<Arguments>{ TryCompileOldArgParser }
     .Bind("COMPILE_OUTPUT_VARIABLE"_s, &Arguments::CompileOutputVariable)
     .Bind("COMPILE_OUTPUT_VARIABLE"_s, &Arguments::CompileOutputVariable)
     .Bind("RUN_OUTPUT_VARIABLE"_s, &Arguments::RunOutputVariable)
     .Bind("RUN_OUTPUT_VARIABLE"_s, &Arguments::RunOutputVariable)
     .Bind("RUN_OUTPUT_STDOUT_VARIABLE"_s, &Arguments::RunOutputStdOutVariable)
     .Bind("RUN_OUTPUT_STDOUT_VARIABLE"_s, &Arguments::RunOutputStdOutVariable)
@@ -161,10 +180,10 @@ auto const TryRunArgParser =
 }
 }
 
 
 Arguments cmCoreTryCompile::ParseArgs(
 Arguments cmCoreTryCompile::ParseArgs(
-  cmRange<std::vector<std::string>::const_iterator> args, bool isTryRun)
+  const cmRange<std::vector<std::string>::const_iterator>& args,
+  const cmArgumentParser<Arguments>& parser,
+  std::vector<std::string>& unparsedArguments)
 {
 {
-  std::vector<std::string> unparsedArguments;
-  const auto& parser = (isTryRun ? TryRunArgParser : TryCompileArgParser);
   auto arguments = parser.Parse(args, &unparsedArguments, 0);
   auto arguments = parser.Parse(args, &unparsedArguments, 0);
   if (!arguments.MaybeReportError(*(this->Makefile)) &&
   if (!arguments.MaybeReportError(*(this->Makefile)) &&
       !unparsedArguments.empty()) {
       !unparsedArguments.empty()) {
@@ -174,6 +193,26 @@ Arguments cmCoreTryCompile::ParseArgs(
     }
     }
     this->Makefile->IssueMessage(MessageType::AUTHOR_WARNING, m);
     this->Makefile->IssueMessage(MessageType::AUTHOR_WARNING, m);
   }
   }
+  return arguments;
+}
+
+Arguments cmCoreTryCompile::ParseArgs(
+  cmRange<std::vector<std::string>::const_iterator> args, bool isTryRun)
+{
+  std::vector<std::string> unparsedArguments;
+  if (cmHasLiteralPrefix(*(++args.begin()), "SOURCE")) {
+    // New signature.
+    auto arguments =
+      this->ParseArgs(args, isTryRun ? TryRunArgParser : TryCompileArgParser,
+                      unparsedArguments);
+    arguments.BinaryDirectory = unique_binary_directory;
+    return arguments;
+  }
+
+  // Old signature.
+  auto arguments = this->ParseArgs(
+    args, isTryRun ? TryRunOldArgParser : TryCompileOldArgParser,
+    unparsedArguments);
   // For historical reasons, treat some empty-valued keyword
   // For historical reasons, treat some empty-valued keyword
   // arguments as if they were not specified at all.
   // arguments as if they were not specified at all.
   if (arguments.OutputVariable && arguments.OutputVariable->empty()) {
   if (arguments.OutputVariable && arguments.OutputVariable->empty()) {
@@ -210,6 +249,7 @@ bool cmCoreTryCompile::TryCompileCode(Arguments& arguments,
   // which signature were we called with ?
   // which signature were we called with ?
   this->SrcFileSignature = true;
   this->SrcFileSignature = true;
 
 
+  bool useUniqueBinaryDirectory = false;
   std::string sourceDirectory;
   std::string sourceDirectory;
   std::string projectName;
   std::string projectName;
   std::string targetName;
   std::string targetName;
@@ -230,7 +270,17 @@ bool cmCoreTryCompile::TryCompileCode(Arguments& arguments,
     targetName = targetNameBuf;
     targetName = targetNameBuf;
   }
   }
 
 
-  if (arguments.BinaryDirectory && !arguments.BinaryDirectory->empty()) {
+  if (!arguments.BinaryDirectory || arguments.BinaryDirectory->empty()) {
+    this->Makefile->IssueMessage(MessageType::FATAL_ERROR,
+                                 "No <bindir> specified.");
+    return false;
+  }
+  if (*arguments.BinaryDirectory == unique_binary_directory) {
+    // leave empty until we're ready to create it, so we don't try to remove
+    // a non-existing directory if we abort due to e.g. bad arguments
+    this->BinaryDirectory.clear();
+    useUniqueBinaryDirectory = true;
+  } else {
     if (!cmSystemTools::FileIsFullPath(*arguments.BinaryDirectory)) {
     if (!cmSystemTools::FileIsFullPath(*arguments.BinaryDirectory)) {
       this->Makefile->IssueMessage(
       this->Makefile->IssueMessage(
         MessageType::FATAL_ERROR,
         MessageType::FATAL_ERROR,
@@ -244,10 +294,6 @@ bool cmCoreTryCompile::TryCompileCode(Arguments& arguments,
     if (this->SrcFileSignature) {
     if (this->SrcFileSignature) {
       this->BinaryDirectory += "/CMakeFiles/CMakeTmp";
       this->BinaryDirectory += "/CMakeFiles/CMakeTmp";
     }
     }
-  } else {
-    this->Makefile->IssueMessage(MessageType::FATAL_ERROR,
-                                 "No <bindir> specified.");
-    return false;
   }
   }
 
 
   std::vector<std::string> targets;
   std::vector<std::string> targets;
@@ -331,7 +377,14 @@ bool cmCoreTryCompile::TryCompileCode(Arguments& arguments,
     }
     }
   }
   }
   // make sure the binary directory exists
   // make sure the binary directory exists
-  cmSystemTools::MakeDirectory(this->BinaryDirectory);
+  if (useUniqueBinaryDirectory) {
+    this->BinaryDirectory =
+      cmStrCat(this->Makefile->GetHomeOutputDirectory(),
+               "/CMakeFiles/CMakeScratch/TryCompile-XXXXXX");
+    cmSystemTools::MakeTempDirectory(this->BinaryDirectory);
+  } else {
+    cmSystemTools::MakeDirectory(this->BinaryDirectory);
+  }
 
 
   // do not allow recursive try Compiles
   // do not allow recursive try Compiles
   if (this->BinaryDirectory == this->Makefile->GetHomeOutputDirectory()) {
   if (this->BinaryDirectory == this->Makefile->GetHomeOutputDirectory()) {
@@ -635,7 +688,7 @@ bool cmCoreTryCompile::TryCompileCode(Arguments& arguments,
       fprintf(fout, " \"%s\"", si.c_str());
       fprintf(fout, " \"%s\"", si.c_str());
 
 
       // Add dependencies on any non-temporary sources.
       // Add dependencies on any non-temporary sources.
-      if (si.find("CMakeTmp") == std::string::npos) {
+      if (!IsTemporary(si)) {
         this->Makefile->AddCMakeDependFile(si);
         this->Makefile->AddCMakeDependFile(si);
       }
       }
     }
     }
@@ -914,17 +967,23 @@ bool cmCoreTryCompile::TryCompileCode(Arguments& arguments,
   return res == 0;
   return res == 0;
 }
 }
 
 
+bool cmCoreTryCompile::IsTemporary(std::string const& path)
+{
+  return ((path.find("CMakeTmp") != std::string::npos) ||
+          (path.find("CMakeScratch") != std::string::npos));
+}
+
 void cmCoreTryCompile::CleanupFiles(std::string const& binDir)
 void cmCoreTryCompile::CleanupFiles(std::string const& binDir)
 {
 {
   if (binDir.empty()) {
   if (binDir.empty()) {
     return;
     return;
   }
   }
 
 
-  if (binDir.find("CMakeTmp") == std::string::npos) {
+  if (!IsTemporary(binDir)) {
     cmSystemTools::Error(
     cmSystemTools::Error(
       "TRY_COMPILE attempt to remove -rf directory that does not contain "
       "TRY_COMPILE attempt to remove -rf directory that does not contain "
-      "CMakeTmp:" +
-      binDir);
+      "CMakeTmp or CMakeScratch: \"" +
+      binDir + "\"");
     return;
     return;
   }
   }
 
 
@@ -970,6 +1029,10 @@ void cmCoreTryCompile::CleanupFiles(std::string const& binDir)
       }
       }
     }
     }
   }
   }
+
+  if (binDir.find("CMakeScratch") != std::string::npos) {
+    cmSystemTools::RemoveADirectory(binDir);
+  }
 }
 }
 
 
 void cmCoreTryCompile::FindOutputFile(const std::string& targetName,
 void cmCoreTryCompile::FindOutputFile(const std::string& targetName,

+ 17 - 3
Source/cmCoreTryCompile.h

@@ -67,13 +67,21 @@ public:
                       bool isTryRun);
                       bool isTryRun);
 
 
   /**
   /**
-   * This is the core code for try compile. It is here so that other
-   * commands, such as TryRun can access the same logic without
-   * duplication.
+   * This is the core code for try compile. It is here so that other commands,
+   * such as TryRun can access the same logic without duplication.
+   *
+   * This function requires at least two \p arguments and will crash if given
+   * fewer.
    */
    */
   bool TryCompileCode(Arguments& arguments,
   bool TryCompileCode(Arguments& arguments,
                       cmStateEnums::TargetType targetType);
                       cmStateEnums::TargetType targetType);
 
 
+  /**
+   * Returns \c true if \p path resides within a CMake temporary directory,
+   * otherwise returns \c false.
+   */
+  static bool IsTemporary(std::string const& path);
+
   /**
   /**
    * This deletes all the files created by TryCompileCode.
    * This deletes all the files created by TryCompileCode.
    * This way we do not have to rely on the timing and
    * This way we do not have to rely on the timing and
@@ -94,4 +102,10 @@ public:
   std::string FindErrorMessage;
   std::string FindErrorMessage;
   bool SrcFileSignature = false;
   bool SrcFileSignature = false;
   cmMakefile* Makefile;
   cmMakefile* Makefile;
+
+private:
+  Arguments ParseArgs(
+    const cmRange<std::vector<std::string>::const_iterator>& args,
+    const cmArgumentParser<Arguments>& parser,
+    std::vector<std::string>& unparsedArguments);
 };
 };

+ 92 - 1
Source/cmSystemTools.cxx

@@ -11,6 +11,11 @@
 // NOLINTNEXTLINE(bugprone-reserved-identifier)
 // NOLINTNEXTLINE(bugprone-reserved-identifier)
 #  define _XOPEN_SOURCE 700
 #  define _XOPEN_SOURCE 700
 #endif
 #endif
+#if defined(__APPLE__)
+// Restore Darwin APIs removed by _POSIX_C_SOURCE.
+// NOLINTNEXTLINE(bugprone-reserved-identifier)
+#  define _DARWIN_C_SOURCE
+#endif
 
 
 #include "cmSystemTools.h"
 #include "cmSystemTools.h"
 
 
@@ -88,7 +93,6 @@
 #  include <unistd.h>
 #  include <unistd.h>
 
 
 #  include <sys/time.h>
 #  include <sys/time.h>
-#  include <sys/types.h>
 #endif
 #endif
 
 
 #if defined(_WIN32) &&                                                        \
 #if defined(_WIN32) &&                                                        \
@@ -1001,6 +1005,93 @@ void cmSystemTools::InitializeLibUV()
 #endif
 #endif
 }
 }
 
 
+#if defined(_WIN32)
+#  include <random>
+
+#  include <wctype.h>
+#  ifdef _MSC_VER
+using mode_t = cmSystemTools::SystemTools::mode_t;
+#  endif
+#else
+#  include <sys/stat.h>
+#endif
+
+inline int Mkdir(const char* dir, const mode_t* mode)
+{
+#if defined(_WIN32)
+  int ret = _wmkdir(cmSystemTools::ConvertToWindowsExtendedPath(dir).c_str());
+  if (ret == 0 && mode)
+    cmSystemTools::SystemTools::SetPermissions(dir, *mode);
+  return ret;
+#else
+  return mkdir(dir, mode ? *mode : 0777);
+#endif
+}
+
+cmsys::Status cmSystemTools::MakeTempDirectory(std::string& path,
+                                               const mode_t* mode)
+{
+  if (path.empty()) {
+    return cmsys::Status::POSIX(EINVAL);
+  }
+  return cmSystemTools::MakeTempDirectory(&path.front(), mode);
+}
+
+cmsys::Status cmSystemTools::MakeTempDirectory(char* path, const mode_t* mode)
+{
+  if (!path) {
+    return cmsys::Status::POSIX(EINVAL);
+  }
+
+  // verify that path ends with "XXXXXX"
+  const auto l = std::strlen(path);
+  if (!cmHasLiteralSuffix(cm::string_view{ path, l }, "XXXXXX")) {
+    return cmsys::Status::POSIX(EINVAL);
+  }
+
+  // create parent directories
+  auto* sep = path;
+  while ((sep = strchr(sep, '/'))) {
+    // all underlying functions use C strings,
+    // so temporarily end the string here
+    *sep = '\0';
+    Mkdir(path, mode);
+
+    *sep = '/';
+    ++sep;
+  }
+
+#ifdef _WIN32
+  const int nchars = 36;
+  const char chars[nchars + 1] = "abcdefghijklmnopqrstuvwxyz0123456789";
+
+  std::random_device rd;
+  std::mt19937 rg{ rd() };
+  std::uniform_int_distribution<int> dist{ 0, nchars - 1 };
+
+  for (auto tries = 100; tries; --tries) {
+    for (auto n = l - 6; n < l; ++n) {
+      path[n] = chars[dist(rg)];
+    }
+    if (Mkdir(path, mode) == 0) {
+      return cmsys::Status::Success();
+    } else if (errno != EEXIST) {
+      return cmsys::Status::POSIX_errno();
+    }
+  }
+  return cmsys::Status::POSIX(EAGAIN);
+#else
+  if (mkdtemp(path)) {
+    if (mode) {
+      chmod(path, *mode);
+    }
+  } else {
+    return cmsys::Status::POSIX_errno();
+  }
+  return cmsys::Status::Success();
+#endif
+}
+
 #ifdef _WIN32
 #ifdef _WIN32
 namespace {
 namespace {
 bool cmMoveFile(std::wstring const& oldname, std::wstring const& newname,
 bool cmMoveFile(std::wstring const& oldname, std::wstring const& newname,

+ 25 - 0
Source/cmSystemTools.h

@@ -4,6 +4,10 @@
 
 
 #include "cmConfigure.h" // IWYU pragma: keep
 #include "cmConfigure.h" // IWYU pragma: keep
 
 
+#if !defined(_WIN32)
+#  include <sys/types.h>
+#endif
+
 #include <cstddef>
 #include <cstddef>
 #include <functional>
 #include <functional>
 #include <map>
 #include <map>
@@ -151,6 +155,27 @@ public:
     Failure,
     Failure,
   };
   };
 
 
+#if defined(_MSC_VER)
+  /** Visual C++ does not define mode_t. */
+  using mode_t = unsigned short;
+#endif
+
+  /**
+   * Make a new temporary directory.  The path must end in "XXXXXX", and will
+   * be modified to reflect the name of the directory created.  This function
+   * is similar to POSIX mkdtemp (and is implemented using the same where that
+   * function is available).
+   *
+   * This function can make a full path even if none of the directories existed
+   * prior to calling this function.
+   *
+   * Note that this function may modify \p path even if it does not succeed.
+   */
+  static cmsys::Status MakeTempDirectory(char* path,
+                                         const mode_t* mode = nullptr);
+  static cmsys::Status MakeTempDirectory(std::string& path,
+                                         const mode_t* mode = nullptr);
+
   /** Copy a file. */
   /** Copy a file. */
   static bool CopySingleFile(const std::string& oldname,
   static bool CopySingleFile(const std::string& oldname,
                              const std::string& newname);
                              const std::string& newname);

+ 3 - 0
Source/cmake.cxx

@@ -2139,6 +2139,9 @@ int cmake::ActualConfigure()
   this->UpdateConversionPathTable();
   this->UpdateConversionPathTable();
   this->CleanupCommandsAndMacros();
   this->CleanupCommandsAndMacros();
 
 
+  cmSystemTools::RemoveADirectory(this->GetHomeOutputDirectory() +
+                                  "/CMakeFiles/CMakeScratch");
+
   int res = this->DoPreConfigureChecks();
   int res = this->DoPreConfigureChecks();
   if (res < 0) {
   if (res < 0) {
     return -2;
     return -2;

+ 1 - 1
Tests/RunCMake/try_compile/BadLinkLibraries-stderr.txt

@@ -1,4 +1,4 @@
-CMake Error at BadLinkLibraries.cmake:2 \(try_compile\):
+CMake Error at BadLinkLibraries.cmake:[0-9]+ \(try_compile\):
   Only libraries may be used as try_compile or try_run IMPORTED
   Only libraries may be used as try_compile or try_run IMPORTED
   LINK_LIBRARIES.  Got not_a_library of type UTILITY.
   LINK_LIBRARIES.  Got not_a_library of type UTILITY.
 Call Stack \(most recent call first\):
 Call Stack \(most recent call first\):

+ 5 - 1
Tests/RunCMake/try_compile/BadLinkLibraries.cmake

@@ -1,3 +1,7 @@
+include(${CMAKE_CURRENT_SOURCE_DIR}/${try_compile_DEFS})
+
 add_custom_target(not_a_library)
 add_custom_target(not_a_library)
-try_compile(RESULT ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/src.c
+
+try_compile(RESULT ${try_compile_bindir_or_SOURCES}
+  ${CMAKE_CURRENT_SOURCE_DIR}/src.c
   LINK_LIBRARIES not_a_library)
   LINK_LIBRARIES not_a_library)

+ 1 - 1
Tests/RunCMake/try_compile/BadSources1-stderr.txt

@@ -1,4 +1,4 @@
-CMake Error at BadSources1.cmake:1 \(try_compile\):
+CMake Error at BadSources1.cmake:[0-9]+ \(try_compile\):
   Unknown extension ".c" for file
   Unknown extension ".c" for file
 
 
     .*/Tests/RunCMake/try_compile/src.c
     .*/Tests/RunCMake/try_compile/src.c

+ 3 - 1
Tests/RunCMake/try_compile/BadSources1.cmake

@@ -1 +1,3 @@
-try_compile(RESULT ${CMAKE_CURRENT_BINARY_DIR} SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src.c)
+include(${CMAKE_CURRENT_SOURCE_DIR}/${try_compile_DEFS})
+try_compile(RESULT ${try_compile_bindir_or_SOURCES}
+  ${try_compile_redundant_SOURCES} ${CMAKE_CURRENT_SOURCE_DIR}/src.c)

+ 1 - 1
Tests/RunCMake/try_compile/BadSources2-stderr.txt

@@ -1,4 +1,4 @@
-CMake Error at BadSources2.cmake:2 \(try_compile\):
+CMake Error at BadSources2.cmake:[0-9]+ \(try_compile\):
   Unknown extension ".cxx" for file
   Unknown extension ".cxx" for file
 
 
     .*/Tests/RunCMake/try_compile/src.cxx
     .*/Tests/RunCMake/try_compile/src.cxx

+ 4 - 3
Tests/RunCMake/try_compile/BadSources2.cmake

@@ -1,5 +1,6 @@
+include(${CMAKE_CURRENT_SOURCE_DIR}/${try_compile_DEFS})
 enable_language(C)
 enable_language(C)
-try_compile(RESULT ${CMAKE_CURRENT_BINARY_DIR}
-  SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src.c
-          ${CMAKE_CURRENT_SOURCE_DIR}/src.cxx
+try_compile(RESULT ${try_compile_bindir_or_SOURCES}
+  ${try_compile_redundant_SOURCES} ${CMAKE_CURRENT_SOURCE_DIR}/src.c
+                                   ${CMAKE_CURRENT_SOURCE_DIR}/src.cxx
   )
   )

+ 1 - 1
Tests/RunCMake/try_compile/CStandard-stderr.txt

@@ -1,4 +1,4 @@
-^CMake Error at .*/Tests/RunCMake/try_compile/CStandard-build/CMakeFiles/CMakeTmp/CMakeLists.txt:[0-9]+ \(add_executable\):
+^CMake Error at .*/Tests/RunCMake/try_compile/CStandard-build/CMakeFiles/CMake(Tmp|Scratch/TryCompile-[^/]+)/CMakeLists.txt:[0-9]+ \(add_executable\):
   C_STANDARD is set to invalid value '3'
   C_STANDARD is set to invalid value '3'
 +
 +
 CMake Error at CStandard.cmake:[0-9]+ \(try_compile\):
 CMake Error at CStandard.cmake:[0-9]+ \(try_compile\):

+ 6 - 2
Tests/RunCMake/try_compile/CStandard.cmake

@@ -1,7 +1,11 @@
+include(${CMAKE_CURRENT_SOURCE_DIR}/${try_compile_DEFS})
+
 enable_language(C)
 enable_language(C)
-try_compile(result ${CMAKE_CURRENT_BINARY_DIR}
-  SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src.c
+
+try_compile(result ${try_compile_bindir_or_SOURCES}
+  ${try_compile_redundant_SOURCES} ${CMAKE_CURRENT_SOURCE_DIR}/src.c
   C_STANDARD 3
   C_STANDARD 3
   OUTPUT_VARIABLE out
   OUTPUT_VARIABLE out
   )
   )
+
 message("try_compile output:\n${out}")
 message("try_compile output:\n${out}")

+ 11 - 4
Tests/RunCMake/try_compile/CStandardGNU.cmake

@@ -1,23 +1,30 @@
+include(${CMAKE_CURRENT_SOURCE_DIR}/${try_compile_DEFS})
+
 enable_language(C)
 enable_language(C)
-try_compile(result ${CMAKE_CURRENT_BINARY_DIR}
-  SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/CStandardGNU.c
+
+try_compile(result ${try_compile_bindir_or_SOURCES}
+  ${try_compile_redundant_SOURCES} ${CMAKE_CURRENT_SOURCE_DIR}/CStandardGNU.c
   C_STANDARD 99
   C_STANDARD 99
   C_STANDARD_REQUIRED 1
   C_STANDARD_REQUIRED 1
   C_EXTENSIONS 0
   C_EXTENSIONS 0
   OUTPUT_VARIABLE out
   OUTPUT_VARIABLE out
   )
   )
+
 if(NOT result)
 if(NOT result)
   message(FATAL_ERROR "try_compile failed:\n${out}")
   message(FATAL_ERROR "try_compile failed:\n${out}")
 endif()
 endif()
 
 
 cmake_policy(SET CMP0067 NEW)
 cmake_policy(SET CMP0067 NEW)
+
 set(CMAKE_C_STANDARD 99)
 set(CMAKE_C_STANDARD 99)
 set(CMAKE_C_STANDARD_REQUIRED 1)
 set(CMAKE_C_STANDARD_REQUIRED 1)
 set(CMAKE_C_EXTENSIONS 0)
 set(CMAKE_C_EXTENSIONS 0)
-try_compile(result ${CMAKE_CURRENT_BINARY_DIR}
-  SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/CStandardGNU.c
+
+try_compile(result ${try_compile_bindir_or_SOURCES}
+  ${try_compile_redundant_SOURCES} ${CMAKE_CURRENT_SOURCE_DIR}/CStandardGNU.c
   OUTPUT_VARIABLE out
   OUTPUT_VARIABLE out
   )
   )
+
 if(NOT result)
 if(NOT result)
   message(FATAL_ERROR "try_compile failed:\n${out}")
   message(FATAL_ERROR "try_compile failed:\n${out}")
 endif()
 endif()

+ 6 - 2
Tests/RunCMake/try_compile/CStandardNoDefault.cmake

@@ -1,9 +1,13 @@
+include(${CMAKE_CURRENT_SOURCE_DIR}/${try_compile_DEFS})
+
 enable_language(C)
 enable_language(C)
-try_compile(result ${CMAKE_CURRENT_BINARY_DIR}
-  SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src.c
+
+try_compile(result ${try_compile_bindir_or_SOURCES}
+  ${try_compile_redundant_SOURCES} ${CMAKE_CURRENT_SOURCE_DIR}/src.c
   C_STANDARD 3 # bogus, but not used
   C_STANDARD 3 # bogus, but not used
   OUTPUT_VARIABLE out
   OUTPUT_VARIABLE out
   )
   )
+
 if(NOT result)
 if(NOT result)
   message(FATAL_ERROR "try_compile failed:\n${out}")
   message(FATAL_ERROR "try_compile failed:\n${out}")
 endif()
 endif()

+ 1 - 1
Tests/RunCMake/try_compile/CopyFileErrorNoCopyFile-stderr.txt

@@ -1,4 +1,4 @@
-CMake Error at CopyFileErrorNoCopyFile.cmake:1 \(try_compile\):
+CMake Error at CopyFileErrorNoCopyFile.cmake:[0-9]+ \(try_compile\):
   COPY_FILE_ERROR may be used only with COPY_FILE
   COPY_FILE_ERROR may be used only with COPY_FILE
 Call Stack \(most recent call first\):
 Call Stack \(most recent call first\):
   CMakeLists.txt:3 \(include\)
   CMakeLists.txt:3 \(include\)

+ 3 - 1
Tests/RunCMake/try_compile/CopyFileErrorNoCopyFile.cmake

@@ -1,2 +1,4 @@
-try_compile(RESULT ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/src.c
+include(${CMAKE_CURRENT_SOURCE_DIR}/${try_compile_DEFS})
+try_compile(RESULT ${try_compile_bindir_or_SOURCES}
+  ${CMAKE_CURRENT_SOURCE_DIR}/src.c
   COPY_FILE_ERROR _copied)
   COPY_FILE_ERROR _copied)

+ 1 - 1
Tests/RunCMake/try_compile/CudaStandard-stderr.txt

@@ -1,4 +1,4 @@
-^CMake Error at .*/Tests/RunCMake/try_compile/CudaStandard-build/CMakeFiles/CMakeTmp/CMakeLists.txt:[0-9]+ \(add_executable\):
+^CMake Error at .*/Tests/RunCMake/try_compile/CudaStandard-build/CMakeFiles/CMake(Tmp|Scratch/TryCompile-[^/]+)/CMakeLists.txt:[0-9]+ \(add_executable\):
   CUDA_STANDARD is set to invalid value '4'
   CUDA_STANDARD is set to invalid value '4'
 +
 +
 CMake Error at CudaStandard.cmake:[0-9]+ \(try_compile\):
 CMake Error at CudaStandard.cmake:[0-9]+ \(try_compile\):

+ 6 - 2
Tests/RunCMake/try_compile/CudaStandard.cmake

@@ -1,7 +1,11 @@
+include(${CMAKE_CURRENT_SOURCE_DIR}/${try_compile_DEFS})
+
 enable_language(CUDA)
 enable_language(CUDA)
-try_compile(result ${CMAKE_CURRENT_BINARY_DIR}
-  SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src.cu
+
+try_compile(result ${try_compile_bindir_or_SOURCES}
+  ${try_compile_redundant_SOURCES} ${CMAKE_CURRENT_SOURCE_DIR}/src.cu
   CUDA_STANDARD 4
   CUDA_STANDARD 4
   OUTPUT_VARIABLE out
   OUTPUT_VARIABLE out
   )
   )
+
 message("try_compile output:\n${out}")
 message("try_compile output:\n${out}")

+ 3 - 3
Tests/RunCMake/try_compile/CxxStandard-stderr.txt

@@ -1,13 +1,13 @@
-^(CMake Error in .*/Tests/RunCMake/try_compile/CxxStandard-build/CMakeFiles/CMakeTmp/CMakeLists.txt:
+^(CMake Error in .*/Tests/RunCMake/try_compile/CxxStandard-build/CMakeFiles/CMake(Tmp|Scratch/TryCompile-[^/]+)/CMakeLists.txt:
   The CXX_STANDARD property on target "cmTC_[0-9a-f]*" contained an invalid
   The CXX_STANDARD property on target "cmTC_[0-9a-f]*" contained an invalid
   value: "3".
   value: "3".
 
 
 
 
-)?CMake Error at .*/Tests/RunCMake/try_compile/CxxStandard-build/CMakeFiles/CMakeTmp/CMakeLists.txt:[0-9]+ \(add_executable\):
+)?CMake Error at .*/Tests/RunCMake/try_compile/CxxStandard-build/CMakeFiles/CMake(Tmp|Scratch/TryCompile-[^/]+)/CMakeLists.txt:[0-9]+ \(add_executable\):
   CXX_STANDARD is set to invalid value '3'
   CXX_STANDARD is set to invalid value '3'
 
 
 (
 (
-CMake Error in .*/Tests/RunCMake/try_compile/CxxStandard-build/CMakeFiles/CMakeTmp/CMakeLists.txt:
+CMake Error in .*/Tests/RunCMake/try_compile/CxxStandard-build/CMakeFiles/CMake(Tmp|Scratch/TryCompile-[^/]+)/CMakeLists.txt:
   The CXX_STANDARD property on target "cmTC_[0-9a-f]*" contained an invalid
   The CXX_STANDARD property on target "cmTC_[0-9a-f]*" contained an invalid
   value: "3".
   value: "3".
 
 

+ 6 - 2
Tests/RunCMake/try_compile/CxxStandard.cmake

@@ -1,7 +1,11 @@
+include(${CMAKE_CURRENT_SOURCE_DIR}/${try_compile_DEFS})
+
 enable_language(CXX)
 enable_language(CXX)
-try_compile(result ${CMAKE_CURRENT_BINARY_DIR}
-  SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src.cxx
+
+try_compile(result ${try_compile_bindir_or_SOURCES}
+  ${try_compile_redundant_SOURCES} ${CMAKE_CURRENT_SOURCE_DIR}/src.cxx
   CXX_STANDARD 3
   CXX_STANDARD 3
   OUTPUT_VARIABLE out
   OUTPUT_VARIABLE out
   )
   )
+
 message("try_compile output:\n${out}")
 message("try_compile output:\n${out}")

+ 11 - 4
Tests/RunCMake/try_compile/CxxStandardGNU.cmake

@@ -1,23 +1,30 @@
+include(${CMAKE_CURRENT_SOURCE_DIR}/${try_compile_DEFS})
+
 enable_language(CXX)
 enable_language(CXX)
-try_compile(result ${CMAKE_CURRENT_BINARY_DIR}
-  SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/CxxStandardGNU.cxx
+
+try_compile(result ${try_compile_bindir_or_SOURCES}
+  ${try_compile_redundant_SOURCES} ${CMAKE_CURRENT_SOURCE_DIR}/CxxStandardGNU.cxx
   CXX_STANDARD 11
   CXX_STANDARD 11
   CXX_STANDARD_REQUIRED 1
   CXX_STANDARD_REQUIRED 1
   CXX_EXTENSIONS 0
   CXX_EXTENSIONS 0
   OUTPUT_VARIABLE out
   OUTPUT_VARIABLE out
   )
   )
+
 if(NOT result)
 if(NOT result)
   message(FATAL_ERROR "try_compile failed:\n${out}")
   message(FATAL_ERROR "try_compile failed:\n${out}")
 endif()
 endif()
 
 
 cmake_policy(SET CMP0067 NEW)
 cmake_policy(SET CMP0067 NEW)
+
 set(CMAKE_CXX_STANDARD 11)
 set(CMAKE_CXX_STANDARD 11)
 set(CMAKE_CXX_STANDARD_REQUIRED 1)
 set(CMAKE_CXX_STANDARD_REQUIRED 1)
 set(CMAKE_CXX_EXTENSIONS 0)
 set(CMAKE_CXX_EXTENSIONS 0)
-try_compile(result ${CMAKE_CURRENT_BINARY_DIR}
-  SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/CxxStandardGNU.cxx
+
+try_compile(result ${try_compile_bindir_or_SOURCES}
+  ${try_compile_redundant_SOURCES} ${CMAKE_CURRENT_SOURCE_DIR}/CxxStandardGNU.cxx
   OUTPUT_VARIABLE out
   OUTPUT_VARIABLE out
   )
   )
+
 if(NOT result)
 if(NOT result)
   message(FATAL_ERROR "try_compile failed:\n${out}")
   message(FATAL_ERROR "try_compile failed:\n${out}")
 endif()
 endif()

+ 6 - 2
Tests/RunCMake/try_compile/CxxStandardNoDefault.cmake

@@ -1,9 +1,13 @@
+include(${CMAKE_CURRENT_SOURCE_DIR}/${try_compile_DEFS})
+
 enable_language(CXX)
 enable_language(CXX)
-try_compile(result ${CMAKE_CURRENT_BINARY_DIR}
-  SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src.cxx
+
+try_compile(result ${try_compile_bindir_or_SOURCES}
+  ${try_compile_redundant_SOURCES} ${CMAKE_CURRENT_SOURCE_DIR}/src.cxx
   CXX_STANDARD 3 # bogus, but not used
   CXX_STANDARD 3 # bogus, but not used
   OUTPUT_VARIABLE out
   OUTPUT_VARIABLE out
   )
   )
+
 if(NOT result)
 if(NOT result)
   message(FATAL_ERROR "try_compile failed:\n${out}")
   message(FATAL_ERROR "try_compile failed:\n${out}")
 endif()
 endif()

+ 4 - 1
Tests/RunCMake/try_compile/EmptyListArgs.cmake

@@ -1,6 +1,9 @@
+include(${CMAKE_CURRENT_SOURCE_DIR}/${try_compile_DEFS})
+
 enable_language(C)
 enable_language(C)
 
 
-try_compile(RESULT ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/src.c
+try_compile(RESULT ${try_compile_bindir_or_SOURCES}
+  ${CMAKE_CURRENT_SOURCE_DIR}/src.c
   CMAKE_FLAGS           # no values
   CMAKE_FLAGS           # no values
   COMPILE_DEFINITIONS   # no values
   COMPILE_DEFINITIONS   # no values
   LINK_LIBRARIES        # no values
   LINK_LIBRARIES        # no values

+ 5 - 2
Tests/RunCMake/try_compile/EmptyValueArgs.cmake

@@ -1,4 +1,7 @@
-try_compile(RESULT ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/src.c
+include(${CMAKE_CURRENT_SOURCE_DIR}/${try_compile_DEFS})
+try_compile(RESULT ${try_compile_bindir_or_SOURCES}
+  ${CMAKE_CURRENT_SOURCE_DIR}/src.c
   COPY_FILE "")
   COPY_FILE "")
-try_compile(RESULT ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/src.c
+try_compile(RESULT ${try_compile_bindir_or_SOURCES}
+  ${CMAKE_CURRENT_SOURCE_DIR}/src.c
   COPY_FILE "x" COPY_FILE_ERROR "")
   COPY_FILE "x" COPY_FILE_ERROR "")

+ 4 - 2
Tests/RunCMake/try_compile/EnvConfig.cmake

@@ -1,3 +1,5 @@
+include(${CMAKE_CURRENT_SOURCE_DIR}/${try_compile_DEFS})
+
 enable_language(C)
 enable_language(C)
 
 
 set(ENV{CMAKE_BUILD_TYPE} "Bad")
 set(ENV{CMAKE_BUILD_TYPE} "Bad")
@@ -6,8 +8,8 @@ set(ENV{CMAKE_CONFIGURATION_TYPES} "Bad;Debug")
 add_library(tc_defs INTERFACE IMPORTED)
 add_library(tc_defs INTERFACE IMPORTED)
 target_compile_definitions(tc_defs INTERFACE "TC_CONFIG_$<UPPER_CASE:$<CONFIG>>")
 target_compile_definitions(tc_defs INTERFACE "TC_CONFIG_$<UPPER_CASE:$<CONFIG>>")
 
 
-try_compile(ENV_CONFIG_RESULT "${CMAKE_BINARY_DIR}"
-  SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/EnvConfig.c"
+try_compile(ENV_CONFIG_RESULT "${try_compile_bindir_or_SOURCES}"
+  ${try_compile_redundant_SOURCES} "${CMAKE_CURRENT_SOURCE_DIR}/EnvConfig.c"
   COPY_FILE "${CMAKE_CURRENT_BINARY_DIR}/EnvConfig.bin"
   COPY_FILE "${CMAKE_CURRENT_BINARY_DIR}/EnvConfig.bin"
   OUTPUT_VARIABLE tc_output
   OUTPUT_VARIABLE tc_output
   LINK_LIBRARIES tc_defs
   LINK_LIBRARIES tc_defs

+ 8 - 4
Tests/RunCMake/try_compile/ISPCDuplicateTarget.cmake

@@ -1,8 +1,12 @@
+include(${CMAKE_CURRENT_SOURCE_DIR}/${try_compile_DEFS})
+
 enable_language(ISPC)
 enable_language(ISPC)
-set(CMAKE_ISPC_INSTRUCTION_SETS avx512skx-i32x16
-                                avx512skx-i32x16)
-try_compile(result ${CMAKE_CURRENT_BINARY_DIR}
-  SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src.ispc
+
+set(CMAKE_ISPC_INSTRUCTION_SETS avx512skx-i32x16 avx512skx-i32x16)
+
+try_compile(result ${try_compile_bindir_or_SOURCES}
+  ${try_compile_redundant_SOURCES} ${CMAKE_CURRENT_SOURCE_DIR}/src.ispc
   OUTPUT_VARIABLE out
   OUTPUT_VARIABLE out
   )
   )
+
 message("try_compile output:\n${out}")
 message("try_compile output:\n${out}")

+ 9 - 4
Tests/RunCMake/try_compile/ISPCDuplicateTargetNinja.cmake

@@ -1,11 +1,16 @@
+include(${CMAKE_CURRENT_SOURCE_DIR}/${try_compile_DEFS})
+
 enable_language(ISPC)
 enable_language(ISPC)
-set(CMAKE_ISPC_INSTRUCTION_SETS avx512skx-i32x16
-                                avx512skx-i32x16)
-try_compile(result ${CMAKE_CURRENT_BINARY_DIR}
-  SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src.ispc
+
+set(CMAKE_ISPC_INSTRUCTION_SETS avx512skx-i32x16 avx512skx-i32x16)
+
+try_compile(result ${try_compile_bindir_or_SOURCES}
+  ${try_compile_redundant_SOURCES} ${CMAKE_CURRENT_SOURCE_DIR}/src.ispc
   OUTPUT_VARIABLE out
   OUTPUT_VARIABLE out
   )
   )
+
 message("try_compile output:\n${out}")
 message("try_compile output:\n${out}")
+
 if(NOT result)
 if(NOT result)
   message(FATAL_ERROR "making Ninja and Ninja Multi-Config behave the same")
   message(FATAL_ERROR "making Ninja and Ninja Multi-Config behave the same")
 endif()
 endif()

+ 7 - 2
Tests/RunCMake/try_compile/ISPCInvalidTarget.cmake

@@ -1,7 +1,12 @@
+include(${CMAKE_CURRENT_SOURCE_DIR}/${try_compile_DEFS})
+
 enable_language(ISPC)
 enable_language(ISPC)
+
 set(CMAKE_ISPC_INSTRUCTION_SETS "avxknl-i32x16")
 set(CMAKE_ISPC_INSTRUCTION_SETS "avxknl-i32x16")
-try_compile(result ${CMAKE_CURRENT_BINARY_DIR}
-  SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src.ispc
+
+try_compile(result ${try_compile_bindir_or_SOURCES}
+  ${try_compile_redundant_SOURCES} ${CMAKE_CURRENT_SOURCE_DIR}/src.ispc
   OUTPUT_VARIABLE out
   OUTPUT_VARIABLE out
   )
   )
+
 message("try_compile output:\n${out}")
 message("try_compile output:\n${out}")

+ 7 - 2
Tests/RunCMake/try_compile/ISPCTargets.cmake

@@ -1,7 +1,12 @@
+include(${CMAKE_CURRENT_SOURCE_DIR}/${try_compile_DEFS})
+
 enable_language(ISPC)
 enable_language(ISPC)
+
 set(CMAKE_ISPC_INSTRUCTION_SETS avx512knl-i32x16 avx512skx-i32x16)
 set(CMAKE_ISPC_INSTRUCTION_SETS avx512knl-i32x16 avx512skx-i32x16)
-try_compile(result ${CMAKE_CURRENT_BINARY_DIR}
-  SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src.ispc
+
+try_compile(result ${try_compile_bindir_or_SOURCES}
+  ${try_compile_redundant_SOURCES} ${CMAKE_CURRENT_SOURCE_DIR}/src.ispc
   OUTPUT_VARIABLE out
   OUTPUT_VARIABLE out
   )
   )
+
 message("try_compile output:\n${out}")
 message("try_compile output:\n${out}")

+ 1 - 1
Tests/RunCMake/try_compile/NoArgs-stderr.txt

@@ -1,4 +1,4 @@
-CMake Error at NoArgs.cmake:1 \(try_compile\):
+CMake Error at NoArgs.cmake:[0-9]+ \(try_compile\):
   try_compile unknown error.
   try_compile unknown error.
 Call Stack \(most recent call first\):
 Call Stack \(most recent call first\):
   CMakeLists.txt:3 \(include\)
   CMakeLists.txt:3 \(include\)

+ 1 - 1
Tests/RunCMake/try_compile/NoCStandard-stderr.txt

@@ -1,4 +1,4 @@
-CMake Error at NoCStandard.cmake:1 \(try_compile\):
+CMake Error at NoCStandard.cmake:[0-9]+ \(try_compile\):
   Error after keyword "C_STANDARD":
   Error after keyword "C_STANDARD":
 
 
     missing required value
     missing required value

+ 3 - 1
Tests/RunCMake/try_compile/NoCStandard.cmake

@@ -1,2 +1,4 @@
-try_compile(result ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/src.c
+include(${CMAKE_CURRENT_SOURCE_DIR}/${try_compile_DEFS})
+try_compile(result ${try_compile_bindir_or_SOURCES}
+  ${CMAKE_CURRENT_SOURCE_DIR}/src.c
   C_STANDARD)
   C_STANDARD)

+ 1 - 1
Tests/RunCMake/try_compile/NoCopyFile-stderr.txt

@@ -1,4 +1,4 @@
-CMake Error at NoCopyFile.cmake:1 \(try_compile\):
+CMake Error at NoCopyFile.cmake:[0-9]+ \(try_compile\):
   Error after keyword "COPY_FILE":
   Error after keyword "COPY_FILE":
 
 
     missing required value
     missing required value

+ 3 - 1
Tests/RunCMake/try_compile/NoCopyFile.cmake

@@ -1,2 +1,4 @@
-try_compile(RESULT ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/src.c
+include(${CMAKE_CURRENT_SOURCE_DIR}/${try_compile_DEFS})
+try_compile(RESULT ${try_compile_bindir_or_SOURCES}
+  ${CMAKE_CURRENT_SOURCE_DIR}/src.c
   COPY_FILE)
   COPY_FILE)

+ 1 - 1
Tests/RunCMake/try_compile/NoCopyFile2-stderr.txt

@@ -1,4 +1,4 @@
-CMake Error at NoCopyFile2.cmake:1 \(try_compile\):
+CMake Error at NoCopyFile2.cmake:[0-9]+ \(try_compile\):
   Error after keyword "COPY_FILE":
   Error after keyword "COPY_FILE":
 
 
     missing required value
     missing required value

+ 3 - 1
Tests/RunCMake/try_compile/NoCopyFile2.cmake

@@ -1,2 +1,4 @@
-try_compile(RESULT ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/src.c
+include(${CMAKE_CURRENT_SOURCE_DIR}/${try_compile_DEFS})
+try_compile(RESULT ${try_compile_bindir_or_SOURCES}
+  ${CMAKE_CURRENT_SOURCE_DIR}/src.c
   COPY_FILE CMAKE_FLAGS -DA=B)
   COPY_FILE CMAKE_FLAGS -DA=B)

+ 1 - 1
Tests/RunCMake/try_compile/NoCopyFileError-stderr.txt

@@ -1,4 +1,4 @@
-CMake Error at NoCopyFileError.cmake:1 \(try_compile\):
+CMake Error at NoCopyFileError.cmake:[0-9]+ \(try_compile\):
   Error after keyword "COPY_FILE_ERROR":
   Error after keyword "COPY_FILE_ERROR":
 
 
     missing required value
     missing required value

+ 3 - 1
Tests/RunCMake/try_compile/NoCopyFileError.cmake

@@ -1,2 +1,4 @@
-try_compile(RESULT ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/src.c
+include(${CMAKE_CURRENT_SOURCE_DIR}/${try_compile_DEFS})
+try_compile(RESULT ${try_compile_bindir_or_SOURCES}
+  ${CMAKE_CURRENT_SOURCE_DIR}/src.c
   COPY_FILE ${CMAKE_CURRENT_BINARY_DIR}/copied.bin COPY_FILE_ERROR)
   COPY_FILE ${CMAKE_CURRENT_BINARY_DIR}/copied.bin COPY_FILE_ERROR)

+ 1 - 1
Tests/RunCMake/try_compile/NoOutputVariable-stderr.txt

@@ -1,4 +1,4 @@
-CMake Error at NoOutputVariable.cmake:1 \(try_compile\):
+CMake Error at NoOutputVariable.cmake:[0-9]+ \(try_compile\):
   Error after keyword "OUTPUT_VARIABLE":
   Error after keyword "OUTPUT_VARIABLE":
 
 
     missing required value
     missing required value

+ 3 - 1
Tests/RunCMake/try_compile/NoOutputVariable.cmake

@@ -1,2 +1,4 @@
-try_compile(RESULT ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/src.c
+include(${CMAKE_CURRENT_SOURCE_DIR}/${try_compile_DEFS})
+try_compile(RESULT ${try_compile_bindir_or_SOURCES}
+  ${CMAKE_CURRENT_SOURCE_DIR}/src.c
   OUTPUT_VARIABLE)
   OUTPUT_VARIABLE)

+ 1 - 1
Tests/RunCMake/try_compile/NoOutputVariable2-stderr.txt

@@ -1,4 +1,4 @@
-CMake Error at NoOutputVariable2.cmake:1 \(try_compile\):
+CMake Error at NoOutputVariable2.cmake:[0-9]+ \(try_compile\):
   Error after keyword "OUTPUT_VARIABLE":
   Error after keyword "OUTPUT_VARIABLE":
 
 
     missing required value
     missing required value

+ 3 - 1
Tests/RunCMake/try_compile/NoOutputVariable2.cmake

@@ -1,2 +1,4 @@
-try_compile(RESULT ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/src.c
+include(${CMAKE_CURRENT_SOURCE_DIR}/${try_compile_DEFS})
+try_compile(RESULT ${try_compile_bindir_or_SOURCES}
+  ${CMAKE_CURRENT_SOURCE_DIR}/src.c
   OUTPUT_VARIABLE CMAKE_FLAGS -DA=B)
   OUTPUT_VARIABLE CMAKE_FLAGS -DA=B)

+ 1 - 1
Tests/RunCMake/try_compile/NoSources-stderr.txt

@@ -1,4 +1,4 @@
-CMake Error at NoSources.cmake:1 \(try_compile\):
+CMake Error at NoSources.cmake:[0-9]+ \(try_compile\):
   Error after keyword "SOURCES":
   Error after keyword "SOURCES":
 
 
     missing required value
     missing required value

+ 1 - 1
Tests/RunCMake/try_compile/NonSourceCompileDefinitions-stderr.txt

@@ -1,4 +1,4 @@
-CMake Error at NonSourceCompileDefinitions.cmake:1 \(try_compile\):
+CMake Error at NonSourceCompileDefinitions.cmake:[0-9]+ \(try_compile\):
   COMPILE_DEFINITIONS specified on a srcdir type TRY_COMPILE
   COMPILE_DEFINITIONS specified on a srcdir type TRY_COMPILE
 Call Stack \(most recent call first\):
 Call Stack \(most recent call first\):
   CMakeLists.txt:3 \(include\)
   CMakeLists.txt:3 \(include\)

+ 1 - 1
Tests/RunCMake/try_compile/NonSourceCopyFile-stderr.txt

@@ -1,4 +1,4 @@
-CMake Error at NonSourceCopyFile.cmake:1 \(try_compile\):
+CMake Error at NonSourceCopyFile.cmake:[0-9]+ \(try_compile\):
   COPY_FILE specified on a srcdir type TRY_COMPILE
   COPY_FILE specified on a srcdir type TRY_COMPILE
 Call Stack \(most recent call first\):
 Call Stack \(most recent call first\):
   CMakeLists.txt:3 \(include\)
   CMakeLists.txt:3 \(include\)

+ 1 - 1
Tests/RunCMake/try_compile/ObjCStandard-stderr.txt

@@ -1,4 +1,4 @@
-^CMake Error at .*/Tests/RunCMake/try_compile/ObjCStandard-build/CMakeFiles/CMakeTmp/CMakeLists.txt:[0-9]+ \(add_executable\):
+^CMake Error at .*/Tests/RunCMake/try_compile/ObjCStandard-build/CMakeFiles/CMake(Tmp|Scratch/TryCompile-[^/]+)/CMakeLists.txt:[0-9]+ \(add_executable\):
   OBJC_STANDARD is set to invalid value '3'
   OBJC_STANDARD is set to invalid value '3'
 +
 +
 CMake Error at ObjCStandard.cmake:[0-9]+ \(try_compile\):
 CMake Error at ObjCStandard.cmake:[0-9]+ \(try_compile\):

+ 6 - 2
Tests/RunCMake/try_compile/ObjCStandard.cmake

@@ -1,7 +1,11 @@
+include(${CMAKE_CURRENT_SOURCE_DIR}/${try_compile_DEFS})
+
 enable_language(OBJC)
 enable_language(OBJC)
-try_compile(result ${CMAKE_CURRENT_BINARY_DIR}
-  SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src.m
+
+try_compile(result ${try_compile_bindir_or_SOURCES}
+  ${CMAKE_CURRENT_SOURCE_DIR}/src.m
   OBJC_STANDARD 3
   OBJC_STANDARD 3
   OUTPUT_VARIABLE out
   OUTPUT_VARIABLE out
   )
   )
+
 message("try_compile output:\n${out}")
 message("try_compile output:\n${out}")

+ 1 - 1
Tests/RunCMake/try_compile/ObjCxxStandard-stderr.txt

@@ -1,4 +1,4 @@
-^CMake Error at .*/Tests/RunCMake/try_compile/ObjCxxStandard-build/CMakeFiles/CMakeTmp/CMakeLists.txt:[0-9]+ \(add_executable\):
+^CMake Error at .*/Tests/RunCMake/try_compile/ObjCxxStandard-build/CMakeFiles/CMake(Tmp|Scratch/TryCompile-[^/]+)/CMakeLists.txt:[0-9]+ \(add_executable\):
   OBJCXX_STANDARD is set to invalid value '3'
   OBJCXX_STANDARD is set to invalid value '3'
 +
 +
 CMake Error at ObjCxxStandard.cmake:[0-9]+ \(try_compile\):
 CMake Error at ObjCxxStandard.cmake:[0-9]+ \(try_compile\):

+ 6 - 2
Tests/RunCMake/try_compile/ObjCxxStandard.cmake

@@ -1,7 +1,11 @@
+include(${CMAKE_CURRENT_SOURCE_DIR}/${try_compile_DEFS})
+
 enable_language(OBJCXX)
 enable_language(OBJCXX)
-try_compile(result ${CMAKE_CURRENT_BINARY_DIR}
-  SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src.mm
+
+try_compile(result ${try_compile_bindir_or_SOURCES}
+  ${CMAKE_CURRENT_SOURCE_DIR}/src.mm
   OBJCXX_STANDARD 3
   OBJCXX_STANDARD 3
   OUTPUT_VARIABLE out
   OUTPUT_VARIABLE out
   )
   )
+
 message("try_compile output:\n${out}")
 message("try_compile output:\n${out}")

+ 1 - 1
Tests/RunCMake/try_compile/OneArg-stderr.txt

@@ -1,4 +1,4 @@
-CMake Error at OneArg.cmake:1 \(try_compile\):
+CMake Error at OneArg.cmake:[0-9]+ \(try_compile\):
   try_compile unknown error.
   try_compile unknown error.
 Call Stack \(most recent call first\):
 Call Stack \(most recent call first\):
   CMakeLists.txt:3 \(include\)
   CMakeLists.txt:3 \(include\)

+ 10 - 55
Tests/RunCMake/try_compile/RunCMakeTest.cmake

@@ -1,38 +1,28 @@
 include(RunCMake)
 include(RunCMake)
 
 
-run_cmake(CopyFileErrorNoCopyFile)
 run_cmake(NoArgs)
 run_cmake(NoArgs)
 run_cmake(OneArg)
 run_cmake(OneArg)
 run_cmake(TwoArgs)
 run_cmake(TwoArgs)
-run_cmake(NoCopyFile)
-run_cmake(NoCopyFile2)
-run_cmake(NoCopyFileError)
-run_cmake(NoCStandard)
-run_cmake(NoOutputVariable)
-run_cmake(NoOutputVariable2)
 run_cmake(NoSources)
 run_cmake(NoSources)
-run_cmake(BadLinkLibraries)
-run_cmake(BadSources1)
-run_cmake(BadSources2)
-run_cmake(NonSourceCopyFile)
-run_cmake(NonSourceCompileDefinitions)
 run_cmake(BinDirEmpty)
 run_cmake(BinDirEmpty)
 run_cmake(BinDirRelative)
 run_cmake(BinDirRelative)
-run_cmake(EmptyValueArgs)
-run_cmake(EmptyListArgs)
-run_cmake(TryRunArgs)
 
 
-run_cmake(EnvConfig)
+set(RunCMake_TEST_OPTIONS -Dtry_compile_DEFS=old_signature.cmake)
+include(${RunCMake_SOURCE_DIR}/old_and_new_signature_tests.cmake)
+unset(RunCMake_TEST_OPTIONS)
+
+set(RunCMake_TEST_OPTIONS -Dtry_compile_DEFS=new_signature.cmake)
+include(${RunCMake_SOURCE_DIR}/old_and_new_signature_tests.cmake)
+unset(RunCMake_TEST_OPTIONS)
+
+run_cmake(NonSourceCopyFile)
+run_cmake(NonSourceCompileDefinitions)
 
 
 set(RunCMake_TEST_OPTIONS --debug-trycompile)
 set(RunCMake_TEST_OPTIONS --debug-trycompile)
 run_cmake(PlatformVariables)
 run_cmake(PlatformVariables)
 run_cmake(WarnDeprecated)
 run_cmake(WarnDeprecated)
 unset(RunCMake_TEST_OPTIONS)
 unset(RunCMake_TEST_OPTIONS)
 
 
-run_cmake(TargetTypeExe)
-run_cmake(TargetTypeInvalid)
-run_cmake(TargetTypeStatic)
-
 if (CMAKE_SYSTEM_NAME MATCHES "^(Linux|Darwin|Windows)$" AND
 if (CMAKE_SYSTEM_NAME MATCHES "^(Linux|Darwin|Windows)$" AND
     CMAKE_C_COMPILER_ID MATCHES "^(MSVC|GNU|LCC|Clang|AppleClang)$")
     CMAKE_C_COMPILER_ID MATCHES "^(MSVC|GNU|LCC|Clang|AppleClang)$")
   set (RunCMake_TEST_OPTIONS -DRunCMake_C_COMPILER_ID=${CMAKE_C_COMPILER_ID})
   set (RunCMake_TEST_OPTIONS -DRunCMake_C_COMPILER_ID=${CMAKE_C_COMPILER_ID})
@@ -40,41 +30,6 @@ if (CMAKE_SYSTEM_NAME MATCHES "^(Linux|Darwin|Windows)$" AND
   unset (RunCMake_TEST_OPTIONS)
   unset (RunCMake_TEST_OPTIONS)
 endif()
 endif()
 
 
-if(CMAKE_C_STANDARD_DEFAULT)
-  run_cmake(CStandard)
-elseif(DEFINED CMAKE_C_STANDARD_DEFAULT)
-  run_cmake(CStandardNoDefault)
-endif()
-if(CMAKE_OBJC_STANDARD_DEFAULT)
-  run_cmake(ObjCStandard)
-endif()
-if(CMAKE_CXX_STANDARD_DEFAULT)
-  run_cmake(CxxStandard)
-elseif(DEFINED CMAKE_CXX_STANDARD_DEFAULT)
-  run_cmake(CxxStandardNoDefault)
-endif()
-if(CMAKE_OBJCXX_STANDARD_DEFAULT)
-  run_cmake(ObjCxxStandard)
-endif()
-if(CMake_TEST_CUDA)
-  run_cmake(CudaStandard)
-endif()
-if(CMake_TEST_ISPC)
-  run_cmake(ISPCTargets)
-  run_cmake(ISPCInvalidTarget)
-  set(ninja "")
-  if(RunCMake_GENERATOR MATCHES "Ninja")
-    set(ninja "Ninja")
-  endif()
-  run_cmake(ISPCDuplicateTarget${ninja})
-endif()
-if((CMAKE_C_COMPILER_ID MATCHES "GNU" AND NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 4.4) OR CMAKE_C_COMPILER_ID MATCHES "LCC")
-  run_cmake(CStandardGNU)
-endif()
-if((CMAKE_CXX_COMPILER_ID MATCHES "GNU" AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.4) OR CMAKE_C_COMPILER_ID MATCHES "LCC")
-  run_cmake(CxxStandardGNU)
-endif()
-
 run_cmake(CMP0056)
 run_cmake(CMP0056)
 run_cmake(CMP0066)
 run_cmake(CMP0066)
 run_cmake(CMP0067)
 run_cmake(CMP0067)

+ 8 - 2
Tests/RunCMake/try_compile/TargetTypeExe.cmake

@@ -1,14 +1,20 @@
+include(${CMAKE_CURRENT_SOURCE_DIR}/${try_compile_DEFS})
+
 enable_language(C)
 enable_language(C)
+
 set(CMAKE_TRY_COMPILE_TARGET_TYPE EXECUTABLE)
 set(CMAKE_TRY_COMPILE_TARGET_TYPE EXECUTABLE)
-try_compile(result ${CMAKE_CURRENT_BINARY_DIR}
-  SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src.c
+
+try_compile(result ${try_compile_bindir_or_SOURCES}
+  ${try_compile_redundant_SOURCES} ${CMAKE_CURRENT_SOURCE_DIR}/src.c
   OUTPUT_VARIABLE out
   OUTPUT_VARIABLE out
   COPY_FILE ${CMAKE_CURRENT_BINARY_DIR}/copy
   COPY_FILE ${CMAKE_CURRENT_BINARY_DIR}/copy
   COPY_FILE_ERROR copy_err
   COPY_FILE_ERROR copy_err
   )
   )
+
 if(NOT result)
 if(NOT result)
   message(FATAL_ERROR "try_compile failed:\n${out}")
   message(FATAL_ERROR "try_compile failed:\n${out}")
 endif()
 endif()
+
 if(copy_err)
 if(copy_err)
   message(FATAL_ERROR "try_compile COPY_FILE failed:\n${copy_err}")
   message(FATAL_ERROR "try_compile COPY_FILE failed:\n${copy_err}")
 endif()
 endif()

+ 1 - 1
Tests/RunCMake/try_compile/TargetTypeInvalid-stderr.txt

@@ -1,4 +1,4 @@
-^CMake Error at TargetTypeInvalid.cmake:2 \(try_compile\):
+^CMake Error at TargetTypeInvalid.cmake:[0-9]+ \(try_compile\):
   Invalid value 'INVALID' for CMAKE_TRY_COMPILE_TARGET_TYPE.  Only
   Invalid value 'INVALID' for CMAKE_TRY_COMPILE_TARGET_TYPE.  Only
   'EXECUTABLE' and 'STATIC_LIBRARY' are allowed.
   'EXECUTABLE' and 'STATIC_LIBRARY' are allowed.
 Call Stack \(most recent call first\):
 Call Stack \(most recent call first\):

+ 5 - 1
Tests/RunCMake/try_compile/TargetTypeInvalid.cmake

@@ -1,2 +1,6 @@
+include(${CMAKE_CURRENT_SOURCE_DIR}/${try_compile_DEFS})
+
 set(CMAKE_TRY_COMPILE_TARGET_TYPE INVALID)
 set(CMAKE_TRY_COMPILE_TARGET_TYPE INVALID)
-try_compile(result ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/src.c)
+
+try_compile(result ${try_compile_bindir_or_SOURCES}
+  ${CMAKE_CURRENT_SOURCE_DIR}/src.c)

+ 8 - 2
Tests/RunCMake/try_compile/TargetTypeStatic.cmake

@@ -1,14 +1,20 @@
+include(${CMAKE_CURRENT_SOURCE_DIR}/${try_compile_DEFS})
+
 enable_language(C)
 enable_language(C)
+
 set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
 set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
-try_compile(result ${CMAKE_CURRENT_BINARY_DIR}
-  SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/other.c
+
+try_compile(result ${try_compile_bindir_or_SOURCES}
+  ${try_compile_redundant_SOURCES} ${CMAKE_CURRENT_SOURCE_DIR}/other.c
   OUTPUT_VARIABLE out
   OUTPUT_VARIABLE out
   COPY_FILE ${CMAKE_CURRENT_BINARY_DIR}/copy
   COPY_FILE ${CMAKE_CURRENT_BINARY_DIR}/copy
   COPY_FILE_ERROR copy_err
   COPY_FILE_ERROR copy_err
   )
   )
+
 if(NOT result)
 if(NOT result)
   message(FATAL_ERROR "try_compile failed:\n${out}")
   message(FATAL_ERROR "try_compile failed:\n${out}")
 endif()
 endif()
+
 if(copy_err)
 if(copy_err)
   message(FATAL_ERROR "try_compile COPY_FILE failed:\n${copy_err}")
   message(FATAL_ERROR "try_compile COPY_FILE failed:\n${copy_err}")
 endif()
 endif()

+ 4 - 1
Tests/RunCMake/try_compile/TryRunArgs.cmake

@@ -1,6 +1,9 @@
+include(${CMAKE_CURRENT_SOURCE_DIR}/${try_compile_DEFS})
+
 enable_language(C)
 enable_language(C)
 
 
-try_compile(RESULT ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/src.c
+try_compile(RESULT ${try_compile_bindir_or_SOURCES}
+  ${CMAKE_CURRENT_SOURCE_DIR}/src.c
   COPY_FILE "${CMAKE_CURRENT_BINARY_DIR}/out.bin"
   COPY_FILE "${CMAKE_CURRENT_BINARY_DIR}/out.bin"
   COMPILE_OUTPUT_VARIABLE compOutputVar
   COMPILE_OUTPUT_VARIABLE compOutputVar
   RUN_OUTPUT_VARIABLE runOutputVar
   RUN_OUTPUT_VARIABLE runOutputVar

+ 1 - 1
Tests/RunCMake/try_compile/TwoArgs-stderr.txt

@@ -1,4 +1,4 @@
-CMake Error at TwoArgs.cmake:1 \(try_compile\):
+CMake Error at TwoArgs.cmake:[0-9]+ \(try_compile\):
   try_compile unknown error.
   try_compile unknown error.
 Call Stack \(most recent call first\):
 Call Stack \(most recent call first\):
   CMakeLists.txt:3 \(include\)
   CMakeLists.txt:3 \(include\)

+ 2 - 0
Tests/RunCMake/try_compile/new_signature.cmake

@@ -0,0 +1,2 @@
+set(try_compile_bindir_or_SOURCES SOURCES)
+set(try_compile_redundant_SOURCES "")

+ 54 - 0
Tests/RunCMake/try_compile/old_and_new_signature_tests.cmake

@@ -0,0 +1,54 @@
+run_cmake(CopyFileErrorNoCopyFile)
+run_cmake(NoCopyFile)
+run_cmake(NoCopyFile2)
+run_cmake(NoCopyFileError)
+run_cmake(NoCStandard)
+run_cmake(NoOutputVariable)
+run_cmake(NoOutputVariable2)
+run_cmake(BadLinkLibraries)
+run_cmake(BadSources1)
+run_cmake(BadSources2)
+run_cmake(EmptyValueArgs)
+run_cmake(EmptyListArgs)
+run_cmake(TryRunArgs)
+
+run_cmake(EnvConfig)
+
+run_cmake(TargetTypeExe)
+run_cmake(TargetTypeInvalid)
+run_cmake(TargetTypeStatic)
+
+if(CMAKE_C_STANDARD_DEFAULT)
+  run_cmake(CStandard)
+elseif(DEFINED CMAKE_C_STANDARD_DEFAULT)
+  run_cmake(CStandardNoDefault)
+endif()
+if(CMAKE_OBJC_STANDARD_DEFAULT)
+  run_cmake(ObjCStandard)
+endif()
+if(CMAKE_CXX_STANDARD_DEFAULT)
+  run_cmake(CxxStandard)
+elseif(DEFINED CMAKE_CXX_STANDARD_DEFAULT)
+  run_cmake(CxxStandardNoDefault)
+endif()
+if(CMAKE_OBJCXX_STANDARD_DEFAULT)
+  run_cmake(ObjCxxStandard)
+endif()
+if(CMake_TEST_CUDA)
+  run_cmake(CudaStandard)
+endif()
+if(CMake_TEST_ISPC)
+  run_cmake(ISPCTargets)
+  run_cmake(ISPCInvalidTarget)
+  set(ninja "")
+  if(RunCMake_GENERATOR MATCHES "Ninja")
+    set(ninja "Ninja")
+  endif()
+  run_cmake(ISPCDuplicateTarget${ninja})
+endif()
+if((CMAKE_C_COMPILER_ID MATCHES "GNU" AND NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 4.4) OR CMAKE_C_COMPILER_ID MATCHES "LCC")
+  run_cmake(CStandardGNU)
+endif()
+if((CMAKE_CXX_COMPILER_ID MATCHES "GNU" AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.4) OR CMAKE_C_COMPILER_ID MATCHES "LCC")
+  run_cmake(CxxStandardGNU)
+endif()

+ 2 - 0
Tests/RunCMake/try_compile/old_signature.cmake

@@ -0,0 +1,2 @@
+set(try_compile_bindir_or_SOURCES ${CMAKE_CURRENT_BINARY_DIR})
+set(try_compile_redundant_SOURCES SOURCES)

+ 1 - 1
Tests/RunCMake/try_run/BadLinkLibraries-stderr.txt

@@ -1,4 +1,4 @@
-CMake Error at BadLinkLibraries.cmake:2 \(try_run\):
+CMake Error at BadLinkLibraries.cmake:[0-9+] \(try_run\):
   Only libraries may be used as try_compile or try_run IMPORTED
   Only libraries may be used as try_compile or try_run IMPORTED
   LINK_LIBRARIES.  Got not_a_library of type UTILITY.
   LINK_LIBRARIES.  Got not_a_library of type UTILITY.
 Call Stack \(most recent call first\):
 Call Stack \(most recent call first\):

+ 5 - 2
Tests/RunCMake/try_run/BadLinkLibraries.cmake

@@ -1,4 +1,7 @@
+include(${CMAKE_CURRENT_SOURCE_DIR}/${try_compile_DEFS})
+
 add_custom_target(not_a_library)
 add_custom_target(not_a_library)
-try_run(RUN_RESULT COMPILE_RESULT
-  ${CMAKE_CURRENT_BINARY_DIR}/CMakeTmp ${CMAKE_CURRENT_SOURCE_DIR}/src.c
+
+try_run(RUN_RESULT COMPILE_RESULT ${try_compile_bindir_or_SOURCES}
+  ${CMAKE_CURRENT_SOURCE_DIR}/src.c
   LINK_LIBRARIES not_a_library)
   LINK_LIBRARIES not_a_library)

+ 4 - 2
Tests/RunCMake/try_run/NoCompileOutputVariable.cmake

@@ -1,4 +1,6 @@
-try_run(RUN_RESULT COMPILE_RESULT
-  ${CMAKE_CURRENT_BINARY_DIR}/CMakeTmp ${CMAKE_CURRENT_SOURCE_DIR}/src.c
+include(${CMAKE_CURRENT_SOURCE_DIR}/${try_compile_DEFS})
+
+try_run(RUN_RESULT COMPILE_RESULT ${try_compile_bindir_or_SOURCES}
+  ${CMAKE_CURRENT_SOURCE_DIR}/src.c
   COMPILE_OUTPUT_VARIABLE
   COMPILE_OUTPUT_VARIABLE
   )
   )

+ 4 - 2
Tests/RunCMake/try_run/NoRunOutputVariable.cmake

@@ -1,4 +1,6 @@
-try_run(RUN_RESULT COMPILE_RESULT
-  ${CMAKE_CURRENT_BINARY_DIR}/CMakeTmp ${CMAKE_CURRENT_SOURCE_DIR}/src.c
+include(${CMAKE_CURRENT_SOURCE_DIR}/${try_compile_DEFS})
+
+try_run(RUN_RESULT COMPILE_RESULT ${try_compile_bindir_or_SOURCES}
+  ${CMAKE_CURRENT_SOURCE_DIR}/src.c
   RUN_OUTPUT_VARIABLE
   RUN_OUTPUT_VARIABLE
   )
   )

+ 1 - 1
Tests/RunCMake/try_run/NoRunStdErrVariable-stderr.txt

@@ -1,4 +1,4 @@
-^CMake Error at NoRunStdErrVariable.cmake:1 \(try_run\):
+^CMake Error at NoRunStdErrVariable.cmake:[0-9]+ \(try_run\):
   Error after keyword "RUN_OUTPUT_STDERR_VARIABLE":
   Error after keyword "RUN_OUTPUT_STDERR_VARIABLE":
 
 
     missing required value
     missing required value

+ 4 - 2
Tests/RunCMake/try_run/NoRunStdErrVariable.cmake

@@ -1,5 +1,7 @@
-try_run(RUN_RESULT COMPILE_RESULT
-  ${CMAKE_CURRENT_BINARY_DIR}/CMakeTmp ${CMAKE_CURRENT_SOURCE_DIR}/src.c
+include(${CMAKE_CURRENT_SOURCE_DIR}/${try_compile_DEFS})
+
+try_run(RUN_RESULT COMPILE_RESULT ${try_compile_bindir_or_SOURCES}
+  ${CMAKE_CURRENT_SOURCE_DIR}/src.c
   WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/CMakeTmp/workdir
   WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/CMakeTmp/workdir
   RUN_OUTPUT_STDERR_VARIABLE
   RUN_OUTPUT_STDERR_VARIABLE
   )
   )

+ 1 - 1
Tests/RunCMake/try_run/NoRunStdOutVariable-stderr.txt

@@ -1,4 +1,4 @@
-^CMake Error at NoRunStdOutVariable.cmake:1 \(try_run\):
+^CMake Error at NoRunStdOutVariable.cmake:[0-9]+ \(try_run\):
   Error after keyword "RUN_OUTPUT_STDOUT_VARIABLE":
   Error after keyword "RUN_OUTPUT_STDOUT_VARIABLE":
 
 
     missing required value
     missing required value

+ 4 - 2
Tests/RunCMake/try_run/NoRunStdOutVariable.cmake

@@ -1,5 +1,7 @@
-try_run(RUN_RESULT COMPILE_RESULT
-  ${CMAKE_CURRENT_BINARY_DIR}/CMakeTmp ${CMAKE_CURRENT_SOURCE_DIR}/src.c
+include(${CMAKE_CURRENT_SOURCE_DIR}/${try_compile_DEFS})
+
+try_run(RUN_RESULT COMPILE_RESULT ${try_compile_bindir_or_SOURCES}
+  ${CMAKE_CURRENT_SOURCE_DIR}/src.c
   WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/CMakeTmp/workdir
   WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/CMakeTmp/workdir
   RUN_OUTPUT_STDOUT_VARIABLE
   RUN_OUTPUT_STDOUT_VARIABLE
   )
   )

+ 4 - 2
Tests/RunCMake/try_run/NoWorkingDirectory.cmake

@@ -1,4 +1,6 @@
-try_run(RUN_RESULT COMPILE_RESULT
-  ${CMAKE_CURRENT_BINARY_DIR}/CMakeTmp ${CMAKE_CURRENT_SOURCE_DIR}/src.c
+include(${CMAKE_CURRENT_SOURCE_DIR}/${try_compile_DEFS})
+
+try_run(RUN_RESULT COMPILE_RESULT ${try_compile_bindir_or_SOURCES}
+  ${CMAKE_CURRENT_SOURCE_DIR}/src.c
   WORKING_DIRECTORY
   WORKING_DIRECTORY
   )
   )

+ 9 - 10
Tests/RunCMake/try_run/RunCMakeTest.cmake

@@ -1,8 +1,16 @@
 include(RunCMake)
 include(RunCMake)
 
 
-run_cmake(BadLinkLibraries)
 run_cmake(BinDirEmpty)
 run_cmake(BinDirEmpty)
 run_cmake(BinDirRelative)
 run_cmake(BinDirRelative)
+run_cmake(NoOutputVariable)
+
+set(RunCMake_TEST_OPTIONS -Dtry_compile_DEFS=old_signature.cmake)
+include(${RunCMake_SOURCE_DIR}/old_and_new_signature_tests.cmake)
+unset(RunCMake_TEST_OPTIONS)
+
+set(RunCMake_TEST_OPTIONS -Dtry_compile_DEFS=new_signature.cmake)
+include(${RunCMake_SOURCE_DIR}/old_and_new_signature_tests.cmake)
+unset(RunCMake_TEST_OPTIONS)
 
 
 if (CMAKE_SYSTEM_NAME MATCHES "^(Linux|Darwin|Windows)$" AND
 if (CMAKE_SYSTEM_NAME MATCHES "^(Linux|Darwin|Windows)$" AND
     CMAKE_C_COMPILER_ID MATCHES "^(MSVC|GNU|LCC|Clang|AppleClang)$")
     CMAKE_C_COMPILER_ID MATCHES "^(MSVC|GNU|LCC|Clang|AppleClang)$")
@@ -10,12 +18,3 @@ if (CMAKE_SYSTEM_NAME MATCHES "^(Linux|Darwin|Windows)$" AND
   run_cmake(LinkOptions)
   run_cmake(LinkOptions)
   unset (RunCMake_TEST_OPTIONS)
   unset (RunCMake_TEST_OPTIONS)
 endif()
 endif()
-
-run_cmake(WorkingDirArg)
-
-run_cmake(NoOutputVariable)
-run_cmake(NoCompileOutputVariable)
-run_cmake(NoRunOutputVariable)
-run_cmake(NoRunStdOutVariable)
-run_cmake(NoRunStdErrVariable)
-run_cmake(NoWorkingDirectory)

+ 4 - 2
Tests/RunCMake/try_run/WorkingDirArg.cmake

@@ -1,5 +1,7 @@
-try_run(RUN_RESULT COMPILE_RESULT
-  ${CMAKE_CURRENT_BINARY_DIR}/CMakeTmp ${CMAKE_CURRENT_SOURCE_DIR}/src.c
+include(${CMAKE_CURRENT_SOURCE_DIR}/${try_compile_DEFS})
+
+try_run(RUN_RESULT COMPILE_RESULT ${try_compile_bindir_or_SOURCES}
+  ${CMAKE_CURRENT_SOURCE_DIR}/src.c
   RUN_OUTPUT_VARIABLE RUN_OUTPUT
   RUN_OUTPUT_VARIABLE RUN_OUTPUT
   WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/CMakeTmp/workdir
   WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/CMakeTmp/workdir
   )
   )

+ 2 - 0
Tests/RunCMake/try_run/new_signature.cmake

@@ -0,0 +1,2 @@
+set(try_compile_bindir_or_SOURCES SOURCES)
+set(try_compile_redundant_SOURCES "")

+ 11 - 0
Tests/RunCMake/try_run/old_and_new_signature_tests.cmake

@@ -0,0 +1,11 @@
+run_cmake(BadLinkLibraries)
+run_cmake(BinDirEmpty)
+run_cmake(BinDirRelative)
+
+run_cmake(WorkingDirArg)
+
+run_cmake(NoCompileOutputVariable)
+run_cmake(NoRunOutputVariable)
+run_cmake(NoRunStdOutVariable)
+run_cmake(NoRunStdErrVariable)
+run_cmake(NoWorkingDirectory)

+ 2 - 0
Tests/RunCMake/try_run/old_signature.cmake

@@ -0,0 +1,2 @@
+set(try_compile_bindir_or_SOURCES ${CMAKE_CURRENT_BINARY_DIR})
+set(try_compile_redundant_SOURCES SOURCES)

+ 37 - 240
Tests/TryCompile/CMakeLists.txt

@@ -4,6 +4,18 @@ if(POLICY CMP0129)
 endif()
 endif()
 project(TryCompile)
 project(TryCompile)
 
 
+macro(EXPECT_PASS var out)
+  if(NOT ${var})
+    message(SEND_ERROR "Should pass failed ${out}")
+  endif()
+endmacro()
+
+macro(EXPECT_FAIL var out)
+  if(${var})
+    message(SEND_ERROR "Should fail passed ${out}")
+  endif()
+endmacro()
+
 macro(TEST_ASSERT value msg)
 macro(TEST_ASSERT value msg)
   if (NOT ${value})
   if (NOT ${value})
     message (SEND_ERROR "Assertion failure:" ${msg} )
     message (SEND_ERROR "Assertion failure:" ${msg} )
@@ -28,112 +40,31 @@ macro(TEST_EXPECT_CONTAINS command expected)
   endif()
   endif()
 endmacro()
 endmacro()
 
 
-
-# try to compile a file that should compile
-try_compile(SHOULD_PASS
-    ${TryCompile_BINARY_DIR}
-    ${TryCompile_SOURCE_DIR}/pass.c
-    OUTPUT_VARIABLE TRY_OUT)
-if(NOT SHOULD_PASS)
-  message(SEND_ERROR "should pass failed ${TRY_OUT}")
-endif()
-
-# try to compile a file that should compile
-# also check that COPY_FILE works
-try_compile(SHOULD_PASS
-    ${TryCompile_BINARY_DIR}
-    ${TryCompile_SOURCE_DIR}/pass.c
-    OUTPUT_VARIABLE TRY_OUT
-    COPY_FILE ${TryCompile_BINARY_DIR}/CopyOfPass
-    )
-
-if(NOT SHOULD_PASS)
-  message(SEND_ERROR "should pass failed ${TRY_OUT}")
-endif()
-if(NOT EXISTS "${TryCompile_BINARY_DIR}/CopyOfPass")
-   message(SEND_ERROR "COPY_FILE to \"${TryCompile_BINARY_DIR}/CopyOfPass\" failed")
-else()
-   file(REMOVE "${TryCompile_BINARY_DIR}/CopyOfPass")
-endif()
-
-# try to compile a file that should compile
-# also check that COPY_FILE_ERROR works
-file(WRITE ${TryCompile_BINARY_DIR}/invalid "")
-try_compile(SHOULD_PASS
-    ${TryCompile_BINARY_DIR}
-    ${TryCompile_SOURCE_DIR}/pass.c
-    OUTPUT_VARIABLE TRY_OUT
-    COPY_FILE ${TryCompile_BINARY_DIR}/invalid/path
-    COPY_FILE_ERROR _captured
-    )
-if(NOT SHOULD_PASS)
-  message(SEND_ERROR "should pass failed ${TRY_OUT}")
-endif()
-if(NOT _captured MATCHES "Cannot copy output executable.*/invalid/path")
-  message(SEND_ERROR "COPY_FILE_ERROR did not capture expected message")
-endif()
-
-# try to compile a file that should not compile
-try_compile(SHOULD_FAIL
-    ${TryCompile_BINARY_DIR}
-    ${TryCompile_SOURCE_DIR}/fail.c
-    OUTPUT_VARIABLE TRY_OUT)
-if(SHOULD_FAIL)
-   message(SEND_ERROR "Should fail passed ${TRY_OUT}")
-endif()
-
-# try to compile two files that should compile
-try_compile(SHOULD_PASS
-    ${TryCompile_BINARY_DIR}
-    SOURCES ${TryCompile_SOURCE_DIR}/pass2a.c ${TryCompile_SOURCE_DIR}/pass2b.cxx
-    OUTPUT_VARIABLE TRY_OUT)
-if(NOT SHOULD_PASS)
-  message(SEND_ERROR "should pass failed ${TRY_OUT}")
-endif()
-
-# try to compile two files that should not compile
-try_compile(SHOULD_FAIL
-    ${TryCompile_BINARY_DIR}
-    SOURCES ${TryCompile_SOURCE_DIR}/fail2a.c ${TryCompile_SOURCE_DIR}/fail2b.c
-    OUTPUT_VARIABLE TRY_OUT)
-if(SHOULD_FAIL)
-   message(SEND_ERROR "Should fail passed ${TRY_OUT}")
-endif()
-
-# try to compile a file that should compile
-set(_c_flags "${CMAKE_C_FLAGS}")
-if(WATCOM)
-  string(APPEND CMAKE_C_FLAGS " -dTESTDEF")
-else()
-  string(APPEND CMAKE_C_FLAGS " \"-DTESTDEF\"")
-endif()
-try_compile(SHOULD_PASS
-    ${TryCompile_BINARY_DIR}
-    ${TryCompile_SOURCE_DIR}/testdef.c
-    OUTPUT_VARIABLE TRY_OUT)
-if(NOT SHOULD_PASS)
-  message(SEND_ERROR "should pass failed ${TRY_OUT}")
-endif()
-set(CMAKE_C_FLAGS "${_c_flags}")
-
-try_compile(CMAKE_ANSI_FOR_SCOPE
-  ${TryCompile_BINARY_DIR}
-    ${CMAKE_ROOT}/Modules/TestForAnsiForScope.cxx OUTPUT_VARIABLE OUT)
-if (CMAKE_ANSI_FOR_SCOPE)
-   message("Compiler supports ansi for")
-else()
-   message("Compiler does not support ansi for scope")
-endif()
-
-message("use the module now")
-include(${CMAKE_ROOT}/Modules/TestForANSIForScope.cmake)
-if (CMAKE_ANSI_FOR_SCOPE)
-   message("Compiler supports ansi for")
-else()
-   message("Compiler does not support ansi for scope")
-endif()
-
-# try to compile a project
+if (APPLE)
+  enable_language(OBJC)
+  enable_language(OBJCXX)
+endif()
+
+
+# run old signature tests
+set(try_compile_bindir_or_SOURCES ${TryCompile_BINARY_DIR})
+set(try_compile_redundant_SOURCES SOURCES)
+set(try_compile_output_vars OUTPUT_VARIABLE TRY_OUT)
+set(try_compile_compile_output_var TRY_OUT)
+set(try_compile_run_output_var TRY_OUT)
+include(old_and_new_signature_tests.cmake)
+
+# run new signature tests
+set(try_compile_bindir_or_SOURCES SOURCES)
+set(try_compile_redundant_SOURCES "")
+set(try_compile_output_vars
+  COMPILE_OUTPUT_VARIABLE COMPILE_OUT
+  RUN_OUTPUT_VARIABLE RUN_OUTPUT)
+set(try_compile_compile_output_var COMPILE_OUT)
+set(try_compile_run_output_var RUN_OUTPUT)
+include(old_and_new_signature_tests.cmake)
+
+# try to compile a project (old signature)
 message("Testing try_compile project mode")
 message("Testing try_compile project mode")
 try_compile(TEST_INNER
 try_compile(TEST_INNER
   ${TryCompile_BINARY_DIR}/CMakeFiles/Inner
   ${TryCompile_BINARY_DIR}/CMakeFiles/Inner
@@ -142,123 +73,8 @@ try_compile(TEST_INNER
   OUTPUT_VARIABLE output)
   OUTPUT_VARIABLE output)
 TEST_ASSERT(TEST_INNER "try_compile project mode failed:\n${output}")
 TEST_ASSERT(TEST_INNER "try_compile project mode failed:\n${output}")
 
 
-try_compile(COMPILE_DEFINITIONS_LIST_EXPANDED
-    ${TryCompile_BINARY_DIR}
-    ${TryCompile_SOURCE_DIR}/check_a_b.c
-    OUTPUT_VARIABLE output
-    COMPILE_DEFINITIONS "-DDEF_A;-DDEF_B"
-    )
-if(COMPILE_DEFINITIONS_LIST_EXPANDED)
-  message(STATUS "COMPILE_DEFINITIONS list expanded correctly")
-else()
-  string(REPLACE "\n" "\n  " output "  ${output}")
-  message(SEND_ERROR "COMPILE_DEFINITIONS list did not expand correctly\n${output}")
-endif()
-
-try_compile(SHOULD_FAIL_DUE_TO_BAD_SOURCE
-    ${TryCompile_BINARY_DIR}
-    ${TryCompile_SOURCE_DIR}/pass.c
-    OUTPUT_VARIABLE output
-    COMPILE_DEFINITIONS "bad#source.c"
-    )
-if(SHOULD_FAIL_DUE_TO_BAD_SOURCE AND NOT CMAKE_GENERATOR MATCHES "Watcom WMake|NMake Makefiles")
-  string(REPLACE "\n" "\n  " output "  ${output}")
-  message(SEND_ERROR "try_compile with bad#source.c did not fail:\n${output}")
-elseif(NOT output MATCHES [[(bad#source\.c|bad\.c|bad')]])
-  string(REPLACE "\n" "\n  " output "  ${output}")
-  message(SEND_ERROR "try_compile with bad#source.c failed without mentioning bad source:\n${output}")
-else()
-  message(STATUS "try_compile with bad#source.c correctly failed")
-endif()
-
 add_executable(TryCompile pass.c)
 add_executable(TryCompile pass.c)
 
 
-######################################
-
-# now two tests for try_run()
-
-# try to run a file that should compile and run without error
-# also check that OUTPUT_VARIABLE contains both the compile output
-# and the run output
-try_run(SHOULD_RUN SHOULD_COMPILE
-    ${TryCompile_BINARY_DIR}
-    ${TryCompile_SOURCE_DIR}/exit_success.c
-    OUTPUT_VARIABLE TRY_OUT)
-if(NOT SHOULD_COMPILE)
-  message(SEND_ERROR "exit_success failed compiling: ${TRY_OUT}")
-endif()
-if(NOT "${SHOULD_RUN}" STREQUAL "0")
-  message(SEND_ERROR "exit_success failed running with exit code ${SHOULD_RUN}")
-endif()
-# check the compile output for the filename
-if(NOT "${TRY_OUT}" MATCHES "exit_success")
-  message(SEND_ERROR " TRY_OUT didn't contain \"exit_success\": \"${TRY_OUT}\"")
-endif()
-# check the run output
-if(NOT "${TRY_OUT}" MATCHES "hello world")
-  message(SEND_ERROR " TRY_OUT didn't contain \"hello world\": \"${TRY_OUT}\"")
-endif()
-
-try_run(ARG_TEST_RUN ARG_TEST_COMPILE
-    ${TryCompile_BINARY_DIR}
-    ${TryCompile_SOURCE_DIR}/expect_arg.c
-    OUTPUT_VARIABLE TRY_OUT
-    ARGS arg1 arg2)
-if(NOT ARG_TEST_COMPILE)
-  message(SEND_ERROR "expect_arg failed compiling: ${TRY_OUT}")
-endif()
-if(NOT "${ARG_TEST_RUN}" STREQUAL "0")
-  message(SEND_ERROR "expect_arg failed running with exit code ${ARG_TEST_RUN} ${TRY_OUT}")
-endif()
-
-# try to run a file that should compile and run, but return an error
-try_run(SHOULD_EXIT_WITH_ERROR SHOULD_COMPILE
-    ${TryCompile_BINARY_DIR}
-    ${TryCompile_SOURCE_DIR}/exit_with_error.c
-    COMPILE_OUTPUT_VARIABLE COMPILE_OUTPUT
-    RUN_OUTPUT_VARIABLE RUN_OUTPUT)
-
-if(NOT SHOULD_COMPILE)
-  message(STATUS " exit_with_error failed compiling: ${COMPILE_OUTPUT}")
-endif()
-if("${SHOULD_EXIT_WITH_ERROR}" STREQUAL "0")
-  message(SEND_ERROR " exit_with_error passed with exit code ${SHOULD_EXIT_WITH_ERROR}")
-endif()
-
-# check the compile output, it should contain the filename
-if(NOT "${COMPILE_OUTPUT}" MATCHES "exit_with_error")
-  message(SEND_ERROR " COMPILE_OUT didn't contain \"exit_with_error\": \"${COMPILE_OUTPUT}\"")
-endif()
-#... but not the run time output
-if("${COMPILE_OUTPUT}" MATCHES "hello world")
-  message(SEND_ERROR " COMPILE_OUT contains the run output: \"${COMPILE_OUTPUT}\"")
-endif()
-# check the run output, it should contain stdout
-if(NOT "${RUN_OUTPUT}" MATCHES "hello world")
-  message(SEND_ERROR " RUN_OUTPUT didn't contain \"hello world\": \"${RUN_OUTPUT}\"")
-endif()
-
-# try to run a file and parse stdout and stderr separately
-try_run(SHOULD_EXIT_WITH_ERROR SHOULD_COMPILE
-    ${TryCompile_BINARY_DIR}
-    ${TryCompile_SOURCE_DIR}/stdout_and_stderr.c
-    COMPILE_OUTPUT_VARIABLE COMPILE_OUTPUT
-    RUN_OUTPUT_STDOUT_VARIABLE RUN_OUTPUT_STDOUT
-    RUN_OUTPUT_STDERR_VARIABLE RUN_OUTPUT_STDERR)
-
-if(NOT SHOULD_COMPILE)
-  message(STATUS " exit_with_error failed compiling: ${COMPILE_OUTPUT}")
-endif()
-
-# check the run stdout output
-if(NOT "${RUN_OUTPUT_STDOUT}" MATCHES "hello world")
-  message(SEND_ERROR " RUN_OUTPUT_STDOUT didn't contain \"hello world\": \"${RUN_OUTPUT_STDOUT}\"")
-endif()
-# check the run stderr output
-if(NOT "${RUN_OUTPUT_STDERR}" MATCHES "error")
-  message(SEND_ERROR " RUN_OUTPUT_STDERR didn't contain \"error\": \"${RUN_OUTPUT_STDERR}\"")
-endif()
-
 #######################################################################
 #######################################################################
 #
 #
 # also test that the CHECK_C_SOURCE_COMPILES, CHECK_CXX_SOURCE_COMPILES
 # also test that the CHECK_C_SOURCE_COMPILES, CHECK_CXX_SOURCE_COMPILES
@@ -377,25 +193,6 @@ if (APPLE)
     TEST_ASSERT(SIMPLE_OBJCXX_RUN_SHOULD_WORK "CHECK_OBJCXX_SOURCE_RUNS() failed, but should have succeeded")
     TEST_ASSERT(SIMPLE_OBJCXX_RUN_SHOULD_WORK "CHECK_OBJCXX_SOURCE_RUNS() failed, but should have succeeded")
     TEST_FAIL(OBJCXX_RUN_SHOULD_FAIL "CHECK_OBJCXX_SOURCE_RUNS() succeeds, but should have failed")
     TEST_FAIL(OBJCXX_RUN_SHOULD_FAIL "CHECK_OBJCXX_SOURCE_RUNS() succeeds, but should have failed")
     TEST_ASSERT(OBJCXX_RUN_SHOULD_WORK "CHECK_OBJCXX_SOURCE_RUNS() failed, but should have succeeded")
     TEST_ASSERT(OBJCXX_RUN_SHOULD_WORK "CHECK_OBJCXX_SOURCE_RUNS() failed, but should have succeeded")
-
-    # try to compile a file that should compile
-    try_compile(SHOULD_PASS
-      ${TryCompile_BINARY_DIR}
-      ${TryCompile_SOURCE_DIR}/pass.m
-      OUTPUT_VARIABLE TRY_OUT)
-    if(NOT SHOULD_PASS)
-      message(SEND_ERROR "should pass failed ${TRY_OUT}")
-    endif()
-
-    # try to compile a file that should not compile
-    try_compile(SHOULD_FAIL
-      ${TryCompile_BINARY_DIR}
-      ${TryCompile_SOURCE_DIR}/fail.m
-      OUTPUT_VARIABLE TRY_OUT)
-    if(SHOULD_FAIL)
-      message(SEND_ERROR "Should fail passed ${TRY_OUT}")
-    endif()
-
 endif()
 endif()
 
 
 #######################################################################
 #######################################################################

+ 245 - 0
Tests/TryCompile/old_and_new_signature_tests.cmake

@@ -0,0 +1,245 @@
+# try to compile a file that should compile
+try_compile(SHOULD_PASS
+  ${try_compile_bindir_or_SOURCES}
+  ${TryCompile_SOURCE_DIR}/pass.c
+  OUTPUT_VARIABLE TRY_OUT)
+EXPECT_PASS(SHOULD_PASS "${TRY_OUT}")
+
+# try to compile a file that should compile
+# also check that COPY_FILE works
+try_compile(SHOULD_PASS
+  ${try_compile_bindir_or_SOURCES}
+  ${TryCompile_SOURCE_DIR}/pass.c
+  OUTPUT_VARIABLE TRY_OUT
+  COPY_FILE ${TryCompile_BINARY_DIR}/CopyOfPass
+  )
+EXPECT_PASS(SHOULD_PASS "${TRY_OUT}")
+
+if(NOT EXISTS "${TryCompile_BINARY_DIR}/CopyOfPass")
+  message(SEND_ERROR "COPY_FILE to \"${TryCompile_BINARY_DIR}/CopyOfPass\" failed")
+else()
+  file(REMOVE "${TryCompile_BINARY_DIR}/CopyOfPass")
+endif()
+
+# try to compile a file that should compile
+# also check that COPY_FILE_ERROR works
+file(WRITE ${TryCompile_BINARY_DIR}/invalid "")
+try_compile(SHOULD_PASS
+  ${try_compile_bindir_or_SOURCES}
+  ${TryCompile_SOURCE_DIR}/pass.c
+  OUTPUT_VARIABLE TRY_OUT
+  COPY_FILE ${TryCompile_BINARY_DIR}/invalid/path
+  COPY_FILE_ERROR _captured
+  )
+EXPECT_PASS(SHOULD_PASS "${TRY_OUT}")
+
+if(NOT _captured MATCHES "Cannot copy output executable.*/invalid/path")
+  message(SEND_ERROR "COPY_FILE_ERROR did not capture expected message")
+endif()
+
+# try to compile a file that should not compile
+try_compile(SHOULD_FAIL
+  ${try_compile_bindir_or_SOURCES}
+  ${TryCompile_SOURCE_DIR}/fail.c
+  OUTPUT_VARIABLE TRY_OUT)
+EXPECT_FAIL(SHOULD_FAIL "${TRY_OUT}")
+
+# try to compile two files that should compile
+try_compile(SHOULD_PASS
+  ${try_compile_bindir_or_SOURCES}
+  ${try_compile_redundant_SOURCES}
+  ${TryCompile_SOURCE_DIR}/pass2a.c
+  ${TryCompile_SOURCE_DIR}/pass2b.cxx
+  OUTPUT_VARIABLE TRY_OUT)
+EXPECT_PASS(SHOULD_PASS "${TRY_OUT}")
+
+# try to compile two files that should not compile
+try_compile(SHOULD_FAIL
+  ${try_compile_bindir_or_SOURCES}
+  ${try_compile_redundant_SOURCES}
+  ${TryCompile_SOURCE_DIR}/fail2a.c
+  ${TryCompile_SOURCE_DIR}/fail2b.c
+  OUTPUT_VARIABLE TRY_OUT)
+EXPECT_FAIL(SHOULD_FAIL "${TRY_OUT}")
+
+# try to compile a file that should compile
+set(_c_flags "${CMAKE_C_FLAGS}")
+if(WATCOM)
+  string(APPEND CMAKE_C_FLAGS " -dTESTDEF")
+else()
+  string(APPEND CMAKE_C_FLAGS " \"-DTESTDEF\"")
+endif()
+try_compile(SHOULD_PASS
+  ${try_compile_bindir_or_SOURCES}
+  ${TryCompile_SOURCE_DIR}/testdef.c
+  OUTPUT_VARIABLE TRY_OUT)
+EXPECT_PASS(SHOULD_PASS "${TRY_OUT}")
+set(CMAKE_C_FLAGS "${_c_flags}")
+
+try_compile(CMAKE_ANSI_FOR_SCOPE
+  ${try_compile_bindir_or_SOURCES}
+  ${CMAKE_ROOT}/Modules/TestForAnsiForScope.cxx OUTPUT_VARIABLE OUT)
+if(CMAKE_ANSI_FOR_SCOPE)
+  message("Compiler supports ansi for")
+else()
+  message("Compiler does not support ansi for scope")
+endif()
+
+message("use the module now")
+include(${CMAKE_ROOT}/Modules/TestForANSIForScope.cmake)
+if(CMAKE_ANSI_FOR_SCOPE)
+  message("Compiler supports ansi for")
+else()
+  message("Compiler does not support ansi for scope")
+endif()
+
+# test that COMPILE_DEFINITIONS are correctly expanded
+try_compile(COMPILE_DEFINITIONS_LIST_EXPANDED
+    ${try_compile_bindir_or_SOURCES}
+    ${TryCompile_SOURCE_DIR}/check_a_b.c
+    OUTPUT_VARIABLE output
+    COMPILE_DEFINITIONS "-DDEF_A;-DDEF_B"
+    )
+if(COMPILE_DEFINITIONS_LIST_EXPANDED)
+  message(STATUS "COMPILE_DEFINITIONS list expanded correctly")
+else()
+  string(REPLACE "\n" "\n  " output "  ${output}")
+  message(SEND_ERROR "COMPILE_DEFINITIONS list did not expand correctly\n${output}")
+endif()
+
+# try to compile a file that doesn't exist
+try_compile(SHOULD_FAIL_DUE_TO_BAD_SOURCE
+    ${try_compile_bindir_or_SOURCES}
+    ${TryCompile_SOURCE_DIR}/pass.c
+    OUTPUT_VARIABLE output
+    COMPILE_DEFINITIONS "bad#source.c"
+    )
+if(SHOULD_FAIL_DUE_TO_BAD_SOURCE AND NOT CMAKE_GENERATOR MATCHES "Watcom WMake|NMake Makefiles")
+  string(REPLACE "\n" "\n  " output "  ${output}")
+  message(SEND_ERROR "try_compile with bad#source.c did not fail:\n${output}")
+elseif(NOT output MATCHES [[(bad#source\.c|bad\.c|bad')]])
+  string(REPLACE "\n" "\n  " output "  ${output}")
+  message(SEND_ERROR "try_compile with bad#source.c failed without mentioning bad source:\n${output}")
+else()
+  message(STATUS "try_compile with bad#source.c correctly failed")
+endif()
+
+if(APPLE)
+  # try to compile a file that should compile
+  try_compile(SHOULD_PASS
+    ${try_compile_bindir_or_SOURCES}
+    ${TryCompile_SOURCE_DIR}/pass.m
+    OUTPUT_VARIABLE TRY_OUT)
+  if(NOT SHOULD_PASS)
+    message(SEND_ERROR "should pass failed ${TRY_OUT}")
+  endif()
+
+  # try to compile a file that should not compile
+  try_compile(SHOULD_FAIL
+    ${try_compile_bindir_or_SOURCES}
+    ${TryCompile_SOURCE_DIR}/fail.m
+    OUTPUT_VARIABLE TRY_OUT)
+  if(SHOULD_FAIL)
+    message(SEND_ERROR "Should fail passed ${TRY_OUT}")
+  endif()
+endif()
+
+######################################
+
+# now test try_run()
+
+# try to run a file that should compile and run without error
+# also check that OUTPUT_VARIABLE contains both the compile output
+# and the run output
+try_run(SHOULD_RUN SHOULD_COMPILE
+    ${try_compile_bindir_or_SOURCES}
+    ${TryCompile_SOURCE_DIR}/exit_success.c
+    ${try_compile_output_vars})
+if(NOT SHOULD_COMPILE)
+  message(SEND_ERROR
+    "exit_success failed compiling: ${${try_compile_compile_output_var}}")
+endif()
+if(NOT "${SHOULD_RUN}" STREQUAL "0")
+  message(SEND_ERROR
+    "exit_success failed running with exit code ${SHOULD_RUN}")
+endif()
+# check the compile output for the filename
+if(NOT "${${try_compile_compile_output_var}}" MATCHES "exit_success")
+  message(SEND_ERROR
+    " ${try_compile_compile_output_var} didn't contain \"exit_success\":"
+    " \"${${try_compile_compile_output_var}}\"")
+endif()
+# check the run output
+if(NOT "${${try_compile_run_output_var}}" MATCHES "hello world")
+  message(SEND_ERROR
+    " ${try_compile_run_output_var} didn't contain \"hello world\":"
+    " \"${${try_compile_run_output_var}}\"")
+endif()
+
+try_run(ARG_TEST_RUN ARG_TEST_COMPILE
+    ${try_compile_bindir_or_SOURCES}
+    ${TryCompile_SOURCE_DIR}/expect_arg.c
+    COMPILE_OUTPUT_VARIABLE TRY_OUT
+    ARGS arg1 arg2)
+if(NOT ARG_TEST_COMPILE)
+  message(SEND_ERROR "expect_arg failed compiling: ${TRY_OUT}")
+endif()
+if(NOT "${ARG_TEST_RUN}" STREQUAL "0")
+  message(SEND_ERROR "expect_arg failed running with exit code ${ARG_TEST_RUN} ${TRY_OUT}")
+endif()
+
+# try to run a file that should compile and run, but return an error
+try_run(SHOULD_EXIT_WITH_ERROR SHOULD_COMPILE
+    ${try_compile_bindir_or_SOURCES}
+    ${TryCompile_SOURCE_DIR}/exit_with_error.c
+    COMPILE_OUTPUT_VARIABLE COMPILE_OUTPUT
+    RUN_OUTPUT_VARIABLE RUN_OUTPUT)
+
+if(NOT SHOULD_COMPILE)
+  message(STATUS " exit_with_error failed compiling: ${COMPILE_OUTPUT}")
+endif()
+if("${SHOULD_EXIT_WITH_ERROR}" STREQUAL "0")
+  message(SEND_ERROR " exit_with_error passed with exit code ${SHOULD_EXIT_WITH_ERROR}")
+endif()
+
+# check the compile output, it should contain the filename
+if(NOT "${COMPILE_OUTPUT}" MATCHES "exit_with_error")
+  message(SEND_ERROR " COMPILE_OUT didn't contain \"exit_with_error\": \"${COMPILE_OUTPUT}\"")
+endif()
+#... but not the run time output
+if("${COMPILE_OUTPUT}" MATCHES "hello world")
+  message(SEND_ERROR " COMPILE_OUT contains the run output: \"${COMPILE_OUTPUT}\"")
+endif()
+# check the run output, it should contain stdout
+if(NOT "${RUN_OUTPUT}" MATCHES "hello world")
+  message(SEND_ERROR " RUN_OUTPUT didn't contain \"hello world\": \"${RUN_OUTPUT}\"")
+endif()
+
+# try to run a file and parse stdout and stderr separately
+# also check that COPY_FILE works
+try_run(SHOULD_EXIT_WITH_ERROR SHOULD_COMPILE
+  ${try_compile_bindir_or_SOURCES}
+  ${TryCompile_SOURCE_DIR}/stdout_and_stderr.c
+  COPY_FILE ${TryCompile_BINARY_DIR}/CopyOfRun
+  COMPILE_OUTPUT_VARIABLE COMPILE_OUTPUT
+  RUN_OUTPUT_STDOUT_VARIABLE RUN_OUTPUT_STDOUT
+  RUN_OUTPUT_STDERR_VARIABLE RUN_OUTPUT_STDERR)
+
+if(NOT SHOULD_COMPILE)
+  message(STATUS " exit_with_error failed compiling: ${COMPILE_OUTPUT}")
+endif()
+
+if(NOT EXISTS "${TryCompile_BINARY_DIR}/CopyOfRun")
+  message(SEND_ERROR "COPY_FILE to \"${TryCompile_BINARY_DIR}/CopyOfRun\" failed")
+else()
+  file(REMOVE "${TryCompile_BINARY_DIR}/CopyOfRun")
+endif()
+
+# check the run stdout output
+if(NOT "${RUN_OUTPUT_STDOUT}" MATCHES "hello world")
+  message(SEND_ERROR " RUN_OUTPUT_STDOUT didn't contain \"hello world\": \"${RUN_OUTPUT_STDOUT}\"")
+endif()
+# check the run stderr output
+if(NOT "${RUN_OUTPUT_STDERR}" MATCHES "error")
+  message(SEND_ERROR " RUN_OUTPUT_STDERR didn't contain \"error\": \"${RUN_OUTPUT_STDERR}\"")
+endif()