Skip to content

Commit

Permalink
added CMake build scripts (replaces VS .sln)
Browse files Browse the repository at this point in the history
- added CMake scripts with build support for Windows/Visual Studio
- improved V8Locker messages (shows the conflicting thread names)
- removed Visual Studio solution & project files
  • Loading branch information
drywolf committed Feb 22, 2017
1 parent 9d6ab7f commit 9686139
Show file tree
Hide file tree
Showing 18 changed files with 267 additions and 271 deletions.
107 changes: 107 additions & 0 deletions CMakeLists.txt
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)
#{
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
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)
79 changes: 79 additions & 0 deletions cmake/FindJava.cmake
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}")
41 changes: 41 additions & 0 deletions cmake/NodeJsUtils.cmake
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)
14 changes: 14 additions & 0 deletions cmake/Policies.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

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.
Loading

0 comments on commit 9686139

Please sign in to comment.