Mohsin Kazmi | 2419508 | 2018-09-13 09:59:50 +0200 | [diff] [blame] | 1 | # 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 | |
| 14 | find_path(VNET_INCLUDE_DIR NAMES vnet/api_errno.h) |
| 15 | find_library(VPPINFRA_DIR NAMES vppinfra REQUIRED) |
| 16 | find_library(VLIBMEMORYCLIENT_DIR NAMES vlibmemoryclient REQUIRED) |
| 17 | find_library(SVM_DIR NAMES svm REQUIRED) |
| 18 | |
| 19 | include_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}) |
| 24 | add_compile_options(-Wall) |
| 25 | ############# Common package ################## |
| 26 | add_library(jvpp_common SHARED jvpp-common/jvpp_common.c) |
| 27 | set_target_properties(jvpp_common PROPERTIES SOVERSION ${JAPI_LIB_VERSION}) |
| 28 | target_link_libraries(jvpp_common ${VPPINFRA_DIR}) |
| 29 | install(TARGETS jvpp_common DESTINATION lib COMPONENT libjvpp_common) |
| 30 | install(FILES jvpp-common/jvpp_common.h DESTINATION include/japi/) |
| 31 | |
| 32 | set(JVPP_LIBS jvpp_common ${VPPINFRA_DIR} ${VLIBMEMORYCLIENT_DIR} ${SVM_DIR} |
| 33 | Threads::Threads m rt) |
| 34 | |
| 35 | ############# Registry package ################## |
| 36 | set(PACKAGE_DIR_JVPP_REGISTRY io/fd/vpp/jvpp) |
| 37 | unset(files) |
| 38 | FILE(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 | |
| 44 | add_custom_target (jvpp-registry-classes) |
| 45 | add_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 | |
| 54 | add_library(jvpp_registry SHARED jvpp-registry/jvpp_registry.c) |
| 55 | target_link_libraries(jvpp_registry ${JVPP_LIBS}) |
| 56 | include_directories(jvpp-registry) |
| 57 | add_dependencies(jvpp_registry jvpp_common jvpp-registry-classes) |
| 58 | |
| 59 | add_custom_target (jvpp-registry) |
| 60 | add_dependencies(jvpp-registry jvpp_registry) |
| 61 | add_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 | ) |
| 72 | install( |
| 73 | FILES ${CMAKE_CURRENT_BINARY_DIR}/jvpp-registry-${JAPI_LIB_VERSION}.jar |
| 74 | DESTINATION share/java |
| 75 | ) |
| 76 | |
| 77 | ############## Functions ######################### |
| 78 | function(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 | ) |
| 97 | endfunction() |
| 98 | |
| 99 | function(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 | ) |
| 116 | endfunction() |
| 117 | |
| 118 | function(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}) |
| 125 | endfunction() |
| 126 | |
| 127 | ############ Core Package ####################### |
| 128 | unset (files) |
| 129 | unset (JSON_API_PATH) |
| 130 | set (JSON_API_PATH ${CMAKE_BINARY_DIR}/../vpp) |
| 131 | |
| 132 | FILE(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 | |
| 138 | java_api_binding (core core ${files}) |
| 139 | |
| 140 | ############ Plugin Packages ####################### |
| 141 | unset (ACL_JSON_FILE) |
| 142 | unset (NAT_JSON_FILE) |
| 143 | unset (NSH_JSON_FILE) |
| 144 | unset (GTPU_JSON_FILE) |
| 145 | unset (PPPOE_JSON_FILE) |
| 146 | unset (IOAM_TRACE_JSON_FILE) |
| 147 | unset (IOAM_POT_JSON_FILE) |
| 148 | unset (IOAM_EXPORT_JSON_FILE) |
| 149 | |
| 150 | set (plugin_path ${CMAKE_BINARY_DIR}/../vpp/plugins) |
| 151 | |
| 152 | find_file(ACL_JSON_FILE NAMES acl.api.json HINTS ${plugin_path} PATH_SUFFIXES acl) |
| 153 | find_file(NAT_JSON_FILE NAMES nat.api.json HINTS ${plugin_path} PATH_SUFFIXES nat) |
| 154 | find_file(NSH_JSON_FILE NAMES nsh.api.json HINTS ${plugin_path} PATH_SUFFIXES nsh) |
| 155 | find_file(GTPU_JSON_FILE NAMES gtpu.api.json HINTS ${plugin_path} PATH_SUFFIXES gtpu) |
| 156 | find_file(PPPOE_JSON_FILE NAMES pppoe.api.json HINTS ${plugin_path} PATH_SUFFIXES pppoe) |
| 157 | find_file(IOAM_TRACE_JSON_FILE NAMES trace.api.json HINTS ${plugin_path} PATH_SUFFIXES ioam/lib-trace) |
| 158 | find_file(IOAM_POT_JSON_FILE NAMES pot.api.json HINTS ${plugin_path} PATH_SUFFIXES ioam/lib-pot) |
| 159 | find_file(IOAM_EXPORT_JSON_FILE NAMES ioam_export.api.json HINTS ${plugin_path} PATH_SUFFIXES ioam/export) |
| 160 | |
| 161 | if(ACL_JSON_FILE) |
| 162 | java_api_binding (acl acl ${ACL_JSON_FILE}) |
| 163 | endif() |
| 164 | |
| 165 | if(NAT_JSON_FILE) |
| 166 | java_api_binding (nat nat ${NAT_JSON_FILE}) |
| 167 | endif() |
| 168 | |
| 169 | if(NSH_JSON_FILE) |
| 170 | java_api_binding (nsh nsh ${NSH_JSON_FILE}) |
| 171 | endif() |
| 172 | |
| 173 | if(GTPU_JSON_FILE) |
| 174 | java_api_binding (gtpu gtpu ${GTPU_JSON_FILE}) |
| 175 | endif() |
| 176 | |
| 177 | if(PPPOE_JSON_FILE) |
| 178 | java_api_binding (pppoe pppoe ${PPPOE_JSON_FILE}) |
| 179 | endif() |
| 180 | |
| 181 | if(IOAM_TRACE_JSON_FILE) |
| 182 | java_api_binding (ioamtrace ioam_trace ${IOAM_TRACE_JSON_FILE}) |
| 183 | endif() |
| 184 | |
| 185 | if(IOAM_POT_JSON_FILE) |
| 186 | java_api_binding (ioampot ioam_pot ${IOAM_POT_JSON_FILE}) |
| 187 | endif() |
| 188 | |
| 189 | if(IOAM_EXPORT_JSON_FILE) |
| 190 | java_api_binding (ioamexport ioam_export ${IOAM_EXPORT_JSON_FILE}) |
| 191 | endif() |