[CMake] Enabling C99 in CMake

Todd Gamblin tgamblin at llnl.gov
Mon Jun 27 12:40:19 EDT 2011


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.

I think it would be acceptable if things failed later than that.  e.g., you could have:

> project(foo C CXX)

Suppose a C89-only compiler is detected.  The build now knows that's the only dialect it supports.  It should fail when it sees this later:

> 	set_target_properties(the_target PROPERTIES C_DIALECT C99)

If, however, there is a C99 file that does NOT have such a property set on it, I don't think there is anything you can do about that.  Here, the build would just fail when it tries to compile that file.  I think the right behavior is to keep the current behavior for files/targets/projects that do not have dialect properties set on them.

-Todd





> 
> -- Owen Shepherd
> http://www.owenshepherd.net
> owen.shepherd at e43.eu (general) / oshepherd1 at shef.ac.uk (academic)
> 
> 
> 
> 
> _______________________________________________
> 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

______________________________________________________________________
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