-
Notifications
You must be signed in to change notification settings - Fork 632
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
japi: Move Java API binding to cmake
Change-Id: I264d547a06e3636d021a74cd26efb8137f629cbc Signed-off-by: Mohsin Kazmi <[email protected]> Signed-off-by: Michal Cmarada <[email protected]>
- Loading branch information
1 parent
e82eb63
commit 2419508
Showing
7 changed files
with
308 additions
and
386 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,44 @@ | ||
# Copyright (c) 2017-2018 Cisco and/or its affiliates. | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at: | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
japi_configure_depend = vpp-install | ||
japi_source = extras | ||
japi_configure_subdir = japi | ||
japi_CPPFLAGS = $(call installed_includes_fn, vpp) $(call installed_includes_fn, vpp)/vpp_plugins | ||
japi_LDFLAGS = $(call installed_libs_fn, vpp) | ||
|
||
ifneq ($(shell which cmake3),) | ||
CMAKE?=cmake3 | ||
else | ||
CMAKE?=cmake | ||
endif | ||
|
||
japi_cmake_args ?= | ||
japi_cmake_args += -DCMAKE_INSTALL_PREFIX:PATH=$(PACKAGE_INSTALL_DIR) | ||
japi_cmake_args += -DCMAKE_C_FLAGS="$($(TAG)_TAG_CFLAGS)" | ||
japi_cmake_args += -DCMAKE_SHARED_LINKER_FLAGS="$($(TAG)_TAG_LDFLAGS)" | ||
japi_cmake_args += -DCMAKE_PREFIX_PATH:PATH="$(PACKAGE_INSTALL_DIR)/../vpp" | ||
ifeq ("$(V)","1") | ||
japi_cmake_args += -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON | ||
endif | ||
|
||
#Use devtoolset on centos 7 | ||
ifneq ($(wildcard /opt/rh/devtoolset-7/enable),) | ||
japi_cmake_args += -DCMAKE_PROGRAM_PATH:PATH="/opt/rh/devtoolset-7/root/bin" | ||
endif | ||
|
||
japi_configure = \ | ||
cd $(PACKAGE_BUILD_DIR) && \ | ||
$(CMAKE) -G Ninja $(japi_cmake_args) $(call find_source_fn,$(PACKAGE_SOURCE))$(PACKAGE_SUBDIR) | ||
|
||
japi_build = $(CMAKE) --build $(PACKAGE_BUILD_DIR) -- $(MAKE_PARALLEL_FLAGS) | ||
|
||
japi_install = $(CMAKE) --build $(PACKAGE_BUILD_DIR) -- install |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
# Copyright (c) 2018 Cisco and/or its affiliates. | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at: | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
cmake_minimum_required(VERSION 3.5 FATAL_ERROR) | ||
|
||
project(japi) | ||
|
||
include(CheckCCompilerFlag) | ||
|
||
if(CMAKE_SYSTEM_PROCESSOR MATCHES "amd64.*|x86_64.*|AMD64.*") | ||
set(CMAKE_C_FLAGS "-march=corei7 -mtune=corei7-avx ${CMAKE_C_FLAGS}") | ||
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(aarch64.*|AARCH64.*)") | ||
set(CMAKE_C_FLAGS "-march=armv8-a+crc ${CMAKE_C_FLAGS}") | ||
endif() | ||
|
||
check_c_compiler_flag("-Wno-address-of-packed-member" compiler_flag_no_address_of_packed_member) | ||
if (compiler_flag_no_address_of_packed_member) | ||
add_definitions(-Wno-address-of-packed-member) | ||
endif() | ||
|
||
execute_process( | ||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../../src | ||
COMMAND scripts/version | ||
OUTPUT_VARIABLE JAPI_VERSION | ||
OUTPUT_STRIP_TRAILING_WHITESPACE | ||
) | ||
string(REPLACE "-" ";" JAPI_LIB_VERSION ${JAPI_VERSION}) | ||
list(GET JAPI_LIB_VERSION 0 JAPI_LIB_VERSION) | ||
|
||
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) | ||
set(CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_PREFIX}/lib) | ||
set(CMAKE_INSTALL_MESSAGE NEVER) | ||
|
||
find_package(Threads REQUIRED) | ||
|
||
unset(dirlist) | ||
|
||
macro(subdirlist dirlist dirpath) | ||
file(GLOB dirs RELATIVE ${dirpath} ${dirpath}/*) | ||
foreach(dir ${dirs}) | ||
if(IS_DIRECTORY ${dirpath}/${dir}) | ||
list(APPEND dirlist ${dirpath}/${dir}) | ||
endif() | ||
endforeach() | ||
endmacro() | ||
|
||
list(APPEND dirlist $ENV{JAVA_HOME}) | ||
subdirlist(dirlist /usr/lib/jvm) | ||
subdirlist(dirlist /usr/lib64/jvm) | ||
|
||
unset(JAVA_HOME_SET) | ||
find_path(JAVA_HOME_SET NAMES include/jni.h PATHS ${dirlist}) | ||
if (NOT JAVA_HOME_SET) | ||
message("JAVA_HOME is not found") | ||
else() | ||
set(ENV{JAVA_HOME} "${JAVA_HOME_SET}") | ||
endif() | ||
|
||
message("JAVA_HOME: $ENV{JAVA_HOME}") | ||
|
||
find_package(Java 1.8 REQUIRED COMPONENTS Development) | ||
get_filename_component(jvm_path ${Java_JAVAC_EXECUTABLE} DIRECTORY) | ||
set (Java_INCLUDE_DIRS ${jvm_path}/../include ${jvm_path}/../include/linux) | ||
|
||
message("Found java headers ${Java_INCLUDE_DIRS}") | ||
message("Found javac at: " ${Java_JAVAC_EXECUTABLE}) | ||
add_subdirectory(java) |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,191 @@ | ||
# Copyright (c) 2018 Cisco and/or its affiliates. | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at: | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
find_path(VNET_INCLUDE_DIR NAMES vnet/api_errno.h) | ||
find_library(VPPINFRA_DIR NAMES vppinfra REQUIRED) | ||
find_library(VLIBMEMORYCLIENT_DIR NAMES vlibmemoryclient REQUIRED) | ||
find_library(SVM_DIR NAMES svm REQUIRED) | ||
|
||
include_directories(${VNET_INCLUDE_DIR} | ||
${VNET_INCLUDE_DIR}/vpp_plugins | ||
${Java_INCLUDE_DIRS} | ||
${CMAKE_CURRENT_SOURCE_DIR} | ||
${CMAKE_BINARY_DIR/../vpp/plugins}) | ||
add_compile_options(-Wall) | ||
############# Common package ################## | ||
add_library(jvpp_common SHARED jvpp-common/jvpp_common.c) | ||
set_target_properties(jvpp_common PROPERTIES SOVERSION ${JAPI_LIB_VERSION}) | ||
target_link_libraries(jvpp_common ${VPPINFRA_DIR}) | ||
install(TARGETS jvpp_common DESTINATION lib COMPONENT libjvpp_common) | ||
install(FILES jvpp-common/jvpp_common.h DESTINATION include/japi/) | ||
|
||
set(JVPP_LIBS jvpp_common ${VPPINFRA_DIR} ${VLIBMEMORYCLIENT_DIR} ${SVM_DIR} | ||
Threads::Threads m rt) | ||
|
||
############# Registry package ################## | ||
set(PACKAGE_DIR_JVPP_REGISTRY io/fd/vpp/jvpp) | ||
unset(files) | ||
FILE(GLOB files RELATIVE | ||
${CMAKE_CURRENT_SOURCE_DIR} | ||
${CMAKE_CURRENT_SOURCE_DIR}/jvpp-registry/${PACKAGE_DIR_JVPP_REGISTRY}/*.java | ||
${CMAKE_CURRENT_SOURCE_DIR}/jvpp-registry/${PACKAGE_DIR_JVPP_REGISTRY}/*/*.java | ||
) | ||
|
||
add_custom_target (jvpp-registry-classes) | ||
add_custom_command (TARGET jvpp-registry-classes | ||
PRE_BUILD | ||
COMMAND mkdir -p jvpp-registry/target | ||
COMMAND mkdir -p ${CMAKE_CURRENT_BINARY_DIR}/jvpp-registry | ||
COMMAND ${Java_JAVAC_EXECUTABLE} | ||
ARGS -d ${CMAKE_CURRENT_SOURCE_DIR}/jvpp-registry/target -h jvpp-registry ${files} | ||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} | ||
) | ||
|
||
add_library(jvpp_registry SHARED jvpp-registry/jvpp_registry.c) | ||
target_link_libraries(jvpp_registry ${JVPP_LIBS}) | ||
include_directories(jvpp-registry) | ||
add_dependencies(jvpp_registry jvpp_common jvpp-registry-classes) | ||
|
||
add_custom_target (jvpp-registry) | ||
add_dependencies(jvpp-registry jvpp_registry) | ||
add_custom_command(TARGET jvpp-registry | ||
PRE_BUILD | ||
COMMAND cp ${CMAKE_BINARY_DIR}/lib/libjvpp_registry.so jvpp-registry/target | ||
COMMAND ${Java_JAR_EXECUTABLE} ARGS cf | ||
${CMAKE_CURRENT_BINARY_DIR}/jvpp-registry-${JAPI_LIB_VERSION}.jar | ||
-C jvpp-registry/target . | ||
COMMAND rm ARGS -rf jvpp-registry/target | ||
jvpp-registry/io_fd_vpp_jvpp_*.h | ||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} | ||
COMMENT "JAR_GEN registry" | ||
) | ||
install( | ||
FILES ${CMAKE_CURRENT_BINARY_DIR}/jvpp-registry-${JAPI_LIB_VERSION}.jar | ||
DESTINATION share/java | ||
) | ||
|
||
############## Functions ######################### | ||
function(japigen name) | ||
if(NOT VPP_JAVA_APIGEN) | ||
set(VPP_JAVA_APIGEN ${CMAKE_CURRENT_SOURCE_DIR}/jvpp/gen/jvpp_gen.py) | ||
endif() | ||
add_custom_target(japigen-${name} DEPENDS jvpp-registry) | ||
add_custom_command(TARGET japigen-${name} | ||
POST_BUILD | ||
COMMAND mkdir -p jvpp-${name}/target | ||
COMMAND mkdir -p ${CMAKE_CURRENT_BINARY_DIR}/jvpp-${name} | ||
COMMAND ${VPP_JAVA_APIGEN} | ||
ARGS --plugin_name ${name} --root_dir jvpp-${name} -i ${ARGN} | ||
COMMAND find jvpp-${name} -name \*.java > jvpp-${name}/jvpp-${name}.files | ||
COMMAND ${Java_JAVAC_EXECUTABLE} | ||
ARGS -cp ${CMAKE_CURRENT_BINARY_DIR}/jvpp-registry-${JAPI_LIB_VERSION}.jar -d | ||
${CMAKE_CURRENT_SOURCE_DIR}/jvpp-${name}/target -h jvpp-${name} | ||
@jvpp-${name}/jvpp-${name}.files | ||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} | ||
COMMENT "JAVA_API_GEN ${name}" | ||
) | ||
endfunction() | ||
|
||
function(jargen name) | ||
add_custom_command(TARGET jvpp_${name} | ||
POST_BUILD | ||
COMMAND cp ${CMAKE_BINARY_DIR}/lib/libjvpp_${name}.so jvpp-${name}/target | ||
COMMAND ${Java_JAR_EXECUTABLE} ARGS cf | ||
${CMAKE_CURRENT_BINARY_DIR}/jvpp-${name}-${JAPI_LIB_VERSION}.jar | ||
-C jvpp-${name}/target . | ||
COMMAND rm ARGS -rf jvpp-${name}/target jvpp-${name}/jvpp-${name}.files | ||
jvpp-${name}/jvpp_${name}_gen.h jvpp-${name}/io_fd_vpp_jvpp_*.h | ||
jvpp-registry/io_fd_vpp_jvpp_*.h | ||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} | ||
COMMENT "JAR_GEN ${name}" | ||
) | ||
install( | ||
FILES ${CMAKE_CURRENT_BINARY_DIR}/jvpp-${name}-${JAPI_LIB_VERSION}.jar | ||
DESTINATION share/java | ||
) | ||
endfunction() | ||
|
||
function(java_api_binding name src_file) | ||
japigen (${name} ${ARGN}) | ||
add_library(jvpp_${name} SHARED jvpp-${name}/jvpp_${src_file}.c) | ||
target_link_libraries(jvpp_${name} ${JVPP_LIBS}) | ||
include_directories(jvpp-${name}) | ||
add_dependencies(jvpp_${name} jvpp_common jvpp_registry japigen-${name}) | ||
jargen (${name}) | ||
endfunction() | ||
|
||
############ Core Package ####################### | ||
unset (files) | ||
unset (JSON_API_PATH) | ||
set (JSON_API_PATH ${CMAKE_BINARY_DIR}/../vpp) | ||
|
||
FILE(GLOB_RECURSE files RELATIVE | ||
${CMAKE_CURRENT_SOURCE_DIR} | ||
${JSON_API_PATH}/vnet/*.api.json | ||
${JSON_API_PATH}/vpp/*.api.json | ||
) | ||
|
||
java_api_binding (core core ${files}) | ||
|
||
############ Plugin Packages ####################### | ||
unset (ACL_JSON_FILE) | ||
unset (NAT_JSON_FILE) | ||
unset (NSH_JSON_FILE) | ||
unset (GTPU_JSON_FILE) | ||
unset (PPPOE_JSON_FILE) | ||
unset (IOAM_TRACE_JSON_FILE) | ||
unset (IOAM_POT_JSON_FILE) | ||
unset (IOAM_EXPORT_JSON_FILE) | ||
|
||
set (plugin_path ${CMAKE_BINARY_DIR}/../vpp/plugins) | ||
|
||
find_file(ACL_JSON_FILE NAMES acl.api.json HINTS ${plugin_path} PATH_SUFFIXES acl) | ||
find_file(NAT_JSON_FILE NAMES nat.api.json HINTS ${plugin_path} PATH_SUFFIXES nat) | ||
find_file(NSH_JSON_FILE NAMES nsh.api.json HINTS ${plugin_path} PATH_SUFFIXES nsh) | ||
find_file(GTPU_JSON_FILE NAMES gtpu.api.json HINTS ${plugin_path} PATH_SUFFIXES gtpu) | ||
find_file(PPPOE_JSON_FILE NAMES pppoe.api.json HINTS ${plugin_path} PATH_SUFFIXES pppoe) | ||
find_file(IOAM_TRACE_JSON_FILE NAMES trace.api.json HINTS ${plugin_path} PATH_SUFFIXES ioam/lib-trace) | ||
find_file(IOAM_POT_JSON_FILE NAMES pot.api.json HINTS ${plugin_path} PATH_SUFFIXES ioam/lib-pot) | ||
find_file(IOAM_EXPORT_JSON_FILE NAMES ioam_export.api.json HINTS ${plugin_path} PATH_SUFFIXES ioam/export) | ||
|
||
if(ACL_JSON_FILE) | ||
java_api_binding (acl acl ${ACL_JSON_FILE}) | ||
endif() | ||
|
||
if(NAT_JSON_FILE) | ||
java_api_binding (nat nat ${NAT_JSON_FILE}) | ||
endif() | ||
|
||
if(NSH_JSON_FILE) | ||
java_api_binding (nsh nsh ${NSH_JSON_FILE}) | ||
endif() | ||
|
||
if(GTPU_JSON_FILE) | ||
java_api_binding (gtpu gtpu ${GTPU_JSON_FILE}) | ||
endif() | ||
|
||
if(PPPOE_JSON_FILE) | ||
java_api_binding (pppoe pppoe ${PPPOE_JSON_FILE}) | ||
endif() | ||
|
||
if(IOAM_TRACE_JSON_FILE) | ||
java_api_binding (ioamtrace ioam_trace ${IOAM_TRACE_JSON_FILE}) | ||
endif() | ||
|
||
if(IOAM_POT_JSON_FILE) | ||
java_api_binding (ioampot ioam_pot ${IOAM_POT_JSON_FILE}) | ||
endif() | ||
|
||
if(IOAM_EXPORT_JSON_FILE) | ||
java_api_binding (ioamexport ioam_export ${IOAM_EXPORT_JSON_FILE}) | ||
endif() |
Oops, something went wrong.