Merge topic 'target-SKIP_LINTING'

f100769d72 Add `SKIP_LINTING` target property and `CMAKE_SKIP_LINTING` variable
0d6b5d54b2 Tests/RunCMake/MultiLint: Extract test preparation code into separate file
3a21092d75 Tests/RunCMake/MultiLint: Refactor test runs

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !11139
This commit is contained in:
Brad King
2025-09-10 09:53:48 -04:00
committed by Kitware Robot
17 changed files with 163 additions and 49 deletions
+1
View File
@@ -404,6 +404,7 @@ Properties on Targets
/prop_tgt/RUNTIME_OUTPUT_NAME
/prop_tgt/RUNTIME_OUTPUT_NAME_CONFIG
/prop_tgt/SKIP_BUILD_RPATH
/prop_tgt/SKIP_LINTING
/prop_tgt/SOURCE_DIR
/prop_tgt/SOURCES
/prop_tgt/SOVERSION
+1
View File
@@ -574,6 +574,7 @@ Variables that Control the Build
/variable/CMAKE_SHARED_LINKER_FLAGS_INIT
/variable/CMAKE_SKIP_BUILD_RPATH
/variable/CMAKE_SKIP_INSTALL_RPATH
/variable/CMAKE_SKIP_LINTING
/variable/CMAKE_STATIC_LINKER_FLAGS
/variable/CMAKE_STATIC_LINKER_FLAGS_CONFIG
/variable/CMAKE_STATIC_LINKER_FLAGS_CONFIG_INIT
+5
View File
@@ -41,3 +41,8 @@ By using the ``SKIP_LINTING`` property, you can selectively exclude specific
source files from the linting process. This allows you to focus the
linting tools on the relevant parts of your project, enhancing the efficiency
and effectiveness of the linting workflow.
See Also
^^^^^^^^
* :prop_tgt:`SKIP_LINTING` target property
+25
View File
@@ -0,0 +1,25 @@
SKIP_LINTING
------------
.. versionadded:: 4.2
Exclude all sources of a target from running configured linting tools.
When this boolean property is enabled on a target, C/C++ linting tools enabled
for that target (e.g. :prop_tgt:`<LANG>_CPPLINT`, :prop_tgt:`<LANG>_CLANG_TIDY`,
:prop_tgt:`<LANG>_CPPCHECK`, :prop_tgt:`<LANG>_ICSTAT` and
:prop_tgt:`<LANG>_INCLUDE_WHAT_YOU_USE`) will not be invoked for source files
compiled by the target. If the :prop_sf:`SKIP_LINTING` source-file property
is set on a specific source, it takes precedence over this target-wide property.
This is a convenience alternative to setting the :prop_sf:`SKIP_LINTING`
source file property individually on each source. If either the target's
:prop_tgt:`SKIP_LINTING` or a source’s :prop_sf:`SKIP_LINTING` is enabled,
that source will be excluded from linting.
The property has no effect on targets that do not have sources.
See Also
^^^^^^^^
* :prop_sf:`SKIP_LINTING` source file property
+7
View File
@@ -0,0 +1,7 @@
target-SKIP_LINTING
-------------------
* The :variable:`CMAKE_SKIP_LINTING` variable and corresponding
:prop_tgt:`SKIP_LINTING` target property were added to tell the
:ref:`Command-Line Build Tool Generators` to skip linting all
sources in a target.
+9
View File
@@ -0,0 +1,9 @@
CMAKE_SKIP_LINTING
------------------
.. versionadded:: 4.2
Default value for the :prop_tgt:`SKIP_LINTING` target property.
This is used to initialize the :prop_tgt:`SKIP_LINTING` target property
for all targets created *afterward*.
+11 -7
View File
@@ -1011,14 +1011,18 @@ void cmFastbuildNormalTargetGenerator::CollapseAllExecsIntoOneScriptfile(
std::string cmFastbuildNormalTargetGenerator::ComputeCodeCheckOptions(
cmSourceFile const& srcFile)
{
cmValue const skipCodeCheck = srcFile.GetProperty("SKIP_LINTING");
std::string staticCheckRule;
if (!skipCodeCheck.IsOn()) {
std::string compilerLauncher;
staticCheckRule = this->GenerateCodeCheckRules(srcFile, compilerLauncher,
"", Config, nullptr);
LogMessage(cmStrCat("CodeCheck: ", staticCheckRule));
cmValue const srcSkipCodeCheckVal = srcFile.GetProperty("SKIP_LINTING");
bool const skipCodeCheck = srcSkipCodeCheckVal.IsSet()
? srcSkipCodeCheckVal.IsOn()
: this->GetGeneratorTarget()->GetPropertyAsBool("SKIP_LINTING");
if (skipCodeCheck) {
return {};
}
std::string compilerLauncher;
std::string staticCheckRule = this->GenerateCodeCheckRules(
srcFile, compilerLauncher, "", Config, nullptr);
LogMessage(cmStrCat("CodeCheck: ", staticCheckRule));
return staticCheckRule;
}
+6 -2
View File
@@ -1091,8 +1091,12 @@ void cmMakefileTargetGenerator::WriteObjectRuleFiles(
compilerLauncher = GetCompilerLauncher(lang, config);
}
cmValue const skipCodeCheck = source.GetProperty("SKIP_LINTING");
if (!skipCodeCheck.IsOn()) {
cmValue const srcSkipCodeCheckVal = source.GetProperty("SKIP_LINTING");
bool const skipCodeCheck = srcSkipCodeCheckVal.IsSet()
? srcSkipCodeCheckVal.IsOn()
: this->GetGeneratorTarget()->GetPropertyAsBool("SKIP_LINTING");
if (!skipCodeCheck) {
std::string const codeCheck = this->GenerateCodeCheckRules(
source, compilerLauncher, "$(CMAKE_COMMAND)", config, nullptr);
if (!codeCheck.empty()) {
+6 -2
View File
@@ -1423,8 +1423,12 @@ void cmNinjaTargetGenerator::WriteObjectBuildStatement(
auto compilerLauncher = this->GetCompilerLauncher(language, config);
cmValue const skipCodeCheck = source->GetProperty("SKIP_LINTING");
if (!skipCodeCheck.IsOn()) {
cmValue const srcSkipCodeCheckVal = source->GetProperty("SKIP_LINTING");
bool const skipCodeCheck = srcSkipCodeCheckVal.IsSet()
? srcSkipCodeCheckVal.IsOn()
: this->GetGeneratorTarget()->GetPropertyAsBool("SKIP_LINTING");
if (!skipCodeCheck) {
auto const cmakeCmd = this->GetLocalGenerator()->ConvertToOutputFormat(
cmSystemTools::GetCMakeCommand(), cmLocalGenerator::SHELL);
vars["CODE_CHECK"] =
+2
View File
@@ -465,6 +465,7 @@ TargetProperty const StaticTargetProperties[] = {
{ "Fortran_LINKER_LAUNCHER"_s, IC::CanCompileSources },
// Static analysis
{ "SKIP_LINTING"_s, IC::CanCompileSources },
// -- C
{ "C_CLANG_TIDY"_s, IC::CanCompileSources },
{ "C_CLANG_TIDY_EXPORT_FIXES_DIR"_s, IC::CanCompileSources },
@@ -1805,6 +1806,7 @@ void cmTarget::CopyImportedCxxModulesProperties(cmTarget const* tgt)
"CXX_CPPCHECK",
"CXX_ICSTAT",
"CXX_INCLUDE_WHAT_YOU_USE",
"SKIP_LINTING",
// Build graph properties
"EXCLUDE_FROM_ALL",
@@ -1,7 +1,3 @@
enable_language(CXX)
set(CMAKE_CXX_INCLUDE_WHAT_YOU_USE "$<1:${PSEUDO_IWYU}>" -some -args)
set(CMAKE_CXX_CLANG_TIDY "$<1:${PSEUDO_TIDY}>" -bad)
set(CMAKE_CXX_CPPLINT "$<1:${PSEUDO_CPPLINT}>" --error)
set(CMAKE_CXX_CPPCHECK "$<1:${PSEUDO_CPPCHECK}>" -error)
add_executable(main main.cxx)
set_source_files_properties(main.cxx PROPERTIES SKIP_LINTING OFF)
include(${CMAKE_CURRENT_LIST_DIR}/setup_skip_linter_test.cmake)
setup_skip_linter_test(CXX)
@@ -1,7 +1,3 @@
enable_language(CXX)
set(CMAKE_CXX_INCLUDE_WHAT_YOU_USE "$<1:${PSEUDO_IWYU}>" -some -args)
set(CMAKE_CXX_CLANG_TIDY "$<1:${PSEUDO_TIDY}>" -bad)
set(CMAKE_CXX_CPPLINT "$<1:${PSEUDO_CPPLINT}>" --error)
set(CMAKE_CXX_CPPCHECK "$<1:${PSEUDO_CPPCHECK}>" -error)
add_executable(main main.cxx)
set_source_files_properties(main.cxx PROPERTIES SKIP_LINTING ON)
include(${CMAKE_CURRENT_LIST_DIR}/setup_skip_linter_test.cmake)
setup_skip_linter_test(CXX)
@@ -1,7 +1,3 @@
enable_language(C)
set(CMAKE_C_INCLUDE_WHAT_YOU_USE "${PSEUDO_IWYU}" -some -args)
set(CMAKE_C_CLANG_TIDY "${PSEUDO_TIDY}" -bad)
set(CMAKE_C_CPPLINT "${PSEUDO_CPPLINT}" --error)
set(CMAKE_C_CPPCHECK "${PSEUDO_CPPCHECK}" -error)
add_executable(main main.c)
set_source_files_properties(main.c PROPERTIES SKIP_LINTING OFF)
include(${CMAKE_CURRENT_LIST_DIR}/setup_skip_linter_test.cmake)
setup_skip_linter_test(C)
@@ -1,7 +1,3 @@
enable_language(C)
set(CMAKE_C_INCLUDE_WHAT_YOU_USE "${PSEUDO_IWYU}" -some -args)
set(CMAKE_C_CLANG_TIDY "${PSEUDO_TIDY}" -bad)
set(CMAKE_C_CPPLINT "${PSEUDO_CPPLINT}" --error)
set(CMAKE_C_CPPCHECK "${PSEUDO_CPPCHECK}" -error)
add_executable(main main.c)
set_source_files_properties(main.c PROPERTIES SKIP_LINTING ON)
include(${CMAKE_CURRENT_LIST_DIR}/setup_skip_linter_test.cmake)
setup_skip_linter_test(C)
+57 -14
View File
@@ -27,21 +27,64 @@ if(NOT RunCMake_GENERATOR STREQUAL "Watcom WMake")
run_multilint(genex)
endif()
function(run_skip_linting test_name)
set(RunCMake_TEST_BINARY_DIR "${RunCMake_BINARY_DIR}/${test_name}-build")
set(RunCMake_TEST_NO_CLEAN 1)
function(run_skip_linting test_name prop_sf prop_tgt)
set(RunCMake_TEST_VARIANT_DESCRIPTION " (prop_sf=${prop_sf}, prop_tgt=${prop_tgt})")
list(APPEND RunCMake_TEST_OPTIONS "-Dprop_sf=${prop_sf}" "-Dprop_tgt=${prop_tgt}")
run_cmake(${test_name})
set(RunCMake_TEST_OUTPUT_MERGE 1)
run_cmake_command(${test_name}-Build ${CMAKE_COMMAND} --build .)
set(RunCMake_TEST_BINARY_DIR "${RunCMake_BINARY_DIR}/${test_name}-build")
set(RunCMake_TEST_NO_CLEAN 1)
run_cmake(${test_name})
set(RunCMake_TEST_OUTPUT_MERGE 1)
run_cmake_command(${test_name}-Build ${CMAKE_COMMAND} --build .)
endfunction()
run_skip_linting(C_skip_linting_ON)
run_skip_linting(CXX_skip_linting_ON)
run_skip_linting(C_skip_linting_OFF)
run_skip_linting(CXX_skip_linting_OFF)
# There are a few `SKIP_LINTING` source/target propertiy combinations
# that affect the final result:
#
# prop_sf prop_tgt result
# ---------------------------
# - - OFF
# OFF - OFF
# ON - ON
# - OFF OFF
# OFF OFF OFF
# ON OFF ON
# - ON ON
# OFF ON OFF
# ON ON ON
#
# where `-` means unset property.
#
# Here's the same table for convenience sorted by `result`:
#
# prop_sf prop_tgt result
# ---------------------------
# - - OFF
# OFF - OFF
# - OFF OFF
# OFF OFF OFF
# OFF ON OFF
# ON - ON
# ON OFF ON
# - ON ON
# ON ON ON
if(NOT RunCMake_GENERATOR STREQUAL "Watcom WMake")
run_skip_linting(C-launch_skip_linting_ON)
run_skip_linting(CXX-launch_skip_linting_ON)
endif()
foreach(lang IN ITEMS C CXX)
# Testing `SKIP_LINTING=OFF` (first half of the table above)
set(prop_sf_OFF_variants "-" OFF "-" OFF OFF)
set(prop_tgt_OFF_variants "-" "-" OFF OFF ON)
foreach(prop_fs prop_tgt IN ZIP_LISTS prop_sf_OFF_variants prop_tgt_OFF_variants)
run_skip_linting(${lang}_skip_linting_OFF "${prop_fs}" "${prop_tgt}")
endforeach()
# Testing `SKIP_LINTING=ON` (second half of the table above)
set(prop_sf_ON_variants ON ON "-" ON)
set(prop_tgt_ON_variants "-" OFF ON ON)
foreach(prop_fs prop_tgt IN ZIP_LISTS prop_sf_ON_variants prop_tgt_ON_variants)
run_skip_linting(${lang}_skip_linting_ON "${prop_fs}" "${prop_tgt}")
if(NOT RunCMake_GENERATOR STREQUAL "Watcom WMake")
run_skip_linting(${lang}-launch_skip_linting_ON "${prop_fs}" "${prop_tgt}")
endif()
endforeach()
endforeach()
@@ -0,0 +1,24 @@
include_guard()
function(setup_skip_linter_test lang)
if(lang STREQUAL "CXX")
set(maybe_genex_pre "$<1:")
set(maybe_genex_post ">")
endif()
set(CMAKE_${lang}_INCLUDE_WHAT_YOU_USE "${maybe_genex_pre}${PSEUDO_IWYU}${maybe_genex_post}" -some -args)
set(CMAKE_${lang}_CLANG_TIDY "${maybe_genex_pre}${PSEUDO_TIDY}${maybe_genex_post}" -bad)
set(CMAKE_${lang}_CPPLINT "${maybe_genex_pre}${PSEUDO_CPPLINT}${maybe_genex_post}" --error)
set(CMAKE_${lang}_CPPCHECK "${maybe_genex_pre}${PSEUDO_CPPCHECK}${maybe_genex_post}" -error)
string(TOLOWER "${lang}" ext)
add_executable(main main.${ext})
if(NOT prop_sf STREQUAL "-")
set_source_files_properties(main.${ext} PROPERTIES SKIP_LINTING ${prop_sf})
endif()
if(NOT prop_tgt STREQUAL "-")
set_target_properties(main PROPERTIES SKIP_LINTING ${prop_tgt})
endif()
endfunction()
@@ -114,6 +114,7 @@ set(properties
"OBJCXX_LINKER_LAUNCHER" "ccache" "<SAME>"
# Static analysis
"SKIP_LINTING" "OFF" "<SAME>"
## C
"C_CLANG_TIDY" "clang-tidy" "<SAME>"
"C_CLANG_TIDY_EXPORT_FIXES_DIR" "${dir}" "<SAME>"