Quantcast
Viewing all articles
Browse latest Browse all 7427

C/C++ • Re: Working with node-gyp and C++, is there a way to make a dependency on a particular library optional?

Here's a somewhat, but not fully satisfactory solution, which requires a user to install the module like this:

npm install node-dht-sensor --use_libgpiod=true

...if they need (or want... this does work on a RPi 4 too) to use libgpiod, allowing the standard installation without the extra parameter to impose no new library dependencies.

Code:

{  "targets": [    {      "variables": {        "dht_verbose%": "false",        "use_libgpiod%" : "false"      },      "target_name": "node_dht_sensor",      "sources": [        "src/bcm2835/bcm2835.c",        "src/node-dht-sensor.cpp",        "src/dht-sensor.cpp",        "src/util.cpp",        "src/abstract-gpio.cpp",      ],      "include_dirs": [        "<!@(node -p \"require('node-addon-api').include\")"      ],      "dependencies": [        "<!(node -p \"require('node-addon-api').gyp\")"      ],      "defines": [ 'NAPI_DISABLE_CPP_EXCEPTIONS' ],      "conditions": [        ["dht_verbose=='true'", {          "defines": [ "VERBOSE" ]        }],        ["use_libgpiod=='true'", {          "defines": [ "USE_LIBGPIOD" ],          'libraries': [            '-lgpiod'          ]        }]      ]    }  ]}
What I'd really like to do, however, if it's at all possible, is to replace "use_libgpiod=='true'" with something automatic, the moral equivalent of "available(libgpiod)" or "exists('/usr/include/gpiod.h')", in case any such node-gyp capability exists which simply can't be easily found in the documentation.

Statistics: Posted by kshetline — Fri Feb 14, 2025 3:12 am



Viewing all articles
Browse latest Browse all 7427

Trending Articles