[CMake] What is the proper way to force compiler?

J Decker d3ck0r at gmail.com
Tue Mar 2 15:27:47 EST 2010


On Tue, Mar 2, 2010 at 11:36 AM, Alexander Neundorf
<a.neundorf-work at gmx.net> wrote:
> On Tuesday 02 March 2010, J Decker wrote:
>> I'd like to know why I have to do this at the end of each CMakeLists.txt...
>>
>> if( C++ )
>>   set( CMAKE_C_COMPILER "${CMAKE_CXX_COMPILER}" )
>>   set( CMAKE_C_COMPILE_OBJECT "${CMAKE_CXX_COMPILE_OBJECT}" )
>> endif()
>
> in general, you shouldn't have to do this at all.
> This is only for very exotic circumstances.
> Why do you actually do that at all ?
>

Actually there are properties on the source files to make this change
rather than forcing it... but, I do it because there are features that
compile better with C++.  Although C Compilers often give me a way to
hook into their runtime init (code that is run before main) it's
easier (and more standard) to implement static classes that do the same
deadstart initialization.

Although the code is C, renaming all the files to C++ isn't really proper.

Plus, the code will even compile with /CLR under visual studio and be
'managed', but that requires compilation as C++.

> Alex
>


More information about the CMake mailing list