On 06/24/2011 12:32 AM, Todd Gamblin wrote: > 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.
AFAIK, it is usually a single flag which specifies the dialect although compilers tend to use countless command line options, even the dialect- related ones. Thus, I'm quite sure that the user is regularly able to figure out this flag for its inclusion in the CC environment variable. However, mixed-dialect projects are special in this regard and could indeed be handled well with dialect switches which are fine-tuned by the project itself - as long as the compiler supports every required dialect. For an approach how to accomplish this specifically for all compilers through a platform/compiler-independent interface, see my reply to Jed's posting; of course, I'd be particularly interested in your opinion whether that approach does suit your needs. > 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. CMake's autodetection of the compiler already fails if the compiler is just not in the PATH or unusually named, and that's not uncommon, and if one has multiple compilers installed - which is not uncommon, too - CMake will detect only one of them anyway, so it might happen quite quickly that the wrong compiler is chosen. For this reason, I think it should be absolutely tolerable for the user to denote a suitable compiler, and an additional specification of a dialect flag should also be no unsustainable burden. Of course, an effort to provide dialect flags in a platform/compiler-independent way is no harm at all, and if the CMake community will settle on a solution, I would appreciate it. >> 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. CMake provides - and projects use - numerous checks for headers, libraries, functions, struct/class members etc.; why should a C99 project not examine the compiler for its C99 capabilities in a plat- form/compiler-independent manner? Your point relies on the assumption that the compiler accepts multiple dialects, but there are compilers which do not, and if CMake detects - or the user specifies - a C89 compiler for a C99 project, there're mysterious error messages as error: expected '=', ',', ';', 'asm' or '__attribute__' before 'p' when declaring a "void *restrict p" pointer, e.g. IMO, understanding such error messages and drawing the correct conclusions is much more difficult for the user than being told explicitly and right from the very first that the projects needs a C99 compiler. Regards, Michael _______________________________________________ Powered by www.kitware.com Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Follow this link to subscribe/unsubscribe: http://www.cmake.org/mailman/listinfo/cmake