blob: fdd34691a1215197c6c63e3d4b282e1713258637 [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
Damjan Marionaf7892c2020-10-22 14:23:47 +020016 "LTO"
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 Marion599efc62020-05-07 16:49:45 +020037 DESTINATION ${VPP_LIBRARY_DIR}
Damjan Marion43b06062018-08-29 22:20:45 +020038 COMPONENT ${ARG_COMPONENT}
39 )
Damjan Marion4553c952018-08-26 11:04:40 +020040
Damjan Marionaf7892c2020-10-22 14:23:47 +020041 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")
46 endif()
47
Damjan Marion4553c952018-08-26 11:04:40 +020048 if(ARG_MULTIARCH_SOURCES)
Ole Troan7d527a22020-12-02 14:19:49 +010049 vpp_library_set_multiarch_sources(${lib} DEPENDS ${ARG_DEPENDS} SOURCES ${ARG_MULTIARCH_SOURCES})
Damjan Marion4553c952018-08-26 11:04:40 +020050 endif()
51
52 if(ARG_API_FILES)
Oliver Gilesdc203712019-12-05 23:37:36 +020053 vpp_add_api_files(${lib} core vpp ${ARG_API_FILES})
Damjan Marion4553c952018-08-26 11:04:40 +020054 foreach(file ${ARG_API_FILES})
55 get_filename_component(dir ${file} DIRECTORY)
Damjan Marion43b06062018-08-29 22:20:45 +020056 install(
BenoƮt Ganne98438e42019-07-25 16:26:20 +020057 FILES ${file} ${CMAKE_CURRENT_BINARY_DIR}/${file}.h
Ole Troan2a1ca782019-09-19 01:08:30 +020058 ${CMAKE_CURRENT_BINARY_DIR}/${file}_enum.h
59 ${CMAKE_CURRENT_BINARY_DIR}/${file}_types.h
Ole Troandf87f802020-11-18 19:17:48 +010060 ${CMAKE_CURRENT_BINARY_DIR}/${file}_tojson.h
61 ${CMAKE_CURRENT_BINARY_DIR}/${file}_fromjson.h
Damjan Marion43b06062018-08-29 22:20:45 +020062 DESTINATION include/${lib}/${dir}
63 COMPONENT vpp-dev
64 )
Damjan Marion4553c952018-08-26 11:04:40 +020065 endforeach()
66 endif()
67
Ole Troan7d527a22020-12-02 14:19:49 +010068 if(NOT VPP_EXTERNAL_PROJECT)
69 add_dependencies(${lib} api_headers)
70 endif()
71
Damjan Marion4553c952018-08-26 11:04:40 +020072 if(ARG_DEPENDS)
73 add_dependencies(${lib} ${ARG_DEPENDS})
74 endif()
75
76 # install headers
77 if(ARG_INSTALL_HEADERS)
78 foreach(file ${ARG_INSTALL_HEADERS})
79 get_filename_component(dir ${file} DIRECTORY)
Damjan Marion43b06062018-08-29 22:20:45 +020080 install(
81 FILES ${file}
82 DESTINATION include/${lib}/${dir}
Damjan Marioneeadc142018-09-13 20:02:12 +020083 COMPONENT ${ARG_COMPONENT}-dev
Damjan Marion43b06062018-08-29 22:20:45 +020084 )
Damjan Marion4553c952018-08-26 11:04:40 +020085 endforeach()
86 endif()
87endmacro()
88
89##############################################################################
90# header files
91##############################################################################
92function (add_vpp_headers path)
93 foreach(file ${ARGN})
94 get_filename_component(dir ${file} DIRECTORY)
Damjan Marion833de8c2018-09-07 12:39:02 +020095 install(
96 FILES ${file}
97 DESTINATION include/${path}/${dir}
98 COMPONENT vpp-dev
99 )
Damjan Marion4553c952018-08-26 11:04:40 +0200100 endforeach()
101endfunction()
Ole Troandf87f802020-11-18 19:17:48 +0100102
103macro(add_vpp_test_library lib)
104 cmake_parse_arguments(TEST
105 ""
106 ""
107 ${ARGN}
108 )
109
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)
116 endif()
117 include_directories(${CMAKE_CURRENT_BINARY_DIR})
118 set_target_properties(${test_lib} PROPERTIES NO_SONAME 1)
119 set_target_properties(${test_lib} PROPERTIES
120 PREFIX ""
121 LIBRARY_OUTPUT_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/vat2_plugins)
122
123 # Later: Install and package
124 # install .so
125 #install(
126 # TARGETS ${test_lib}
127 # DESTINATION ${VPP_LIBRARY_DIR}/vat2_plugins
128 # #COMPONENT ${ARG_COMPONENT}
129 # )
130 endforeach()
131endmacro()