[CMake] support for -fsyntax-only (and generating Qt/KDE's auto-generated content)

Sylvain Joubert joubert.sy at gmail.com
Tue Oct 9 12:43:19 EDT 2018


I'd also like something like that for another use case of mine which 
stumble upon the same limitations (compiler checks, linking and Qt 
generated content).

My use case is for static analysis builds. For example, my CI setup has 
multiple of them including cppcheck, clang-tidy and iwyu through the 
CMake integration. And since I'd like to keep separate builds for each 
of them this requires 3 full build whose results I don't really care.

So if we can achieve a light build mode, that would be great. In my case 
I could completely deactivate the build part including the syntax 
checking since that's done by the static analysis tools anyway. Thinking 
of that maybe we can completely disable the build invocation and add 
support for a "syntax only" analysis tool that would feats your need.

Anyhow, we can't deactivate all the build. As you said auto-generated 
content, custom targets,... would need to stay.

Sylvain

Le 09/10/2018 à 16:38, René J.V. Bertin a écrit :
> Hi,
> 
> Apologies, longish post ahead. I've tried to present my idea and the thought train leading up to it as succinctly as possible. Hope I at least strike a chord!
> 
> Clang and GCC have long supported an option that makes them stop after the syntax-verification stage: -fsyntax-only . This has the advantage (see below) that it's much faster than a regular build and that no output is generated. The absent output is also a problem and the reason I'm posting about it here:
> - compiler checking fails because of the missing output.
> - link and archive (static lib) creation fail because of missing files.
> 
> The first problem should not be hard to fix (filter out -fsyntax-only from the arguments used to check the compiler). The 2nd problem can be addressed by ignoring the exit code from linking and archiving commands (possible with make, presumably with ninja too).
> 
> Would it be feasible to implement "something" that makes it possible to run a full pure-syntax-checking "build", either as a special target or as a separate mode of operation or CMAKE_BUILD_TYPE?
> 
> I think this could be useful in general esp. with larger projects, allowing to check "quickly" if a change (triggering a full rebuild) breaks something. QtWebKit would be an appropriate example: it uses a central header to set the configuration preprocessor tokens so toggling even one of these switches causes *everything* to be rebuilt.
> 
> Some more observations which outline a context where cmake-level support for a pure syntax-checking run would be beneficial (also the context that made me remember the -fsyntax-only option):
> 
> - a number of IDEs (can) use CMake as the basis for project definition.
> - They also provide parsing facilities that also use information from cmake to control the parser.
> - KDE has long used cmake instead of autoconf (or qmake) and is based on Qt, which means KDE projects depend on auto-generation of files which need to be included in C++ code.
> - Parsing or even syntax-checking won't work to at least some degree without those auto-generated files.
> - opening a project in an IDE is not always done with the intention to build it; in absence of such an intention one usually does expect to be able to rely on parsing and syntax checking.
> - Auto-generation of Qt's automatic content occurs during a full build, when needed.
> 
> That last observation is the big bottleneck; a full build can be very costly. If there were a dedicated target to generate just all automatic content one could just build that target and there would be no issue left. Whether or not this is impossible is unclear, and at least not entirely a CMake issue.
> 
> Here too something like -DCMAKE_BUILD_TYPE=SyntaxOnly would be a workable solution.
> 
> R.
> 



More information about the CMake mailing list