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() |
Damjan Marion | d16004d | 2018-08-26 10:14:52 +0200 | [diff] [blame] | 23 | add_custom_command (OUTPUT ${output_name} |
| 24 | COMMAND mkdir -p ${output_dir} |
Damjan Marion | 0fa900e | 2018-09-12 12:12:36 +0200 | [diff] [blame] | 25 | COMMAND ${VPP_APIGEN} |
Damjan Marion | d16004d | 2018-08-26 10:14:52 +0200 | [diff] [blame] | 26 | ARGS --includedir ${CMAKE_SOURCE_DIR} --input ${CMAKE_CURRENT_SOURCE_DIR}/${file} --output ${output_name} |
| 27 | DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${file} |
| 28 | COMMENT "Generating API header ${output_name}" |
| 29 | ) |
| 30 | endfunction() |
| 31 | |
Damjan Marion | 833de8c | 2018-09-07 12:39:02 +0200 | [diff] [blame] | 32 | function(vpp_generate_api_json_header file dir component) |
Damjan Marion | d16004d | 2018-08-26 10:14:52 +0200 | [diff] [blame] | 33 | set (output_name ${CMAKE_CURRENT_BINARY_DIR}/${file}.json) |
| 34 | get_filename_component(output_dir ${output_name} DIRECTORY) |
Damjan Marion | 0fa900e | 2018-09-12 12:12:36 +0200 | [diff] [blame] | 35 | if(NOT VPP_APIGEN) |
| 36 | set(VPP_APIGEN ${CMAKE_SOURCE_DIR}/tools/vppapigen/vppapigen) |
| 37 | endif() |
Damjan Marion | d16004d | 2018-08-26 10:14:52 +0200 | [diff] [blame] | 38 | add_custom_command (OUTPUT ${output_name} |
| 39 | COMMAND mkdir -p ${output_dir} |
Damjan Marion | 0fa900e | 2018-09-12 12:12:36 +0200 | [diff] [blame] | 40 | COMMAND ${VPP_APIGEN} |
Damjan Marion | d16004d | 2018-08-26 10:14:52 +0200 | [diff] [blame] | 41 | ARGS --includedir ${CMAKE_SOURCE_DIR} --input ${CMAKE_CURRENT_SOURCE_DIR}/${file} JSON --output ${output_name} |
| 42 | DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${file} |
| 43 | COMMENT "Generating API header ${output_name}" |
| 44 | ) |
Damjan Marion | 833de8c | 2018-09-07 12:39:02 +0200 | [diff] [blame] | 45 | install( |
| 46 | FILES ${output_name} |
| 47 | DESTINATION share/vpp/api/${dir}/ |
| 48 | COMPONENT ${component} |
| 49 | ) |
Damjan Marion | d16004d | 2018-08-26 10:14:52 +0200 | [diff] [blame] | 50 | endfunction() |
| 51 | |
| 52 | ############################################################################## |
| 53 | # generate the .h and .json files for a .api file |
| 54 | # @param file - the name of the .api |
| 55 | # @param dir - the install directory under ROOT/share/vpp/api to place the |
| 56 | # generated .json file |
| 57 | ############################################################################## |
Damjan Marion | 833de8c | 2018-09-07 12:39:02 +0200 | [diff] [blame] | 58 | function(vpp_generate_api_header file dir component) |
Damjan Marion | d16004d | 2018-08-26 10:14:52 +0200 | [diff] [blame] | 59 | vpp_generate_api_c_header (${file}) |
Damjan Marion | 833de8c | 2018-09-07 12:39:02 +0200 | [diff] [blame] | 60 | vpp_generate_api_json_header (${file} ${dir} ${component}) |
Damjan Marion | d16004d | 2018-08-26 10:14:52 +0200 | [diff] [blame] | 61 | endfunction() |
| 62 | |
Damjan Marion | 4c64b6e | 2018-08-26 18:14:46 +0200 | [diff] [blame] | 63 | function(vpp_add_api_files name) |
Damjan Marion | d16004d | 2018-08-26 10:14:52 +0200 | [diff] [blame] | 64 | unset(header_files) |
Damjan Marion | 4c64b6e | 2018-08-26 18:14:46 +0200 | [diff] [blame] | 65 | set(target ${name}_api_headers) |
| 66 | file(RELATIVE_PATH rpath ${CMAKE_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}) |
Damjan Marion | d16004d | 2018-08-26 10:14:52 +0200 | [diff] [blame] | 67 | foreach(file ${ARGN}) |
Damjan Marion | 833de8c | 2018-09-07 12:39:02 +0200 | [diff] [blame] | 68 | vpp_generate_api_header (${file} core vpp) |
Damjan Marion | 4c64b6e | 2018-08-26 18:14:46 +0200 | [diff] [blame] | 69 | list(APPEND header_files ${file}.h ${file}.json) |
| 70 | set_property(GLOBAL APPEND PROPERTY VPP_API_FILES ${rpath}/${file}) |
Damjan Marion | d16004d | 2018-08-26 10:14:52 +0200 | [diff] [blame] | 71 | endforeach() |
| 72 | add_custom_target(${target} DEPENDS ${header_files}) |
| 73 | endfunction() |
| 74 | |
| 75 | add_custom_target(api_headers |
| 76 | DEPENDS vlibmemory_api_headers vnet_api_headers vpp_api_headers |
| 77 | ) |
| 78 | |