node-gyp is a build generator for node addon development, similar to cmake. However, it's default for node and requires fewer configuration.

Set variables

{
  "variables": {
    "heads_sdk_ver": "1.23"
  },
  "targets": [
    {
      'libraries': [
        "<(module_root_dir)/heads-cpp-sdk/lib/Release/libnats_framework.so.<(heads_sdk_ver)",
      ]
    }
  ]
}

Set variables under variables key, then use it with `<(var_name)`. Some default variables are also useful, like `module_root_dir` meaning the project base directory.

Conditional compilation

{
    'conditions': [
        ['OS=="win"', {
            'defines': [],
            'libraries': [],
            'include_dirs': [],
        }],
        ['OS=="linux"', {
        }],
    ]
}

Spread build specific fields under conditions structure. They'll be merged into main build config.

Copy files

{
    'copies': [
        {
            "destination": "<(module_root_dir)/build/Release/",
            "files": [
                "<(module_root_dir)/nats-sdk/win/x64/Release/nats.dll",
            ]
        },
    ]
}

If you need to copy some file after build, eg assets or dynamic libraries, put them under copies key.

Set rpath under linux

{
    "link_settings": {
        "libraries": [
            "-Wl,-rpath,'$$ORIGIN'",
        ],
    },
}

addon built on linux link to dynamic libraries using absolute path. This path will change on deployment machines. Set this rpath argument to overwrite rpath setting.