I'm new to moc, so pardon me if there's a better way of accomplishing this.
I hooked up a Qt project to gyp, and used gyp to generate it's 'moc' files as a separate target:
'targets':
[
{
'target_name': 'editor_generate_mocs',
'type': 'none',
'sources':
[
'src/editorwindow.h',
],
'direct_dependent_settings':
{
'sources':
[
'<(SHARED_INTERMEDIATE_DIR)/editorwindow_moc.cpp',
]
},
'rules':
[
{
'rule_name': 'generate_qt_mocs_rule',
'extension': '.h',
'msvs_cygwin_shell' : 0, # Don't run cygwin set_env to run a command.
'inputs':
[
'>(qt_dir)/bin/moc.exe',
],
'outputs':
[
'<(SHARED_INTERMEDIATE_DIR)/<(RULE_INPUT_ROOT)_moc.cpp',
],
'action':
[
'>(qt_dir)/bin/moc.exe',
'--compiler-flavor', 'msvc',
'<(RULE_INPUT_PATH)',
'-o', '<(SHARED_INTERMEDIATE_DIR)/<(RULE_INPUT_ROOT)_moc.cpp'
],
'message': '<(SHARED_INTERMEDIATE_DIR)/<(RULE_INPUT_ROOT)_moc.cpp'
}
]
},
# ..., rest of my targets
}
]
This works pretty great: however I don't like that in order to add another 'source' file, I'd have to add a line to the 'sources' section, as well as copy/paste the line in direct_dependent_settings for the output sources that are generated.
Ideally I'd love an automatic variable that the rule defines for the list of outputs ("<(RULE_OUTPUTS)"?), or possibly better would be a way to define a variable based on the list of sources; i.e., something like:
'targets':
[
{
'target_name': 'editor_generate_mocs',
'type': 'none',
'sources':
[
'src/editorwindow.h',
],
# Pseudo code begin
'variables':
{
'generated_moc_files': [ "<(SHARED_INTERMEDIATE_DIR)/%s_moc.cpp"%( path.basename(x) ) for x in <@(SOURCES)],
},
# End pseudo code
'direct_dependent_settings':
{
'sources': <@(generated_moc_files)
},
'rules':
[
{
'rule_name': 'generate_qt_mocs_rule',
'extension': '.h',
'msvs_cygwin_shell' : 0, # Don't run cygwin set_env to run a command.
'inputs':
[
'>(qt_dir)/bin/moc.exe',
],
'outputs':
[
'<(SHARED_INTERMEDIATE_DIR)/<(RULE_INPUT_ROOT)_moc.cpp',
],
'action':
[
'>(qt_dir)/bin/moc.exe',
'--compiler-flavor', 'msvc',
'<(RULE_INPUT_PATH)',
'-o', '<(SHARED_INTERMEDIATE_DIR)/<(RULE_INPUT_ROOT)_moc.cpp'
],
'message': '<(SHARED_INTERMEDIATE_DIR)/<(RULE_INPUT_ROOT)_moc.cpp'
}
]
},
# ..., rest of my targets
}
]
Is there a better way of accomplishing what I'm setting out to do?