Damjan Marion | d16004d | 2018-08-26 10:14:52 +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 | ############################################################################## |
| 15 | # API |
| 16 | ############################################################################## |
| 17 | function(vpp_generate_api_c_header file) |
| 18 | set (output_name ${CMAKE_CURRENT_BINARY_DIR}/${file}.h) |
| 19 | get_filename_component(output_dir ${output_name} DIRECTORY) |
Damjan Marion | 0fa900e | 2018-09-12 12:12:36 +0200 | [diff] [blame] | 20 | if(NOT VPP_APIGEN) |
| 21 | set(VPP_APIGEN ${CMAKE_SOURCE_DIR}/tools/vppapigen/vppapigen) |
| 22 | endif() |
Benoît Ganne | 6ceee45 | 2019-07-25 17:15:59 +0200 | [diff] [blame] | 23 | if (VPP_INCLUDE_DIR) |
| 24 | set(includedir "--includedir" ${VPP_INCLUDE_DIR}) |
| 25 | endif() |
Damjan Marion | d16004d | 2018-08-26 10:14:52 +0200 | [diff] [blame] | 26 | add_custom_command (OUTPUT ${output_name} |
| 27 | COMMAND mkdir -p ${output_dir} |
Damjan Marion | 0fa900e | 2018-09-12 12:12:36 +0200 | [diff] [blame] | 28 | COMMAND ${VPP_APIGEN} |
Ole Troan | 2a1ca78 | 2019-09-19 01:08:30 +0200 | [diff] [blame] | 29 | ARGS ${includedir} --includedir ${CMAKE_SOURCE_DIR} --input ${CMAKE_CURRENT_SOURCE_DIR}/${file} --outputdir ${output_dir} --output ${output_name} |
Ole Troan | e4f849c | 2018-11-29 20:14:33 +0100 | [diff] [blame] | 30 | DEPENDS ${VPP_APIGEN} ${CMAKE_CURRENT_SOURCE_DIR}/${file} |
Damjan Marion | d16004d | 2018-08-26 10:14:52 +0200 | [diff] [blame] | 31 | COMMENT "Generating API header ${output_name}" |
| 32 | ) |
| 33 | endfunction() |
| 34 | |
Damjan Marion | 833de8c | 2018-09-07 12:39:02 +0200 | [diff] [blame] | 35 | function(vpp_generate_api_json_header file dir component) |
Damjan Marion | d16004d | 2018-08-26 10:14:52 +0200 | [diff] [blame] | 36 | set (output_name ${CMAKE_CURRENT_BINARY_DIR}/${file}.json) |
| 37 | get_filename_component(output_dir ${output_name} DIRECTORY) |
Damjan Marion | 0fa900e | 2018-09-12 12:12:36 +0200 | [diff] [blame] | 38 | if(NOT VPP_APIGEN) |
| 39 | set(VPP_APIGEN ${CMAKE_SOURCE_DIR}/tools/vppapigen/vppapigen) |
| 40 | endif() |
Benoît Ganne | 6ceee45 | 2019-07-25 17:15:59 +0200 | [diff] [blame] | 41 | if (VPP_INCLUDE_DIR) |
| 42 | set(includedir "--includedir" ${VPP_INCLUDE_DIR}) |
| 43 | endif() |
Damjan Marion | d16004d | 2018-08-26 10:14:52 +0200 | [diff] [blame] | 44 | add_custom_command (OUTPUT ${output_name} |
| 45 | COMMAND mkdir -p ${output_dir} |
Damjan Marion | 0fa900e | 2018-09-12 12:12:36 +0200 | [diff] [blame] | 46 | COMMAND ${VPP_APIGEN} |
Benoît Ganne | 6ceee45 | 2019-07-25 17:15:59 +0200 | [diff] [blame] | 47 | ARGS ${includedir} --includedir ${CMAKE_SOURCE_DIR} --input ${CMAKE_CURRENT_SOURCE_DIR}/${file} JSON --output ${output_name} |
Ole Troan | e4f849c | 2018-11-29 20:14:33 +0100 | [diff] [blame] | 48 | DEPENDS ${VPP_APIGEN} ${CMAKE_CURRENT_SOURCE_DIR}/${file} |
Damjan Marion | d16004d | 2018-08-26 10:14:52 +0200 | [diff] [blame] | 49 | COMMENT "Generating API header ${output_name}" |
| 50 | ) |
Damjan Marion | 833de8c | 2018-09-07 12:39:02 +0200 | [diff] [blame] | 51 | install( |
| 52 | FILES ${output_name} |
| 53 | DESTINATION share/vpp/api/${dir}/ |
| 54 | COMPONENT ${component} |
| 55 | ) |
Damjan Marion | d16004d | 2018-08-26 10:14:52 +0200 | [diff] [blame] | 56 | endfunction() |
| 57 | |
| 58 | ############################################################################## |
Oliver Giles | dc20371 | 2019-12-05 23:37:36 +0200 | [diff] [blame] | 59 | # VPP-API |
| 60 | ############################################################################## |
| 61 | function(vpp_generate_vapi_c_header f) |
| 62 | get_filename_component(output ${f}.vapi.h NAME) |
| 63 | set (output_name ${CMAKE_BINARY_DIR}/vpp-api/vapi/${output}) |
| 64 | if(NOT VPP_VAPI_C_GEN) |
| 65 | set(VPP_VAPI_C_GEN ${CMAKE_SOURCE_DIR}/vpp-api/vapi/vapi_c_gen.py) |
| 66 | set(VPP_VAPI_C_GEN_DEPENDS |
| 67 | ${CMAKE_SOURCE_DIR}/vpp-api/vapi/vapi_c_gen.py |
| 68 | ${CMAKE_SOURCE_DIR}/vpp-api/vapi/vapi_json_parser.py |
| 69 | ) |
| 70 | endif() |
| 71 | |
| 72 | # C VAPI Headers |
| 73 | set(input ${CMAKE_CURRENT_BINARY_DIR}/${f}.json) |
| 74 | add_custom_command( |
| 75 | OUTPUT ${output_name} |
| 76 | WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/vpp-api/vapi |
| 77 | COMMAND ${VPP_VAPI_C_GEN} |
| 78 | ARGS --remove-path ${input} |
| 79 | DEPENDS ${input} ${VPP_VAPI_C_GEN_DEPENDS} |
| 80 | COMMENT "Generating VAPI C header ${output_name}" |
| 81 | ) |
| 82 | install( |
| 83 | FILES ${output_name} |
| 84 | DESTINATION include/vapi |
| 85 | COMPONENT vpp-dev |
| 86 | ) |
| 87 | endfunction () |
| 88 | |
| 89 | function (vpp_generate_vapi_cpp_header f) |
| 90 | get_filename_component(output ${f}.vapi.hpp NAME) |
| 91 | set (output_name ${CMAKE_BINARY_DIR}/vpp-api/vapi/${output}) |
| 92 | if(NOT VPP_VAPI_CPP_GEN) |
| 93 | set(VPP_VAPI_CPP_GEN ${CMAKE_SOURCE_DIR}/vpp-api/vapi/vapi_cpp_gen.py) |
| 94 | set(VPP_VAPI_CPP_GEN_DEPENDS |
| 95 | ${CMAKE_SOURCE_DIR}/vpp-api/vapi/vapi_cpp_gen.py |
| 96 | ${CMAKE_SOURCE_DIR}/vpp-api/vapi/vapi_json_parser.py |
| 97 | ) |
| 98 | endif() |
| 99 | # C++ VAPI Headers |
| 100 | set(input ${CMAKE_CURRENT_BINARY_DIR}/${f}.json) |
| 101 | add_custom_command( |
| 102 | OUTPUT ${output_name} |
| 103 | WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/vpp-api/vapi |
| 104 | COMMAND ${VPP_VAPI_CPP_GEN} |
| 105 | ARGS --gen-h-prefix=vapi --remove-path ${input} |
| 106 | DEPENDS ${input} ${VPP_VAPI_CPP_GEN_DEPENDS} |
| 107 | COMMENT "Generating VAPI C++ header ${output_name}" |
| 108 | ) |
| 109 | install( |
| 110 | FILES ${output_name} |
| 111 | DESTINATION include/vapi |
| 112 | COMPONENT vpp-dev |
| 113 | ) |
| 114 | endfunction () |
| 115 | |
| 116 | |
| 117 | ############################################################################## |
Damjan Marion | d16004d | 2018-08-26 10:14:52 +0200 | [diff] [blame] | 118 | # generate the .h and .json files for a .api file |
| 119 | # @param file - the name of the .api |
| 120 | # @param dir - the install directory under ROOT/share/vpp/api to place the |
| 121 | # generated .json file |
| 122 | ############################################################################## |
Damjan Marion | 833de8c | 2018-09-07 12:39:02 +0200 | [diff] [blame] | 123 | function(vpp_generate_api_header file dir component) |
Oliver Giles | dc20371 | 2019-12-05 23:37:36 +0200 | [diff] [blame] | 124 | vpp_generate_api_c_header (${file}) |
| 125 | vpp_generate_api_json_header (${file} ${dir} ${component}) |
| 126 | vpp_generate_vapi_c_header (${file}) |
| 127 | vpp_generate_vapi_cpp_header (${file}) |
Damjan Marion | d16004d | 2018-08-26 10:14:52 +0200 | [diff] [blame] | 128 | endfunction() |
| 129 | |
Oliver Giles | dc20371 | 2019-12-05 23:37:36 +0200 | [diff] [blame] | 130 | function(vpp_add_api_files name dir component) |
Damjan Marion | d16004d | 2018-08-26 10:14:52 +0200 | [diff] [blame] | 131 | unset(header_files) |
Damjan Marion | 4c64b6e | 2018-08-26 18:14:46 +0200 | [diff] [blame] | 132 | set(target ${name}_api_headers) |
| 133 | file(RELATIVE_PATH rpath ${CMAKE_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}) |
Damjan Marion | d16004d | 2018-08-26 10:14:52 +0200 | [diff] [blame] | 134 | foreach(file ${ARGN}) |
Oliver Giles | dc20371 | 2019-12-05 23:37:36 +0200 | [diff] [blame] | 135 | vpp_generate_api_header (${file} ${dir} ${component}) |
| 136 | # Basic api headers get installed in a subdirectory according to |
| 137 | # their component name, but vapi is expected to be found directly under |
| 138 | # "vapi". Both by in-source components (e.g. vpp-api/vapi/vapi.c), and |
| 139 | # out-of-tree plugins use #include <vapi/component.api.vapi.h>. |
| 140 | # ${file} contains the subdirectory, so strip it here. |
| 141 | get_filename_component(name ${file} NAME) |
| 142 | list(APPEND header_files |
| 143 | ${file}.h |
| 144 | ${file}.json |
| 145 | ${CMAKE_BINARY_DIR}/vpp-api/vapi/${name}.vapi.h |
| 146 | ${CMAKE_BINARY_DIR}/vpp-api/vapi/${name}.vapi.hpp |
| 147 | ) |
Damjan Marion | d16004d | 2018-08-26 10:14:52 +0200 | [diff] [blame] | 148 | endforeach() |
| 149 | add_custom_target(${target} DEPENDS ${header_files}) |
| 150 | endfunction() |
| 151 | |
| 152 | add_custom_target(api_headers |
Jakub Grajciar | 53f06a0 | 2020-03-30 08:12:57 +0200 | [diff] [blame] | 153 | DEPENDS vlibmemory_api_headers vnet_api_headers vpp_api_headers vlib_api_headers |
Damjan Marion | d16004d | 2018-08-26 10:14:52 +0200 | [diff] [blame] | 154 | ) |