Permalink
Browse files

Add cmake build support.

Squashed commit of ca128f7 with
contributions from Mark Constable (markc@renta.net) and Daniel Gröber
(darklord@darkboxed.org).
  • Loading branch information...
1 parent b52b419 commit 446beebd79d52b24bd8d9e0a44f6378a711f32b9 @thughes thughes committed with ry Nov 22, 2010
View
@@ -0,0 +1,71 @@
+cmake_minimum_required(VERSION 2.6)
+project(node)
+
+#
+# options
+#
+
+option(SHARED_V8 "use system shared V8 library")
+option(SHARED_LIBEV "use system shared libev library")
+option(SHARED_CARES "use system shared c-ares library")
+option(V8_SNAPSHOT "turn on snapshot when building stock v8")
+
+
+# cmake policies to get rid of some warnings
+cmake_policy(SET CMP0009 NEW)
+
+# generic cmake configuration
+include("cmake/configure.cmake")
+
+# find and configure libs
+include("cmake/libs.cmake")
+
+# setup node build targets
+include("cmake/node_build.cmake")
+
+# setup v8 build targets
+include("cmake/v8_build.cmake")
+
+# docs
+include("cmake/docs.cmake")
+
+# tests
+include("cmake/tests.cmake")
+
+# package
+include("cmake/package.cmake")
+
+
+#
+# Final build configuration output
+#
+
+message("** Build Summary **")
+message(" Version: ${node_version_string}")
+message(" Prefix: ${PREFIX}")
+message(" Build Type: ${CMAKE_BUILD_TYPE}")
+message(" Architecture: ${CMAKE_SYSTEM_PROCESSOR}")
+
+if(SHARED_V8)
+message(" V8: ${V8_LIBRARY_PATH}")
+#else()
+#message(" V8 jobs: ${parallel_jobs}")
+endif()
+
+if(SHARED_libev)
+ message(" libev: ${LIBEV_LIBRARY}")
+endif()
+
+if(SHARED_CARES)
+ message(" libc-ares: ${LIBCARES_LIBRARY}")
+endif()
+
+message(" RT library: ${RT}")
+message(" DL library: ${DL}")
+
+if(${OPENSSL_FOUND} MATCHES TRUE)
+ message(" OpenSSL: Found!")
+endif()
+
+# message(" CCFLAGS: ${CCFLAGS}")
+# message(" CPPFLAGS: ${CPPFLAGS}")
@@ -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})
View
@@ -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()
View
@@ -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
+# )
View
@@ -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()
View
@@ -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()
View
@@ -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)
View
@@ -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()
Oops, something went wrong.

0 comments on commit 446beeb

Please sign in to comment.