3131# NodeJS_EXECUTABLE_ONLY - Find only NodeJS executable (avoid library and include files)
3232# NodeJS_SHARED_UV - If it is enabled, libuv won't be required by this script
3333# NodeJS_BUILD_FROM_SOURCE - If it is enabled, NodeJS runtime library will be built from source
34+ # NodeJS_BUILD_WITHOUT_ICU - If it is enabled, NodeJS runtime library will be built without internationalization support
3435# NodeJS_INSTALL_PREFIX - Define a custom install prefix for NodeJS (Linux / Darwin only)
3536
3637# Prevent vervosity if already included
@@ -41,6 +42,7 @@ endif()
4142option (NodeJS_CMAKE_DEBUG "Print paths for debugging NodeJS dependencies." OFF )
4243option (NodeJS_SHARED_UV "If it is enabled, libuv won't be required by this script." OFF )
4344option (NodeJS_BUILD_FROM_SOURCE "If it is enabled, NodeJS runtime library will be built from source." OFF )
45+ option (NodeJS_BUILD_WITHOUT_ICU "If it is enabled, NodeJS runtime library will be built without internationalization support." OFF )
4446
4547# Include package manager
4648include (FindPackageHandleStandardArgs)
@@ -100,12 +102,14 @@ set(NodeJS_INCLUDE_PATHS
100102)
101103
102104# Find NodeJS executable
103- find_program (NodeJS_EXECUTABLE
104- NAMES node nodejs node.exe
105- HINTS ${NodeJS_PATHS}
106- PATH_SUFFIXES bin
107- DOC "NodeJS JavaScript Runtime Interpreter"
108- )
105+ if (NOT NodeJS_EXECUTABLE)
106+ find_program (NodeJS_EXECUTABLE
107+ NAMES node nodejs node.exe
108+ HINTS ${NodeJS_PATHS}
109+ PATH_SUFFIXES bin
110+ DOC "NodeJS JavaScript Runtime Interpreter"
111+ )
112+ endif ()
109113
110114if (NodeJS_EXECUTABLE)
111115 # Detect NodeJS version
@@ -159,67 +163,69 @@ if(NodeJS_EXECUTABLE)
159163 endif ()
160164endif ()
161165
162- if (NOT NodeJS_INCLUDE_DIR)
163- # Find NodeJS includes
164- find_path (NodeJS_INCLUDE_DIR
165- NAMES ${NodeJS_HEADERS}
166- PATHS ${NodeJS_INCLUDE_PATHS}
167- PATH_SUFFIXES ${NodeJS_INCLUDE_SUFFIXES}
168- DOC "NodeJS JavaScript Runtime Headers"
169- )
170- endif ()
166+ if (NOT NodeJS_BUILD_FROM_SOURCE)
167+ if (NOT NodeJS_INCLUDE_DIR)
168+ # Find NodeJS includes
169+ find_path (NodeJS_INCLUDE_DIR
170+ NAMES ${NodeJS_HEADERS}
171+ PATHS ${NodeJS_INCLUDE_PATHS}
172+ PATH_SUFFIXES ${NodeJS_INCLUDE_SUFFIXES}
173+ DOC "NodeJS JavaScript Runtime Headers"
174+ )
175+ endif ()
171176
172- # Check if the include directory contains all headers in the same folder
173- if (NodeJS_INCLUDE_DIR)
174- foreach (HEADER IN ITEMS ${NodeJS_HEADERS} )
175- if (NOT EXISTS ${NodeJS_INCLUDE_DIR} /${HEADER} )
176- message (WARNING "NodeJS header ${HEADER} not found in ${NodeJS_INCLUDE_DIR} " )
177- unset (NodeJS_INCLUDE_DIR CACHE )
178- break ()
179- endif ()
180- endforeach ()
181- endif ()
177+ # Check if the include directory contains all headers in the same folder
178+ if (NodeJS_INCLUDE_DIR)
179+ foreach (HEADER IN ITEMS ${NodeJS_HEADERS} )
180+ if (NOT EXISTS ${NodeJS_INCLUDE_DIR} /${HEADER} )
181+ message (WARNING "NodeJS header ${HEADER} not found in ${NodeJS_INCLUDE_DIR} " )
182+ unset (NodeJS_INCLUDE_DIR CACHE )
183+ break ()
184+ endif ()
185+ endforeach ()
186+ endif ()
182187
183- # Find NodeJS V8 includes
184- if (NOT NodeJS_V8_INCLUDE_DIR)
185- find_path (NodeJS_V8_INCLUDE_DIR
186- NAMES ${NodeJS_V8_HEADERS}
187- PATHS ${NodeJS_INCLUDE_PATHS}
188- PATH_SUFFIXES ${NodeJS_INCLUDE_SUFFIXES}
189- DOC "NodeJS JavaScript Runtime V8 Headers"
190- )
191- endif ()
188+ # Find NodeJS V8 includes
189+ if (NOT NodeJS_V8_INCLUDE_DIR)
190+ find_path (NodeJS_V8_INCLUDE_DIR
191+ NAMES ${NodeJS_V8_HEADERS}
192+ PATHS ${NodeJS_INCLUDE_PATHS}
193+ PATH_SUFFIXES ${NodeJS_INCLUDE_SUFFIXES}
194+ DOC "NodeJS JavaScript Runtime V8 Headers"
195+ )
196+ endif ()
192197
193- # Check if the include directory contains all headers in the same folder
194- if (NodeJS_V8_INCLUDE_DIR)
195- foreach (HEADER IN ITEMS ${NodeJS_V8_HEADERS} )
196- if (NOT EXISTS ${NodeJS_V8_INCLUDE_DIR} /${HEADER} )
197- message (WARNING "NodeJS header ${HEADER} not found in ${NodeJS_V8_INCLUDE_DIR} " )
198- unset (NodeJS_V8_INCLUDE_DIR CACHE )
199- break ()
200- endif ()
201- endforeach ()
202- endif ()
198+ # Check if the include directory contains all headers in the same folder
199+ if (NodeJS_V8_INCLUDE_DIR)
200+ foreach (HEADER IN ITEMS ${NodeJS_V8_HEADERS} )
201+ if (NOT EXISTS ${NodeJS_V8_INCLUDE_DIR} /${HEADER} )
202+ message (WARNING "NodeJS header ${HEADER} not found in ${NodeJS_V8_INCLUDE_DIR} " )
203+ unset (NodeJS_V8_INCLUDE_DIR CACHE )
204+ break ()
205+ endif ()
206+ endforeach ()
207+ endif ()
203208
204- # Find NodeJS UV includes
205- if (NOT NodeJS_UV_INCLUDE_DIR)
206- find_path (NodeJS_UV_INCLUDE_DIR
207- NAMES ${NodeJS_UV_HEADERS}
208- PATHS ${NodeJS_INCLUDE_PATHS}
209- PATH_SUFFIXES ${NodeJS_INCLUDE_SUFFIXES}
210- DOC "NodeJS JavaScript Runtime UV Headers"
211- )
212- endif ()
209+ # Find NodeJS UV includes
210+ if (NOT NodeJS_UV_INCLUDE_DIR)
211+ find_path (NodeJS_UV_INCLUDE_DIR
212+ NAMES ${NodeJS_UV_HEADERS}
213+ PATHS ${NodeJS_INCLUDE_PATHS}
214+ PATH_SUFFIXES ${NodeJS_INCLUDE_SUFFIXES}
215+ DOC "NodeJS JavaScript Runtime UV Headers"
216+ )
217+ endif ()
213218
214- # Check if the include directory contains all headers in the same folder
215- if (NodeJS_UV_INCLUDE_DIR)
216- foreach (HEADER IN ITEMS ${NodeJS_UV_HEADERS} )
217- if (NOT EXISTS ${NodeJS_UV_INCLUDE_DIR} /${HEADER} )
218- message (WARNING "NodeJS header ${HEADER} not found in ${NodeJS_UV_INCLUDE_DIR} " )
219- unset (NodeJS_UV_INCLUDE_DIR CACHE )
220- break ()
221- endif ()
222- endforeach ()
219+ # Check if the include directory contains all headers in the same folder
220+ if (NodeJS_UV_INCLUDE_DIR)
221+ foreach (HEADER IN ITEMS ${NodeJS_UV_HEADERS} )
222+ if (NOT EXISTS ${NodeJS_UV_INCLUDE_DIR} /${HEADER} )
223+ message (WARNING "NodeJS header ${HEADER} not found in ${NodeJS_UV_INCLUDE_DIR} " )
224+ unset (NodeJS_UV_INCLUDE_DIR CACHE )
225+ break ()
226+ endif ()
227+ endforeach ()
228+ endif ()
223229endif ()
224230
225231# Download includes in case they are not distributed
@@ -447,6 +453,12 @@ if(NOT NodeJS_LIBRARY)
447453 set (NodeJS_BUILD_TYPE release)
448454 endif ()
449455
456+ if (NodeJS_BUILD_WITHOUT_ICU)
457+ set (BUILD_ICU_FLAGS without-intl)
458+ else ()
459+ set (BUILD_ICU_FLAGS)
460+ endif ()
461+
450462 # Building NodeJS 14 as library in Windows is broken (so we need to patch it)
451463 if (WIN32 AND NodeJS_VERSION_MAJOR GREATER_EQUAL 14)
452464 find_package (Python COMPONENTS Interpreter REQUIRED)
@@ -463,7 +475,7 @@ if(NOT NodeJS_LIBRARY)
463475 endif ()
464476
465477 execute_process (
466- COMMAND vcbuild.bat dll ${NodeJS_BUILD_TYPE} ${NodeJS_COMPILE_ARCH} ${NodeJS_MSVC_VER}
478+ COMMAND vcbuild.bat dll ${NodeJS_BUILD_TYPE} ${NodeJS_COMPILE_ARCH} ${NodeJS_MSVC_VER} ${BUILD_ICU_FLAGS}
467479 WORKING_DIRECTORY "${NodeJS_OUTPUT_PATH} "
468480 )
469481
@@ -484,32 +496,32 @@ if(NOT NodeJS_LIBRARY)
484496 else ()
485497 message (STATUS "Configure NodeJS shared library" )
486498
487- # Select the ICU library depending on the NodeJS version
488- if ("${NodeJS_VERSION_MAJOR} " GREATER_EQUAL "18" )
489- set (ICU_URL "https://github.com/unicode-org/icu/releases/download/release-71-1/icu4c-71_1-src.zip" )
490- elseif ("${NodeJS_VERSION_MAJOR} " GREATER_EQUAL "16" )
491- set (ICU_URL "https://github.com/unicode-org/icu/releases/download/release-69-1/icu4c-69_1-src.zip" )
492- elseif ("${NodeJS_VERSION_MAJOR} " GREATER_EQUAL "15" )
493- set (ICU_URL "https://github.com/unicode-org/icu/releases/download/release-67-1/icu4c-67_1-src.zip" )
494- elseif ("${NodeJS_VERSION_MAJOR} " GREATER_EQUAL "14" )
495- set (ICU_URL "https://github.com/unicode-org/icu/releases/download/release-66-1/icu4c-66_1-src.zip" )
496- elseif ("${NodeJS_VERSION_MAJOR} " GREATER_EQUAL "12" )
497- set (ICU_URL "https://github.com/unicode-org/icu/releases/download/release-65-1/icu4c-65_1-src.zip" )
498- elseif ("${NodeJS_VERSION_MAJOR} " GREATER_EQUAL "10" )
499- set (ICU_URL "https://github.com/unicode-org/icu/releases/download/release-64-2/icu4c-64_2-src.zip" )
500- endif ()
501-
502- if ("${CMAKE_BUILD_TYPE} " STREQUAL "Debug" )
503- set (ICU_DEBUG --debug)
499+ if (NodeJS_BUILD_WITHOUT_ICU)
500+ set (BUILD_ICU_FLAGS "--without-intl" )
504501 else ()
505- set (ICU_DEBUG)
506- endif ()
502+ # Select the ICU library depending on the NodeJS version
503+ if ("${NodeJS_VERSION_MAJOR} " GREATER_EQUAL "18" )
504+ set (ICU_URL "https://github.com/unicode-org/icu/releases/download/release-72-1/icu4c-72_1-src.zip" )
505+ elseif ("${NodeJS_VERSION_MAJOR} " GREATER_EQUAL "16" )
506+ set (ICU_URL "https://github.com/unicode-org/icu/releases/download/release-69-1/icu4c-69_1-src.zip" )
507+ elseif ("${NodeJS_VERSION_MAJOR} " GREATER_EQUAL "15" )
508+ set (ICU_URL "https://github.com/unicode-org/icu/releases/download/release-67-1/icu4c-67_1-src.zip" )
509+ elseif ("${NodeJS_VERSION_MAJOR} " GREATER_EQUAL "14" )
510+ set (ICU_URL "https://github.com/unicode-org/icu/releases/download/release-66-1/icu4c-66_1-src.zip" )
511+ elseif ("${NodeJS_VERSION_MAJOR} " GREATER_EQUAL "12" )
512+ set (ICU_URL "https://github.com/unicode-org/icu/releases/download/release-65-1/icu4c-65_1-src.zip" )
513+ elseif ("${NodeJS_VERSION_MAJOR} " GREATER_EQUAL "10" )
514+ set (ICU_URL "https://github.com/unicode-org/icu/releases/download/release-64-2/icu4c-64_2-src.zip" )
515+ endif ()
507516
508- # Workaround for OpenSSL bug: https://github.com/metacall/core/issues/223
509- if (APPLE )
510- set (ICU_ENV_VAR ${CMAKE_COMMAND} -E env PYTHONHTTPSVERIFY=0)
511- else ()
512- set (ICU_ENV_VAR)
517+ # Workaround for OpenSSL bug: https://github.com/metacall/core/issues/223
518+ if (APPLE )
519+ set (ICU_ENV_VAR ${CMAKE_COMMAND} -E env PYTHONHTTPSVERIFY=0)
520+ else ()
521+ set (ICU_ENV_VAR)
522+ endif ()
523+
524+ set (BUILD_ICU_FLAGS "--with-icu-source=${ICU_URL} " )
513525 endif ()
514526
515527 if (NodeJS_INSTALL_PREFIX)
@@ -518,7 +530,17 @@ if(NOT NodeJS_LIBRARY)
518530 set (NodeJS_PREFIX)
519531 endif ()
520532
521- execute_process (COMMAND ${ICU_ENV_VAR} sh -c "./configure ${NodeJS_PREFIX} --with-icu-source=${ICU_URL} --shared ${ICU_DEBUG} " WORKING_DIRECTORY "${NodeJS_OUTPUT_PATH} " )
533+ if ("${CMAKE_BUILD_TYPE} " STREQUAL "Debug" )
534+ set (BUILD_DEBUG "--debug" )
535+
536+ if (OPTION_BUILD_SANITIZER)
537+ set (BUILD_DEBUG "${BUILD_DEBUG} --enable-asan" )
538+ endif ()
539+ else ()
540+ set (BUILD_DEBUG)
541+ endif ()
542+
543+ execute_process (COMMAND ${ICU_ENV_VAR} sh -c "./configure ${NodeJS_PREFIX} ${BUILD_ICU_FLAGS} --shared ${BUILD_DEBUG} " WORKING_DIRECTORY "${NodeJS_OUTPUT_PATH} " )
522544
523545 message (STATUS "Build NodeJS shared library" )
524546
0 commit comments