MantisBT - CMake
View Issue Details
0012300CMakeCMakepublic2011-06-22 16:492014-11-03 08:38
Todd Gamblin 
Stephen Kelly 
highfeaturealways
closedfixed 
AllAllAll
CMake 2.8.4 
CMake 3.1 
0012300: CMake has no cross-platform way to ask for C99
There is currently no good cross-platform way in CMake to specify that C files should be built for C99.

If you google for this, there are threads on the CMake list that suggest this:

    set(CMAKE_C_FLAGS "-std=c99")

However, that's the GNU way to enable C99, and other compilers do it differently. It would be nice if there were some flags for this set for you in whatever platform file you're using, e.g.:

    set(CMAKE_C_FLAGS "${CMAKE_ENABLE_C99}")

Or something to that effect. Then you'd pick up -qlanglvl=c99 for xlc, -std=c99 for gcc, etc.

Would it be reasonable to add this to platform files? CMAKE_SYSTEM_C99_FLAGS or something similar?

Note: for GNU there is std=c99 *and* std=gnu99, and one might need a way to prefer the latter. std=c99 is strict, and doesn't allow things (like inline asm) that other compilers allow in c99 mode. I'm not sure what the best way to get consistent behavior here would be. I would need to look at flags on some of the major compilers to figure this one out.

Should this be a variable or something else? A language mode seems like overkill (e.g. enable_language(C99)).
1. Start a project
2. Try to enable C99 without a giant multi-compiler if/else statement
3. Fail
Related email thread citing a need for this in VTK to eliminate warnings:

http://www.cmake.org/pipermail/cmake/2011-June/045072.html [^]
No tags attached.
related to 0013842closed Stephen Kelly No Support for C++11 
Issue History
2011-06-22 16:49Todd GamblinNew Issue
2011-10-21 08:33Olaf LenzNote Added: 0027605
2011-10-21 09:44Sean McBrideNote Added: 0027606
2012-08-11 21:09David ColeStatusnew => backlog
2012-08-11 21:09David ColeNote Added: 0030366
2013-03-13 17:10Ian Liu RodriguesNote Added: 0032618
2013-11-02 11:34Stephen KellyRelationship addedrelated to 0013842
2014-05-28 15:57Stephen KellyAssigned To => Stephen Kelly
2014-05-28 15:57Stephen KellyStatusbacklog => assigned
2014-05-28 15:57Stephen KellyNote Added: 0035958
2014-05-28 15:57Stephen KellyStatusassigned => resolved
2014-05-28 15:57Stephen KellyFixed in Version => CMake 3.1
2014-05-28 15:57Stephen KellyResolutionopen => fixed
2014-11-03 08:38Robert MaynardNote Added: 0037148
2014-11-03 08:38Robert MaynardStatusresolved => closed

Notes
(0027605)
Olaf Lenz   
2011-10-21 08:33   
I want to second.
(0027606)
Sean McBride   
2011-10-21 09:44   
The same need exists for C++. Any given .cxx file may be C++98, C++03, or C++11. Each very similar to the other, but none entirely compatible.
(0030366)
David Cole   
2012-08-11 21:09   
Sending old, never assigned issues to the backlog.

(The age of the bug, plus the fact that it's never been assigned to anyone means that nobody is actively working on it...)

If an issue you care about is sent to the backlog when you feel it should have been addressed in a different manner, please bring it up on the CMake mailing list for discussion. Sign up for the mailing list here, if you're not already on it: http://www.cmake.org/mailman/listinfo/cmake [^]

It's easy to re-activate a bug here if you can find a CMake developer who has the bandwidth to take it on, and ferry a fix through to our 'next' branch for dashboard testing.
(0032618)
Ian Liu Rodrigues   
2013-03-13 17:10   
I've made a very simple solution to this, by looking into Automake's code. It tries to compile a C program containing a number of C99 features.

Here is the example: https://gist.github.com/ianliu/5156223 [^]

I hope this can be of some use. Should the GPL notice become a problem tell me so I can change it.
(0035958)
Stephen Kelly   
2014-05-28 15:57   
The implementation of the 'compile features' concept is now in master:

 http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=ca5d990f [^] [^]

which includes several ways of requiring or optionally using C99 or C11 features. There are gaps in the compiler support matrix, but the functionality is in, and extending the compiler support can be recorded with other bug reports.
(0037148)
Robert Maynard   
2014-11-03 08:38   
Closing resolved issues that have not been updated in more than 4 months.