mirror of
https://gitlab.kitware.com/cmake/cmake.git
synced 2026-09-25 04:09:36 +03:00
ctest: Avoid unused-cli warning when propagating SITE/BUILDNAME
Commit 433721b7a7 (ctest: Pass CTEST_SITE/CTEST_BUILD_NAME to configure
step, 2026-06-15) updated ctest_configure() to pass `-DSITE=...` and
`-DBUILDNAME=...` to the configure command whenever CTEST_SITE or
CTEST_BUILD_NAME are set. Projects that don't include the CTest module never
reference these cache variables, causing CMake to report an unused-cli warning.
Use `-C <initial-cache>` instead of `-D` to seed SITE/BUILDNAME. Cache entries
set using `-C` are not tracked by CMake's unused-cli diagnostic, so projects
using the CTest module still get DartConfiguration.tcl populated correctly,
while projects that never reference SITE/BUILDNAME no longer see the warning.
Fixes: #27953
This commit is contained in:
@@ -24,6 +24,7 @@
|
||||
#include "cmJSONState.h"
|
||||
#include "cmList.h"
|
||||
#include "cmMakefile.h"
|
||||
#include "cmOutputConverter.h"
|
||||
#include "cmStringAlgorithms.h"
|
||||
#include "cmSystemTools.h"
|
||||
#include "cmValue.h"
|
||||
@@ -127,17 +128,29 @@ bool ConstructConfigureCommand(cmExecutionStatus& status, cmMakefile& mf,
|
||||
|
||||
// Propagate CTEST_SITE / CTEST_BUILD_NAME into the SITE / BUILDNAME
|
||||
// cache variables so DartConfiguration.tcl gets generated with
|
||||
// correct values.
|
||||
// correct values. We use an initial cache script (-C) instead of
|
||||
// defining them on the command-line (-D) to avoid unused-cli warnings
|
||||
// for projects that don't include the CTest module.
|
||||
cmValue site = mf.GetDefinition("CTEST_SITE");
|
||||
if (cmNonempty(site)) {
|
||||
configureCommand += " \"-DSITE:STRING=";
|
||||
configureCommand += *site;
|
||||
configureCommand += "\"";
|
||||
}
|
||||
cmValue buildName = mf.GetDefinition("CTEST_BUILD_NAME");
|
||||
if (cmNonempty(buildName)) {
|
||||
configureCommand += " \"-DBUILDNAME:STRING=";
|
||||
configureCommand += *buildName;
|
||||
if (cmNonempty(site) || cmNonempty(buildName)) {
|
||||
std::string const initialCacheFile =
|
||||
cmStrCat(cmSystemTools::CollapseFullPath(buildDirectory),
|
||||
"/Testing/Temporary/CTestConfigureInitialCache.cmake");
|
||||
cmGeneratedFileStream initialCache(initialCacheFile);
|
||||
if (cmNonempty(site)) {
|
||||
initialCache << "set(SITE " << cmOutputConverter::EscapeForCMake(*site)
|
||||
<< " CACHE STRING \"\")\n";
|
||||
}
|
||||
if (cmNonempty(buildName)) {
|
||||
initialCache << "set(BUILDNAME "
|
||||
<< cmOutputConverter::EscapeForCMake(*buildName)
|
||||
<< " CACHE STRING \"\")\n";
|
||||
}
|
||||
initialCache.Close();
|
||||
|
||||
configureCommand += " \"-C";
|
||||
configureCommand += initialCacheFile;
|
||||
configureCommand += "\"";
|
||||
}
|
||||
|
||||
|
||||
@@ -694,6 +694,33 @@ function(run_configure_empty_bindir)
|
||||
endfunction()
|
||||
run_configure_empty_bindir()
|
||||
|
||||
# Verify that ctest_configure() does not trigger a spurious unused-cli
|
||||
# warning about BUILDNAME/SITE when CTEST_SITE/CTEST_BUILD_NAME are set
|
||||
# but the project does not include(CTest). See issue #27953.
|
||||
function(run_configure_site_buildname_no_unused_cli)
|
||||
set(src "${RunCMake_BINARY_DIR}/configure-site-buildname-no-unused-cli-src")
|
||||
set(bin "${RunCMake_BINARY_DIR}/configure-site-buildname-no-unused-cli-bin")
|
||||
file(REMOVE_RECURSE "${src}" "${bin}")
|
||||
file(MAKE_DIRECTORY "${src}")
|
||||
file(WRITE "${src}/CMakeLists.txt"
|
||||
"cmake_minimum_required(VERSION 3.10)\nproject(Minimal LANGUAGES NONE)\n")
|
||||
set(RunCMake_TEST_BINARY_DIR "${bin}")
|
||||
set(RunCMake_TEST_NO_CLEAN 1)
|
||||
ctest_source_dir_generator_args(generator_args)
|
||||
set(RunCMake_TEST_NOT_EXPECT_stdout "CMake Warning \\(unused-cli\\)")
|
||||
run_cmake_command(configure-site-buildname-no-unused-cli
|
||||
${CMAKE_CTEST_COMMAND}
|
||||
--source-dir "${src}"
|
||||
--build-dir "${bin}"
|
||||
${generator_args}
|
||||
-D "CTEST_SITE=Test Site"
|
||||
-D "CTEST_BUILD_NAME=Test Build"
|
||||
-T Configure
|
||||
-V)
|
||||
unset(RunCMake_TEST_NOT_EXPECT_stdout)
|
||||
endfunction()
|
||||
run_configure_site_buildname_no_unused_cli()
|
||||
|
||||
# Verify expected error condition when --source-dir does not contain
|
||||
# a CMakeLists.txt file.
|
||||
function(run_configure_no_cmakelists)
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
^Cannot find file: [^
|
||||
]*/DartConfiguration\.tcl$
|
||||
Reference in New Issue
Block a user