build: export vapi generation in vpp-dev
Adds the higher-level vapi generation to cmake/api.cmake and exposes the necessary python scripts in vpp-dev, so that out-of-tree/downstream plugins can also leverage the more convenient API. Type: feature Signed-off-by: Oliver Giles <oliver_g@radwin.com> Change-Id: I8c40a14d27ba3cb972c6907632e03c0e7b0ce982
This commit is contained in:

committed by
Damjan Marion

parent
3d14f03619
commit
dc20371f83
@ -403,6 +403,9 @@ fi
|
||||
%files devel
|
||||
%defattr(-,bin,bin)
|
||||
/usr/bin/vppapigen
|
||||
/usr/bin/vapi_c_gen.py
|
||||
/usr/bin/vapi_cpp_gen.py
|
||||
/usr/bin/vapi_json_parser.py
|
||||
%{_includedir}/*
|
||||
/usr/share/doc/vpp/examples/sample-plugin
|
||||
/usr/share/vpp
|
||||
|
@ -15,6 +15,8 @@ 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)
|
||||
find_program(VPP_VAPI_C_GEN vapi_c_gen.py)
|
||||
find_program(VPP_VAPI_CPP_GEN vapi_cpp_gen.py)
|
||||
|
||||
if(VPP_INCLUDE_DIR AND VPP_APIGEN)
|
||||
include_directories (${VPP_INCLUDE_DIR})
|
||||
|
@ -55,6 +55,65 @@ function(vpp_generate_api_json_header file dir component)
|
||||
)
|
||||
endfunction()
|
||||
|
||||
##############################################################################
|
||||
# VPP-API
|
||||
##############################################################################
|
||||
function(vpp_generate_vapi_c_header f)
|
||||
get_filename_component(output ${f}.vapi.h NAME)
|
||||
set (output_name ${CMAKE_BINARY_DIR}/vpp-api/vapi/${output})
|
||||
if(NOT VPP_VAPI_C_GEN)
|
||||
set(VPP_VAPI_C_GEN ${CMAKE_SOURCE_DIR}/vpp-api/vapi/vapi_c_gen.py)
|
||||
set(VPP_VAPI_C_GEN_DEPENDS
|
||||
${CMAKE_SOURCE_DIR}/vpp-api/vapi/vapi_c_gen.py
|
||||
${CMAKE_SOURCE_DIR}/vpp-api/vapi/vapi_json_parser.py
|
||||
)
|
||||
endif()
|
||||
|
||||
# C VAPI Headers
|
||||
set(input ${CMAKE_CURRENT_BINARY_DIR}/${f}.json)
|
||||
add_custom_command(
|
||||
OUTPUT ${output_name}
|
||||
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/vpp-api/vapi
|
||||
COMMAND ${VPP_VAPI_C_GEN}
|
||||
ARGS --remove-path ${input}
|
||||
DEPENDS ${input} ${VPP_VAPI_C_GEN_DEPENDS}
|
||||
COMMENT "Generating VAPI C header ${output_name}"
|
||||
)
|
||||
install(
|
||||
FILES ${output_name}
|
||||
DESTINATION include/vapi
|
||||
COMPONENT vpp-dev
|
||||
)
|
||||
endfunction ()
|
||||
|
||||
function (vpp_generate_vapi_cpp_header f)
|
||||
get_filename_component(output ${f}.vapi.hpp NAME)
|
||||
set (output_name ${CMAKE_BINARY_DIR}/vpp-api/vapi/${output})
|
||||
if(NOT VPP_VAPI_CPP_GEN)
|
||||
set(VPP_VAPI_CPP_GEN ${CMAKE_SOURCE_DIR}/vpp-api/vapi/vapi_cpp_gen.py)
|
||||
set(VPP_VAPI_CPP_GEN_DEPENDS
|
||||
${CMAKE_SOURCE_DIR}/vpp-api/vapi/vapi_cpp_gen.py
|
||||
${CMAKE_SOURCE_DIR}/vpp-api/vapi/vapi_json_parser.py
|
||||
)
|
||||
endif()
|
||||
# C++ VAPI Headers
|
||||
set(input ${CMAKE_CURRENT_BINARY_DIR}/${f}.json)
|
||||
add_custom_command(
|
||||
OUTPUT ${output_name}
|
||||
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/vpp-api/vapi
|
||||
COMMAND ${VPP_VAPI_CPP_GEN}
|
||||
ARGS --gen-h-prefix=vapi --remove-path ${input}
|
||||
DEPENDS ${input} ${VPP_VAPI_CPP_GEN_DEPENDS}
|
||||
COMMENT "Generating VAPI C++ header ${output_name}"
|
||||
)
|
||||
install(
|
||||
FILES ${output_name}
|
||||
DESTINATION include/vapi
|
||||
COMPONENT vpp-dev
|
||||
)
|
||||
endfunction ()
|
||||
|
||||
|
||||
##############################################################################
|
||||
# generate the .h and .json files for a .api file
|
||||
# @param file - the name of the .api
|
||||
@ -62,18 +121,30 @@ endfunction()
|
||||
# generated .json file
|
||||
##############################################################################
|
||||
function(vpp_generate_api_header file dir component)
|
||||
vpp_generate_api_c_header (${file})
|
||||
vpp_generate_api_json_header (${file} ${dir} ${component})
|
||||
vpp_generate_api_c_header (${file})
|
||||
vpp_generate_api_json_header (${file} ${dir} ${component})
|
||||
vpp_generate_vapi_c_header (${file})
|
||||
vpp_generate_vapi_cpp_header (${file})
|
||||
endfunction()
|
||||
|
||||
function(vpp_add_api_files name)
|
||||
function(vpp_add_api_files name dir component)
|
||||
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 vpp)
|
||||
list(APPEND header_files ${file}.h ${file}.json)
|
||||
set_property(GLOBAL APPEND PROPERTY VPP_API_FILES ${rpath}/${file})
|
||||
vpp_generate_api_header (${file} ${dir} ${component})
|
||||
# Basic api headers get installed in a subdirectory according to
|
||||
# their component name, but vapi is expected to be found directly under
|
||||
# "vapi". Both by in-source components (e.g. vpp-api/vapi/vapi.c), and
|
||||
# out-of-tree plugins use #include <vapi/component.api.vapi.h>.
|
||||
# ${file} contains the subdirectory, so strip it here.
|
||||
get_filename_component(name ${file} NAME)
|
||||
list(APPEND header_files
|
||||
${file}.h
|
||||
${file}.json
|
||||
${CMAKE_BINARY_DIR}/vpp-api/vapi/${name}.vapi.h
|
||||
${CMAKE_BINARY_DIR}/vpp-api/vapi/${name}.vapi.hpp
|
||||
)
|
||||
endforeach()
|
||||
add_custom_target(${target} DEPENDS ${header_files})
|
||||
endfunction()
|
||||
|
@ -43,7 +43,7 @@ macro(add_vpp_library lib)
|
||||
endif()
|
||||
|
||||
if(ARG_API_FILES)
|
||||
vpp_add_api_files(${lib} ${ARG_API_FILES})
|
||||
vpp_add_api_files(${lib} core vpp ${ARG_API_FILES})
|
||||
foreach(file ${ARG_API_FILES})
|
||||
get_filename_component(dir ${file} DIRECTORY)
|
||||
install(
|
||||
|
@ -31,12 +31,10 @@ macro(add_vpp_plugin name)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
file(RELATIVE_PATH rpath ${CMAKE_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
vpp_add_api_files(${plugin_name} plugins ${PLUGIN_COMPONENT} ${PLUGIN_API_FILES})
|
||||
foreach(f ${PLUGIN_API_FILES})
|
||||
get_filename_component(dir ${f} DIRECTORY)
|
||||
vpp_generate_api_header(${f} plugins ${PLUGIN_COMPONENT})
|
||||
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
|
||||
${CMAKE_CURRENT_BINARY_DIR}/${f}_enum.h
|
||||
@ -47,6 +45,9 @@ macro(add_vpp_plugin name)
|
||||
endforeach()
|
||||
add_library(${plugin_name} SHARED ${PLUGIN_SOURCES} ${api_includes})
|
||||
set_target_properties(${plugin_name} PROPERTIES NO_SONAME 1)
|
||||
if(PLUGIN_API_FILES)
|
||||
add_dependencies(${plugin_name} ${plugin_name}_api_headers)
|
||||
endif()
|
||||
if(NOT VPP_EXTERNAL_PROJECT)
|
||||
add_dependencies(${plugin_name} vpp_version_h api_headers)
|
||||
endif()
|
||||
|
@ -16,60 +16,13 @@ include_directories (
|
||||
${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 api_headers
|
||||
COMMENT "Generating VAPI C header ${output}"
|
||||
)
|
||||
install(
|
||||
FILES ${CMAKE_CURRENT_BINARY_DIR}/${output}
|
||||
DESTINATION include/vapi
|
||||
COMPONENT vpp-dev
|
||||
)
|
||||
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 --gen-h-prefix=vapi --remove-path ${input}
|
||||
DEPENDS ${input} vapi_cpp_gen.py vapi_json_parser.py api_headers
|
||||
COMMENT "Generating VAPI C++ header ${output}"
|
||||
)
|
||||
install(
|
||||
FILES ${CMAKE_CURRENT_BINARY_DIR}/${output}
|
||||
DESTINATION include/vapi
|
||||
COMPONENT vpp-dev
|
||||
)
|
||||
list(APPEND VAPICLIENT_API_CPP_HEADERS ${output})
|
||||
endforeach ()
|
||||
|
||||
add_custom_target(all-vapi-headers 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
|
||||
DEPENDS all-vapi-headers
|
||||
DEPENDS api_headers
|
||||
)
|
||||
|
||||
install(
|
||||
@ -95,3 +48,13 @@ install(
|
||||
COMPONENT
|
||||
vpp-dev
|
||||
)
|
||||
|
||||
install(
|
||||
PROGRAMS
|
||||
vapi_c_gen.py
|
||||
vapi_cpp_gen.py
|
||||
vapi_json_parser.py
|
||||
|
||||
DESTINATION bin
|
||||
COMPONENT vpp-dev
|
||||
)
|
||||
|
@ -38,7 +38,7 @@ set(VPP_API_FILES
|
||||
api/vpe.api
|
||||
)
|
||||
|
||||
vpp_add_api_files(vpp ${VPP_API_FILES})
|
||||
vpp_add_api_files(vpp core vpp ${VPP_API_FILES})
|
||||
|
||||
foreach(file ${VPP_API_FILES})
|
||||
get_filename_component(dir ${file} DIRECTORY)
|
||||
|
Reference in New Issue
Block a user