I recently had an issue where my IDE (Visual Studio) had no support for CMake.js and this was my solution.
This solution sets up all the CMake.js variables. By defining CMAKE_JS_INC
and CMAKE_JS_LIB
for use in your project.
Just call setup_cmakejs()
to define the variables. It is also compatible with Windows development environments. Linux and macOS are untested, but assumedly work just fine.
Happy coding!
Here's an example just in case you need it:
cmake_minimum_required(VERSION 3.2.2)
include("cmakejs.cmake")
setup_cmakejs()
project (my_project_name)
include_directories(${CMAKE_JS_INC})
file(GLOB SOURCE_FILES "main.cpp")
add_library(${PROJECT_NAME} SHARED ${SOURCE_FILES} ${CMAKE_JS_SRC})
set_target_properties(${PROJECT_NAME} PROPERTIES
PREFIX ""
SUFFIX ".node"
RUNTIME_OUTPUT_DIRECTORY ${ARTIFACTS_DIRECTORY}
LINKER_LANGUAGE CXX
)
target_link_libraries(${PROJECT_NAME} ${CMAKE_JS_LIB})
Thank you so much! I'm relatively new to node.js and trying to setup a C++ project with Node.js, Vue.js + Electron front end. I got the front end architecture running in a day or two but I've been struggling with C++ integration for a week! Especially troublesome was Clion integration with Cmake-js (4 days wasted on this).
Your code finally saved me! Thank you!