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:
6 # http://www.apache.org/licenses/LICENSE-2.0
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.
14 macro(add_vpp_library lib)
15 cmake_parse_arguments(ARG
18 "SOURCES;MULTIARCH_SOURCES;API_FILES;LINK_LIBRARIES;INSTALL_HEADERS;DEPENDS"
22 add_library(${lib} SHARED ${ARG_SOURCES})
24 set_target_properties(${lib} PROPERTIES SOVERSION ${VPP_LIB_VERSION})
28 if(ARG_LINK_LIBRARIES)
29 target_link_libraries(${lib} ${ARG_LINK_LIBRARIES})
33 set(ARG_COMPONENT vpp)
37 DESTINATION ${VPP_LIBRARY_DIR}
38 COMPONENT ${ARG_COMPONENT}
41 if (ARG_LTO AND VPP_USE_LTO)
42 set_property(TARGET ${lib} PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
43 target_compile_options (${lib} PRIVATE "-ffunction-sections")
44 target_compile_options (${lib} PRIVATE "-fdata-sections")
45 target_link_libraries (${lib} "-Wl,--gc-sections")
48 if(ARG_MULTIARCH_SOURCES)
49 vpp_library_set_multiarch_sources(${lib} DEPENDS ${ARG_DEPENDS} SOURCES ${ARG_MULTIARCH_SOURCES})
53 vpp_add_api_files(${lib} core vpp ${ARG_API_FILES})
54 foreach(file ${ARG_API_FILES})
55 get_filename_component(dir ${file} DIRECTORY)
57 FILES ${file} ${CMAKE_CURRENT_BINARY_DIR}/${file}.h
58 ${CMAKE_CURRENT_BINARY_DIR}/${file}_enum.h
59 ${CMAKE_CURRENT_BINARY_DIR}/${file}_types.h
60 ${CMAKE_CURRENT_BINARY_DIR}/${file}_tojson.h
61 ${CMAKE_CURRENT_BINARY_DIR}/${file}_fromjson.h
62 DESTINATION include/${lib}/${dir}
68 if(NOT VPP_EXTERNAL_PROJECT)
69 add_dependencies(${lib} api_headers)
73 add_dependencies(${lib} ${ARG_DEPENDS})
77 if(ARG_INSTALL_HEADERS)
78 foreach(file ${ARG_INSTALL_HEADERS})
79 get_filename_component(dir ${file} DIRECTORY)
82 DESTINATION include/${lib}/${dir}
83 COMPONENT ${ARG_COMPONENT}-dev
89 ##############################################################################
91 ##############################################################################
92 function (add_vpp_headers path)
94 get_filename_component(dir ${file} DIRECTORY)
97 DESTINATION include/${path}/${dir}
103 macro(add_vpp_test_library lib)
104 cmake_parse_arguments(TEST
110 foreach(file ${ARGN})
111 get_filename_component(name ${file} NAME_WE)
112 set(test_lib ${lib}_${name}_plugin)
113 add_library(${test_lib} SHARED ${file}_test2.c)
114 if(NOT VPP_EXTERNAL_PROJECT)
115 add_dependencies(${test_lib} api_headers)
117 include_directories(${CMAKE_CURRENT_BINARY_DIR})
118 set_target_properties(${test_lib} PROPERTIES NO_SONAME 1)
119 set_target_properties(${test_lib} PROPERTIES
121 LIBRARY_OUTPUT_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/vat2_plugins)
123 # Later: Install and package
126 # TARGETS ${test_lib}
127 # DESTINATION ${VPP_LIBRARY_DIR}/vat2_plugins
128 # #COMPONENT ${ARG_COMPONENT}