[CMake] Enabling C99 in CMake

Hendrik Sattler post at hendrik-sattler.de
Tue Jun 28 01:26:30 EDT 2011


Am Montag, 27. Juni 2011, 18:40:19 schrieb Todd Gamblin:
> On Jun 26, 2011, at 7:12 AM, Owen Shepherd wrote:
> > On 25/06/2011 07:30, "Michael Hertling" <mhertling at online.de> wrote:
> >> On 06/24/2011 04:16 PM, Owen Shepherd wrote:
> >>> 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.
> > 
> > Sorry - I should have said property rather than flag. That is, something
> > along the lines of
> > 
> > 	set_target_properties(the_target PROPERTIES C_DIALECT C99)
> > 
> > Or
> > 
> > 	set_source_files_properties(myfile.c PROPERTIES C_DIALECT C99)
> > 
> > (I'm not entirely sure here whether the source file property should be
> > C_DIALECT or just DIALECT. The language, after all, should be unambiguous
> > at this point)
> > 
> > It would then be the responsibility of the Cmake machinery to choose the
> > right compiler and set it up for building code with the given dialect.
> 
> I *think* Michael's concern here is that if you have a project that uses
> C99, it should fail as fast as possible, e.g. when it knows that the
> detected/provided compiler does not support C99 as it processes the
> 'project' command at the beginning of the CMakeLists.txt file.

Please keep in mind that porjects might use _some_ but not all aspects of C99 
because they want to support a compiler like MSVC which is not fully C99 
compatible. What do you want to do with those?

Also the project might have adding header files (e.g. unofficial versions of 
inttypes.h and stdint.h for MSVC) to allow usage of C99 although the plain 
compiler does not support that.

HS


More information about the CMake mailing list