0d1e97cb6a36a0e6202dc291593d232ad76dc594
[vpp.git] / src / cmake / library.cmake
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
16     ""
17     "COMPONENT"
18     "SOURCES;MULTIARCH_SOURCES;API_FILES;LINK_LIBRARIES;INSTALL_HEADERS;DEPENDS"
19     ${ARGN}
20   )
21
22   add_library(${lib} SHARED ${ARG_SOURCES})
23   target_compile_options(${lib} PRIVATE -Wall)
24
25   # library deps
26   if(ARG_LINK_LIBRARIES)
27     target_link_libraries(${lib} ${ARG_LINK_LIBRARIES})
28   endif()
29   # install .so
30   if(NOT ARG_COMPONENT)
31     set(ARG_COMPONENT vpp)
32   endif()
33   install(
34     TARGETS ${lib}
35     DESTINATION ${VPP_LIB_DIR_NAME}
36     COMPONENT ${ARG_COMPONENT}
37   )
38
39   if(ARG_MULTIARCH_SOURCES)
40     vpp_library_set_multiarch_sources(${lib} ${ARG_MULTIARCH_SOURCES})
41   endif()
42
43   if(ARG_API_FILES)
44     vpp_add_api_files(${lib} ${ARG_API_FILES})
45     foreach(file ${ARG_API_FILES})
46       get_filename_component(dir ${file} DIRECTORY)
47       install(
48         FILES ${CMAKE_CURRENT_BINARY_DIR}/${file}.h
49         DESTINATION include/${lib}/${dir}
50         COMPONENT vpp-dev
51       )
52     endforeach()
53   endif()
54
55   if(ARG_DEPENDS)
56     add_dependencies(${lib} ${ARG_DEPENDS})
57   endif()
58
59   # install headers
60   if(ARG_INSTALL_HEADERS)
61     foreach(file ${ARG_INSTALL_HEADERS})
62       get_filename_component(dir ${file} DIRECTORY)
63       install(
64         FILES ${file}
65         DESTINATION include/${lib}/${dir}
66         COMPONENT vpp-dev
67       )
68     endforeach()
69   endif()
70 endmacro()
71
72 ##############################################################################
73 # header files
74 ##############################################################################
75 function (add_vpp_headers path)
76   foreach(file ${ARGN})
77     get_filename_component(dir ${file} DIRECTORY)
78     install(FILES ${file} DESTINATION include/${path}/${dir})
79   endforeach()
80 endfunction()