premake / premake-core

Premake
https://premake.github.io/
BSD 3-Clause "New" or "Revised" License
3.2k stars 618 forks source link

Add option to enforce build-time code analysis for VS projects #2190

Closed theComputeKid closed 7 months ago

theComputeKid commented 7 months ago

What does this PR do?

This is a follow up to a previous PR: #2187

After enabling clang-tidy as an option in the VS IDE (#2187), this patch allows us to enforce it at build time. This can significantly increase build time, as you would expect from any static analysis tool. When building VS projects using this option, along with #2187, the log will show:

     2>ClangTidy:
         C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\Llvm\x64\bin\clang-tidy.exe -p="..\myProj.ClangTidy"
         Suppressed 3 warnings (3 in non-user code).
         Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.

A few people have asked for compile_command.json generation. On Linux/Macos, tools exist to generate this (e.g. bear etc). This is tricky on windows. As an extra side-benefit of this change, as seen in the log above, a compile_commands.json file is generated in the location specified with the -p flag. However, while useful, this is a side-effect of this change and not its primary purpose.

How does this PR change Premake's behavior?

Add configuration-scoped option runcodeanalysis for Visual Studio 2019 and above.

Did you check all the boxes?

Jarod42 commented 7 months ago

A few people have asked for compile_command.json generation.

There is 2 (external) premake modules which should do that:

theComputeKid commented 7 months ago

@nickclark2016 : If you don't mind, could you also review the addition of clangtidy to the sidebar, as it is related to this change. I was unaware of the need to add this and I missed it in #2187. In any case, I will make the addition you requested. Thank you.