0

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.

istarus
  • 181
  • 1
  • 6

1 Answers1

1

Try passing -Goutput_dir=bld/Example to gyp.

thakis
  • 5,405
  • 1
  • 33
  • 33
  • It does provide an answer to the question. Why do you think this is not an answer? – thakis Apr 09 '15 at 22:07
  • Because an answer should explain why it fix the issue. A comment say to *try it maybe work* but if you are not sure and you cannot explain way that should be just a comment. – Michele d'Amico Apr 09 '15 at 22:23
  • I'm reasonably sure that it'll work (I work on both gyp and ninja). I don't see a "maybe" in my answer. – thakis Apr 09 '15 at 22:36
  • 1
    I've not doubt that it works. But that doesn't mater, an answer is not just a *solution to solve a issue*, you should explain by cite documentation or sources or some valid argument the root of the issue and how to solve/fix it. Who read your answer should understand where it come and if what you say fit his requirements. This is why on SO this kind of answer are considerate off topic... But your answer is not the first and will be not the last like this. My comment it was just a tip. – Michele d'Amico Apr 09 '15 at 23:05