On 06/23/2011 05:09 AM, Todd Gamblin wrote:
> On Jun 22, 2011, at 3:46 PM, Michael Hertling wrote:
> 
>> Wouldn't a simple
>>
>> CC="gcc -std=c99" cmake <path/to/source>
>>
>> for the initial configuration be an appropriate solution?
> 
> I would say no, because whether or not the project is written in C99 or not 
> isn't something the caller of cmake should have to know.  It's something the 
> developers should know, and whoever is building the code shouldn't have to 
> care.
> 
> -Todd

While I can understand your point, I'm of a different opinion: In the
end, it's the responsibility of the user to provide the project with a
suitable compiler. The fact that CMake usually finds one automatically
is very convenient, but not self-evident, so I'd take it as absolutely
normal to specify the compiler used to build the project. Compare the
following two cases:

(1) You want to use, say, /opt/gcc-4.7/bin/gcc for your project. Of
course, CMake doesn't find this compiler by itself, so you issue

CC=/opt/gcc-4.7/bin/gcc cmake <path/to/source>

for the project's initial configuration.

(2) You need to use a C99 compiler for your project, but CMake invokes
the C99-capable GCC without the -std=c99 switch, so you issue

CC="gcc -std=c99" cmake <path/to/source>

for the project's initial configuration.

Case (1) is widely accepted, and case (2) doesn't differ basically from
(1), IMO; in both cases, you specify a desired/needed compiler for your
project, or in other words: A specification of your project's compiler
is not limited to the latter's location in the file system, but might
also span very well compiler-specific switches like the -std=c99 one.
Of course, that's just my personal opinion, but in doing so, you do
not need to modify any CMake files or even the CMakeLists.txt files
of your project; all you need is to have a C99 compiler available.

However, you might possibly add a check to your project, e.g. using
TRY_COMPILE() or CheckCSourceCompiles(), with C99 source code a C89
compiler can't build, and if this check fails, you can notify the
user of the need to reconfigure and specify a C99 compiler. If a
project must use the GNU compiler, one would do quite the same.

Regards,

Michael
_______________________________________________
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

Reply via email to