diff --git a/modules/vstudio/_preload.lua b/modules/vstudio/_preload.lua
index cfd73e75a..47f5cddec 100644
--- a/modules/vstudio/_preload.lua
+++ b/modules/vstudio/_preload.lua
@@ -216,6 +216,12 @@
}
}
+ p.api.register {
+ name = "clangtidy",
+ scope = "config",
+ kind = "boolean"
+ }
+
p.api.register {
name = "vsprops",
scope = "config",
diff --git a/modules/vstudio/tests/_tests.lua b/modules/vstudio/tests/_tests.lua
index 3bf71afba..b3f2fe12b 100644
--- a/modules/vstudio/tests/_tests.lua
+++ b/modules/vstudio/tests/_tests.lua
@@ -102,6 +102,7 @@ return {
-- Visual Studio 2019+ C/C++ Projects
"vc2019/test_compile_settings.lua",
"vc2019/test_link.lua",
+ "vc2019/test_output_props.lua",
"vc2019/test_toolset_settings.lua",
-- Visual Studio 2022+ C/C++ Projects
diff --git a/modules/vstudio/tests/vc2010/test_output_props.lua b/modules/vstudio/tests/vc2010/test_output_props.lua
index 9ec9a4457..582121c34 100644
--- a/modules/vstudio/tests/vc2010/test_output_props.lua
+++ b/modules/vstudio/tests/vc2010/test_output_props.lua
@@ -25,6 +25,24 @@
vc2010.outputProperties(cfg)
end
+--
+-- Ensure clangtidy is not enabled for vc2010.
+--
+
+function suite.onClangTidy()
+ clangtidy "On"
+ prepare()
+ test.capture [[
+
+ true
+ bin\Debug\
+ obj\Debug\
+ MyProject
+ .exe
+
+ ]]
+end
+
--
-- Check the structure with the default project values.
diff --git a/modules/vstudio/tests/vc2019/test_output_props.lua b/modules/vstudio/tests/vc2019/test_output_props.lua
new file mode 100644
index 000000000..c9ba51e2f
--- /dev/null
+++ b/modules/vstudio/tests/vc2019/test_output_props.lua
@@ -0,0 +1,64 @@
+--
+-- tests/actions/vstudio/vc2019/test_output_props.lua
+-- Validate generation of the output property groups.
+-- Copyright (c) 2024 Jason Perkins and the Premake project
+--
+
+local p = premake
+local suite = test.declare("vstudio_vs2019_output_props")
+local vc2010 = p.vstudio.vc2010
+
+
+--
+-- Setup
+--
+
+local wks, prj
+
+function suite.setup()
+ p.action.set("vs2019")
+ wks, prj = test.createWorkspace()
+end
+
+local function prepare()
+ local cfg = test.getconfig(prj, "Debug")
+ vc2010.outputProperties(cfg)
+end
+
+--
+-- Check clangtidy code analysis enabled.
+--
+
+function suite.onClangTidy_Enabled()
+ clangtidy "On"
+ prepare()
+ test.capture [[
+
+ true
+ bin\Debug\
+ obj\Debug\
+ MyProject
+ .exe
+ true
+
+ ]]
+end
+
+--
+-- Check clangtidy code analysis disabled.
+--
+
+function suite.onClangTidy_Disabled()
+ clangtidy "Off"
+ prepare()
+ test.capture [[
+
+ true
+ bin\Debug\
+ obj\Debug\
+ MyProject
+ .exe
+ false
+
+ ]]
+end
diff --git a/modules/vstudio/vs2010_vcxproj.lua b/modules/vstudio/vs2010_vcxproj.lua
index e2f77c0d1..337164f1c 100644
--- a/modules/vstudio/vs2010_vcxproj.lua
+++ b/modules/vstudio/vs2010_vcxproj.lua
@@ -322,6 +322,7 @@
m.extensionsToDeleteOnClean,
m.executablePath,
m.allModulesPublic,
+ m.clangtidy,
}
end
end
@@ -3036,6 +3037,11 @@
m.element("TargetName", nil, "%s%s", cfg.buildtarget.prefix, cfg.buildtarget.basename)
end
+ function m.clangtidy(cfg)
+ if _ACTION >= "vs2019" and cfg.clangtidy ~= nil then
+ m.element("EnableClangTidyCodeAnalysis", nil, iif(cfg.clangtidy, "true", "false"))
+ end
+ end
function m.latestTargetPlatformVersion(prj)
-- See https://developercommunity.visualstudio.com/content/problem/140294/windowstargetplatformversion-makes-it-impossible-t.html
diff --git a/website/docs/clangtidy.md b/website/docs/clangtidy.md
new file mode 100644
index 000000000..25e04f5bd
--- /dev/null
+++ b/website/docs/clangtidy.md
@@ -0,0 +1,26 @@
+Enables clang-tidy code analysis for Visual Studio.
+
+The `clangtidy` option enables running clang-tidy code analysis in Visual Studio projects.
+
+```lua
+clangtidy("value")
+```
+
+### Parameters ###
+
+`value` is one of:
+
+- `On`
+- `Off`
+
+### Applies To ###
+
+The `config` scope.
+
+### Availability ###
+
+Premake 5.0.0 beta 3 or later for Visual Studio 2019 and later.
+
+### See Also ###
+
+* [Using Clang-Tidy in Visual Studio](https://learn.microsoft.com/en-us/cpp/code-quality/clang-tidy?view=msvc-170)