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})
If you define the CMake variable for NPM_COMMAND with the desired package manager's executable elsewhere in your project (i.e. prior to function being called) you should be able to get this functionality. As far as I know, the syntax used above should work with yarn and will
almost definitely work with pnpm.