[CMake] building c code as c++ code

John Pretz pretz at umdgrb.umd.edu
Sun Jun 10 10:55:14 EDT 2007


Hi,

I am evaluating the possibility of using cmake to build the code for a 
c/c++ project I'm working on.  The code is mostly legacy code, so for 
the purposes of this question, please assume that I cannot change the 
code or rename the files.

There is a c and c++ part to this codebase.  The c stuff is straight c 
but builds with either a c or c++ compiler.  The c++  portion links to 
the c portion, but it links to it assuming it was built using a c++ 
compiler, so there are no 'extern "C"{}' guards around included c 
headers.  All of the c code has a .c extension.

What I need to do is convince cmake that this .c source code is supposed 
to be compiled with a c++ compiler.  If I rename the files (foo.c -> 
foo.cxx), it builds correctly, but again, assume I'm not allowed to 
modify the files.

I've googled around and looked at the cmake wiki and documentation.  I 
cannot find anything that really does this.

I've prepared a slimmed-down example of the situation I'm in.  Please 
see the attached tarball.  It should compile, but not link. Simply 
renaming the 'say_hi_cstyle.c' file to 'say_hi_cstyle.cxx', and it 
builds fine, so I imagine it'll work great if I can just convince cmake 
of what I want.

If anybody knows how do this, any help would be appreciated.

Thanks for looking,

John
-------------- next part --------------
A non-text attachment was scrubbed...
Name: cmake-example.tgz
Type: application/x-gzip
Size: 926 bytes
Desc: not available
Url : http://public.kitware.com/pipermail/cmake/attachments/20070610/1062de4e/cmake-example.bin


More information about the CMake mailing list