[cmake-developers] [PATCH 0/3] The CMake Ninja generator.

Nicolas Desprès nicolas.despres at gmail.com
Fri Nov 18 04:00:52 EST 2011


2011/11/15 Bill Hoffman <bill.hoffman at kitware.com>

> On 11/15/2011 1:11 PM, Nicolas Desprès wrote:
>
>>
>>
>> 2011/11/15 Bill Hoffman <bill.hoffman at kitware.com
>> <mailto:bill.hoffman at kitware.**com <bill.hoffman at kitware.com>>>
>>
>>
>>    On 11/15/2011 12:54 PM, Nicolas Desprès wrote:
>>
>>        Too much in my opinion. Specially the && operator of the shell.
>>        Using
>>        cmake -E is the first step. I am planning to suggest an evolution
>> of
>>        Ninja to fix this issue. Actually, it is the main issue which
>>        stop me
>>        while writing the beginning of this generator.
>>        Cheers,
>>
>>
>>    What type of evolution will Ninja need?   I suppose it could use
>>    cmake scripts and exectue_process which can do && type things pretty
>>    easy.
>>
>>
>> Writting cmake script is one solution but since (at least when I started
>> the Ninja Generator) Ninja uses $in as input file for the build
>> statement it can be hard to pass to the cmake script.  I had a
>> discussion on this email some month ago about how to pass argument to
>> the cmake script. Maybe it will work using -D option. Not sure about
>> that. It is old in my mind and I have to check this out again.
>>
>
> -D will work, but is a bit ugly.  I see the ninja build files do not have
> a rule per file, but rather have production rules most of the time?


Actually you have rule statement like this one for instance:

# Rule for compiling CXX files.
rule CXX_COMPILER
  depfile = $out.d
  command = /usr/bin/c++   $DEFINES -MMD -MF $out.d $FLAGS -o $out -c $in
  description = Building CXX object $out

Where you can describe only one command and not a list of command. And you
have build statement where you mention outputs, inputs the rule to deals
with them and overload some variables. For example:

build Source/kwsys/CMakeFiles/cmsys.dir/SystemTools.cxx.o: CXX_COMPILER
../Source/kwsys/SystemTools.cxx
  DEFINES = -DKWSYS_NAMESPACE=cmsys
  FLAGS = -g -ISource -ISource/kwsys


>
>
>> In a general manner I wanted to prevent Ninja to spawn a shell which in
>> turn parse the command since it is not that portable on Windows and thus
>> to provide an alternative syntax to just spawn a process. Something
>> closer to "execute_process" than "system" to say it shortly.
>>
>>
> OK, so ninja does not have a native execute_process.  How is anyone doing
> anything with ninja on windows  right now?
>

Sorry for the delayed answer.  I wanted to take the time to have a look at
Ninja's source code to give the right answer. So actually, there is two
implementations of the Subprocess class. The one for Linux spawn a /bin/sh
whereas the one for Windows uses CreateProcessA():

  // Do not prepend 'cmd /c' on Windows, this breaks command
  // lines greater than 8,191 chars.
  if (!CreateProcessA(NULL, (char*)command.c_str(), NULL, NULL,
                      /* inherit handles */ TRUE, 0,
                      NULL, NULL,
                      &startup_info, &process_info)) {
    Win32Fatal("CreateProcess");
  }

So actually contrary to what I said before the Windows implementation is
quite good.

Finally, the only thing missing would be the ability to call several
commands if a cmake script is not enough.

Cheers,

-- 
Nicolas Desprès
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake-developers/attachments/20111118/287d09a4/attachment.html>


More information about the cmake-developers mailing list