-
Notifications
You must be signed in to change notification settings - Fork 137
/
CMakeLists.txt
28 lines (22 loc) · 1.3 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
cmake_minimum_required(VERSION 3.15)
project(hello)
set(CMAKEJS_USING_CMAKEJS FALSE) # this should have been done with '--link-level=2' on the CLI, testing this way for now
# For CMake IDE tools support (do yarn/install first and keep your node_modules folder around)
if(NOT DEFINED CMAKE_JS_VERSION)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/node_modules/cmake-js/share/cmake")
endif()
include(CMakeJS)
add_library(addon SHARED "src/hello/addon.cpp")
target_link_libraries(addon PRIVATE cmake-js::node-addon-api) # relocatable deps resolved!
set_target_properties(addon PROPERTIES PREFIX "" SUFFIX ".node")
set_target_properties(addon PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
target_compile_definitions(addon PUBLIC BUILDING_NODE_EXTENSION)
target_compile_definitions(addon PUBLIC NAPI_VERSION=8)
target_compile_definitions(addon PUBLIC NAPI_CPP_EXCEPTIONS_MAYBE)
# For Visual Studio generators
if(MSVC)
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>" CACHE STRING "Select the MSVC runtime library for use by compilers targeting the MSVC ABI." FORCE)
if(CMAKE_JS_NODELIB_DEF AND CMAKE_JS_NODELIB_TARGET)
execute_process(COMMAND ${CMAKE_AR} /def:${CMAKE_JS_NODELIB_DEF} /out:${CMAKE_JS_NODELIB_TARGET} ${CMAKE_STATIC_LINKER_FLAGS})
endif()
endif()