Skip to content

Commit 42e79c6

Browse files
committed
Add workaround for find nodejs headers.
1 parent 59f986b commit 42e79c6

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

cmake/FindNodeJS.cmake

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,30 @@ if(NOT NODEJS_LIBRARY)
352352
endif()
353353

354354
if(NOT NODEJS_INCLUDE_DIR)
355+
# TODO: Headers are not properly installed, instead of placing all of them in the same folder
356+
# they are placed in different folders after install (deps/{v8,uv}), this workaround will solve
357+
# the include dependency problem, but this needs to be refactored in the future for properly handling headers,
358+
# meanwhile we will install them manually
359+
360+
# NodeJS download and output path (workaround to compile node as a shared library)
361+
set(NODEJS_DOWNLOAD_URL "https://nodejs.org/dist/v${NODEJS_VERSION}/node-v${NODEJS_VERSION}-headers.tar.gz")
362+
set(NODEJS_DOWNLOAD_FILE "${CMAKE_CURRENT_BINARY_DIR}/node-v${NODEJS_VERSION}-headers.tar.gz")
363+
set(NODEJS_OUTPUT_PATH "${CMAKE_CURRENT_BINARY_DIR}/node-v${NODEJS_VERSION}-headers")
364+
365+
# Download node if needed
366+
if(NOT EXISTS "${NODEJS_DOWNLOAD_FILE}")
367+
message(STATUS "Downloading NodeJS headers")
368+
file(DOWNLOAD ${NODEJS_DOWNLOAD_URL} ${NODEJS_DOWNLOAD_FILE})
369+
endif()
370+
371+
# Decompress node if needed
372+
if(NOT EXISTS "${NODEJS_OUTPUT_PATH}")
373+
message(STATUS "Extract NodeJS headers")
374+
execute_process(COMMAND ${CMAKE_COMMAND} -E tar "xvf" "${NODEJS_DOWNLOAD_FILE}" WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}" OUTPUT_QUIET)
375+
endif()
376+
377+
set(NODEJS_INCLUDE_PATHS ${NODEJS_OUTPUT_PATH})
378+
355379
# Find NodeJS includes
356380
find_path(NODEJS_INCLUDE_DIR ${NODEJS_HEADERS}
357381
PATHS ${NODEJS_INCLUDE_PATHS}

0 commit comments

Comments
 (0)