Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cross-platform, cross-compile build toolchain #280

Merged
merged 25 commits into from Jun 22, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
9686139
added CMake build scripts (replaces VS .sln)
drywolf Feb 22, 2017
b57b921
changed NodeJS dependency default path
drywolf Feb 22, 2017
d89202e
Merge remote-tracking branch 'upstream/master'
drywolf May 3, 2017
9c75430
MacOS build working (some Node.js tests failing)
drywolf May 12, 2017
45e487d
Merge remote-tracking branch 'upstream/master'
drywolf May 12, 2017
bf02e87
MacOS linking fix & script cleanups
drywolf May 13, 2017
076ffe2
split up python build-scripts
drywolf May 13, 2017
f3e69cc
moved python build utils to separate directory
drywolf May 13, 2017
6d2bbb8
split cmake generation and jni compile
drywolf May 13, 2017
1ff1de4
updated win32 node link libs (node v7.4.0+)
drywolf May 14, 2017
54fdc43
fixed win32 build for 7.4.0 + module linking sanity checks
drywolf May 14, 2017
d0deb23
win32 build-steps config
drywolf May 15, 2017
3954205
adding android build support
drywolf May 16, 2017
18c7b37
android builds working (arm & x86) ... no automatic bundling yet
drywolf May 21, 2017
9cd7c6a
linux build support, android fixes & build-output reuse
drywolf May 29, 2017
7f2e8cf
docker android testing support
drywolf Jun 3, 2017
2f66df8
fixed hardcoded build_cwd for node.js build artifact reuse
drywolf Jun 4, 2017
9e45f55
fixed all open TODOs & refactored build-system code
drywolf Jun 11, 2017
8297dab
added some more build-system features & utils
drywolf Jun 14, 2017
63ac9d1
build-system refactoring & code cleanups
drywolf Jun 15, 2017
da5d322
Merge remote-tracking branch 'upstream/master'
drywolf Jun 15, 2017
de97277
updated build documentation in README.md
drywolf Jun 15, 2017
80f16de
improved --help message & fixed macos native lib copy
drywolf Jun 15, 2017
9359bb8
fixes based on feedback in PR #280 by matiwinnetou
drywolf Jun 20, 2017
d339049
Merge remote-tracking branch 'upstream/master'
drywolf Jun 20, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
107 changes: 107 additions & 0 deletions CMakeLists.txt
@@ -0,0 +1,107 @@
cmake_minimum_required (VERSION 2.6)
project (j2v8)

# adding cmake directory for includes
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)

include (BuildUtils)
include (NodeJsUtils)
include (Policies)

#-----------------------------------------------------------------------
# CMAKE OPTIONS
#-----------------------------------------------------------------------
option(J2V8_NODE_COMPATIBLE "Build the J2V8 native bridge with Node.js support enabled" ON)
option(J2V8_BUILD_ONLY_DEBUG_RELEASE "Generate only Debug and Release configurations (exclude RelWithDebInfo and MinSizeRel)" ON)

