Using a separate build directory with Gyp and Ninja

1.2k views Asked by At

The question I have deals with trying to use a separate directory for build output. In particular, I have the following directory/file structure:

src/
   Example/
      Hello.gyp
      HelloWorld.cpp
      HelloWorld.h
      Util.h
bld/
   Example/

Hello.gyp looks like this:

{
   'targets': [
      {
         'target_name': 'generated_code',
         'type': 'none',
         'actions': [
            {
               'action_name': 'cpp_compile',
               'inputs': [
                  'HelloWorld.cpp',
               ],
               'outputs': [
                  'a.out',
               ],
               'action': [
                  'g++', '<(_inputs)',
               ],
            },
         ],
      },
   ],
}

What I want to do is generate bld/Example/a.out (without doing something like mv) using ninja. I have tried the following:

(1)

% cd src/Example
% gyp Hello.gyp --depth=. --generator-output=../../bld/Example -f ninja
% cd ../../bld/Example
% ninja -C out/Default
ninja: Entering directory `out/Default'
[1/1] ACTION generated_code: cpp_compile_b5a6de50eda755567ffb7e384fc76492
% ls
out
% ls ../../src/Example/
Hello.gyp  HelloWorld.cpp  HelloWorld.h  Util.h  a.out

as well as

(2)

% cd bld/Example
% gyp ../../src/Example/Hello.gyp --depth=. -f ninja
% ninja -C out/Default
ninja: Entering directory `out/Default'
[1/1] ACTION generated_code: cpp_compile_fb764512ff3485761831ee0d8df0b433
% ls
out
% ls ../../src/Example
Hello.gyp  HelloWorld.cpp  HelloWorld.h  Util.h  a.out

Neither approach works since a.out is in src/Example instead of bld/Example. The problem seems to be that ninja does a cd into src/Example and runs g++ instead of running it inside bld/Example (where the ninja command is run). So what should I do differently in order to have a.out in bld/Example (so that it's equivalent to running g++ ../../src/Example/HelloWorld.cpp from bld/Example)?

Thanks.

1

There are 1 answers

4
thakis On

Try passing -Goutput_dir=bld/Example to gyp.