blob: 18ab8ed55f3cdbd8c27610ddf6ba09d48ed5a69e [file] [log] [blame]
Damjan Marion4553c952018-08-26 11:04:40 +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
14macro(add_vpp_library lib)
15 cmake_parse_arguments(ARG
16 ""
Damjan Marion43b06062018-08-29 22:20:45 +020017 "COMPONENT"
Damjan Marion4553c952018-08-26 11:04:40 +020018 "SOURCES;MULTIARCH_SOURCES;API_FILES;LINK_LIBRARIES;INSTALL_HEADERS;DEPENDS"
19 ${ARGN}
20 )
21
22 add_library(${lib} SHARED ${ARG_SOURCES})
Damjan Marion958192d2018-09-13 18:43:19 +020023 if(VPP_LIB_VERSION)
24 set_target_properties(${lib} PROPERTIES SOVERSION ${VPP_LIB_VERSION})
25 endif()
Damjan Marion4553c952018-08-26 11:04:40 +020026
27 # library deps
28 if(ARG_LINK_LIBRARIES)
29 target_link_libraries(${lib} ${ARG_LINK_LIBRARIES})
30 endif()
31 # install .so
Damjan Marion43b06062018-08-29 22:20:45 +020032 if(NOT ARG_COMPONENT)
33 set(ARG_COMPONENT vpp)
34 endif()
35 install(
36 TARGETS ${lib}
Damjan Marion79dcbc72018-09-12 14:01:10 +020037 DESTINATION lib
Damjan Marion43b06062018-08-29 22:20:45 +020038 COMPONENT ${ARG_COMPONENT}
39 )
Damjan Marion4553c952018-08-26 11:04:40 +020040
41 if(ARG_MULTIARCH_SOURCES)
42 vpp_library_set_multiarch_sources(${lib} ${ARG_MULTIARCH_SOURCES})
43 endif()
44
45 if(ARG_API_FILES)
Damjan Marion4c64b6e2018-08-26 18:14:46 +020046 vpp_add_api_files(${lib} ${ARG_API_FILES})
Damjan Marion4553c952018-08-26 11:04:40 +020047 foreach(file ${ARG_API_FILES})
48 get_filename_component(dir ${file} DIRECTORY)
Damjan Marion43b06062018-08-29 22:20:45 +020049 install(
50 FILES ${CMAKE_CURRENT_BINARY_DIR}/${file}.h
51 DESTINATION include/${lib}/${dir}
52 COMPONENT vpp-dev
53 )
Damjan Marion4553c952018-08-26 11:04:40 +020054 endforeach()
55 endif()
56
57 if(ARG_DEPENDS)
58 add_dependencies(${lib} ${ARG_DEPENDS})
59 endif()
60
61 # install headers
62 if(ARG_INSTALL_HEADERS)
63 foreach(file ${ARG_INSTALL_HEADERS})
64 get_filename_component(dir ${file} DIRECTORY)
Damjan Marion43b06062018-08-29 22:20:45 +020065 install(
66 FILES ${file}
67 DESTINATION include/${lib}/${dir}
Damjan Marioneeadc142018-09-13 20:02:12 +020068 COMPONENT ${ARG_COMPONENT}-dev
Damjan Marion43b06062018-08-29 22:20:45 +020069 )
Damjan Marion4553c952018-08-26 11:04:40 +020070 endforeach()
71 endif()
72endmacro()
73
74##############################################################################
75# header files
76##############################################################################
77function (add_vpp_headers path)
78 foreach(file ${ARGN})
79 get_filename_component(dir ${file} DIRECTORY)
Damjan Marion833de8c2018-09-07 12:39:02 +020080 install(
81 FILES ${file}
82 DESTINATION include/${path}/${dir}
83 COMPONENT vpp-dev
84 )
Damjan Marion4553c952018-08-26 11:04:40 +020085 endforeach()
86endfunction()