build: use GNUInstallDirs install destinations
[vpp.git] / src / vpp-api / vapi / CMakeLists.txt
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 include_directories (
15   ${CMAKE_CURRENT_SOURCE_DIR}/..
16   ${CMAKE_CURRENT_BINARY_DIR}/..
17   ${CMAKE_CURRENT_BINARY_DIR}
18 )
19
20 add_vpp_library(vapiclient
21   SOURCES
22   vapi.c
23   libvapiclient.map
24
25   LINK_LIBRARIES vppinfra vlibmemoryclient svm pthread m rt
26   DEPENDS api_headers
27 )
28
29 install(
30   FILES
31     vapi.h
32     vapi_common.h
33     vapi_dbg.h
34     vapi.hpp
35     vapi_internal.h
36   DESTINATION
37     ${CMAKE_INSTALL_INCLUDEDIR}/vapi
38   COMPONENT
39     vpp-dev
40 )
41
42 install(
43   FILES
44     vapi_c_gen.py
45     vapi_json_parser.py
46     vapi_cpp_gen.py
47   DESTINATION
48     share/vpp
49   COMPONENT
50     vpp-dev
51 )
52
53 install(
54   PROGRAMS
55   vapi_c_gen.py
56   vapi_cpp_gen.py
57   vapi_json_parser.py
58
59   DESTINATION ${VPP_RUNTIME_DIR}
60   COMPONENT vpp-dev
61 )
62
63 vpp_find_path(SUBUNIT_INCLUDE_DIR NAMES subunit/child.h)
64 vpp_find_library(SUBUNIT_LIB NAMES subunit)
65
66 if(SUBUNIT_INCLUDE_DIR AND SUBUNIT_LIB)
67   message (STATUS "Found subunit in ${SUBUNIT_INCLUDE_DIR} and ${SUBUNIT_LIB}")
68
69   add_custom_command(
70     OUTPUT fake.api.vapi.h
71     WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
72     COMMAND ${PYENV} ${CMAKE_CURRENT_SOURCE_DIR}/vapi_c_gen.py
73     ARGS --remove-path ${CMAKE_CURRENT_SOURCE_DIR}/fake.api.json
74     DEPENDS fake.api.json
75     COMMENT "Generating fake VAPI C header ${output_name}"
76   )
77
78   add_custom_command(
79     OUTPUT fake.api.vapi.hpp
80     WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
81     COMMAND ${PYENV} ${CMAKE_CURRENT_SOURCE_DIR}/vapi_cpp_gen.py
82     ARGS --remove-path ${CMAKE_CURRENT_SOURCE_DIR}/fake.api.json
83     DEPENDS fake.api.json
84     COMMENT "Generating fake VAPI C++ header ${output_name}"
85   )
86
87   add_custom_target(fake_api_vapi_h DEPENDS fake.api.vapi.h)
88   add_custom_target(fake_api_vapi_hpp DEPENDS fake.api.vapi.hpp)
89
90   set(libs vppinfra vlibmemoryclient svm pthread check rt m vapiclient ${SUBUNIT_LIB})
91
92   add_vpp_executable(vapi_c_test
93     SOURCES
94     vapi_c_test.c
95     DEPENDS fake_api_vapi_h
96     LINK_LIBRARIES ${libs}
97   )
98
99   enable_language(CXX)
100   add_vpp_executable(vapi_cpp_test
101     SOURCES
102     vapi_cpp_test.cpp
103     DEPENDS fake_api_vapi_hpp
104     LINK_LIBRARIES ${libs}
105   )
106
107 else()
108   message (WARNING "subunit library not found - vapi tests disabled")
109 endif()