summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDamjan Marion <damarion@cisco.com>2018-08-26 18:14:46 +0200
committerMarco Varlese <marco.varlese@suse.de>2018-08-27 12:25:48 +0000
commit4c64b6edc86f7732f4a160b948b3386e4021a265 (patch)
tree296a8425f5b5274cf772fa3e62c4c145096a481e /src
parent3ce5f914ed6bd78f4b72bb5dfd4be480084094d1 (diff)
cmake: add vapi build
Change-Id: Id939a0cbe35601478ad262f49bb0a1abdb62aa45 Signed-off-by: Damjan Marion <damarion@cisco.com>
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt2
-rw-r--r--src/cmake/api.cmake7
-rw-r--r--src/cmake/library.cmake2
-rw-r--r--src/cmake/plugin.cmake6
-rw-r--r--src/vpp-api/CMakeLists.txt2
-rw-r--r--src/vpp-api/vapi/CMakeLists.txt75
-rwxr-xr-xsrc/vpp-api/vapi/vapi_c_gen.py19
-rwxr-xr-xsrc/vpp-api/vapi/vapi_cpp_gen.py18
-rw-r--r--src/vpp-api/vapi/vapi_json_parser.py2
-rw-r--r--src/vpp/CMakeLists.txt2
10 files changed, 116 insertions, 19 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 0f218cb139d..51f9f7edb63 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -61,7 +61,7 @@ include(cmake/deb.cmake)
##############################################################################
# subdirs
##############################################################################
-foreach (DIR vppinfra svm vlib vlibmemory vlibapi vnet vpp vpp-api vat vcl plugins)
+foreach (DIR vppinfra svm vlib vlibmemory vlibapi vnet vpp vat vcl plugins vpp-api)
add_subdirectory(${DIR})
endforeach ()
diff --git a/src/cmake/api.cmake b/src/cmake/api.cmake
index 644e80b8270..533448ad16e 100644
--- a/src/cmake/api.cmake
+++ b/src/cmake/api.cmake
@@ -50,11 +50,14 @@ function(vpp_generate_api_header file dir)
vpp_generate_api_json_header (${file} ${dir})
endfunction()
-function(vpp_add_api_files target)
+function(vpp_add_api_files name)
unset(header_files)
+ set(target ${name}_api_headers)
+ file(RELATIVE_PATH rpath ${CMAKE_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR})
foreach(file ${ARGN})
vpp_generate_api_header (${file} core)
- list (APPEND header_files ${file}.h ${file}.json)
+ list(APPEND header_files ${file}.h ${file}.json)
+ set_property(GLOBAL APPEND PROPERTY VPP_API_FILES ${rpath}/${file})
endforeach()
add_custom_target(${target} DEPENDS ${header_files})
endfunction()
diff --git a/src/cmake/library.cmake b/src/cmake/library.cmake
index 6aa0ae848f9..9ed53e9dba7 100644
--- a/src/cmake/library.cmake
+++ b/src/cmake/library.cmake
@@ -33,7 +33,7 @@ macro(add_vpp_library lib)
endif()
if(ARG_API_FILES)
- vpp_add_api_files(${lib}_api_headers ${ARG_API_FILES})
+ vpp_add_api_files(${lib} ${ARG_API_FILES})
foreach(file ${ARG_API_FILES})
get_filename_component(dir ${file} DIRECTORY)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${file}.h DESTINATION include/${lib}/${dir})
diff --git a/src/cmake/plugin.cmake b/src/cmake/plugin.cmake
index 4087325b0d6..a5b4bf51a16 100644
--- a/src/cmake/plugin.cmake
+++ b/src/cmake/plugin.cmake
@@ -20,9 +20,11 @@ macro(add_vpp_plugin name)
)
set(plugin_name ${name}_plugin)
set(api_headers)
+ file(RELATIVE_PATH rpath ${CMAKE_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR})
foreach(f ${PLUGIN_API_FILES})
- vpp_generate_api_header(${f} plugins)
- list(APPEND api_headers ${f}.h ${f}.json)
+ vpp_generate_api_header(${f} plugins)
+ list(APPEND api_headers ${f}.h ${f}.json)
+ set_property(GLOBAL APPEND PROPERTY VPP_API_FILES ${rpath}/${f})
endforeach()
add_library(${plugin_name} SHARED ${PLUGIN_SOURCES} ${api_headers})
add_dependencies(${plugin_name} vpp_version_h api_headers)
diff --git a/src/vpp-api/CMakeLists.txt b/src/vpp-api/CMakeLists.txt
index cfabc7151ef..5715069097c 100644
--- a/src/vpp-api/CMakeLists.txt
+++ b/src/vpp-api/CMakeLists.txt
@@ -27,3 +27,5 @@ add_dependencies(vppapiclient vpp_version_h api_headers)
add_vpp_headers(vpp-api
client/vppapiclient.h
)
+
+add_subdirectory(vapi)
diff --git a/src/vpp-api/vapi/CMakeLists.txt b/src/vpp-api/vapi/CMakeLists.txt
new file mode 100644
index 00000000000..8feb12e3dcf
--- /dev/null
+++ b/src/vpp-api/vapi/CMakeLists.txt
@@ -0,0 +1,75 @@
+# 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.
+
+include_directories (
+ ${CMAKE_CURRENT_SOURCE_DIR}/..
+ ${CMAKE_CURRENT_BINARY_DIR}/..
+)
+
+unset(VAPICLIENT_API_C_HEADERS)
+unset(VAPICLIENT_API_CPP_HEADERS)
+
+get_property(VPP_API_FILES GLOBAL PROPERTY VPP_API_FILES)
+foreach(f ${VPP_API_FILES})
+ get_filename_component(output ${f}.vapi.h NAME)
+ set(input ${CMAKE_BINARY_DIR}/${f}.json)
+
+ # C VAPI Headers
+ add_custom_command(
+ OUTPUT ${output}
+ WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
+ COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/vapi_c_gen.py
+ ARGS --remove-path ${input}
+ DEPENDS ${input} vapi_c_gen.py vapi_json_parser.py
+ COMMENT "Generating VAPI C header ${output}"
+ )
+ install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${output} DESTINATION include/vapi)
+ list(APPEND VAPICLIENT_API_CPP_HEADERS ${output})
+
+ # C++ VAPI Headers
+ get_filename_component(output ${f}.vapi.hpp NAME)
+ add_custom_command(
+ OUTPUT ${output}
+ WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
+ COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/vapi_cpp_gen.py
+ ARGS --remove-path ${input}
+ DEPENDS ${input} vapi_cpp_gen.py vapi_json_parser.py
+ COMMENT "Generating VAPI C++ header ${output}"
+ )
+ install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${output} DESTINATION include/vapi)
+ list(APPEND VAPICLIENT_API_CPP_HEADERS ${output})
+endforeach ()
+
+add_custom_target(all-vapi-headers ALL DEPENDS
+ ${VAPICLIENT_API_C_HEADERS}
+ ${VAPICLIENT_API_CPP_HEADERS}
+)
+
+add_vpp_library(vapiclient
+ SOURCES
+ vapi.c
+ libvapiclient.map
+
+ LINK_LIBRARIES vppinfra vlibmemoryclient svm pthread m rt
+)
+
+install(
+ FILES
+ vapi.h
+ vapi_common.h
+ vapi_dbg.h
+ vapi.hpp
+ vapi_internal.h
+
+ DESTINATION include/vapi
+)
diff --git a/src/vpp-api/vapi/vapi_c_gen.py b/src/vpp-api/vapi/vapi_c_gen.py
index 5a185398e89..445790d1059 100755
--- a/src/vpp-api/vapi/vapi_c_gen.py
+++ b/src/vpp-api/vapi/vapi_c_gen.py
@@ -532,6 +532,7 @@ vapi_send_with_control_ping (vapi_ctx_t ctx, void *msg, u32 context)
def gen_json_unified_header(parser, logger, j, io, name):
+ d, f = os.path.split(j)
logger.info("Generating header `%s'" % name)
orig_stdout = sys.stdout
sys.stdout = io
@@ -561,7 +562,7 @@ def gen_json_unified_header(parser, logger, j, io, name):
print("extern vapi_msg_id_t %s;" % m.get_msg_id_name())
print("")
print("#define DEFINE_VAPI_MSG_IDS_%s\\" %
- j.replace(".", "_").replace("/", "_").replace("-", "_").upper())
+ f.replace(".", "_").replace("/", "_").replace("-", "_").upper())
print("\\\n".join([
" vapi_msg_id_t %s;" % m.get_msg_id_name()
for m in parser.messages_by_json[j].values()
@@ -639,15 +640,19 @@ def json_to_c_header_name(json_name):
raise Exception("Unexpected json name `%s'!" % json_name)
-def gen_c_unified_headers(parser, logger, prefix):
+def gen_c_unified_headers(parser, logger, prefix, remove_path):
if prefix == "" or prefix is None:
prefix = ""
else:
prefix = "%s/" % prefix
for j in parser.json_files:
- with open('%s%s' % (prefix, json_to_c_header_name(j)), "w") as io:
+ if remove_path:
+ d, f = os.path.split(j)
+ else:
+ f = j
+ with open('%s%s' % (prefix, json_to_c_header_name(f)), "w") as io:
gen_json_unified_header(
- parser, logger, j, io, json_to_c_header_name(j))
+ parser, logger, j, io, json_to_c_header_name(f))
if __name__ == '__main__':
@@ -673,6 +678,8 @@ if __name__ == '__main__':
'(may be specified multiple times)')
argparser.add_argument('--prefix', action='store', default=None,
help='path prefix')
+ argparser.add_argument('--remove-path', action='store_true',
+ help='remove path from filename')
args = argparser.parse_args()
jsonparser = JsonParser(logger, args.files,
@@ -686,7 +693,7 @@ if __name__ == '__main__':
# Damjan), to avoid symbol version issues in .so
# gen_c_headers_and_code(jsonparser, logger, args.prefix)
- gen_c_unified_headers(jsonparser, logger, args.prefix)
+ gen_c_unified_headers(jsonparser, logger, args.prefix, args.remove_path)
for e in jsonparser.exceptions:
- logger.error(e)
+ logger.warning(e)
diff --git a/src/vpp-api/vapi/vapi_cpp_gen.py b/src/vpp-api/vapi/vapi_cpp_gen.py
index e83e151a879..adf85c753d8 100755
--- a/src/vpp-api/vapi/vapi_cpp_gen.py
+++ b/src/vpp-api/vapi/vapi_cpp_gen.py
@@ -129,8 +129,9 @@ def gen_json_header(parser, logger, j, io, gen_h_prefix, add_debug_comments):
logger.info("Generating header `%s'" % io.name)
orig_stdout = sys.stdout
sys.stdout = io
+ d, f = os.path.split(j)
include_guard = "__included_hpp_%s" % (
- j.replace(".", "_").replace("/", "_").replace("-", "_"))
+ f.replace(".", "_").replace("/", "_").replace("-", "_"))
print("#ifndef %s" % include_guard)
print("#define %s" % include_guard)
print("")
@@ -192,7 +193,7 @@ def json_to_cpp_header_name(json_name):
raise Exception("Unexpected json name `%s'!" % json_name)
-def gen_cpp_headers(parser, logger, prefix, gen_h_prefix,
+def gen_cpp_headers(parser, logger, prefix, gen_h_prefix, remove_path,
add_debug_comments=False):
if prefix == "" or prefix is None:
prefix = ""
@@ -203,7 +204,11 @@ def gen_cpp_headers(parser, logger, prefix, gen_h_prefix,
else:
gen_h_prefix = "%s/" % gen_h_prefix
for j in parser.json_files:
- with open('%s%s' % (prefix, json_to_cpp_header_name(j)), "w") as io:
+ if remove_path:
+ d, f = os.path.split(j)
+ else:
+ f = j
+ with open('%s%s' % (prefix, json_to_cpp_header_name(f)), "w") as io:
gen_json_header(parser, logger, j, io,
gen_h_prefix, add_debug_comments)
@@ -233,6 +238,8 @@ if __name__ == '__main__':
help='path prefix')
argparser.add_argument('--gen-h-prefix', action='store', default=None,
help='generated C header prefix')
+ argparser.add_argument('--remove-path', action='store_true',
+ help='remove path from filename')
args = argparser.parse_args()
jsonparser = JsonParser(logger, args.files,
@@ -241,7 +248,8 @@ if __name__ == '__main__':
field_class=CppField,
message_class=CppMessage)
- gen_cpp_headers(jsonparser, logger, args.prefix, args.gen_h_prefix)
+ gen_cpp_headers(jsonparser, logger, args.prefix, args.gen_h_prefix,
+ args.remove_path)
for e in jsonparser.exceptions:
- logger.error(e)
+ logger.warning(e)
diff --git a/src/vpp-api/vapi/vapi_json_parser.py b/src/vpp-api/vapi/vapi_json_parser.py
index 58a75777f11..b18eda42f6b 100644
--- a/src/vpp-api/vapi/vapi_json_parser.py
+++ b/src/vpp-api/vapi/vapi_json_parser.py
@@ -346,7 +346,7 @@ class JsonParser(object):
def finalize_parsing(self):
if len(self.messages) == 0:
for e in self.exceptions:
- self.logger.error(e)
+ self.logger.warning(e)
for jn, j in self.messages_by_json.items():
remove = []
for n, m in j.items():
diff --git a/src/vpp/CMakeLists.txt b/src/vpp/CMakeLists.txt
index 80114bd5249..6f58e8db8ec 100644
--- a/src/vpp/CMakeLists.txt
+++ b/src/vpp/CMakeLists.txt
@@ -39,7 +39,7 @@ set(VPP_API_FILES
oam/oam.api
)
-vpp_add_api_files(vpp_api_headers ${VPP_API_FILES})
+vpp_add_api_files(vpp ${VPP_API_FILES})
foreach(file ${VPP_API_FILES})
get_filename_component(dir ${file} DIRECTORY)