blob: 0cbdd514711fa959ffca0edf87ce22f9e119968b [file] [log] [blame]
Mohsin Kazmi24195082018-09-13 09:59:50 +02001# Copyright (c) 2018 Cisco and/or its affiliates.
2# Licensed under the Apache License, Version 2.0 (the "License");
3# you may not use this file except in compliance with the License.
4# You may obtain a copy of the License at:
5#
6# http://www.apache.org/licenses/LICENSE-2.0
7#
8# Unless required by applicable law or agreed to in writing, software
9# distributed under the License is distributed on an "AS IS" BASIS,
10# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11# See the License for the specific language governing permissions and
12# limitations under the License.
13
14find_path(VNET_INCLUDE_DIR NAMES vnet/api_errno.h)
15find_library(VPPINFRA_DIR NAMES vppinfra REQUIRED)
16find_library(VLIBMEMORYCLIENT_DIR NAMES vlibmemoryclient REQUIRED)
17find_library(SVM_DIR NAMES svm REQUIRED)
18
19include_directories(${VNET_INCLUDE_DIR}
20 ${VNET_INCLUDE_DIR}/vpp_plugins
21 ${Java_INCLUDE_DIRS}
22 ${CMAKE_CURRENT_SOURCE_DIR}
23 ${CMAKE_BINARY_DIR/../vpp/plugins})
24add_compile_options(-Wall)
25############# Common package ##################
26add_library(jvpp_common SHARED jvpp-common/jvpp_common.c)
27set_target_properties(jvpp_common PROPERTIES SOVERSION ${JAPI_LIB_VERSION})
28target_link_libraries(jvpp_common ${VPPINFRA_DIR})
29install(TARGETS jvpp_common DESTINATION lib COMPONENT libjvpp_common)
30install(FILES jvpp-common/jvpp_common.h DESTINATION include/japi/)
31
32set(JVPP_LIBS jvpp_common ${VPPINFRA_DIR} ${VLIBMEMORYCLIENT_DIR} ${SVM_DIR}
33 Threads::Threads m rt)
34
35############# Registry package ##################
36set(PACKAGE_DIR_JVPP_REGISTRY io/fd/vpp/jvpp)
37unset(files)
38FILE(GLOB files RELATIVE
39 ${CMAKE_CURRENT_SOURCE_DIR}
40 ${CMAKE_CURRENT_SOURCE_DIR}/jvpp-registry/${PACKAGE_DIR_JVPP_REGISTRY}/*.java
41 ${CMAKE_CURRENT_SOURCE_DIR}/jvpp-registry/${PACKAGE_DIR_JVPP_REGISTRY}/*/*.java
42)
43
44add_custom_target (jvpp-registry-classes)
45add_custom_command (TARGET jvpp-registry-classes
46 PRE_BUILD
47 COMMAND mkdir -p jvpp-registry/target
48 COMMAND mkdir -p ${CMAKE_CURRENT_BINARY_DIR}/jvpp-registry
49 COMMAND ${Java_JAVAC_EXECUTABLE}
50 ARGS -d ${CMAKE_CURRENT_SOURCE_DIR}/jvpp-registry/target -h jvpp-registry ${files}
51 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
52)
53
54add_library(jvpp_registry SHARED jvpp-registry/jvpp_registry.c)
55target_link_libraries(jvpp_registry ${JVPP_LIBS})
56include_directories(jvpp-registry)
57add_dependencies(jvpp_registry jvpp_common jvpp-registry-classes)
58
59add_custom_target (jvpp-registry)
60add_dependencies(jvpp-registry jvpp_registry)
61add_custom_command(TARGET jvpp-registry
62 PRE_BUILD
63 COMMAND cp ${CMAKE_BINARY_DIR}/lib/libjvpp_registry.so jvpp-registry/target
64 COMMAND ${Java_JAR_EXECUTABLE} ARGS cf
65 ${CMAKE_CURRENT_BINARY_DIR}/jvpp-registry-${JAPI_LIB_VERSION}.jar
66 -C jvpp-registry/target .
67 COMMAND rm ARGS -rf jvpp-registry/target
68 jvpp-registry/io_fd_vpp_jvpp_*.h
69 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
70 COMMENT "JAR_GEN registry"
71)
72install(
73 FILES ${CMAKE_CURRENT_BINARY_DIR}/jvpp-registry-${JAPI_LIB_VERSION}.jar
74 DESTINATION share/java
75)
76
77############## Functions #########################
78function(japigen name)
79 if(NOT VPP_JAVA_APIGEN)
80 set(VPP_JAVA_APIGEN ${CMAKE_CURRENT_SOURCE_DIR}/jvpp/gen/jvpp_gen.py)
81 endif()
82 add_custom_target(japigen-${name} DEPENDS jvpp-registry)
83 add_custom_command(TARGET japigen-${name}
84 POST_BUILD
85 COMMAND mkdir -p jvpp-${name}/target
86 COMMAND mkdir -p ${CMAKE_CURRENT_BINARY_DIR}/jvpp-${name}
87 COMMAND ${VPP_JAVA_APIGEN}
88 ARGS --plugin_name ${name} --root_dir jvpp-${name} -i ${ARGN}
89 COMMAND find jvpp-${name} -name \*.java > jvpp-${name}/jvpp-${name}.files
90 COMMAND ${Java_JAVAC_EXECUTABLE}
91 ARGS -cp ${CMAKE_CURRENT_BINARY_DIR}/jvpp-registry-${JAPI_LIB_VERSION}.jar -d
92 ${CMAKE_CURRENT_SOURCE_DIR}/jvpp-${name}/target -h jvpp-${name}
93 @jvpp-${name}/jvpp-${name}.files
94 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
95 COMMENT "JAVA_API_GEN ${name}"
96 )
97endfunction()
98
99function(jargen name)
100 add_custom_command(TARGET jvpp_${name}
101 POST_BUILD
102 COMMAND cp ${CMAKE_BINARY_DIR}/lib/libjvpp_${name}.so jvpp-${name}/target
103 COMMAND ${Java_JAR_EXECUTABLE} ARGS cf
104 ${CMAKE_CURRENT_BINARY_DIR}/jvpp-${name}-${JAPI_LIB_VERSION}.jar
105 -C jvpp-${name}/target .
106 COMMAND rm ARGS -rf jvpp-${name}/target jvpp-${name}/jvpp-${name}.files
107 jvpp-${name}/jvpp_${name}_gen.h jvpp-${name}/io_fd_vpp_jvpp_*.h
108 jvpp-registry/io_fd_vpp_jvpp_*.h
109 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
110 COMMENT "JAR_GEN ${name}"
111 )
112 install(
113 FILES ${CMAKE_CURRENT_BINARY_DIR}/jvpp-${name}-${JAPI_LIB_VERSION}.jar
114 DESTINATION share/java
115 )
116endfunction()
117
118function(java_api_binding name src_file)
119 japigen (${name} ${ARGN})
120 add_library(jvpp_${name} SHARED jvpp-${name}/jvpp_${src_file}.c)
121 target_link_libraries(jvpp_${name} ${JVPP_LIBS})
122 include_directories(jvpp-${name})
123 add_dependencies(jvpp_${name} jvpp_common jvpp_registry japigen-${name})
124 jargen (${name})
125endfunction()
126
127############ Core Package #######################
128unset (files)
129unset (JSON_API_PATH)
130set (JSON_API_PATH ${CMAKE_BINARY_DIR}/../vpp)
131
132FILE(GLOB_RECURSE files RELATIVE
133 ${CMAKE_CURRENT_SOURCE_DIR}
134 ${JSON_API_PATH}/vnet/*.api.json
135 ${JSON_API_PATH}/vpp/*.api.json
136)
137
138java_api_binding (core core ${files})
139
140############ Plugin Packages #######################
141unset (ACL_JSON_FILE)
142unset (NAT_JSON_FILE)
143unset (NSH_JSON_FILE)
144unset (GTPU_JSON_FILE)
145unset (PPPOE_JSON_FILE)
146unset (IOAM_TRACE_JSON_FILE)
147unset (IOAM_POT_JSON_FILE)
148unset (IOAM_EXPORT_JSON_FILE)
149
150set (plugin_path ${CMAKE_BINARY_DIR}/../vpp/plugins)
151
152find_file(ACL_JSON_FILE NAMES acl.api.json HINTS ${plugin_path} PATH_SUFFIXES acl)
153find_file(NAT_JSON_FILE NAMES nat.api.json HINTS ${plugin_path} PATH_SUFFIXES nat)
154find_file(NSH_JSON_FILE NAMES nsh.api.json HINTS ${plugin_path} PATH_SUFFIXES nsh)
155find_file(GTPU_JSON_FILE NAMES gtpu.api.json HINTS ${plugin_path} PATH_SUFFIXES gtpu)
156find_file(PPPOE_JSON_FILE NAMES pppoe.api.json HINTS ${plugin_path} PATH_SUFFIXES pppoe)
157find_file(IOAM_TRACE_JSON_FILE NAMES trace.api.json HINTS ${plugin_path} PATH_SUFFIXES ioam/lib-trace)
158find_file(IOAM_POT_JSON_FILE NAMES pot.api.json HINTS ${plugin_path} PATH_SUFFIXES ioam/lib-pot)
159find_file(IOAM_EXPORT_JSON_FILE NAMES ioam_export.api.json HINTS ${plugin_path} PATH_SUFFIXES ioam/export)
160
161if(ACL_JSON_FILE)
162 java_api_binding (acl acl ${ACL_JSON_FILE})
163endif()
164
165if(NAT_JSON_FILE)
166 java_api_binding (nat nat ${NAT_JSON_FILE})
167endif()
168
169if(NSH_JSON_FILE)
170 java_api_binding (nsh nsh ${NSH_JSON_FILE})
171endif()
172
173if(GTPU_JSON_FILE)
174 java_api_binding (gtpu gtpu ${GTPU_JSON_FILE})
175endif()
176
177if(PPPOE_JSON_FILE)
178 java_api_binding (pppoe pppoe ${PPPOE_JSON_FILE})
179endif()
180
181if(IOAM_TRACE_JSON_FILE)
182 java_api_binding (ioamtrace ioam_trace ${IOAM_TRACE_JSON_FILE})
183endif()
184
185if(IOAM_POT_JSON_FILE)
186 java_api_binding (ioampot ioam_pot ${IOAM_POT_JSON_FILE})
187endif()
188
189if(IOAM_EXPORT_JSON_FILE)
190 java_api_binding (ioamexport ioam_export ${IOAM_EXPORT_JSON_FILE})
191endif()