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