[CMake] Question about c99

William A. Hoffman billlist at nycap.rr.com
Sat Apr 1 15:49:12 EST 2006


At 11:59 AM 4/1/2006, David wrote:
>Hello,
>
>This might be a stupid question but I'm new to c and cmake so I don't know 
>much about it yet.
>
>I would like to be able to use the for construct like this: 
>for(int i = 0; ..., 
>if I understand correctly I need c99 for this. I think I also need it for the 
>bool keyword. Is this correct?
>
>Do you know how I can tell cmake to compile my program as c99?
>
>Currently my CMakeLists.txt looks like this:
>
>PROJECT(UFO C)
>LINK_LIBRARIES(readline)
>ADD_EXECUTABLE(ufo ufo.c)

This really depends on the C compiler you are using.  You could use
try_compile to test and see if the compiler you are using supports the
feature, and if not, then you can simulate the feature with macros.

Create a try_compile that tests the above featues and sets some
value like C_COMPILER_IS_C99, then do something like this:

#ifndef C_COMPILER_IS_C99
#define for if(false) {} else for
#define bool int
#endif

But, if you are new to C, this would be a bit much.  You just have
to use a c99 compliant compiler, and possibly pass some flags to enable
the c99 features.

-Bill



More information about the CMake mailing list