It consist command instructions required to build c++ code using cmake
//CMake minimum required version
cmake_minimum_required(VERSION 3.15)
// name of the addon
project (addon)
//set c++ language standard
set(CMAKE_CXX_STANDARD 17)
// include cmake-js files to build a node addon
include_directories(${CMAKE_JS_INC})
// location of the C++ source and napi files
file(GLOB SOURCE_FILES "src/*.cpp" "src/*.h")
// This line will tell CMake that we're building a shared library
// from the above source files
// named after the project's name
add_library(${PROJECT_NAME} SHARED ${SOURCE_FILES} ${CMAKE_JS_SRC})
// This line will give our library file a .node extension without any "lib" prefix
set_target_properties(${PROJECT_NAME} PROPERTIES PREFIX "" SUFFIX ".node")
// Essential library files to link to a node addon
target_link_libraries(${PROJECT_NAME} ${CMAKE_JS_LIB})
// Include N-API wrappers
execute_process(COMMAND node -p "require('node-addon-api').include"
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE NODE_ADDON_API_DIR
)
string(REPLACE "\\n" "" NODE_ADDON_API_DIR ${NODE_ADDON_API_DIR})
string(REPLACE "\\"" "" NODE_ADDON_API_DIR ${NODE_ADDON_API_DIR})
target_include_directories(${PROJECT_NAME} PRIVATE ${NODE_ADDON_API_DIR})