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

René J.V. Bertin rjvbertin at gmail.com
Tue Oct 9 10:38:12 EDT 2018


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