cmake编译node插件
如需转载请标明出处:http://blog.csdn.net/itas109
QQ技术交流群:129518033
文章目录
环境:
系统:centos 7
node: v12.13.0
cmake: v2.8.12
1.下载node模块
这里以odbc模块为例,下载地址:https://www.npmjs.com/package/odbc
npm i odbc
2.编写CMakeLists.txt
参考binding.gyp
project(libodbc)
cmake_minimum_required(VERSION 2.8)
MESSAGE(STATUS "operation system is ${CMAKE_SYSTEM}")
IF (CMAKE_SYSTEM_NAME MATCHES "Linux")
add_definitions(-std=gnu++11)
add_definitions(-DNAPI_EXPERIMENTAL)
add_compile_options(-Wall)
add_compile_options(-Wextra)
add_compile_options(-Wno-unused-parameter)
add_compile_options(-DNAPI_DISABLE_CPP_EXCEPTIONS)
#add_compile_options(-g)
include_directories(~/.cache/node-gyp/12.13.0/include/node)
include_directories(~/odbcTest/odbc/node_modules/node-addon-api)
include_directories(./src)
file(GLOB_RECURSE SOURCE_CPP ./src odbc.cpp odbc_connection.cpp odbc_statement.cpp dynodbc.cpp)
add_library( odbc SHARED ${SOURCE_CPP})
target_link_libraries( odbc -lodbc)
ELSE()
MESSAGE(FATAL_ERROR "not support platform: ${CMAKE_SYSTEM_NAME}")
ENDIF()
3.编译
mkdir bin
cmake ..
make
mv libodbc.so odbc.node
License
License under CC BY-NC-ND 4.0: 署名-非商业使用-禁止演绎
Reference:
NULL