blob: 922c83a8b4dac1ba2cf300e5a091004d12bd2910 [file] [log] [blame]
Damjan Mariond16004d2018-08-26 10:14:52 +02001# 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##############################################################################
17function(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 Marion0fa900e2018-09-12 12:12:36 +020020 if(NOT VPP_APIGEN)
21 set(VPP_APIGEN ${CMAKE_SOURCE_DIR}/tools/vppapigen/vppapigen)
22 endif()
Benoît Ganne6ceee452019-07-25 17:15:59 +020023 if (VPP_INCLUDE_DIR)
24 set(includedir "--includedir" ${VPP_INCLUDE_DIR})
25 endif()
Damjan Mariond16004d2018-08-26 10:14:52 +020026 add_custom_command (OUTPUT ${output_name}
27 COMMAND mkdir -p ${output_dir}
Damjan Marion0fa900e2018-09-12 12:12:36 +020028 COMMAND ${VPP_APIGEN}
Ole Troan2a1ca782019-09-19 01:08:30 +020029 ARGS ${includedir} --includedir ${CMAKE_SOURCE_DIR} --input ${CMAKE_CURRENT_SOURCE_DIR}/${file} --outputdir ${output_dir} --output ${output_name}
Ole Troane4f849c2018-11-29 20:14:33 +010030 DEPENDS ${VPP_APIGEN} ${CMAKE_CURRENT_SOURCE_DIR}/${file}
Damjan Mariond16004d2018-08-26 10:14:52 +020031 COMMENT "Generating API header ${output_name}"
32 )
33endfunction()
34
Damjan Marion833de8c2018-09-07 12:39:02 +020035function(vpp_generate_api_json_header file dir component)
Damjan Mariond16004d2018-08-26 10:14:52 +020036 set (output_name ${CMAKE_CURRENT_BINARY_DIR}/${file}.json)
37 get_filename_component(output_dir ${output_name} DIRECTORY)
Damjan Marion0fa900e2018-09-12 12:12:36 +020038 if(NOT VPP_APIGEN)
39 set(VPP_APIGEN ${CMAKE_SOURCE_DIR}/tools/vppapigen/vppapigen)
40 endif()
Benoît Ganne6ceee452019-07-25 17:15:59 +020041 if (VPP_INCLUDE_DIR)
42 set(includedir "--includedir" ${VPP_INCLUDE_DIR})
43 endif()
Damjan Mariond16004d2018-08-26 10:14:52 +020044 add_custom_command (OUTPUT ${output_name}
45 COMMAND mkdir -p ${output_dir}
Damjan Marion0fa900e2018-09-12 12:12:36 +020046 COMMAND ${VPP_APIGEN}
Benoît Ganne6ceee452019-07-25 17:15:59 +020047 ARGS ${includedir} --includedir ${CMAKE_SOURCE_DIR} --input ${CMAKE_CURRENT_SOURCE_DIR}/${file} JSON --output ${output_name}
Ole Troane4f849c2018-11-29 20:14:33 +010048 DEPENDS ${VPP_APIGEN} ${CMAKE_CURRENT_SOURCE_DIR}/${file}
Damjan Mariond16004d2018-08-26 10:14:52 +020049 COMMENT "Generating API header ${output_name}"
50 )
Damjan Marion833de8c2018-09-07 12:39:02 +020051 install(
52 FILES ${output_name}
53 DESTINATION share/vpp/api/${dir}/
54 COMPONENT ${component}
55 )
Damjan Mariond16004d2018-08-26 10:14:52 +020056endfunction()
57
58##############################################################################
59# generate the .h and .json files for a .api file
60# @param file - the name of the .api
61# @param dir - the install directory under ROOT/share/vpp/api to place the
62# generated .json file
63##############################################################################
Damjan Marion833de8c2018-09-07 12:39:02 +020064function(vpp_generate_api_header file dir component)
Damjan Mariond16004d2018-08-26 10:14:52 +020065 vpp_generate_api_c_header (${file})
Damjan Marion833de8c2018-09-07 12:39:02 +020066 vpp_generate_api_json_header (${file} ${dir} ${component})
Damjan Mariond16004d2018-08-26 10:14:52 +020067endfunction()
68
Damjan Marion4c64b6e2018-08-26 18:14:46 +020069function(vpp_add_api_files name)
Damjan Mariond16004d2018-08-26 10:14:52 +020070 unset(header_files)
Damjan Marion4c64b6e2018-08-26 18:14:46 +020071 set(target ${name}_api_headers)
72 file(RELATIVE_PATH rpath ${CMAKE_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR})
Damjan Mariond16004d2018-08-26 10:14:52 +020073 foreach(file ${ARGN})
Damjan Marion833de8c2018-09-07 12:39:02 +020074 vpp_generate_api_header (${file} core vpp)
Damjan Marion4c64b6e2018-08-26 18:14:46 +020075 list(APPEND header_files ${file}.h ${file}.json)
76 set_property(GLOBAL APPEND PROPERTY VPP_API_FILES ${rpath}/${file})
Damjan Mariond16004d2018-08-26 10:14:52 +020077 endforeach()
78 add_custom_target(${target} DEPENDS ${header_files})
79endfunction()
80
81add_custom_target(api_headers
82 DEPENDS vlibmemory_api_headers vnet_api_headers vpp_api_headers
83)
84