I'm writing binding.gyp
file for my new node.js module. I have all my source files under src/
subdirectory. I would like to use all of them while building the module. Instead of modifying binding.gyp each time I add a new cpp file, I would like to list all cpp files through some wildcard mechanism. Does node-gyp support that? Something like following (which doesn't work
{
'targets' : [
{
'target_name' : 'mymod',
'sources' : 'src/*.cpp'
}
]
}
I looked at https://code.google.com/p/gyp/wiki/InputFormatReference , but didn't find anything readily useful.
Figured it out
{
'targets' : [
{
'target_name' : 'mymod',
'sources' : [ '<!@(ls -1 src/*.cpp)' ],
}
]
}
Check out this link
Update
The solution above is not portable across platforms. Here's a portable version:
{
'targets' : [
{
'target_name' : 'mymod',
'sources' : [ "<!@(node -p \"require('fs').readdirSync('./src').map(f=>'src/'+f).join(' ')\")" ],
}
]
}
Essentially it replaces the platform specific directory listing command (ls
), by Javascript code that uses node's fs
module to list the directory contents.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With