# set up the module path
set (CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This appears to be a duplicate line. See line 5.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, good catch ... i will clean this one up in the upcoming PR


# remove the MinSizeRel and RelWithDebInfo configurations
if (J2V8_BUILD_ONLY_DEBUG_RELEASE)
#{
set (CMAKE_CONFIGURATION_TYPES "Debug;Release" CACHE STRING "limited configs" FORCE)
#}
endif ()

#-----------------------------------------------------------------------
# DEPENDENCY SETTINGS & DISCOVERY
#-----------------------------------------------------------------------

# look for dependencies
find_package(Java)

# overridable settings
set (J2V8_JDK_DIR ${Java_ROOT} CACHE STRING "Path to the Java JDK dependency")
set (J2V8_NODEJS_DIR "./node" CACHE STRING "Path to the Node.js dependency")

# get lists of the required Node.js link libraries
get_njs_libs (${J2V8_NODEJS_DIR} "Debug")
get_njs_libs (${J2V8_NODEJS_DIR} "Release")

#-----------------------------------------------------------------------
# INCLUDE DIRECTORIES & SOURCE FILES
#-----------------------------------------------------------------------

# project include directories
set (include_dirs
${J2V8_JDK_DIR}/include
${J2V8_JDK_DIR}/include/win32
${J2V8_NODEJS_DIR}
${J2V8_NODEJS_DIR}/src
${J2V8_NODEJS_DIR}/deps/v8
${J2V8_NODEJS_DIR}/deps/v8/include
)

# project source files
set (src_files
jni/com_eclipsesource_v8_V8Impl.cpp
jni/com_eclipsesource_v8_V8Impl.h
)

source_group("" FILES ${src_files})

#-----------------------------------------------------------------------
# BUILD SETTINGS & COMPILATION
#-----------------------------------------------------------------------

link_static_crt()

# create the j2v8 library
add_library (j2v8 SHARED ${src_files})

# enable Node.js if requested by the set options
if (J2V8_NODE_COMPATIBLE)
#{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are curly braces commented out?

Copy link
Contributor Author

@drywolf drywolf Jul 30, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I use those just by convention to make it easier for the eye to quickly read where the scope of a if-elif-else block starts and ends. This being said, for the next PR I have removed those where only a single line is inside the branch scope. From now on they are only used for if-elif-else blocks that contain multiple lines in their respective blocks (which was the original intent). Thanks for the feedback

set_property (TARGET j2v8 PROPERTY COMPILE_DEFINITIONS ${COMPILE_DEFINITIONS} NODE_COMPATIBLE=1)
#}
endif ()

# build output directory
set (LIBRARY_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/lib)

# set the include directories
include_directories (${include_dirs})

# link the necessary libraries
target_link_libraries (j2v8
debug "${njs_Debug_libs}"
optimized "${njs_Release_libs}"
)

#-----------------------------------------------------------------------
# OUTPUT SETTINGS & POST-BUILD
#-----------------------------------------------------------------------

if (CMAKE_CL_64)
set (ARCH_SUFFIX "_64")
endif ()

set_target_properties (j2v8 PROPERTIES OUTPUT_NAME "${PROJECT_NAME}_win32_x86${ARCH_SUFFIX}")

# copy native lib to Java project resources directory
add_custom_command (TARGET j2v8 POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
$<TARGET_FILE:j2v8>
${CMAKE_SOURCE_DIR}/src/main/resources/lib$<TARGET_FILE_NAME:j2v8>
)
11 changes: 11 additions & 0 deletions cmake/BuildUtils.cmake
@@ -0,0 +1,11 @@

macro (link_static_crt)
foreach(flag_var
CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)

if(${flag_var} MATCHES "/MD")
string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
endif(${flag_var} MATCHES "/MD")
endforeach(flag_var)
endmacro (link_static_crt)
79 changes: 79 additions & 0 deletions cmake/FindJava.cmake
@@ -0,0 +1,79 @@

SET(_JAVA_HINTS $ENV{JAVA_HOME}/bin)

SET(_JAVA_PATHS
/usr/lib/java/bin
/usr/share/java/bin
/usr/local/java/bin
/usr/local/java/share/bin
/usr/java/j2sdk1.4.2_04
/usr/lib/j2sdk1.4-sun/bin
/usr/java/j2sdk1.4.2_09/bin
/usr/lib/j2sdk1.5-sun/bin
/opt/sun-jdk-1.5.0.04/bin
)

FIND_PROGRAM(JAVA_EXECUTABLE
NAMES java
HINTS ${_JAVA_HINTS}
PATHS ${_JAVA_PATHS}
)

IF(JAVA_EXECUTABLE)
EXECUTE_PROCESS(COMMAND ${JAVA_EXECUTABLE} -version
RESULT_VARIABLE res
OUTPUT_VARIABLE var
ERROR_VARIABLE var
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_STRIP_TRAILING_WHITESPACE)

IF( res )
IF(${Java_FIND_REQUIRED})
MESSAGE( FATAL_ERROR "Error executing java -version" )
ELSE()
MESSAGE( STATUS "Warning, could not run java --version")
ENDIF()

ELSE( res )
IF(var MATCHES "java version \"[0-9]+\\.[0-9]+\\.[0-9_.]+[oem-]*\".*")
STRING( REGEX REPLACE ".* version \"([0-9]+\\.[0-9]+\\.[0-9_.]+)[oem-]*\".*"
"\\1" Java_VERSION_STRING "${var}" )
ELSEIF(var MATCHES "java full version \"kaffe-[0-9]+\\.[0-9]+\\.[0-9_]+\".*")
STRING( REGEX REPLACE "java full version \"kaffe-([0-9]+\\.[0-9]+\\.[0-9_]+).*"
"\\1" Java_VERSION_STRING "${var}" )
ELSE()
IF(NOT Java_FIND_QUIETLY)
message(WARNING "regex not supported: ${var}. Please report")
ENDIF(NOT Java_FIND_QUIETLY)
ENDIF()
STRING( REGEX REPLACE "([0-9]+).*" "\\1" Java_VERSION_MAJOR "${Java_VERSION_STRING}" )
STRING( REGEX REPLACE "[0-9]+\\.([0-9]+).*" "\\1" Java_VERSION_MINOR "${Java_VERSION_STRING}" )
STRING( REGEX REPLACE "[0-9]+\\.[0-9]+\\.([0-9]+).*" "\\1" Java_VERSION_PATCH "${Java_VERSION_STRING}" )
STRING( REGEX REPLACE "[0-9]+\\.[0-9]+\\.[0-9]+\\_?\\.?([0-9]*)$" "\\1" Java_VERSION_TWEAK "${Java_VERSION_STRING}" )
if( Java_VERSION_TWEAK STREQUAL "" )
set(Java_VERSION ${Java_VERSION_MAJOR}.${Java_VERSION_MINOR}.${Java_VERSION_PATCH})
else( )
set(Java_VERSION ${Java_VERSION_MAJOR}.${Java_VERSION_MINOR}.${Java_VERSION_PATCH}.${Java_VERSION_TWEAK})
endif( )

IF(NOT Java_FIND_QUIETLY)
MESSAGE( STATUS "Java version ${Java_VERSION} found!" )
ENDIF(NOT Java_FIND_QUIETLY)

ENDIF( res )
ENDIF(JAVA_EXECUTABLE)

UNSET(JAVA_EXECUTABLE CACHE)

if( Java_VERSION_MINOR LESS 6 )
message("-- WARNING: Your system is running Java ${Java_VERSION_MAJOR}.${Java_VERSION_MINOR}. Java JDK 1.6+ is required for compiling ${PROGNAME}.")
set(Java_OLD_VERSION TRUE)
else()
set(Java_OLD_VERSION FALSE)
endif()

if(!$ENV{JAVA_HOME})
message("Cannot find JAVA_HOME. Please setup the path to the base of the Java JDK to JAVA_HOME before compiling.")
endif()

set(Java_ROOT "$ENV{JAVA_HOME}")
41 changes: 41 additions & 0 deletions cmake/NodeJsUtils.cmake
@@ -0,0 +1,41 @@

function (get_njs_libs nodejs_dir config_name)
#{
# base directories for Node.js link libraries
set (njs_build ${nodejs_dir}/build/${config_name})
set (njs_build_lib ${nodejs_dir}/build/${config_name}/lib)

set (njs_extra ${nodejs_dir}/${config_name})
set (njs_extra_lib ${nodejs_dir}/${config_name}/lib)

# project link libraries
set (njs_libs
# nodejs/build/$Config/lib
${njs_build_lib}/v8_base_0.lib
${njs_build_lib}/v8_base_1.lib
${njs_build_lib}/v8_base_2.lib
${njs_build_lib}/v8_base_3.lib
${njs_build_lib}/v8_libbase.lib
${njs_build_lib}/v8_libplatform.lib
${njs_build_lib}/v8_nosnapshot.lib
${njs_build_lib}/v8_snapshot.lib

# nodejs/build/$Config
${njs_build}/mksnapshot.lib

# nodejs/$Config/lib
${njs_extra_lib}/cares.lib
${njs_extra_lib}/gtest.lib
${njs_extra_lib}/http_parser.lib
${njs_extra_lib}/libuv.lib
${njs_extra_lib}/node.lib
${njs_extra_lib}/openssl.lib
${njs_extra_lib}/zlib.lib

# nodejs/$Config
${njs_extra}/cctest.lib
)

set (njs_${config_name}_libs ${njs_libs} PARENT_SCOPE)
#}
endfunction (get_njs_libs)
14 changes: 14 additions & 0 deletions cmake/Policies.cmake
@@ -0,0 +1,14 @@

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should include some docs describing what this does. I don't know what is meant by policy here, and I don't know what these policies (CMP0008 for example) are.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will add links to the corresponding CMake documentation. I added them because if you don't then on some platforms CMake will print a lot of warnings while being invoked on the CMakeLists.txt
These statements strictly define the behavior for what those rules are supposed to do in CMake and get rid of those warnings.

if (COMMAND cmake_policy)
#{
# NEW = Libraries linked by full-path must have a valid library file name.
if (POLICY CMP0008)
cmake_policy (SET CMP0008 NEW)
endif (POLICY CMP0008)

# NEW = Included scripts do automatic cmake_policy PUSH and POP.
if (POLICY CMP0011)
cmake_policy (SET CMP0011 NEW)
endif(POLICY CMP0011)
#}
endif (COMMAND cmake_policy)
Binary file removed j2v8.sdf
Binary file not shown.
28 changes: 0 additions & 28 deletions j2v8.sln

This file was deleted.

Binary file removed j2v8.v12.suo
Binary file not shown.
33 changes: 0 additions & 33 deletions jni/j2v8.filters

This file was deleted.

Binary file removed jni/j2v8.sdf
Binary file not shown.
4 changes: 0 additions & 4 deletions jni/j2v8.user

This file was deleted.

Binary file removed jni/j2v8.v12.suo
Binary file not shown.