forked from laftho/node-nfc-nci
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
77 lines (59 loc) · 2.13 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
cmake_minimum_required(VERSION 3.22.0)
# Include ExternalProject module
include(ExternalProject)
# Name of the project (will be the name of the plugin)
project(node-nfc-nci)
# Variables
set(VENDOR_PREFIX "${CMAKE_SOURCE_DIR}/vendor")
set(VENDOR_INCLUDES "${VENDOR_PREFIX}/include")
set(VENDOR_LIBS "${VENDOR_PREFIX}/lib")
if(EXISTS "${CMAKE_SOURCE_DIR}/node_modules/")
set(NODE_MODULES_PREFIX "${CMAKE_CURRENT_SOURCE_DIR}/node_modules")
else()
set(NODE_MODULES_PREFIX "${CMAKE_CURRENT_SOURCE_DIR}/../../")
endif()
# Resolve common make command
find_program(MAKE_EXE NAMES gmake nmake make)
# Source files
file(GLOB SOURCE_FILES "src/*.cpp" "src/*.h")
#
# nfc nci linux library
#
ExternalProject_Add(libnfc_nci_linux
GIT_REPOSITORY https://github.com/vhs/linux_libnfc-nci.git
GIT_SHALLOW 1
UPDATE_DISCONNECTED 1
PREFIX ${VENDOR_PREFIX}
CONFIGURE_COMMAND ./setup.sh ./configure --enable-alt --prefix ${VENDOR_PREFIX}
BUILD_COMMAND ${MAKE_EXE}
BUILD_IN_SOURCE 1
LOG_DIR "${VENDOR_PREFIX}/logs"
LOG_CONFIGURE 1
LOG_BUILD 1
BUILD_BYPRODUCTS "${VENDOR_LIBS}/libnfc_nci_linux.so"
)
# Build a shared library named after the project from the files in `src/`
add_library(${PROJECT_NAME} SHARED ${SOURCE_FILES})
# Gives our library file a .node extension without any "lib" prefix
set_target_properties(${PROJECT_NAME} PROPERTIES PREFIX "" SUFFIX ".node")
#
# Includes
#
# Common node includes
target_include_directories(${PROJECT_NAME} PRIVATE "/usr/include/node")
# Node Addon API
target_include_directories(${PROJECT_NAME} PRIVATE "${NODE_MODULES_PREFIX}/node-addon-api")
# Node API
target_include_directories(${PROJECT_NAME} PRIVATE "${NODE_MODULES_PREFIX}/node-api-headers/include")
# Project dependencies
target_include_directories(${PROJECT_NAME} PRIVATE ${VENDOR_INCLUDES})
# Required CMake includes
target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_JS_INC})
#
# Linking
#
# Required CMake targets
target_link_libraries(${PROJECT_NAME} ${CMAKE_JS_LIB})
# Add nfc library dependency
add_dependencies(${PROJECT_NAME} libnfc_nci_linux)
target_link_libraries(${PROJECT_NAME} "${VENDOR_LIBS}/libnfc_nci_linux.so")