aboutsummaryrefslogtreecommitdiffstats
path: root/src/examples/sample-plugin
diff options
context:
space:
mode:
authorDamjan Marion <damarion@cisco.com>2018-09-12 12:12:36 +0200
committerDave Barach <openvpp@barachs.net>2018-09-12 17:04:36 +0000
commit0fa900e482451d05449501c1422bfa7c47eec661 (patch)
treec9f17a9fa246221aec040d334ef0ae52143768b5 /src/examples/sample-plugin
parent79dcbc74cd417f4caf41bc398ccba94cab7d656b (diff)
cmake: create cmake VPP module, update sample-plugin so it uses it
Change-Id: I32e91ba8e55797ffe169f98b09bdb42caa5c7de2 Signed-off-by: Damjan Marion <damarion@cisco.com>
Diffstat (limited to 'src/examples/sample-plugin')
-rw-r--r--src/examples/sample-plugin/CMakeLists.txt10
-rw-r--r--src/examples/sample-plugin/Makefile.am58
-rw-r--r--src/examples/sample-plugin/configure.ac41
-rw-r--r--src/examples/sample-plugin/sample/CMakeLists.txt (renamed from src/examples/sample-plugin/sample.am)29
-rw-r--r--src/examples/sample-plugin/sample/node.c20
5 files changed, 32 insertions, 126 deletions
diff --git a/src/examples/sample-plugin/CMakeLists.txt b/src/examples/sample-plugin/CMakeLists.txt
new file mode 100644
index 00000000000..eac58fbc258
--- /dev/null
+++ b/src/examples/sample-plugin/CMakeLists.txt
@@ -0,0 +1,10 @@
+cmake_minimum_required(VERSION 3.5)
+
+project(sample-plugin)
+
+set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
+set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
+
+find_package(VPP)
+
+add_subdirectory(sample)
diff --git a/src/examples/sample-plugin/Makefile.am b/src/examples/sample-plugin/Makefile.am
deleted file mode 100644
index 1825a8f111f..00000000000
--- a/src/examples/sample-plugin/Makefile.am
+++ /dev/null
@@ -1,58 +0,0 @@
-# Copyright (c) 2015 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.
-
-AUTOMAKE_OPTIONS = foreign subdir-objects
-
-AM_CFLAGS = -Wall -I${top_srcdir} -I${top_builddir}
-AM_LDFLAGS = -module -shared -avoid-version
-AM_LIBTOOLFLAGS = --quiet
-SUFFIXES = .api.h .api .api.json
-API_FILES =
-BUILT_SOURCES =
-vppplugins_LTLIBRARIES =
-vppapitestplugins_LTLIBRARIES =
-noinst_HEADERS =
-nobase_apiinclude_HEADERS =
-ACLOCAL_AMFLAGS = -I m4
-
-vppapitestpluginsdir = ${libdir}/vpp_api_test_plugins
-vpppluginsdir = ${libdir}/vpp_plugins
-
-include sample.am
-
-%.api.h: %.api
- @echo " APIGEN " $@ ; \
- mkdir -p `dirname $@` ; \
- vppapigen --input $^ --output $@
-
-%.api.json: %.api
- @echo " JSON APIGEN " $@ ; \
- mkdir -p `dirname $@` ; \
- vppapigen --input $^ JSON --output $@
-
-apidir = $(prefix)/api/plugins
-apiincludedir = ${includedir}/vpp_plugins
-
-api_DATA = \
- $(patsubst %.api,%.api.json,$(API_FILES))
-
-BUILT_SOURCES += \
- $(patsubst %.api,%.api.h,$(API_FILES))
-
-
-# Remove *.la files
-install-data-hook:
- @(cd $(vpppluginsdir) && $(RM) $(vppplugins_LTLIBRARIES))
- @(cd $(vppapitestpluginsdir) && $(RM) $(vppapitestplugins_LTLIBRARIES))
-
-CLEANFILES = $(BUILT_SOURCES)
diff --git a/src/examples/sample-plugin/configure.ac b/src/examples/sample-plugin/configure.ac
deleted file mode 100644
index 69d989183c5..00000000000
--- a/src/examples/sample-plugin/configure.ac
+++ /dev/null
@@ -1,41 +0,0 @@
-AC_INIT(vpp_plugins, 1.0)
-LT_INIT
-AM_INIT_AUTOMAKE
-AM_SILENT_RULES([yes])
-AC_PREFIX_DEFAULT([/usr])
-
-AC_PROG_CC
-
-# Check if compiler supports specific flag
-AC_DEFUN([CC_CHECK_FLAG],
-[
- AC_MSG_CHECKING([if $CC supports $1])
- AC_LANG_PUSH([C])
- ac_saved_cflags="$CFLAGS"
- CFLAGS="-Werror $1"
- AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])],
- [cc_flag_check=yes],
- [cc_flag_check=no]
-)
- AC_MSG_RESULT([$cc_flag_check])
- CFLAGS="$ac_saved_cflags"
- AC_LANG_POP([C])
-])
-
-AC_DEFUN([ENABLE_ARG],
-[
- AC_ARG_ENABLE($1,
- AC_HELP_STRING(patsubst([--enable-$1],[_],[-]), $2),
- [enable_$1=yes n_enable_$1=1],
- [enable_$1=no n_enable_$1=0])
- AM_CONDITIONAL(m4_toupper(ENABLE_$1), test "$enable_$1" = "yes")
- m4_append([list_of_enabled], [$1], [, ])
-])
-
-CC_CHECK_FLAG("-Wno-address-of-packed-member")
-AS_IF([test "$cc_flag_check" = yes],
- [CFLAGS="${CFLAGS} -Wno-address-of-packed-member"], [])
-
-AC_OUTPUT([Makefile])
-
-AC_CONFIG_MACRO_DIR([m4])
diff --git a/src/examples/sample-plugin/sample.am b/src/examples/sample-plugin/sample/CMakeLists.txt
index 871b610aa73..f2fc1434492 100644
--- a/src/examples/sample-plugin/sample.am
+++ b/src/examples/sample-plugin/sample/CMakeLists.txt
@@ -1,4 +1,4 @@
-# Copyright (c) 2016 Cisco and/or its affiliates.
+# 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:
@@ -11,21 +11,22 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-vppapitestplugins_LTLIBRARIES += sample_test_plugin.la
-vppplugins_LTLIBRARIES += sample_plugin.la
+include_directories(${CMAKE_SOURCE_DIR})
-sample_plugin_la_SOURCES = \
- sample/sample.c \
- sample/node.c \
- sample/sample_plugin.api.h
+# for generated API headers:
+include_directories(${CMAKE_BINARY_DIR})
-API_FILES += sample/sample.api
+add_vpp_plugin(sample
+ SOURCES
+ node.c
+ sample.c
-nobase_apiinclude_HEADERS += \
- sample/sample_all_api_h.h \
- sample/sample_msg_enum.h \
- sample/sample.api.h
+ MULTIARCH_SOURCES
+ node.c
-sample_test_plugin_la_SOURCES = sample/sample_test.c sample/sample_plugin.api.h
+ API_FILES
+ sample.api
-# vi:syntax=automake
+ API_TEST_SOURCES
+ sample_test.c
+)
diff --git a/src/examples/sample-plugin/sample/node.c b/src/examples/sample-plugin/sample/node.c
index 7f34be56168..009968b6099 100644
--- a/src/examples/sample-plugin/sample/node.c
+++ b/src/examples/sample-plugin/sample/node.c
@@ -45,7 +45,7 @@ format_sample_trace (u8 * s, va_list * args)
return s;
}
-vlib_node_registration_t sample_node;
+extern vlib_node_registration_t sample_node;
#define foreach_sample_error \
_(SWAPPED, "Mac swap packets processed")
@@ -87,9 +87,8 @@ _(3) \
_(4) \
_(5)
-static uword
-sample_node_fn (vlib_main_t * vm,
- vlib_node_runtime_t * node, vlib_frame_t * frame)
+VLIB_NODE_FN (sample_node) (vlib_main_t * vm, vlib_node_runtime_t * node,
+ vlib_frame_t * frame)
{
u32 n_left_from, *from, *to_next;
sample_next_t next_index;
@@ -285,9 +284,8 @@ sample_node_fn (vlib_main_t * vm,
* Node costs about 17 clocks/pkt at a vector size of 26
*/
#ifdef VERSION_2
-static uword
-sample_node_fn (vlib_main_t * vm,
- vlib_node_runtime_t * node, vlib_frame_t * frame)
+VLIB_NODE_FN (sample_node) (vlib_main_t * vm, vlib_node_runtime_t * node,
+ vlib_frame_t * frame)
{
u32 n_left_from, *from, *to_next;
sample_next_t next_index;
@@ -475,9 +473,8 @@ sample_node_fn (vlib_main_t * vm,
/* This would normally be a stack local, but since it's a constant... */
static const u16 nexts[VLIB_FRAME_SIZE] = { 0 };
-static uword
-sample_node_fn (vlib_main_t * vm,
- vlib_node_runtime_t * node, vlib_frame_t * frame)
+VLIB_NODE_FN (sample_node) (vlib_main_t * vm, vlib_node_runtime_t * node,
+ vlib_frame_t * frame)
{
u32 n_left_from, *from;
u32 pkts_swapped = 0;
@@ -605,7 +602,6 @@ sample_node_fn (vlib_main_t * vm,
/* *INDENT-OFF* */
VLIB_REGISTER_NODE (sample_node) =
{
- .function = sample_node_fn,
.name = "sample",
.vector_size = sizeof (u32),
.format_trace = format_sample_trace,
@@ -623,8 +619,6 @@ VLIB_REGISTER_NODE (sample_node) =
};
/* *INDENT-ON* */
-VLIB_NODE_FUNCTION_MULTIARCH (sample_node, sample_node_fn);
-
/*
* fd.io coding-style-patch-verification: ON
*