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