Damjan Marion | 4553c95 | 2018-08-26 11:04:40 +0200 | [diff] [blame] | 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 | macro(add_vpp_library lib) |
| 15 | cmake_parse_arguments(ARG |
Damjan Marion | af7892c | 2020-10-22 14:23:47 +0200 | [diff] [blame] | 16 | "LTO" |
Damjan Marion | 43b0606 | 2018-08-29 22:20:45 +0200 | [diff] [blame] | 17 | "COMPONENT" |
Damjan Marion | 4553c95 | 2018-08-26 11:04:40 +0200 | [diff] [blame] | 18 | "SOURCES;MULTIARCH_SOURCES;API_FILES;LINK_LIBRARIES;INSTALL_HEADERS;DEPENDS" |
| 19 | ${ARGN} |
| 20 | ) |
| 21 | |
Damjan Marion | 115012a | 2021-04-02 17:35:13 +0200 | [diff] [blame] | 22 | set (lo ${lib}_objs) |
| 23 | add_library(${lo} OBJECT ${ARG_SOURCES}) |
| 24 | set_target_properties(${lo} PROPERTIES POSITION_INDEPENDENT_CODE ON) |
Damjan Marion | 0d39cba | 2021-05-10 14:51:44 +0200 | [diff] [blame] | 25 | target_compile_options(${lo} PUBLIC ${VPP_DEFAULT_MARCH_FLAGS}) |
Damjan Marion | 115012a | 2021-04-02 17:35:13 +0200 | [diff] [blame] | 26 | |
| 27 | add_library(${lib} SHARED) |
| 28 | target_sources(${lib} PRIVATE $<TARGET_OBJECTS:${lo}>) |
| 29 | |
Damjan Marion | 958192d | 2018-09-13 18:43:19 +0200 | [diff] [blame] | 30 | if(VPP_LIB_VERSION) |
| 31 | set_target_properties(${lib} PROPERTIES SOVERSION ${VPP_LIB_VERSION}) |
| 32 | endif() |
Damjan Marion | 4553c95 | 2018-08-26 11:04:40 +0200 | [diff] [blame] | 33 | |
| 34 | # library deps |
| 35 | if(ARG_LINK_LIBRARIES) |
| 36 | target_link_libraries(${lib} ${ARG_LINK_LIBRARIES}) |
| 37 | endif() |
| 38 | # install .so |
Damjan Marion | 43b0606 | 2018-08-29 22:20:45 +0200 | [diff] [blame] | 39 | if(NOT ARG_COMPONENT) |
| 40 | set(ARG_COMPONENT vpp) |
| 41 | endif() |
| 42 | install( |
| 43 | TARGETS ${lib} |
Nick Brown | 48ceadc | 2022-12-13 14:20:35 +0000 | [diff] [blame] | 44 | LIBRARY |
| 45 | DESTINATION ${VPP_LIBRARY_DIR} |
| 46 | COMPONENT ${ARG_COMPONENT} |
| 47 | NAMELINK_COMPONENT ${ARG_COMPONENT}-dev |
Damjan Marion | 43b0606 | 2018-08-29 22:20:45 +0200 | [diff] [blame] | 48 | ) |
Damjan Marion | 4553c95 | 2018-08-26 11:04:40 +0200 | [diff] [blame] | 49 | |
Damjan Marion | af7892c | 2020-10-22 14:23:47 +0200 | [diff] [blame] | 50 | if (ARG_LTO AND VPP_USE_LTO) |
Damjan Marion | 115012a | 2021-04-02 17:35:13 +0200 | [diff] [blame] | 51 | set_property(TARGET ${lo} PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE) |
Damjan Marion | af7892c | 2020-10-22 14:23:47 +0200 | [diff] [blame] | 52 | set_property(TARGET ${lib} PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE) |
| 53 | target_compile_options (${lib} PRIVATE "-ffunction-sections") |
| 54 | target_compile_options (${lib} PRIVATE "-fdata-sections") |
| 55 | target_link_libraries (${lib} "-Wl,--gc-sections") |
Damjan Marion | 1e26724 | 2021-11-06 17:09:37 +0100 | [diff] [blame] | 56 | if(compiler_flag_no_stringop_overflow) |
| 57 | target_link_libraries (${lib} "-Wno-stringop-overflow") |
| 58 | endif() |
Damjan Marion | af7892c | 2020-10-22 14:23:47 +0200 | [diff] [blame] | 59 | endif() |
| 60 | |
Damjan Marion | 4553c95 | 2018-08-26 11:04:40 +0200 | [diff] [blame] | 61 | if(ARG_MULTIARCH_SOURCES) |
Ole Troan | 7d527a2 | 2020-12-02 14:19:49 +0100 | [diff] [blame] | 62 | vpp_library_set_multiarch_sources(${lib} DEPENDS ${ARG_DEPENDS} SOURCES ${ARG_MULTIARCH_SOURCES}) |
Damjan Marion | 4553c95 | 2018-08-26 11:04:40 +0200 | [diff] [blame] | 63 | endif() |
| 64 | |
| 65 | if(ARG_API_FILES) |
Oliver Giles | dc20371 | 2019-12-05 23:37:36 +0200 | [diff] [blame] | 66 | vpp_add_api_files(${lib} core vpp ${ARG_API_FILES}) |
Damjan Marion | 4553c95 | 2018-08-26 11:04:40 +0200 | [diff] [blame] | 67 | foreach(file ${ARG_API_FILES}) |
| 68 | get_filename_component(dir ${file} DIRECTORY) |
Damjan Marion | 43b0606 | 2018-08-29 22:20:45 +0200 | [diff] [blame] | 69 | install( |
BenoƮt Ganne | 98438e4 | 2019-07-25 16:26:20 +0200 | [diff] [blame] | 70 | FILES ${file} ${CMAKE_CURRENT_BINARY_DIR}/${file}.h |
Ole Troan | 2a1ca78 | 2019-09-19 01:08:30 +0200 | [diff] [blame] | 71 | ${CMAKE_CURRENT_BINARY_DIR}/${file}_enum.h |
| 72 | ${CMAKE_CURRENT_BINARY_DIR}/${file}_types.h |
Ole Troan | df87f80 | 2020-11-18 19:17:48 +0100 | [diff] [blame] | 73 | ${CMAKE_CURRENT_BINARY_DIR}/${file}_tojson.h |
| 74 | ${CMAKE_CURRENT_BINARY_DIR}/${file}_fromjson.h |
Damjan Marion | 43b0606 | 2018-08-29 22:20:45 +0200 | [diff] [blame] | 75 | DESTINATION include/${lib}/${dir} |
| 76 | COMPONENT vpp-dev |
| 77 | ) |
Damjan Marion | 4553c95 | 2018-08-26 11:04:40 +0200 | [diff] [blame] | 78 | endforeach() |
| 79 | endif() |
| 80 | |
Ole Troan | 7d527a2 | 2020-12-02 14:19:49 +0100 | [diff] [blame] | 81 | if(NOT VPP_EXTERNAL_PROJECT) |
Damjan Marion | 115012a | 2021-04-02 17:35:13 +0200 | [diff] [blame] | 82 | add_dependencies(${lo} api_headers) |
Ole Troan | 7d527a2 | 2020-12-02 14:19:49 +0100 | [diff] [blame] | 83 | endif() |
| 84 | |
Guillaume Solignac | 08bd44b | 2021-09-28 15:01:26 +0200 | [diff] [blame] | 85 | if(VPP_EXTERNAL_PROJECT AND ARG_API_FILES) |
| 86 | add_dependencies(${lo} ${lib}_api_headers) |
| 87 | endif() |
| 88 | |
Damjan Marion | 4553c95 | 2018-08-26 11:04:40 +0200 | [diff] [blame] | 89 | if(ARG_DEPENDS) |
Damjan Marion | 115012a | 2021-04-02 17:35:13 +0200 | [diff] [blame] | 90 | add_dependencies(${lo} ${ARG_DEPENDS}) |
Damjan Marion | 4553c95 | 2018-08-26 11:04:40 +0200 | [diff] [blame] | 91 | endif() |
| 92 | |
| 93 | # install headers |
| 94 | if(ARG_INSTALL_HEADERS) |
| 95 | foreach(file ${ARG_INSTALL_HEADERS}) |
| 96 | get_filename_component(dir ${file} DIRECTORY) |
Damjan Marion | 43b0606 | 2018-08-29 22:20:45 +0200 | [diff] [blame] | 97 | install( |
| 98 | FILES ${file} |
| 99 | DESTINATION include/${lib}/${dir} |
Damjan Marion | eeadc14 | 2018-09-13 20:02:12 +0200 | [diff] [blame] | 100 | COMPONENT ${ARG_COMPONENT}-dev |
Damjan Marion | 43b0606 | 2018-08-29 22:20:45 +0200 | [diff] [blame] | 101 | ) |
Damjan Marion | 4553c95 | 2018-08-26 11:04:40 +0200 | [diff] [blame] | 102 | endforeach() |
| 103 | endif() |
| 104 | endmacro() |
| 105 | |
| 106 | ############################################################################## |
| 107 | # header files |
| 108 | ############################################################################## |
| 109 | function (add_vpp_headers path) |
| 110 | foreach(file ${ARGN}) |
| 111 | get_filename_component(dir ${file} DIRECTORY) |
Damjan Marion | 833de8c | 2018-09-07 12:39:02 +0200 | [diff] [blame] | 112 | install( |
| 113 | FILES ${file} |
| 114 | DESTINATION include/${path}/${dir} |
| 115 | COMPONENT vpp-dev |
| 116 | ) |
Damjan Marion | 4553c95 | 2018-08-26 11:04:40 +0200 | [diff] [blame] | 117 | endforeach() |
| 118 | endfunction() |
Ole Troan | df87f80 | 2020-11-18 19:17:48 +0100 | [diff] [blame] | 119 | |
Florin Coras | 248210c | 2021-09-14 18:54:45 -0700 | [diff] [blame] | 120 | macro(add_vat_test_library lib) |
| 121 | cmake_parse_arguments(TEST |
| 122 | "" |
| 123 | "" |
| 124 | ${ARGN} |
| 125 | ) |
| 126 | |
| 127 | foreach(file ${ARGN}) |
| 128 | get_filename_component(name ${file} NAME_WE) |
| 129 | set(test_lib ${lib}_${name}_plugin) |
| 130 | add_library(${test_lib} SHARED ${file}) |
| 131 | target_compile_options(${test_lib} PUBLIC ${VPP_DEFAULT_MARCH_FLAGS}) |
| 132 | if(NOT VPP_EXTERNAL_PROJECT) |
| 133 | add_dependencies(${test_lib} api_headers) |
| 134 | endif() |
| 135 | include_directories(${CMAKE_CURRENT_BINARY_DIR}) |
| 136 | set_target_properties(${test_lib} PROPERTIES NO_SONAME 1) |
| 137 | set_target_properties(${test_lib} PROPERTIES |
| 138 | PREFIX "" |
| 139 | LIBRARY_OUTPUT_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/vpp_api_test_plugins) |
| 140 | |
| 141 | # install .so |
| 142 | install( |
| 143 | TARGETS ${test_lib} |
| 144 | DESTINATION ${VPP_LIBRARY_DIR}/vpp_api_test_plugins |
| 145 | COMPONENT ${ARG_COMPONENT} |
| 146 | ) |
| 147 | endforeach() |
| 148 | endmacro() |
| 149 | |
Ole Troan | df87f80 | 2020-11-18 19:17:48 +0100 | [diff] [blame] | 150 | macro(add_vpp_test_library lib) |
| 151 | cmake_parse_arguments(TEST |
| 152 | "" |
| 153 | "" |
| 154 | ${ARGN} |
| 155 | ) |
| 156 | |
| 157 | foreach(file ${ARGN}) |
| 158 | get_filename_component(name ${file} NAME_WE) |
| 159 | set(test_lib ${lib}_${name}_plugin) |
| 160 | add_library(${test_lib} SHARED ${file}_test2.c) |
Damjan Marion | 0d39cba | 2021-05-10 14:51:44 +0200 | [diff] [blame] | 161 | target_compile_options(${test_lib} PUBLIC ${VPP_DEFAULT_MARCH_FLAGS}) |
Ole Troan | df87f80 | 2020-11-18 19:17:48 +0100 | [diff] [blame] | 162 | if(NOT VPP_EXTERNAL_PROJECT) |
| 163 | add_dependencies(${test_lib} api_headers) |
| 164 | endif() |
| 165 | include_directories(${CMAKE_CURRENT_BINARY_DIR}) |
| 166 | set_target_properties(${test_lib} PROPERTIES NO_SONAME 1) |
| 167 | set_target_properties(${test_lib} PROPERTIES |
| 168 | PREFIX "" |
| 169 | LIBRARY_OUTPUT_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/vat2_plugins) |
| 170 | |
Ole Troan | df87f80 | 2020-11-18 19:17:48 +0100 | [diff] [blame] | 171 | # install .so |
Ole Troan | 91144fb | 2021-08-17 12:57:00 +0200 | [diff] [blame] | 172 | install( |
| 173 | TARGETS ${test_lib} |
| 174 | DESTINATION ${VPP_LIBRARY_DIR}/vat2_plugins |
| 175 | COMPONENT ${ARG_COMPONENT} |
| 176 | ) |
Ole Troan | df87f80 | 2020-11-18 19:17:48 +0100 | [diff] [blame] | 177 | endforeach() |
| 178 | endmacro() |
Damjan Marion | 3648d93 | 2021-04-30 20:27:53 +0200 | [diff] [blame] | 179 | |
| 180 | macro(vpp_find_library var) |
| 181 | find_library(${var} ${ARGN}) |
| 182 | mark_as_advanced(${var}) |
| 183 | endmacro() |
| 184 | macro(vpp_find_path var) |
| 185 | find_path(${var} ${ARGN}) |
| 186 | mark_as_advanced(${var}) |
| 187 | endmacro() |