[CMake] Selecting compiler on Windows platform

Josef Karthauser joe.karthauser at geomerics.com
Tue Oct 23 05:28:42 EDT 2007


> -----Original Message-----
> From: cmake-bounces+joe.karthauser=geomerics.com at cmake.org
> [mailto:cmake-bounces+joe.karthauser=geomerics.com at cmake.org] On Behalf
> Of Josef Karthauser
> Sent: 22 October 2007 13:59
> To: a.neundorf-work at gmx.net; cmake at cmake.org
> Subject: RE: [CMake] Selecting compiler on Windows platform
> 
> > > However, I’d like to control this from within a CMake file, and
> this
> > > doesn’t appear possible.  From what I can see,
> > CMakeDetermineCXXCompiler is
> > > loaded and executed prior to the CMakeLists.txt file, which means
> > that I
> > > cannot set the compiler internally.  Is this true,
> >
> > Yes, this is true.
> > One reason is that one build tree must not use several compilers for
> > one language, because all the configure checks are global for one
> > build tree and so the results are only correct for the compiler which
> > was used when they were executed.
> 
> This seems overly restrictive, a tree might contain a number of sub-
> trees which use different compilers.  Whilst I understand the need to
> keep things consistent by default, if a user wants to shoot themselves
> in the foot it ought to be allowed.  (Tools not policy! :)
> 
> I guess I'm going to have to run CMakeDetermineCXXCompiler again
> myself. :/.

For the record, I've solved the problem by setting the environment variables that I require and then running the the determine and test modules again, like so:

   SET(ENV{CC} gcc)
   SET(ENV{CXX} g++)
   INCLUDE(CMakeDetermineCCompiler)
   INCLUDE(CMakeDetermineCXXCompiler)
   INCLUDE(CMakeTestCCompiler)
   INCLUDE(CMakeTestCXXCompiler)

This appears to work, although it of course doesn't disable the initial automatic compiler test.

Joe


More information about the CMake mailing list