summaryrefslogtreecommitdiff
path: root/cmake
diff options
context:
space:
mode:
authorTom Hughes <tom.hughes@palm.com>2010-11-22 10:31:40 -0600
committerRyan Dahl <ry@tinyclouds.org>2010-11-22 13:32:49 -0800
commit446beebd79d52b24bd8d9e0a44f6378a711f32b9 (patch)
tree021d60bfdb825519ab102213c65efb5299e6a2db /cmake
parentb52b4196ab22227aea7afef100c4ca8e2f1b8729 (diff)
downloadnodejs-446beebd79d52b24bd8d9e0a44f6378a711f32b9.tar.gz
nodejs-446beebd79d52b24bd8d9e0a44f6378a711f32b9.tar.bz2
nodejs-446beebd79d52b24bd8d9e0a44f6378a711f32b9.zip
Add cmake build support.
Squashed commit of ca128f7dcd28cbcfba154c8577ed54d4aa71dd02 with contributions from Mark Constable (markc@renta.net) and Daniel Gröber (darklord@darkboxed.org).
Diffstat (limited to 'cmake')
-rw-r--r--cmake/CTestCustom.cmake2
-rw-r--r--cmake/configure.cmake93
-rw-r--r--cmake/docs.cmake80
-rw-r--r--cmake/libc-ares.cmake18
-rw-r--r--cmake/libev.cmake10
-rw-r--r--cmake/libs.cmake39
-rw-r--r--cmake/libv8.cmake15
-rw-r--r--cmake/node_build.cmake76
-rw-r--r--cmake/package.cmake33
-rw-r--r--cmake/tests.cmake86
-rw-r--r--cmake/v8_build.cmake88
11 files changed, 540 insertions, 0 deletions
diff --git a/cmake/CTestCustom.cmake b/cmake/CTestCustom.cmake
new file mode 100644
index 000000000..65af3254c
--- /dev/null
+++ b/cmake/CTestCustom.cmake
@@ -0,0 +1,2 @@
+set(CTEST_CUSTOM_PRE_TEST "sh -c \"rm -rf ../test/tmp && mkdir ../test/tmp\"")
+set(CTEST_CUSTOM_POST_TEST ${CTEST_CUSTOM_PRE_TEST})
diff --git a/cmake/configure.cmake b/cmake/configure.cmake
new file mode 100644
index 000000000..2a4cf10d9
--- /dev/null
+++ b/cmake/configure.cmake
@@ -0,0 +1,93 @@
+#
+# configure node for building
+#
+include(CheckFunctionExists)
+
+
+if(NOT "v${CMAKE_BUILD_TYPE}" MATCHES vDebug)
+ set(CMAKE_BUILD_TYPE "Release")
+endif()
+
+string(TOLOWER ${CMAKE_SYSTEM_NAME} node_platform)
+
+# Get system architecture
+if(${CMAKE_SYSTEM_PROCESSOR} MATCHES i686*)
+ set(node_arch x86)
+elseif(${CMAKE_SYSTEM_PROCESSOR} MATCHES i386*)
+ set(node_arch x86)
+else()
+ set(node_arch ${CMAKE_SYSTEM_PROCESSOR})
+endif()
+
+if(${node_arch} MATCHES unknown)
+ set(node_arch x86)
+endif()
+
+
+# Copy tools directory for out-of-source build
+string(COMPARE EQUAL $(PROJECT_BINARY_DIR) ${PROJECT_SOURCE_DIR} in_source_build)
+if(NOT ${in_source_build})
+ execute_process(COMMAND cmake -E copy_directory ${PROJECT_SOURCE_DIR}/tools ${PROJECT_BINARY_DIR}/tools)
+endif()
+
+# Set some compiler/linker flags..
+set(CMAKE_C_FLAGS_DEBUG "-O0 -Wall -g -Wextra -DDEBUG $ENV{CFLAGS}")
+set(CMAKE_CXX_FLAGS_DEBUG "-O0 -Wall -g -Wextra -DDEBUG $ENV{CXXFLAGS}")
+
+set(CMAKE_C_FLAGS_RELEASE "-g -O3 -DNDEBUG $ENV{CFLAGS}")
+set(CMAKE_CXX_FLAGS_RELEASE "-g -O3 -DNDEBUG $ENV{CXXFLAGS}")
+
+if(${node_platform} MATCHES sunos)
+ # shouldn't this be added to CMAE_C_FLAGS or something?
+ add_definitions(-threads)
+elseif(NOT ${node_platform} MATCHES cygwin*)
+ # shouldn't this be added to CMAE_C_FLAGS or something?
+ add_definitions(-pthread)
+ set(CMAKE_C_FLAGS -rdynamic)
+ set(CMAKE_EXE_LINKER_FLAGS -pthread)
+endif()
+
+if(${node_platform} MATCHES darwin)
+ set(CMAKE_EXE_LINKER_FLAGS "-framework Carbon")
+endif()
+
+check_function_exists(fdatasync HAVE_FDATASYNC)
+if(HAVE_FDATASYNC)
+ add_definitions(-DHAVE_FDATASYNC=1)
+else()
+ add_definitions(-DHAVE_FDATASYNC=0)
+endif()
+
+add_definitions(
+ -DPLATFORM=${node_platform}
+ -DX_STACKSIZE=65536
+ -D_LARGEFILE_SOURCE
+ -D_FILE_OFFSET_BITS=64
+ -DEV_MULTIPLICITY=0
+ )
+
+# set the exec output path to be compatible with the current waf build system
+if(${CMAKE_BUILD_TYPE} MATCHES Debug)
+ set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/debug/)
+else()
+ set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/default/)
+endif()
+
+#
+## ---------------------------------------------------------
+#
+
+file(GLOB js2c_files ${PROJECT_SOURCE_DIR}/lib/*.js)
+set(js2c_files ${PROJECT_SOURCE_DIR}/src/node.js ${js2c_files})
+file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/src)
+
+set(PREFIX ${CMAKE_INSTALL_PREFIX})
+if(${CMAKE_BUILD_TYPE} MATCHES Debug)
+ set(CCFLAGS "${CMAKE_C_FLAGS_DEBUG} ${CMAKE_C_FLAGS}")
+else()
+ set(CCFLAGS "${CMAKE_C_FLAGS_RELEASE} ${CMAKE_C_FLAGS}")
+endif()
+get_directory_property(compile_defs COMPILE_DEFINITIONS)
+foreach(def ${compile_defs})
+ set(CPPFLAGS "${CPPFLAGS} -D${def}")
+endforeach()
diff --git a/cmake/docs.cmake b/cmake/docs.cmake
new file mode 100644
index 000000000..dcf37e040
--- /dev/null
+++ b/cmake/docs.cmake
@@ -0,0 +1,80 @@
+#
+# docs
+#
+
+file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/doc)
+
+set(node_binary ${PROJECT_BINARY_DIR}/default/node)
+set(doctool tools/doctool/doctool.js)
+set(changelog_html ${PROJECT_BINARY_DIR}/doc/changelog.html)
+
+file(GLOB_RECURSE doc_sources RELATIVE ${PROJECT_SOURCE_DIR} doc/*)
+
+foreach(FILE ${doc_sources})
+ string(REGEX REPLACE "(.*)api_assets(.*)" "\\1api/assets\\2" OUT_FILE ${FILE})
+ add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/${OUT_FILE}
+ COMMAND ${CMAKE_COMMAND} -E copy_if_different ${PROJECT_SOURCE_DIR}/${FILE} ${PROJECT_BINARY_DIR}/${OUT_FILE}
+ DEPENDS ${PROJECT_SOURCE_DIR}/${FILE}
+ )
+ list(APPEND doc_sources_copy ${PROJECT_BINARY_DIR}/${OUT_FILE})
+endforeach()
+
+file(GLOB_RECURSE api_markdown RELATIVE ${PROJECT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}/doc/api/*)
+
+foreach(file ${api_markdown})
+ string(REGEX REPLACE "(.*)\\.markdown" "\\1" tmp ${file})
+ set(api_basenames ${api_basenames} ${tmp})
+endforeach()
+
+foreach(api ${api_basenames})
+ set(api_html ${api_html} ${PROJECT_BINARY_DIR}/${api}.html)
+ add_custom_command(
+ OUTPUT "${PROJECT_BINARY_DIR}/${api}.html"
+ COMMAND ${node_binary} ${doctool} ${PROJECT_BINARY_DIR}/doc/template.html "${PROJECT_BINARY_DIR}/${api}.markdown" > "${PROJECT_BINARY_DIR}/${api}.html"
+ WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
+ DEPENDS node ${doctool} ${doc_sources_copy}
+ VERBATIM
+ )
+endforeach()
+
+add_custom_target(
+ doc
+ DEPENDS node ${doc_sources_copy} ${api_html} ${changelog_html}
+ WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
+ )
+
+#add_custom_command(
+# OUTPUT ${PROJECT_BINARY_DIR}/doc/api.html
+# COMMAND ${PROJECT_BINARY_DIR}/default/node tools/ronnjs/bin/ronn.js --fragment doc/api.markdown
+# | sed "s/<h2>\\\(.*\\\)<\\/h2>/<h2 id=\"\\1\">\\1<\\/h2>/g"
+# | cat doc/api_header.html - doc/api_footer.html > ${PROJECT_BINARY_DIR}/doc/api.html
+# WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
+# DEPENDS node doc/api.markdown doc/api_header.html doc/api_footer.html
+# VERBATIM
+# )
+
+add_custom_command(
+ OUTPUT ${changelog_html}
+ COMMAND ${node_binary} ${doctool} doc/template.html ChangeLog
+ | sed "s|assets/|api/assets/|g"
+ | sed "s|<body>|<body id=\"changelog\">|g" > ${changelog_html}
+ WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
+ DEPENDS ChangeLog node ${doctool} ${doc_sources_copy}
+ VERBATIM
+ )
+
+#add_custom_command(
+# OUTPUT ${PROJECT_BINARY_DIR}/doc/changelog.html
+# COMMAND cat doc/changelog_header.html ChangeLog doc/changelog_footer.html > ${PROJECT_BINARY_DIR}/doc/changelog.html
+# WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
+# DEPENDS ChangeLog doc/changelog_header.html doc/changelog_footer.html
+# VERBATIM
+# )
+
+#add_custom_command(
+# OUTPUT ${PROJECT_BINARY_DIR}/doc/node.1
+# COMMAND ${PROJECT_BINARY_DIR}/default/node tools/ronnjs/bin/ronn.js --roff doc/api.markdown > ${PROJECT_BINARY_DIR}/doc/node.1
+# WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
+# DEPENDS node doc/api.markdown tools/ronnjs/bin/ronn.js
+# VERBATIM
+# )
diff --git a/cmake/libc-ares.cmake b/cmake/libc-ares.cmake
new file mode 100644
index 000000000..939864ace
--- /dev/null
+++ b/cmake/libc-ares.cmake
@@ -0,0 +1,18 @@
+if(SHARED_CARES)
+ find_library(LIBCARES_LIBRARY NAMES cares)
+ find_path(LIBCARES_INCLUDE_DIR ares.h
+ PATH_SUFFIXES include
+ ) # Find header
+ find_package_handle_standard_args(libcares DEFAULT_MSG LIBCARES_LIBRARY LIBCARES_INCLUDE_DIR)
+else()
+ set(cares_arch ${node_arch})
+
+ if(${node_arch} MATCHES x86_64)
+ set(cares_arch x64)
+ elseif(${node_arch} MATCHES x86)
+ set(cares_arch ia32)
+ endif()
+
+ add_subdirectory(deps/c-ares)
+ set(LIBCARES_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/deps/c-ares ${CMAKE_SOURCE_DIR}/deps/c-ares/${node_platform}-${cares_arch})
+endif()
diff --git a/cmake/libev.cmake b/cmake/libev.cmake
new file mode 100644
index 000000000..5905175f5
--- /dev/null
+++ b/cmake/libev.cmake
@@ -0,0 +1,10 @@
+if(SHARED_LIBEV)
+ find_library(LIBEV_LIBRARY NAMES ev)
+ find_path(LIBEV_INCLUDE_DIR ev.h
+ PATH_SUFFIXES include/ev include
+ ) # Find header
+ find_package_handle_standard_args(libev DEFAULT_MSG LIBEV_LIBRARY LIBEV_INCLUDE_DIR)
+else()
+ add_subdirectory(deps/libev)
+ set(LIBEV_INCLUDE_DIR deps/libev)
+endif()
diff --git a/cmake/libs.cmake b/cmake/libs.cmake
new file mode 100644
index 000000000..e953bbe32
--- /dev/null
+++ b/cmake/libs.cmake
@@ -0,0 +1,39 @@
+#
+# libraries
+#
+
+include(FindPackageHandleStandardArgs)
+set(HAVE_CONFIG_H True)
+add_definitions(-DHAVE_CONFIG_H=1)
+
+find_package(OpenSSL QUIET)
+find_package(Threads)
+find_library(RT rt)
+find_library(DL dl)
+
+if(RT)
+ set(extra_libs ${extra_libs} ${RT})
+endif()
+
+if(DL)
+ set(extra_libs ${extra_libs} ${DL})
+endif()
+
+if(${node_platform} MATCHES freebsd)
+ find_library(KVM NAMES kvm)
+ set(extra_libs ${extra_libs} KVM)
+endif()
+
+if(${OPENSSL_FOUND} MATCHES True)
+ add_definitions(-DHAVE_OPENSSL=1)
+ set(HAVE_OPENSSL True)
+ set(node_extra_src ${node_extra_src} src/node_crypto.cc)
+ set(extra_libs ${extra_libs} ${OPENSSL_LIBRARIES})
+endif()
+
+include("cmake/libc-ares.cmake")
+include("cmake/libev.cmake")
+include("cmake/libv8.cmake")
+
+add_subdirectory(deps/libeio)
+add_subdirectory(deps/http_parser)
diff --git a/cmake/libv8.cmake b/cmake/libv8.cmake
new file mode 100644
index 000000000..21d741081
--- /dev/null
+++ b/cmake/libv8.cmake
@@ -0,0 +1,15 @@
+set(V8_INCLUDE_NAMES v8.h v8-debug.h v8-profiler.h)
+set(V8_LIBRARY_NAMES v8)
+
+if(SHARED_V8)
+ find_path(V8_INCLUDE_DIR NAMES ${V8_INCLUDE_NAMES})
+ find_library(V8_LIBRARY_PATH NAMES ${V8_LIBRARY_NAMES} NO_CMAKE_PATH)
+else()
+ set(V8_INCLUDE_DIR "${PROJECT_BINARY_DIR}/deps/v8/include")
+ if(${CMAKE_BUILD_TYPE} MATCHES Debug)
+ set(v8_fn "libv8_g.a")
+ else()
+ set(v8_fn "libv8.a")
+ endif()
+ set(V8_LIBRARY_PATH "${PROJECT_BINARY_DIR}/deps/v8/${v8_fn}")
+endif()
diff --git a/cmake/node_build.cmake b/cmake/node_build.cmake
new file mode 100644
index 000000000..f98aa103b
--- /dev/null
+++ b/cmake/node_build.cmake
@@ -0,0 +1,76 @@
+#
+# node build stuff
+#
+
+add_custom_command(
+ OUTPUT ${PROJECT_BINARY_DIR}/src/node_natives.h
+ COMMAND tools/js2c.py ${PROJECT_BINARY_DIR}/src/node_natives.h ${js2c_files}
+ DEPENDS ${js2c_files})
+
+set(node_extra_src "src/platform_${node_platform}.cc")
+
+if(NOT EXISTS ${CMAKE_SOURCE_DIR}/${node_extra_src})
+ set(node_extra_src "src/platform_none.cc")
+endif()
+
+set(node_sources
+ src/node_main.cc
+ src/node.cc
+ src/node_buffer.cc
+ src/node_javascript.cc
+ src/node_extensions.cc
+ src/node_http_parser.cc
+ src/node_net.cc
+ src/node_io_watcher.cc
+ src/node_child_process.cc
+ src/node_constants.cc
+ src/node_cares.cc
+ src/node_events.cc
+ src/node_file.cc
+ src/node_signal_watcher.cc
+ src/node_stat_watcher.cc
+ src/node_stdio.cc
+ src/node_timer.cc
+ src/node_script.cc
+ src/node_natives.h
+ ${node_extra_src})
+
+configure_file(src/node_config.h.in ${PROJECT_BINARY_DIR}/src/node_config.h)
+configure_file(config.h.cmake ${PROJECT_BINARY_DIR}/config.h)
+
+include_directories(
+ src
+ deps/libeio
+ deps/http_parser
+ ${V8_INCLUDE_DIR}
+ ${LIBEV_INCLUDE_DIR}
+ ${LIBCARES_INCLUDE_DIR}
+
+ ${PROJECT_BINARY_DIR}
+ ${PROJECT_BINARY_DIR}/src
+)
+
+add_executable(node ${node_sources})
+set_target_properties(node PROPERTIES DEBUG_POSTFIX "_g")
+target_link_libraries(node
+ ev
+ eio
+ cares
+ http_parser
+ ${V8_LIBRARY_PATH}
+ ${CMAKE_THREAD_LIBS_INIT}
+ ${extra_libs})
+
+
+install(TARGETS node RUNTIME DESTINATION bin)
+install(FILES
+ ${PROJECT_BINARY_DIR}/config.h
+ src/node.h
+ src/node_object_wrap.h
+ src/node_buffer.h
+ src/node_events.h
+ src/node_version.h
+ ${PROJECT_BINARY_DIR}/src/node_config.h
+
+ DESTINATION include/node
+)
diff --git a/cmake/package.cmake b/cmake/package.cmake
new file mode 100644
index 000000000..aeca62100
--- /dev/null
+++ b/cmake/package.cmake
@@ -0,0 +1,33 @@
+#
+# package
+#
+
+if(${node_platform} MATCHES darwin)
+ set(CPACK_GENERATOR "TGZ;PackageMaker")
+ # CPack requires the files to end in .txt
+ configure_file(LICENSE ${PROJECT_BINARY_DIR}/LICENSE.txt COPYONLY)
+ configure_file(ChangeLog ${PROJECT_BINARY_DIR}/ChangeLog.txt COPYONLY)
+ set(CPACK_RESOURCE_FILE_LICENSE "${PROJECT_BINARY_DIR}/LICENSE.txt")
+ set(CPACK_RESOURCE_FILE_README "${PROJECT_BINARY_DIR}/ChangeLog.txt")
+ #set(CPACK_RESOURCE_FILE_WELCOME "")
+else()
+ set(CPACK_GENERATOR "TGZ;DEB;RPM")
+endif()
+set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Tom Hughes <tom.hughes@palm.com>")
+set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Evented I/O for V8 JavaScript.")
+set(CPACK_PACKAGE_DESCRIPTION "Node's goal is to provide an easy way to
+ build scalable network programs.
+
+ Node is similar in design to and influenced by systems like Ruby's Event
+ Machine or Python's Twisted. Node takes the event model a bit further—it
+ presents the event loop as a language construct instead of as a library.")
+set(CPACK_DEBIAN_PACKAGE_SECTION "web")
+file(READ ${PROJECT_SOURCE_DIR}/src/node_version.h node_version_h LIMIT 1024 OFFSET 0)
+string(REGEX REPLACE ".*NODE_MAJOR_VERSION[ ]*([0-9]+).*" "\\1" CPACK_PACKAGE_VERSION_MAJOR "${node_version_h}")
+string(REGEX REPLACE ".*NODE_MINOR_VERSION[ ]*([0-9]+).*" "\\1" CPACK_PACKAGE_VERSION_MINOR "${node_version_h}")
+string(REGEX REPLACE ".*NODE_PATCH_VERSION[ ]*([0-9]+).*" "\\1" CPACK_PACKAGE_VERSION_PATCH "${node_version_h}")
+set(node_version_string "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}")
+
+# Note: this is intentionally at the bottom so that the above CPACK variables
+# are used by CPack.
+include(CPack)
diff --git a/cmake/tests.cmake b/cmake/tests.cmake
new file mode 100644
index 000000000..fb24e44b3
--- /dev/null
+++ b/cmake/tests.cmake
@@ -0,0 +1,86 @@
+#
+# tests
+#
+
+if(${CMAKE_BUILD_TYPE} MATCHES Debug)
+ set(test_bin_dir debug)
+ get_target_property(node_bin node DEBUG_LOCATION)
+else()
+ set(test_bin_dir default)
+ get_target_property(node_bin node LOCATION)
+endif()
+
+enable_testing()
+file(GLOB_RECURSE node_tests ${CMAKE_SOURCE_DIR}/test/*)
+
+foreach(test ${node_tests})
+ if(test MATCHES ".*/test-[^./\ ]*.\\.js" AND NOT test MATCHES ".*disabled.*"
+ AND NOT test MATCHES ".*pummel.*")
+
+ # build a fancy name for each test
+ string(REPLACE ${CMAKE_SOURCE_DIR}/test/ "" test_name ${test})
+ string(REPLACE test- "" test_name ${test_name})
+ string(REPLACE ".js" "" test_name ${test_name})
+ string(REPLACE "/" "-" test_name ${test_name})
+
+ add_test(${test_name} ${node_bin} ${test})
+ endif()
+endforeach()
+
+configure_file(${CMAKE_SOURCE_DIR}/cmake/CTestCustom.cmake ${CMAKE_BINARY_DIR}/CTestCustom.cmake COPYONLY)
+
+add_custom_command(
+ TARGET node POST_BUILD
+ COMMAND ${CMAKE_COMMAND} -E make_directory ${PROJECT_BINARY_DIR}/${test_bin_dir}
+ COMMAND ${CMAKE_COMMAND} -E copy_if_different ${node_bin} ${PROJECT_BINARY_DIR}/${test_bin_dir}
+ WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})
+
+# this target gets overriden by ctest's test target
+# add_custom_target(
+# test
+# COMMAND python tools/test.py --mode=release simple message
+# DEPENDS node
+# WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
+# )
+
+add_custom_target(test-all
+ COMMAND python tools/test.py --mode=debug,release
+ DEPENDS node
+ WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
+ )
+
+add_custom_target(test-release
+ COMMAND python tools/test.py --mode=release
+ DEPENDS node
+ WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
+ )
+
+add_custom_target(test-debug
+ COMMAND python tools/test.py --mode=debug
+ DEPENDS node
+ WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
+ )
+
+add_custom_target(test-message
+ COMMAND python tools/test.py message
+ DEPENDS node
+ WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
+ )
+
+add_custom_target(test-simple
+ COMMAND python tools/test.py simple
+ DEPENDS node
+ WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
+ )
+
+add_custom_target(test-pummel
+ COMMAND python tools/test.py pummel
+ DEPENDS node
+ WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
+ )
+
+add_custom_target(test-internet
+ COMMAND python tools/test.py internet
+ DEPENDS node
+ WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
+ )
diff --git a/cmake/v8_build.cmake b/cmake/v8_build.cmake
new file mode 100644
index 000000000..3f31e3532
--- /dev/null
+++ b/cmake/v8_build.cmake
@@ -0,0 +1,88 @@
+#
+# v8 build stuff
+#
+
+string(TOLOWER ${CMAKE_BUILD_TYPE} v8mode)
+set(v8arch ${node_arch})
+
+if(${node_arch} MATCHES x86_64)
+ set(v8arch x64)
+elseif(${node_arch} MATCHES x86)
+ set(v8arch ia32)
+endif()
+
+
+if(NOT SHARED_V8)
+ if(V8_SNAPSHOT)
+ set(v8snapshot snapshot=on)
+ endif()
+
+ if(${node_platform} MATCHES darwin)
+ execute_process(COMMAND hwprefs cpu_count OUTPUT_VARIABLE cpu_count)
+ elseif(${node_platform} MATCHES linux)
+ execute_process(COMMAND sh -c "cat /proc/cpuinfo | grep processor | sort | uniq | wc -l"
+ OUTPUT_VARIABLE cpu_count)
+ endif()
+
+ if(${cpu_count} GREATER 1)
+ math(EXPR parallel_jobs ${cpu_count}*2)
+ else()
+ set(parallel_jobs 1)
+ endif()
+
+ add_library(v8 STATIC IMPORTED)
+ set_property(TARGET v8
+ PROPERTY IMPORTED_LOCATION ${PROJECT_BINARY_DIR}/deps/v8/${v8_fn})
+
+
+
+ if(CMAKE_VERSION VERSION_GREATER 2.8)
+ # use ExternalProject for CMake >2.8
+ include(ExternalProject)
+
+ ExternalProject_Add(v8_extprj
+ URL ${PROJECT_SOURCE_DIR}/deps/v8
+
+ BUILD_IN_SOURCE True
+ BUILD_COMMAND sh -c "${PROJECT_BINARY_DIR}/tools/scons/scons.py library=static visibility=default ${v8snapshot} mode=${v8mode} verbose=on arch=${v8arch} -j ${parallel_jobs}"
+
+ SOURCE_DIR ${PROJECT_BINARY_DIR}/deps/v8
+ # ignore this stuff, it's not needed for building v8 but ExternalProject
+ # demands these steps
+
+ CONFIGURE_COMMAND "true" # fake configure
+ INSTALL_COMMAND "true" # fake install
+ )
+
+ add_dependencies(node v8_extprj)
+ else(CAMKE_VERSION VERSION_GREATER 2.8)
+ # copy v8 sources inefficiently with CMake versions <2.8
+ file(GLOB_RECURSE v8_sources RELATIVE ${PROJECT_SOURCE_DIR} deps/v8/*)
+
+ if(NOT ${in_source_build})
+ file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/deps/v8)
+
+ foreach(FILE ${v8_sources})
+ add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/${FILE}
+ COMMAND ${CMAKE_COMMAND} -E copy_if_different ${PROJECT_SOURCE_DIR}/${FILE} ${PROJECT_BINARY_DIR}/${FILE}
+ DEPENDS ${PROJECT_SOURCE_DIR}/${FILE}
+ )
+ list(APPEND v8_sources_dest ${PROJECT_BINARY_DIR}/${FILE})
+ endforeach()
+ else()
+ set(v8_sources_dest ${v8_sources})
+ endif()
+
+ add_custom_command(
+ OUTPUT ${PROJECT_BINARY_DIR}/deps/v8/${v8_fn}
+ COMMAND ${PROJECT_BINARY_DIR}/tools/scons/scons.py library=static visibility=default ${v8snapshot} mode=${v8mode} verbose=on arch=${v8arch} -j ${parallel_jobs}
+ WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/deps/v8/
+ DEPENDS ${v8_sources_dest}
+ )
+
+ add_custom_target(v8_stock ALL DEPENDS ${PROJECT_BINARY_DIR}/deps/v8/${v8_fn})
+ set_property(TARGET v8 PROPERTY
+ IMPORTED_LOCATION ${PROJECT_BINARY_DIR}/deps/v8/${v8_fn})
+ add_dependencies(node v8_stock)
+ endif()
+endif()