Skip to content

Commit

Permalink
Support external libnanomsg better for --use_system_libnanomsg=true
Browse files Browse the repository at this point in the history
nanomsg headers are installed in /usr/include/nanomsg.
However, depending on the version, nanomsg.pc provides either
-I/usr/include (useless) or -I/usr/include/nanomsg.

When using --use_system_libnanomsg=true, pass -DSYSTEM_NANOMSG=1
to the compiler.

Keep using the original includes when SYSTEM_NANOMSG is not defined.

Use #include <nanomsg/...> when SYSTEM_NANOMSG is defined because
it works regardless of the nanomsg version in the system.

Signed-off-by: Zoltán Böszörményi <[email protected]>
  • Loading branch information
zboszor committed Feb 8, 2024
1 parent 5d98b8f commit e4cb60f
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
6 changes: 6 additions & 0 deletions binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
'libraries': [
'<!@(pkg-config nanomsg --libs || echo "")'
],
'defines': [
'SYSTEM_NANOMSG=1',
],
}],
['OS=="mac" and use_system_libnanomsg=="true"', {
'include_dirs+': [
Expand All @@ -32,6 +35,9 @@
'libraries': [
'<!@(pkg-config nanomsg --libs || echo "")'
],
'defines': [
'SYSTEM_NANOMSG=1',
],
}],
['OS=="mac" and asan=="true"', {
'xcode_settings': {
Expand Down
27 changes: 27 additions & 0 deletions src/node_nanomsg.cc
Original file line number Diff line number Diff line change
@@ -1,16 +1,43 @@
#ifndef SYSTEM_NANOMSG

#include "bus.h"
#include "inproc.h"
#include "ipc.h"
#include "nn.h"
#include "pair.h"
#include "pipeline.h"

#else

#include "nanomsg/bus.h"
#include "nanomsg/inproc.h"
#include "nanomsg/ipc.h"
#include "nanomsg/nn.h"
#include "nanomsg/pair.h"
#include "nanomsg/pipeline.h"

#endif

#include "poll_ctx.h"

#ifndef SYSTEM_NANOMSG

#include "pubsub.h"
#include "reqrep.h"
#include "survey.h"
#include "tcp.h"
#include "ws.h"

#else

#include "nanomsg/pubsub.h"
#include "nanomsg/reqrep.h"
#include "nanomsg/survey.h"
#include "nanomsg/tcp.h"
#include "nanomsg/ws.h"

#endif

NAN_METHOD(Socket) {
int domain = Nan::To<int>(info[0]).FromJust();
int protocol = Nan::To<int>(info[1]).FromJust();
Expand Down
4 changes: 4 additions & 0 deletions src/poll_ctx.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#ifndef SYSTEM_NANOMSG
#include "nn.h"
#else
#include "nanomsg/nn.h"
#endif
#include "poll_ctx.h"

void PollCtx::on_readable(uv_poll_t* req, int /* status */, int events) {
Expand Down

0 comments on commit e4cb60f

Please sign in to comment.