2015-07-03 22 views
0

本來我綁定文件只有一個目標,並且已經精:重用構建條件

{ 
'targets': [ 
    { 
     'target_name': 'target1', 
     'sources': [ 'source1.cc', 'source2.cc' ], 
     'cflags_cc!': [ '-fno-rtti', '-fno-exceptions' ], 
     'cflags!': [ '-fno-exceptions' ], 
     'conditions': [ 
      #A very, very long condition 
     ] 
    }, 
} 

現在我需要另一個目標是或多或少相同,但建立一個可執行文件而不是鏈接對象。如果我複製原始目標,那就沒問題,但我不想重複condition,這完全一樣。我怎麼能這樣做?

E.g.我的理想bindin.gyp會看起來有點像這樣:

{ 
'conditions': [ 
    #A very, very long condition 
] 

'targets': [ 
    { 
     'target_name': 'target1', 
     'sources': [ 'source1.cc', 'source2.cc' ], 
     'cflags_cc!': [ '-fno-rtti', '-fno-exceptions' ], 
     'cflags!': [ '-fno-exceptions' ], 
     'conditions' : #Refer to the conditions stated above 
    }, 
    { 
     'target_name': 'target2', 
     'type' : 'executable' 
     'sources': [ 'source1.cc', 'source3.cc' ], 
     'cflags_cc!': [ '-fno-rtti', '-fno-exceptions' ], 
     'cflags!': [ '-fno-exceptions' ], 
     'conditions' : #Refer to the conditions stated above 
    }, 
} 

我嘗試使用variables但節點GYP只允許string類型或列表的變量,而「條件」是一個associative array

回答

0

我不是真的很確定,但是根據猜測,您可能會將長條件數組粘貼到第三個目標中,並依賴於來自其他兩個條件的目標。事情是這樣的:

{ 
'targets': [ 
    { 
     'target_name': 'conditions_target', 
     'conditions': [ 
      #A very, very long condition 
     ] 
    }, 
    { 
     'target_name': 'target1', 
     'sources': [ 'source1.cc', 'source2.cc' ], 
     'cflags_cc!': [ '-fno-rtti', '-fno-exceptions' ], 
     'cflags!': [ '-fno-exceptions' ], 
     'dependencies': [ 
      'conditions_target', 
     ], 
    }, 
    { 
     'target_name': 'target2', 
     'type' : 'executable' 
     'sources': [ 'source1.cc', 'source3.cc' ], 
     'cflags_cc!': [ '-fno-rtti', '-fno-exceptions' ], 
     'cflags!': [ '-fno-exceptions' ], 
     'dependencies': [ 
      'conditions_target', 
     ], 
    }, 
} 

但我不是很有經驗的節點GYP和可能打擊的事情了。 更多關於這裏的依賴:https://gyp.gsrc.io/docs/UserDocumentation.md#Dependencies-between-targets