Skip to content

Commit

Permalink
Use post_config.gypi to use shared libraries
Browse files Browse the repository at this point in the history
Node can be compiled with external shared libraries;
in this case append their compile and linker flags last.
  • Loading branch information
saper committed Aug 17, 2017
1 parent 7245415 commit bcb3f7f
Showing 1 changed file with 31 additions and 2 deletions.
33 changes: 31 additions & 2 deletions lib/configure.js
Expand Up @@ -33,6 +33,7 @@ function configure (gyp, argv, callback) {
, buildDir = path.resolve('build')
, configNames = [ 'config.gypi', 'common.gypi' ]
, configs = []
, post_configs = []
, nodeDir
, release = processRelease(argv, gyp, process.version, process.release)

Expand Down Expand Up @@ -110,20 +111,35 @@ function configure (gyp, argv, callback) {

var configFilename = 'config.gypi'
var configPath = path.resolve(buildDir, configFilename)
var postConfigFilename = 'post_config.gypi'
var postConfigPath = path.resolve(buildDir, postConfigFilename)

log.verbose('build/' + configFilename, 'creating config file')

var config = process.config || {}
, defaults = config.target_defaults
, variables = config.variables
, fallback_target_defaults = {}

// default "config.variables"
if (!variables) variables = config.variables = {}

// default "config.defaults"
if (!defaults) defaults = config.target_defaults = {}

// don't inherit the "defaults" from node's `process.config` object.
if ( variables.node_shared_cares ||
variables.node_shared_http_parser ||
variables.node_shared_libuv ||
variables.node_shared_openssl ||
variables.node_shared_zlib ) {
Object.keys(defaults).forEach(function (entry) {
if (entry in {'cflags': 1, 'defines': 1, 'include_dirs': 1, 'libraries': 1}) {
fallback_target_defaults[entry] = defaults[entry]
}
})
}
// if node engine does not have to rely on shared libraries in the system
// do not inherit the "defaults" from node's `process.config` object.
// doing so could cause problems in cases where the `node` executable was
// compiled on a different machine (with different lib/include paths) than
// the machine where the addon is being built to
Expand Down Expand Up @@ -186,7 +202,17 @@ function configure (gyp, argv, callback) {
, json = JSON.stringify(config, boolsToString, 2)
log.verbose('build/' + configFilename, 'writing out config file: %s', configPath)
configs.push(configPath)
fs.writeFile(configPath, [prefix, json, ''].join('\n'), findConfigs)
fs.writeFile(configPath, [prefix, json, ''].join('\n'), function() {

var config = {
"target_defaults": fallback_target_defaults
}
, prefix = '# Do not edit. File was generated by node-gyp\'s "configure" step'
, json = JSON.stringify(config, boolsToString, 2)
log.verbose('build/' + postConfigFilename, 'writing out config file: %s', postConfigPath)
post_configs.push(postConfigPath)
fs.writeFile(postConfigPath, [prefix, json, ''].join('\n'), findConfigs)
})
}

function findConfigs (err) {
Expand Down Expand Up @@ -291,6 +317,9 @@ function configure (gyp, argv, callback) {

argv.push('-I', addon_gypi)
argv.push('-I', common_gypi)
post_configs.forEach(function (config) {
argv.push('-I', config)
})
argv.push('-Dlibrary=shared_library')
argv.push('-Dvisibility=default')
argv.push('-Dnode_root_dir=' + nodeDir)
Expand Down

0 comments on commit bcb3f7f

Please sign in to comment.