[CMake] Native build system invocation

gga ggarra at advancedsl.com.ar
Tue Dec 26 01:32:39 EST 2006


Roman Yakovenko wrote:
> On 12/26/06, gga <ggarra at advancedsl.com.ar> wrote:
>
> Thanks for help. I know how to invoke native build system. What I
> don't know how to make
> it in "portable" way - I don't what to know what is the native build
> system. CMake
> already knows it, so I would like to reuse that knowledge.
>
Hmm.... it isn't clear to me what your problem is.

There isn't much knowledge to cmake, really.  It basically boils down to:
    a) On windows, use nmake for the microsoft compiler
    b) On everything else (including compiling for windows'
cygwin/mingw), use make

The only tricky thing in windows is when people have a mixed environment
where they run cygwin bash for their console, but they still do all
their compilations using VisualStudio + nmake  (I work this way, and
most people I know that work in multiplatform projects do too).  Another
alternative on windows is msys+visual studio (which is now finally
becoming as solid as cygwin, without all its bloat).
But cmake will also probably get tripped about that unless the
CMakeList.txt file checks properly for that.

That's one of the reasons why you simple cannot make a wrapper script
that will work everywhere, as it depends on how people work on windows.

Anyway... coming back to it, cmake does not do anything special. 
My python is somewhat rusty (since I found ruby, I'm trying to do my
best to forget python exists as a language or that I wasted time of my
life to learn it and debug all of its headaches)... but... this will
work for people on windows that use cmd.exe and bash/tcsh/etc for all else:

#!/usr/bin/env python

import os

os.system("cmake .")

if os.name == "nt":
    os.system("nmake")
else:
    os.system("make")


Now, for more complex stuff, python's os.name does not distinguish
between cygwin, msys, and any linux os, and will just give you 'posix'
(unlike ruby's RUBY_PLATFORM that tells you EXACTLY the same as uname). 
Of course, to make matters worse, you may still be running a python that
does not correspond to the environment you will be compiling for...
which complicates things.
So... your best bet is something nasty like:

#!/usr/bin/env python

import os

os.system("cmake .")

if os.name == "nt":
    #
    # @todo:
    #
    # We are running a python compiled with the Microsoft compiler,
    # but user might still want to run a GNU Makefile, which should be
    # invoked by 'make'.
    # Only way to work around that is to open the Makefile and use a regex
    # to find any special GNU make setting (left as an exercise)
    #
    os.system("nmake")
else:
    # See if user set up the Microsoft compiler environment.
    # if he did, he might be using cygwin/msys with visual studio.
    if os.environ["MSVCDir"] or os.environ['VCINSTALLDIR']:
        os.system("nmake")
    else:
        os.system("make")

-- 
Gonzalo Garramuño
ggarra at advancedsl.com.ar

AMD4400 - ASUS48N-E
GeForce7300GT
Kubuntu Edgy



More information about the CMake mailing list