• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1file(READ ${CMAKE_CURRENT_SOURCE_DIR}/version.txt _VERSION)
2set_property(GLOBAL PROPERTY EJDB2_NODE_VERSION_PROPERTY
3                             "${PROJECT_VERSION}.${_VERSION}")
4set(EJDB2_NODE_VERSION "${PROJECT_VERSION}.${_VERSION}")
5
6if(NOT DEFINED NODE_PUB_DIR)
7  set(NODE_PUB_DIR ${CMAKE_CURRENT_BINARY_DIR}/ejdb2_node)
8endif()
9if(NOT DEFINED NODE_BIN_ROOT)
10  set(NODE_BIN_ROOT ${NODE_PUB_DIR})
11endif()
12
13# Nodejs process.arch: 'arm', 'arm64', 'ia32', 'ppc', 'ppc64', 's390', 's390x',
14# 'x32', and 'x64
15if(MSVC64 OR MINGW64)
16  set(PROCESSOR x64)
17elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(amd64.*|x86_64.*|AMD64.*)")
18  set(PROCESSOR x64)
19elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(i686.*|i386.*|x86.*)")
20  set(PROCESSOR x32)
21elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(aarch64.*|AARCH64.*)")
22  set(PROCESSOR arm64)
23elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(arm.*|ARM.*)")
24  set(PROCESSOR arm)
25elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(powerpc|ppc)64.*")
26  set(PROCESSOR ppc64)
27elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(powerpc|ppc)")
28  set(PROCESSOR ppc)
29else()
30  set(PROCESSOR ${CMAKE_SYSTEM_PROCESSOR})
31endif()
32
33string(TOLOWER ${CMAKE_SYSTEM_NAME}-${PROCESSOR} NODE_BIN_SUFFIX)
34set(NODE_BIN_DIR ${NODE_BIN_ROOT}/${NODE_BIN_SUFFIX})
35
36find_program(YARN_EXEC yarn)
37if(YARN_EXEC MATCHES "YARN_EXEC-NOTFOUND")
38  message(FATAL_ERROR "`yarn` executable not found")
39endif()
40
41add_library(ejdb2_node MODULE ejdb2_node.c)
42target_link_libraries(ejdb2_node ejdb2_s ${PROJECT_LLIBRARIES})
43
44set_target_properties(
45  ejdb2_node
46  PROPERTIES OUTPUT_NAME ejdb2_node
47             PREFIX ""
48             SUFFIX ".node"
49             LIBRARY_OUTPUT_DIRECTORY ${NODE_BIN_DIR})
50
51target_compile_options(ejdb2_node PRIVATE -DIW_API_EXPORTS
52                                          -DNODE_ADDON_API_DISABLE_DEPRECATED)
53
54if(APPLE)
55  set_target_properties(
56    ejdb2_node PROPERTIES LINK_FLAGS "-rdynamic -undefined dynamic_lookup")
57else()
58  set_target_properties(
59    ejdb2_node PROPERTIES LINK_FLAGS
60                          "-rdynamic -Wl,--unresolved-symbols=ignore-all")
61endif()
62
63if(CMAKE_BUILD_TYPE STREQUAL "Release")
64  add_custom_command(
65    TARGET ejdb2_node
66    POST_BUILD
67    COMMAND ${STRIP_CMD} $<TARGET_FILE:ejdb2_node>)
68endif()
69
70configure_file(package.json ${NODE_PUB_DIR}/package.json @ONLY)
71configure_file(CHANGELOG.md ${NODE_PUB_DIR}/CHANGELOG.md @ONLY)
72configure_file(README.md ${NODE_PUB_DIR}/README.md COPYONLY)
73configure_file(yarn.lock ${NODE_PUB_DIR}/yarn.lock COPYONLY)
74configure_file(index.js ${NODE_PUB_DIR}/index.js COPYONLY)
75configure_file(index.d.ts ${NODE_PUB_DIR}/index.d.ts COPYONLY)
76configure_file(binary.js ${NODE_PUB_DIR}/binary.js COPYONLY)
77configure_file(utils.js ${NODE_PUB_DIR}/utils.js COPYONLY)
78configure_file(install.js ${NODE_PUB_DIR}/install.js COPYONLY)
79configure_file(test.js ${NODE_PUB_DIR}/test.js COPYONLY)
80
81add_custom_command(
82  COMMAND yarn --non-interactive --no-progress install
83  OUTPUT ${NODE_PUB_DIR}/node_modules
84  DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/yarn.lock
85          ${CMAKE_CURRENT_SOURCE_DIR}/package.json
86  WORKING_DIRECTORY ${NODE_PUB_DIR}
87  VERBATIM)
88add_custom_target(yarn ALL DEPENDS ${NODE_PUB_DIR}/node_modules)
89
90if(BUILD_TESTS)
91  add_test(
92    NAME ejdb2node
93    COMMAND ${YARN_EXEC} --non-interactive --no-progress run test
94    WORKING_DIRECTORY ${NODE_PUB_DIR})
95endif()
96