aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--build-data/packages/sample-plugin.mk26
-rw-r--r--src/CMakeLists.txt3
-rw-r--r--src/cmake/CMakeLists.txt26
-rw-r--r--src/cmake/VPPConfig.cmake38
-rw-r--r--src/cmake/api.cmake10
-rw-r--r--src/cmake/plugin.cmake17
-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
11 files changed, 143 insertions, 135 deletions
diff --git a/build-data/packages/sample-plugin.mk b/build-data/packages/sample-plugin.mk
index 8aca9ea804c..77855671b12 100644
--- a/build-data/packages/sample-plugin.mk
+++ b/build-data/packages/sample-plugin.mk
@@ -17,3 +17,29 @@ sample-plugin_configure_depend = vpp-install
sample-plugin_CPPFLAGS = $(call installed_includes_fn, vpp)
sample-plugin_LDFLAGS = $(call installed_libs_fn, vpp)
sample-plugin_PATH = $(call package_install_dir_fn,vpp)/bin
+
+ifneq ($(shell which cmake3),)
+CMAKE?=cmake3
+else
+CMAKE?=cmake
+endif
+
+sample-plugin_cmake_args ?=
+sample-plugin_cmake_args += -DCMAKE_INSTALL_PREFIX:PATH=$(PACKAGE_INSTALL_DIR)
+sample-plugin_cmake_args += -DCMAKE_C_FLAGS="$($(TAG)_TAG_CFLAGS)"
+sample-plugin_cmake_args += -DCMAKE_SHARED_LINKER_FLAGS="$($(TAG)_TAG_LDFLAGS)"
+sample-plugin_cmake_args += -DCMAKE_PREFIX_PATH:PATH="$(PACKAGE_INSTALL_DIR)/../vpp"
+
+# Use devtoolset on centos 7
+ifneq ($(wildcard /opt/rh/devtoolset-7/enable),)
+sample-plugin_cmake_args += -DCMAKE_PROGRAM_PATH:PATH="/opt/rh/devtoolset-7/root/bin"
+endif
+
+sample-plugin_configure = \
+ cd $(PACKAGE_BUILD_DIR) && \
+ $(CMAKE) -G Ninja $(sample-plugin_cmake_args) \
+ $(call find_source_fn,$(PACKAGE_SOURCE))$(PACKAGE_SUBDIR)
+
+sample-plugin_build = $(CMAKE) --build $(PACKAGE_BUILD_DIR) -- $(MAKE_PARALLEL_FLAGS)
+
+sample-plugin_install = $(CMAKE) --build $(PACKAGE_BUILD_DIR) -- install
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 420725a5f22..05457ebe40c 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -75,7 +75,8 @@ if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
find_package(OpenSSL REQUIRED)
set(SUBDIRS
vppinfra svm vlib vlibmemory vlibapi vnet vpp vat vcl plugins
- vpp-api tools/vppapigen tools/g2 tools/elftool tools/perftool)
+ vpp-api tools/vppapigen tools/g2 tools/elftool tools/perftool cmake
+ )
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin")
set(SUBDIRS vppinfra)
else()
diff --git a/src/cmake/CMakeLists.txt b/src/cmake/CMakeLists.txt
new file mode 100644
index 00000000000..7eb1790f2e8
--- /dev/null
+++ b/src/cmake/CMakeLists.txt
@@ -0,0 +1,26 @@
+# 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.
+
+install(
+ FILES
+ api.cmake
+ cpu.cmake
+ library.cmake
+ plugin.cmake
+ VPPConfig.cmake
+
+ DESTINATION
+ lib/cmake/vpp
+
+ COMPONENT vpp-dev
+)
diff --git a/src/cmake/VPPConfig.cmake b/src/cmake/VPPConfig.cmake
new file mode 100644
index 00000000000..767fe34c189
--- /dev/null
+++ b/src/cmake/VPPConfig.cmake
@@ -0,0 +1,38 @@
+# 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.
+
+get_filename_component(CMAKE_CURRENT_LIST_DIR ${CMAKE_CURRENT_LIST_FILE} PATH)
+
+find_path(VPP_INCLUDE_DIR PATH_SUFFIXES NAMES vppinfra/clib.h)
+find_program(VPP_APIGEN vppapigen)
+
+if(VPP_INCLUDE_DIR AND VPP_APIGEN)
+ include_directories (${VPP_INCLUDE_DIR})
+else()
+ message(FATAL_ERROR "VPP headers, libraries and/or tools not found")
+endif()
+
+set(VPP_EXTERNAL_PROJECT 1)
+
+include(CheckCCompilerFlag)
+
+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()
+
+include(CheckCCompilerFlag)
+include(${CMAKE_CURRENT_LIST_DIR}/cpu.cmake)
+include(${CMAKE_CURRENT_LIST_DIR}/api.cmake)
+include(${CMAKE_CURRENT_LIST_DIR}/library.cmake)
+include(${CMAKE_CURRENT_LIST_DIR}/plugin.cmake)
diff --git a/src/cmake/api.cmake b/src/cmake/api.cmake
index d799c54a0a6..415eb5e8c0c 100644
--- a/src/cmake/api.cmake
+++ b/src/cmake/api.cmake
@@ -17,9 +17,12 @@
function(vpp_generate_api_c_header file)
set (output_name ${CMAKE_CURRENT_BINARY_DIR}/${file}.h)
get_filename_component(output_dir ${output_name} DIRECTORY)
+ if(NOT VPP_APIGEN)
+ set(VPP_APIGEN ${CMAKE_SOURCE_DIR}/tools/vppapigen/vppapigen)
+ endif()
add_custom_command (OUTPUT ${output_name}
COMMAND mkdir -p ${output_dir}
- COMMAND ${CMAKE_SOURCE_DIR}/tools/vppapigen/vppapigen
+ COMMAND ${VPP_APIGEN}
ARGS --includedir ${CMAKE_SOURCE_DIR} --input ${CMAKE_CURRENT_SOURCE_DIR}/${file} --output ${output_name}
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${file}
COMMENT "Generating API header ${output_name}"
@@ -29,9 +32,12 @@ endfunction()
function(vpp_generate_api_json_header file dir component)
set (output_name ${CMAKE_CURRENT_BINARY_DIR}/${file}.json)
get_filename_component(output_dir ${output_name} DIRECTORY)
+ if(NOT VPP_APIGEN)
+ set(VPP_APIGEN ${CMAKE_SOURCE_DIR}/tools/vppapigen/vppapigen)
+ endif()
add_custom_command (OUTPUT ${output_name}
COMMAND mkdir -p ${output_dir}
- COMMAND ${CMAKE_SOURCE_DIR}/tools/vppapigen/vppapigen
+ COMMAND ${VPP_APIGEN}
ARGS --includedir ${CMAKE_SOURCE_DIR} --input ${CMAKE_CURRENT_SOURCE_DIR}/${file} JSON --output ${output_name}
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${file}
COMMENT "Generating API header ${output_name}"
diff --git a/src/cmake/plugin.cmake b/src/cmake/plugin.cmake
index 39c940daed4..f68c955f64f 100644
--- a/src/cmake/plugin.cmake
+++ b/src/cmake/plugin.cmake
@@ -19,7 +19,7 @@ macro(add_vpp_plugin name)
${ARGN}
)
set(plugin_name ${name}_plugin)
- set(api_headers)
+ set(api_includes)
if(NOT PLUGIN_COMPONENT)
set(PLUGIN_COMPONENT vpp-plugin-misc)
endif()
@@ -27,7 +27,7 @@ macro(add_vpp_plugin name)
foreach(f ${PLUGIN_API_FILES})
get_filename_component(dir ${f} DIRECTORY)
vpp_generate_api_header(${f} plugins ${PLUGIN_COMPONENT})
- list(APPEND api_headers ${f}.h ${f}.json)
+ list(APPEND api_includes ${f}.h ${f}.json)
set_property(GLOBAL APPEND PROPERTY VPP_API_FILES ${rpath}/${f})
install(
FILES ${CMAKE_CURRENT_BINARY_DIR}/${f}.h
@@ -35,9 +35,11 @@ macro(add_vpp_plugin name)
COMPONENT vpp-dev
)
endforeach()
- add_library(${plugin_name} SHARED ${PLUGIN_SOURCES} ${api_headers})
+ add_library(${plugin_name} SHARED ${PLUGIN_SOURCES} ${api_includes})
target_compile_options(${plugin_name} PRIVATE -Wall)
- add_dependencies(${plugin_name} vpp_version_h api_headers)
+ if(NOT VPP_EXTERNAL_PROJECT)
+ add_dependencies(${plugin_name} vpp_version_h api_headers)
+ endif()
set_target_properties(${plugin_name} PROPERTIES
PREFIX ""
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/vpp_plugins)
@@ -62,8 +64,11 @@ macro(add_vpp_plugin name)
endif()
if(PLUGIN_API_TEST_SOURCES)
set(test_plugin_name ${name}_test_plugin)
- add_library(${test_plugin_name} SHARED ${PLUGIN_API_TEST_SOURCES} ${api_headers})
- add_dependencies(${test_plugin_name} api_headers)
+ add_library(${test_plugin_name} SHARED ${PLUGIN_API_TEST_SOURCES}
+ ${api_includes})
+ if(NOT VPP_EXTERNAL_PROJECT)
+ add_dependencies(${test_plugin_name} api_headers)
+ endif()
set_target_properties(${test_plugin_name} PROPERTIES
PREFIX ""
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/vpp_api_test_plugins)
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
*