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
Changes from 1 commit
9686139
b57b921
d89202e
9c75430
45e487d
bf02e87
076ffe2
f3e69cc
6d2bbb8
1ff1de4
54fdc43
d0deb23
3954205
18c7b37
9cd7c6a
7f2e8cf
2f66df8
9e45f55
8297dab
63ac9d1
da5d322
de97277
80f16de
9359bb8
d339049
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
|
||
# 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) | ||
#{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are curly braces commented out? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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> | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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}") |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
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) |
This file was deleted.
This file was deleted.
This file was deleted.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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