Açıklama Yok

FindNode.cmake 3.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. # Macro to add directory to NODEJS_INCLUDE_DIRS if it exists and is not /usr/include
  2. macro(add_include_dir dir)
  3. if (IS_DIRECTORY ${dir} AND NOT ${dir} STREQUAL "/usr/include")
  4. set(NODEJS_INCLUDE_DIRS ${NODEJS_INCLUDE_DIRS} ${dir})
  5. endif()
  6. endmacro()
  7. find_program (NODEJS_EXECUTABLE NAMES node nodejs
  8. HINTS
  9. $ENV{NODE_DIR}
  10. PATH_SUFFIXES bin
  11. DOC "Node.js interpreter"
  12. )
  13. include (FindPackageHandleStandardArgs)
  14. # If compat-libuv package exists, it must be at start of include path
  15. find_path (UV_ROOT_DIR "uv.h" PATHS /usr/include/compat-libuv010 NO_DEFAULT_PATH)
  16. if (UV_ROOT_DIR)
  17. # set (NODEJS_INCLUDE_DIRS ${UV_ROOT_DIR})
  18. add_include_dir(${UV_ROOT_DIR})
  19. endif()
  20. # Now look for node. Flag an error if not found
  21. find_path (NODE_ROOT_DIR "include/node/node.h" "include/src/node.h"
  22. PATHS /usr/include/nodejs /usr/local/include/nodejs /usr/local/include)
  23. if (NODE_ROOT_DIR)
  24. add_include_dir(${NODE_ROOT_DIR}/include/src)
  25. add_include_dir(${NODE_ROOT_DIR}/include/node)
  26. add_include_dir(${NODE_ROOT_DIR}/include/deps/v8/include)
  27. add_include_dir(${NODE_ROOT_DIR}/include/deps/uv/include)
  28. else()
  29. unset(NODEJS_INCLUDE_DIRS)
  30. message(ERROR " - node.h not found")
  31. endif()
  32. # Check that v8.h is in NODEJS_INCLUDE_DIRS
  33. find_path (V8_ROOT_DIR "v8.h" PATHS ${NODEJS_INCLUDE_DIRS})
  34. if (NOT V8_ROOT_DIR)
  35. unset(NODEJS_INCLUDE_DIRS)
  36. message(ERROR " - v8.h not found")
  37. endif()
  38. # Check that uv.h is in NODEJS_INCLUDE_DIRS
  39. find_path (UV_ROOT_DIR "uv.h" PATHS ${NODEJS_INCLUDE_DIRS})
  40. if (NOT UV_ROOT_DIR)
  41. unset(NODEJS_INCLUDE_DIRS)
  42. message(ERROR " - uv.h not found")
  43. endif()
  44. find_package_handle_standard_args (Nodejs DEFAULT_MSG
  45. NODEJS_EXECUTABLE
  46. NODEJS_INCLUDE_DIRS
  47. )
  48. if (NODEJS_EXECUTABLE)
  49. execute_process(COMMAND ${NODEJS_EXECUTABLE} --version
  50. OUTPUT_VARIABLE _VERSION
  51. RESULT_VARIABLE _NODE_VERSION_RESULT)
  52. execute_process(COMMAND ${NODEJS_EXECUTABLE} -e "console.log(process.versions.v8)"
  53. OUTPUT_VARIABLE _V8_VERSION
  54. RESULT_VARIABLE _V8_RESULT)
  55. if (NOT _NODE_VERSION_RESULT AND NOT _V8_RESULT)
  56. string (REPLACE "v" "" NODE_VERSION_STRING "${_VERSION}")
  57. string (REPLACE "." ";" _VERSION_LIST "${NODE_VERSION_STRING}")
  58. list (GET _VERSION_LIST 0 NODE_VERSION_MAJOR)
  59. list (GET _VERSION_LIST 1 NODE_VERSION_MINOR)
  60. list (GET _VERSION_LIST 2 NODE_VERSION_PATCH)
  61. set (V8_VERSION_STRING ${_V8_VERSION})
  62. string (REPLACE "." ";" _V8_VERSION_LIST "${_V8_VERSION}")
  63. string (REPLACE "." "" V8_DEFINE_STRING "${_V8_VERSION}")
  64. string (STRIP ${V8_DEFINE_STRING} V8_DEFINE_STRING)
  65. list (GET _V8_VERSION_LIST 0 V8_VERSION_MAJOR)
  66. list (GET _V8_VERSION_LIST 1 V8_VERSION_MINOR)
  67. list (GET _V8_VERSION_LIST 2 V8_VERSION_PATCH)
  68. # we end up with a nasty newline so strip everything that isn't a number
  69. string (REGEX MATCH "^[0-9]*" V8_VERSION_PATCH ${V8_VERSION_PATCH})
  70. else ()
  71. set (NODE_VERSION_STRING "0.10.30")
  72. set (NODE_VERSION_MAJOR "0")
  73. set (NODE_VERSION_MINOR "10")
  74. set (NODE_VERSION_PATCH "30")
  75. set (V8_VERSION_MAJOR "3")
  76. set (V8_VERSION_MINOR "28")
  77. set (V8_VERSION_PATCH "72")
  78. set (V8_VERSION_STRING "3.28.72")
  79. message ("defaulted to node 0.10.30")
  80. endif ()
  81. string (REGEX REPLACE "\n" "" NODE_VERSION_STRING ${NODE_VERSION_STRING})
  82. string (REGEX REPLACE "\n" "" V8_VERSION_STRING ${V8_VERSION_STRING})
  83. message ("INFO - Node version is " ${NODE_VERSION_STRING})
  84. message ("INFO - Node using v8 " ${V8_VERSION_STRING})
  85. mark_as_advanced (NODEJS_EXECUTABLE)
  86. endif ()
  87. mark_as_advanced (NODEJS_EXECUTABLE)