소스 검색

try_compile: Add a NO_LOG option to skip recording in the configure log

Brad King 2 년 전
부모
커밋
d4bf7d80c6

+ 9 - 0
Help/command/try_compile.rst

@@ -20,6 +20,7 @@ Try Compiling Whole Projects
               [TARGET <targetName>]
               [TARGET <targetName>]
               [LOG_DESCRIPTION <text>]
               [LOG_DESCRIPTION <text>]
               [NO_CACHE]
               [NO_CACHE]
+              [NO_LOG]
               [CMAKE_FLAGS <flags>...]
               [CMAKE_FLAGS <flags>...]
               [OUTPUT_VARIABLE <var>])
               [OUTPUT_VARIABLE <var>])
 
 
@@ -50,6 +51,7 @@ which was present in older versions of CMake:
               <projectName> [<targetName>]
               <projectName> [<targetName>]
               [LOG_DESCRIPTION <text>]
               [LOG_DESCRIPTION <text>]
               [NO_CACHE]
               [NO_CACHE]
+              [NO_LOG]
               [CMAKE_FLAGS <flags>...]
               [CMAKE_FLAGS <flags>...]
               [OUTPUT_VARIABLE <var>])
               [OUTPUT_VARIABLE <var>])
 
 
@@ -67,6 +69,7 @@ Try Compiling Source Files
                SOURCE_FROM_FILE <name> <path>       >...
                SOURCE_FROM_FILE <name> <path>       >...
               [LOG_DESCRIPTION <text>]
               [LOG_DESCRIPTION <text>]
               [NO_CACHE]
               [NO_CACHE]
+              [NO_LOG]
               [CMAKE_FLAGS <flags>...]
               [CMAKE_FLAGS <flags>...]
               [COMPILE_DEFINITIONS <defs>...]
               [COMPILE_DEFINITIONS <defs>...]
               [LINK_OPTIONS <options>...]
               [LINK_OPTIONS <options>...]
@@ -120,6 +123,7 @@ which was present in older versions of CMake:
   try_compile(<resultVar> <bindir> <srcfile|SOURCES srcfile...>
   try_compile(<resultVar> <bindir> <srcfile|SOURCES srcfile...>
               [LOG_DESCRIPTION <text>]
               [LOG_DESCRIPTION <text>]
               [NO_CACHE]
               [NO_CACHE]
+              [NO_LOG]
               [CMAKE_FLAGS <flags>...]
               [CMAKE_FLAGS <flags>...]
               [COMPILE_DEFINITIONS <defs>...]
               [COMPILE_DEFINITIONS <defs>...]
               [LINK_OPTIONS <options>...]
               [LINK_OPTIONS <options>...]
@@ -201,6 +205,11 @@ The options are:
   the test is part of a larger inspection), ``NO_CACHE`` may be useful to avoid
   the test is part of a larger inspection), ``NO_CACHE`` may be useful to avoid
   leaking the intermediate result variable into the cache.
   leaking the intermediate result variable into the cache.
 
 
+``NO_LOG``
+  .. versionadded:: 3.26
+
+  Do not record a :manual:`cmake-configure-log(7)` entry for this call.
+
 ``OUTPUT_VARIABLE <var>``
 ``OUTPUT_VARIABLE <var>``
   Store the output from the build process in the given variable.
   Store the output from the build process in the given variable.
 
 

+ 2 - 0
Help/command/try_run.rst

@@ -19,6 +19,7 @@ Try Compiling and Running Source Files
            SOURCE_FROM_FILE <name> <path>       >...
            SOURCE_FROM_FILE <name> <path>       >...
           [LOG_DESCRIPTION <text>]
           [LOG_DESCRIPTION <text>]
           [NO_CACHE]
           [NO_CACHE]
+          [NO_LOG]
           [CMAKE_FLAGS <flags>...]
           [CMAKE_FLAGS <flags>...]
           [COMPILE_DEFINITIONS <defs>...]
           [COMPILE_DEFINITIONS <defs>...]
           [LINK_OPTIONS <options>...]
           [LINK_OPTIONS <options>...]
@@ -58,6 +59,7 @@ which was present in older versions of CMake:
           <bindir> <srcfile|SOURCES srcfile...>
           <bindir> <srcfile|SOURCES srcfile...>
           [LOG_DESCRIPTION <text>]
           [LOG_DESCRIPTION <text>]
           [NO_CACHE]
           [NO_CACHE]
+          [NO_LOG]
           [CMAKE_FLAGS <flags>...]
           [CMAKE_FLAGS <flags>...]
           [COMPILE_DEFINITIONS <defs>...]
           [COMPILE_DEFINITIONS <defs>...]
           [LINK_OPTIONS <options>...]
           [LINK_OPTIONS <options>...]

+ 4 - 0
Help/release/dev/configure-log.rst

@@ -10,3 +10,7 @@ Configure Log
 * The :command:`try_compile` and :command:`try_run` commands gained
 * The :command:`try_compile` and :command:`try_run` commands gained
   a ``LOG_DESCRIPTION`` option specifying text to be recorded in the
   a ``LOG_DESCRIPTION`` option specifying text to be recorded in the
   :manual:`cmake-configure-log(7)`.
   :manual:`cmake-configure-log(7)`.
+
+* The :command:`try_compile` and :command:`try_run` commands gained a
+  ``NO_LOG`` option to skip recording a :manual:`cmake-configure-log(7)`
+  entry.

