CMake as an alternative to autotools (experimental)
[vpp.git] / src / plugins / CMakeLists.txt
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 include_directories (
15   ${CMAKE_CURRENT_SOURCE_DIR}
16   ${CMAKE_CURRENT_BINARY_DIR}
17 )
18
19 macro(add_vpp_plugin plugin_name)
20   set(api_headers)
21   foreach(f ${ARGN})
22      if(${f} MATCHES ".*\.api$")
23        vpp_generate_api_header(${f})
24        list(APPEND api_headers ${f}.h)
25      endif()
26   endforeach()
27   add_library(${plugin_name} SHARED ${ARGN} ${api_headers})
28   add_dependencies(${plugin_name} vpp_version_h api_headers)
29   set_target_properties(${plugin_name} PROPERTIES
30     PREFIX ""
31     LIBRARY_OUTPUT_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/vpp_plugins)
32   install(TARGETS ${plugin_name} DESTINATION lib/vpp_plugins COMPONENT plugins)
33 endmacro()
34
35 macro(add_vpp_api_test_plugin plugin_name)
36   set(api_headers)
37   foreach(f ${ARGN})
38      if(${f} MATCHES ".*\.api$")
39        vpp_generate_api_header(${f})
40        list(APPEND api_headers ${f}.h)
41      endif()
42   endforeach()
43   add_library(${plugin_name} SHARED ${ARGN} ${api_headers})
44   add_dependencies(${plugin_name} api_headers)
45   set_target_properties(${plugin_name} PROPERTIES PREFIX "")
46   set_target_properties(${plugin_name} PROPERTIES
47     PREFIX ""
48     LIBRARY_OUTPUT_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}//vpp_api_test_plugins)
49   install(TARGETS ${plugin_name} DESTINATION lib/vpp_api_test_plugins COMPONENT
50           plugins)
51 endmacro()
52
53 ##############################################################################
54 # find and add all plugin subdirs
55 ############################################################################
56 FILE(GLOB files RELATIVE
57   ${CMAKE_CURRENT_SOURCE_DIR}
58   ${CMAKE_CURRENT_SOURCE_DIR}/*/CMakeLists.txt
59 )
60 foreach (f ${files})
61   get_filename_component(dir ${f} DIRECTORY)
62   add_subdirectory(${dir})
63 endforeach()