[CMake] Enabling C99 in CMake

Michael Hertling mhertling at online.de
Sat Jun 25 02:30:00 EDT 2011


On 06/24/2011 04:16 PM, Owen Shepherd wrote:
> On 23/06/2011 23:32, "Todd Gamblin" <tgamblin at llnl.gov> wrote:
>> 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
> 
> 
> A variable for the compiler-specific flags doesn't work in the case of
> e.g. Sun Studio, where the C99 compiler and C89 compilers are separate
> binaries.

In order to follow up this - very good - objection, the latest Single
Unix Specification requires solely a C99 compiler, and there's no talk
of that compiler's capability to fall back to C89. Thus, one should be
prepared that on SUS-conformant systems, there will be the necessity to
install a C89 compiler separately, so a mixed C89/99 project will need
two C compilers, and that's something CMake currently cannot cope with.
Of course, an obvious solution would be a shell script which scans its
arguments for a special dialect flag and subsequently invokes the C89
or the C99 compiler accordingly. However, such a combination of home-
brewed dialect flag and compiler wrapper script leads back again to

CC=<path/to/script> cmake <path/to/source>

for the project's initial configuration since the script will most
certainly not be detected as a compiler by CMake itself. Moreover,
the wrapper script wouldn't be universally available, so it will
probably remain a site-specific solution.

> I think the appropriate solution here is a project-specific dialect flag -
> perhaps one taking options in the GNU format since it seems most familiar.
> One could perhaps generalise this further - a file-specific dialect flag
> which defaults to the value of the project-specific flag

If there are individual compilers for C89/C99, and a projects needs a
C99 one, any dialect flags - project/directory/target/file specific -
would be of no use, wouldn't they? Rather, one must specify the C99
compiler if it isn't found automatically by CMake during the initial
configuration, and the project might consider to check the compiler's
C99 capabilities.

Regards,

Michael


More information about the CMake mailing list