Skip to content
Snippets Groups Projects
Commit e9826ae4 authored by Adrien Béraud's avatar Adrien Béraud Committed by Adrien Béraud
Browse files

cmake: add support for nodejs

Change-Id: Ia6e13fd3bd27077dac41b210a8dfac8d78ae6d2c
parent 544f35eb
Branches
No related tags found
No related merge requests found
......@@ -14,6 +14,7 @@ set(PROJECT_LABEL "libjami")
option(JAMI_NATPMP "Build with NAT-PMP" ON)
option(JAMI_PUPNP "Build with PUPNP" ON)
option(JAMI_PLUGIN "Build with plugin support" ON)
option(JAMI_NODEJS "Build the NODEJS binding" OFF)
option(JAMI_JNI "Build the JNI binding" OFF)
option(JAMI_DBUS "Build the DBUS binding" OFF)
option(JAMI_VIDEO "Build with video support" ON)
......@@ -36,6 +37,11 @@ endif()
include(CTest)
if(JAMI_NODEJS)
# Required for nodejs binding
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
endif()
if(NOT MSVC)
################################################################################
# Contrib
......@@ -623,6 +629,72 @@ else()
install (TARGETS ${PROJECT_NAME})
if (JAMI_NODEJS)
# Build nodejs binding
include (UseSWIG)
find_package(SWIG 4.2 COMPONENTS javascript REQUIRED)
file(GLOB NODEJS_INTERFACE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/bin/nodejs/*.i)
add_custom_command(
OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/bin/nodejs/jami_wrapper.cpp
COMMAND ${SWIG_EXECUTABLE} -v -c++ -javascript -node -o jami_wrapper.cpp nodejs_interface.i
DEPENDS
${NODEJS_INTERFACE_FILES}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/bin/nodejs
)
# Generate binding.gyp
# We need to pass the link flags to node-gyp
set(_gyp_flags "")
get_target_property(_linked_libs ${PROJECT_NAME} LINK_LIBRARIES)
foreach(LIB IN LISTS _linked_libs)
if ("${LIB}" MATCHES "^PkgConfig::")
string(REPLACE "PkgConfig::" "" PKG_NAME ${LIB})
string(APPEND _gyp_flags " ${${PKG_NAME}_LDFLAGS}")
elseif ("${LIB}" MATCHES ".so$")
get_filename_component(LIB_DIRECTORY ${LIB} DIRECTORY)
get_filename_component(LIB_NAME_WE ${LIB} NAME_WE)
string(REPLACE "lib" "" LIB_NAME_WE ${LIB_NAME_WE})
string(APPEND _gyp_flags " -L${LIB_DIRECTORY} -l${LIB_NAME_WE}")
elseif (TARGET ${LIB})
# TODO generate cmake targets automatically
#string(APPEND _gyp_flags " $<TARGET_FILE:${LIB}>")
else()
string(APPEND _gyp_flags " -l${LIB}")
endif()
endforeach()
list(REVERSE _gyp_flags)
list(REMOVE_DUPLICATES _gyp_flags)
list(REVERSE _gyp_flags)
foreach(item ${_gyp_flags})
if (NOT "${QUOTED_JSON_LIST}" STREQUAL "")
set(QUOTED_JSON_LIST "${QUOTED_JSON_LIST},")
endif()
set(QUOTED_JSON_LIST "${QUOTED_JSON_LIST}\"${item}\"")
endforeach()
string(REPLACE ";" "," _gyp_flags_str ${QUOTED_JSON_LIST})
set(JAMI_LINK_LIBRARIES ${_gyp_flags_str})
set(JAMI_LINK_DIRECTORIES ${CMAKE_CURRENT_BINARY_DIR})
configure_file(
${CMAKE_SOURCE_DIR}/bin/nodejs/binding.gyp.in
${CMAKE_SOURCE_DIR}/bin/nodejs/binding.gyp
)
# Build nodejs binding
add_custom_target(jamid
ALL
COMMAND node-gyp rebuild --target=v18.19.1 --arch=x64
DEPENDS
${CMAKE_CURRENT_SOURCE_DIR}/bin/nodejs/binding.gyp
${CMAKE_CURRENT_SOURCE_DIR}/bin/nodejs/callback.h
${CMAKE_CURRENT_SOURCE_DIR}/bin/nodejs/jami_wrapper.cpp
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/bin/nodejs
)
add_dependencies(jamid ${PROJECT_NAME})
endif()
if (JAMI_JNI)
# Build jni binding
add_library(${PROJECT_NAME}-jni SHARED ${CMAKE_CURRENT_SOURCE_DIR}/bin/jni/jami_wrapper.cpp)
......
FROM ubuntu:22.04 AS jami-daemon
ARG DEBIAN_FRONTEND=noninteractive
ARG config_args
ARG cmake_args
RUN apt-get update && apt-get install -y \
autoconf \
automake \
......@@ -45,14 +45,16 @@ RUN apt-get update && apt-get install -y \
guile-3.0-dev \
nasm \
pkg-config \
yasm
yasm \
libcppunit-dev \
sip-tester
# Install Node
RUN curl -fsSL https://deb.nodesource.com/setup_16.x | bash - && \
RUN curl -fsSL https://deb.nodesource.com/setup_18.x | bash - && \
apt-get install -y nodejs && \
npm install -g node-gyp
# Install latest Swig (4.1)
# Install latest Swig (4.2)
WORKDIR /swig
RUN git clone https://github.com/swig/swig.git && \
cd swig && \
......@@ -62,17 +64,11 @@ RUN git clone https://github.com/swig/swig.git && \
make install
WORKDIR /daemon
COPY contrib/ contrib/
# Build daemon dependencies
RUN mkdir -p contrib/native && \
cd contrib/native && \
../bootstrap && \
make -j$(nproc)
COPY . .
# Build the daemon
RUN ./autogen.sh && \
./configure $config_args && \
RUN mkdir -p build && \
cd build && \
cmake .. $cmake_args && \
make -j$(nproc)
......@@ -198,7 +198,7 @@ docker build --tag jami-daemon .
# To build with custom build args
```bash
docker build --tag jami-daemon --build-arg config_args="--with-nodejs" .
docker build --tag jami-daemon --build-arg cmake_args="-DJAMI_NODEJS=On" .
```
Common Issues
......
jami_wrapper.cpp
binding.gyp
build/
\ No newline at end of file
......@@ -4,10 +4,12 @@
"target_name": "jamid",
"sources": [ "jami_wrapper.cpp" ],
'include_dirs': ['../../src/'],
'libraries': ['-L<(module_root_dir)/../../src/.libs', '-ljami'],
"ldflags": ["-Wl,-Bsymbolic"],
'libraries': ['-L@JAMI_LINK_DIRECTORIES@', '-ljami-core', '-lyaml-cpp', @JAMI_LINK_LIBRARIES@],
'cflags!': [ '-fno-exceptions' ],
'cflags_cc!': [ '-fno-exceptions', '-fno-rtti', '-std=gnu++1y' ],
'cflags_cc': [ '-std=gnu++17' ]
'cflags_cc': [ '-std=gnu++17' ],
}
]
],
'variables' : { 'openssl_fips': '' }
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment