[CMake] Enabling C99 in CMake

Todd Gamblin tgamblin at llnl.gov
Thu Jun 23 18:32:22 EDT 2011


Thanks to Sean and Jed for useful counterexamples.

A few more points:

On Jun 23, 2011, at 8:50 AM, Michael Hertling wrote:

> While I can understand your point, I'm of a different opinion: In the
> end, it's the responsibility of the user to provide the project with a
> suitable compiler.

If it's not autodetected, then yes.  And given this, the user might supply CMake with a perfectly fine compiler, but since they do not know the proper flags for that compiler they won't be able to use it.  So now you're adding to the user's responsibility, when the developer could just as easily specify this.

Add to this Jed's point that some projects have certain targets/directories that should be built with C99 or not, and I think simply specifying things at the command line is overly cumbersome.

Re:
> Case (1) is widely accepted

It's only widely accepted when CMake can't autodetect your compiler, and CMake goes to great lengths to do that for you.  I don't see what the harm is in having it also make a good-faith effort to know dialect switches.

> However, you might possibly add a check to your project, e.g. using
> TRY_COMPILE() or CheckCSourceCompiles(), with C99 source code a C89
> compiler can't build, and if this check fails, you can notify the
> user of the need to reconfigure and specify a C99 compiler. If a
> project must use the GNU compiler, one would do quite the same.

You could do this, but it seems like a lot of work for the developer AND the user compared to my suggestion of just having a variable for the compiler-specific C99 flags, or some similar mechanism.  We know an awful lot of other things about compiler switches.  Dialect seems like a useful thing to add to the platform file.  Someone does this once for each known compiler ID and now no one has to bother with this stuff anymore.

-Todd



______________________________________________________________________
Todd Gamblin, tgamblin at llnl.gov, http://people.llnl.gov/gamblin2
CASC @ Lawrence Livermore National Laboratory, Livermore, CA, USA



More information about the CMake mailing list