+ 1 - 0
Source/cmCoreTryCompile.cxx

@@ -153,6 +153,7 @@ auto const TryCompileBaseArgParser =
     .Bind(0, &Arguments::CompileResultVariable)
     .Bind(0, &Arguments::CompileResultVariable)
     .Bind("LOG_DESCRIPTION"_s, &Arguments::LogDescription)
     .Bind("LOG_DESCRIPTION"_s, &Arguments::LogDescription)
     .Bind("NO_CACHE"_s, &Arguments::NoCache)
     .Bind("NO_CACHE"_s, &Arguments::NoCache)
+    .Bind("NO_LOG"_s, &Arguments::NoLog)
     .Bind("CMAKE_FLAGS"_s, &Arguments::CMakeFlags)
     .Bind("CMAKE_FLAGS"_s, &Arguments::CMakeFlags)
     .Bind("__CMAKE_INTERNAL"_s, &Arguments::CMakeInternal)
     .Bind("__CMAKE_INTERNAL"_s, &Arguments::CMakeInternal)
   /* keep semicolon on own line */;
   /* keep semicolon on own line */;

+ 1 - 0
Source/cmCoreTryCompile.h

@@ -75,6 +75,7 @@ public:
     cm::optional<std::string> CopyFileError;
     cm::optional<std::string> CopyFileError;
     cm::optional<ArgumentParser::NonEmpty<std::string>> LogDescription;
     cm::optional<ArgumentParser::NonEmpty<std::string>> LogDescription;
     bool NoCache = false;
     bool NoCache = false;
+    bool NoLog = false;
 
 
     // Argument for try_run only.
     // Argument for try_run only.
     // Keep in sync with warnings in cmCoreTryCompile::ParseArgs.
     // Keep in sync with warnings in cmCoreTryCompile::ParseArgs.

+ 4 - 3
Source/cmTryCompileCommand.cxx

@@ -81,14 +81,15 @@ bool cmTryCompileCommand(std::vector<std::string> const& args,
     return true;
     return true;
   }
   }
 
 
-  if (cm::optional<cmTryCompileResult> compileResult =
-        tc.TryCompileCode(arguments, targetType)) {
+  cm::optional<cmTryCompileResult> compileResult =
+    tc.TryCompileCode(arguments, targetType);
 #ifndef CMAKE_BOOTSTRAP
 #ifndef CMAKE_BOOTSTRAP
+  if (compileResult && !arguments.NoLog) {
     if (cmConfigureLog* log = mf.GetCMakeInstance()->GetConfigureLog()) {
     if (cmConfigureLog* log = mf.GetCMakeInstance()->GetConfigureLog()) {
       WriteTryCompileEvent(*log, mf, *compileResult);
       WriteTryCompileEvent(*log, mf, *compileResult);
     }
     }
-#endif
   }
   }
+#endif
 
 
   // if They specified clean then we clean up what we can
   // if They specified clean then we clean up what we can
   if (tc.SrcFileSignature) {
   if (tc.SrcFileSignature) {

+ 1 - 1
Source/cmTryRunCommand.cxx

@@ -246,7 +246,7 @@ bool TryRunCommandImpl::TryRunCode(std::vector<std::string> const& argv)
   }
   }
 
 
 #ifndef CMAKE_BOOTSTRAP
 #ifndef CMAKE_BOOTSTRAP
-  if (compileResult) {
+  if (compileResult && !arguments.NoLog) {
     cmMakefile const& mf = *(this->Makefile);
     cmMakefile const& mf = *(this->Makefile);
     if (cmConfigureLog* log = mf.GetCMakeInstance()->GetConfigureLog()) {
     if (cmConfigureLog* log = mf.GetCMakeInstance()->GetConfigureLog()) {
       WriteTryRunEvent(*log, mf, *compileResult, runResult);
       WriteTryRunEvent(*log, mf, *compileResult, runResult);

+ 5 - 0
Tests/RunCMake/try_compile/ConfigureLog.cmake

@@ -5,6 +5,11 @@ try_compile(COMPILE_RESULT
   LOG_DESCRIPTION "Source that should not compile."
   LOG_DESCRIPTION "Source that should not compile."
   )
   )
 
 
+try_compile(COMPILE_RESULT
+  SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/ConfigureLog-test.c
+  NO_LOG
+  )
+
 try_compile(COMPILE_RESULT
 try_compile(COMPILE_RESULT
   SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/ConfigureLog-test.c
   SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/ConfigureLog-test.c
   LOG_DESCRIPTION "Source that should compile."
   LOG_DESCRIPTION "Source that should compile."

+ 5 - 0
Tests/RunCMake/try_run/ConfigureLog.cmake

@@ -3,6 +3,11 @@ try_run(RUN_RESULT COMPILE_RESULT
   LOG_DESCRIPTION "Source that should not compile."
   LOG_DESCRIPTION "Source that should not compile."
   )
   )
 
 
+try_run(RUN_RESULT COMPILE_RESULT
+  SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/ConfigureLog-test.c
+  NO_LOG
+  )
+
 try_run(RUN_RESULT COMPILE_RESULT
 try_run(RUN_RESULT COMPILE_RESULT
   SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/ConfigureLog-test.c
   SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/ConfigureLog-test.c
   LOG_DESCRIPTION "Source that should compile."
   LOG_DESCRIPTION "Source that should compile."