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