• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (c) 2021-2024 Huawei Device Co., Ltd.
2# Licensed under the Apache License, Version 2.0 (the "License");
3# you may not use this file except in compliance with the License.
4# You may obtain a copy of the License at
5#
6# http://www.apache.org/licenses/LICENSE-2.0
7#
8# Unless required by applicable law or agreed to in writing, software
9# distributed under the License is distributed on an "AS IS" BASIS,
10# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11# See the License for the specific language governing permissions and
12# limitations under the License.
13
14
15# Create js plugin
16#
17# Example usage:
18#   panda_ets_interop_js_plugin(plugin_name
19#     SOURCES
20#       path/to/file0.cpp
21#       path/to/file1.cpp
22#     LIBRARIES
23#       lib_name0
24#       lib_name1
25#     LIBRARY_OUTPUT_DIRECTORY
26#   )
27function(panda_ets_interop_js_plugin TARGET)
28    # Parse arguments
29    cmake_parse_arguments(
30        ARG
31        ""
32        "LIBRARY_OUTPUT_DIRECTORY"
33        "SOURCES;LIBRARIES"
34        ${ARGN}
35    )
36
37    if(NOT DEFINED ARG_LIBRARY_OUTPUT_DIRECTORY)
38        # Set default value
39        set(ARG_LIBRARY_OUTPUT_DIRECTORY ${PANDA_BINARY_ROOT}/lib/module)
40    endif()
41
42    panda_add_library(${TARGET} SHARED ${ARG_SOURCES})
43    panda_target_link_libraries(${TARGET} ${ARG_LIBRARIES})
44
45    if(PANDA_TARGET_OHOS)
46        panda_target_link_libraries(${TARGET} ace_napi.z  -Wl,--no-undefined)
47    else()
48        panda_target_include_directories(${TARGET} SYSTEM PRIVATE ${NAPI_HEADERS_PATH})
49        set_target_properties(${TARGET}
50            PROPERTIES
51                # Set module name
52                PREFIX ""
53                OUTPUT_NAME "${TARGET}"
54                SUFFIX ".node"
55
56                # Set output direcory
57                LIBRARY_OUTPUT_DIRECTORY ${ARG_LIBRARY_OUTPUT_DIRECTORY}
58        )
59    endif()
60endfunction(panda_ets_interop_js_plugin)
61
62set(NODE_BINARY "node")
63if(NOT PANDA_TARGET_OHOS AND NOT NAPI_HEADERS_PATH)
64    if (NOT PANDA_TARGET_AMD64 OR NOT PANDA_TARGET_LINUX)
65        message(FATAL_ERROR "By default interop is supported on linux-x64 and OHOS. Set NAPI_HEADERS_PATH to use on other platforms")
66    endif()
67
68    set(NODE_VERSION "v18.13.0")
69    set(DISTRO "linux-x64")
70
71    execute_process(COMMAND ${PANDA_ROOT}/scripts/install-third-party --node
72            WORKING_DIRECTORY ${PANDA_ROOT}
73            RESULT_VARIABLE NODEJS_DOWNLOAD_OK)
74    if (NOT NODEJS_DOWNLOAD_OK EQUAL 0)
75        message(FATAL_ERROR "Unable to install required nodejs dependencies")
76    endif()
77
78    set(NAPI_HEADERS_PATH ${PANDA_ROOT}/third_party/nodejs/node-${NODE_VERSION}-${DISTRO}/include/node)
79    set(NODE_BINARY ${PANDA_ROOT}/third_party/nodejs/node-${NODE_VERSION}-${DISTRO}/bin/node)
80endif()
81