cmake: add add_vpp_library and add_vpp_executable macros

Change-Id: I1382021a6f616571b4b3243ba8c8999239d10815
Signed-off-by: Damjan Marion <damarion@cisco.com>
This commit is contained in:
Damjan Marion
2018-08-26 11:04:40 +02:00
parent d16004d56c
commit 4553c95ab7
13 changed files with 1484 additions and 783 deletions
+2 -10
View File
@@ -53,19 +53,11 @@ find_package(OpenSSL REQUIRED)
include(cmake/memfd.cmake)
include(cmake/api.cmake)
include(cmake/library.cmake)
include(cmake/exec.cmake)
include(cmake/plugin.cmake)
include(cmake/deb.cmake)
##############################################################################
# header files
##############################################################################
function (vpp_add_header_files path)
foreach(file ${ARGN})
get_filename_component(dir ${file} DIRECTORY)
install(FILES ${file} DESTINATION include/${path}/${dir})
endforeach()
endfunction()
##############################################################################
# subdirs
##############################################################################
+34
View File
@@ -0,0 +1,34 @@
# Copyright (c) 2018 Cisco and/or its affiliates.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at:
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
macro(add_vpp_executable exec)
cmake_parse_arguments(ARG
"ENABLE_EXPORTS"
""
"SOURCES;LINK_LIBRARIES;DEPENDS"
${ARGN}
)
add_executable(${exec} ${ARG_SOURCES})
if(ARG_LINK_LIBRARIES)
target_link_libraries(${exec} ${ARG_LINK_LIBRARIES})
endif()
if(ARG_ENABLE_EXPORTS)
set_target_properties(${exec} PROPERTIES ENABLE_EXPORTS 1)
endif()
if(ARG_DEPENDS)
add_dependencies(${exec} ${ARG_DEPENDS})
endif()
install(TARGETS ${exec} DESTINATION bin)
endmacro()
+64
View File
@@ -0,0 +1,64 @@
# Copyright (c) 2018 Cisco and/or its affiliates.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at:
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
macro(add_vpp_library lib)
cmake_parse_arguments(ARG
""
""
"SOURCES;MULTIARCH_SOURCES;API_FILES;LINK_LIBRARIES;INSTALL_HEADERS;DEPENDS"
${ARGN}
)
add_library(${lib} SHARED ${ARG_SOURCES})
# library deps
if(ARG_LINK_LIBRARIES)
target_link_libraries(${lib} ${ARG_LINK_LIBRARIES})
endif()
# install .so
install(TARGETS ${lib} DESTINATION lib)
if(ARG_MULTIARCH_SOURCES)
vpp_library_set_multiarch_sources(${lib} ${ARG_MULTIARCH_SOURCES})
endif()
if(ARG_API_FILES)
vpp_add_api_files(${lib}_api_headers ${ARG_API_FILES})
foreach(file ${ARG_API_FILES})
get_filename_component(dir ${file} DIRECTORY)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${file}.h DESTINATION include/${lib}/${dir})
endforeach()
endif()
if(ARG_DEPENDS)
add_dependencies(${lib} ${ARG_DEPENDS})
endif()
# install headers
if(ARG_INSTALL_HEADERS)
foreach(file ${ARG_INSTALL_HEADERS})
get_filename_component(dir ${file} DIRECTORY)
install(FILES ${file} DESTINATION include/${lib}/${dir})
endforeach()
endif()
endmacro()
##############################################################################
# header files
##############################################################################
function (add_vpp_headers path)
foreach(file ${ARGN})
get_filename_component(dir ${file} DIRECTORY)
install(FILES ${file} DESTINATION include/${path}/${dir})
endforeach()
endfunction()
+21 -24
View File
@@ -14,49 +14,46 @@
##############################################################################
# svm shared library
##############################################################################
add_library(svm SHARED
add_vpp_library(svm
SOURCES
svm.c
ssvm.c
svm_fifo.c
svm_fifo_segment.c
queue.c
message_queue.c
)
target_link_libraries(svm vppinfra rt pthread)
install(TARGETS svm DESTINATION lib)
##############################################################################
# svmdb shared library
##############################################################################
add_library(svmdb SHARED svmdb.c)
target_link_libraries(svmdb svm vppinfra rt pthread)
install(TARGETS svmdb DESTINATION lib)
##############################################################################
# svm headers
##############################################################################
vpp_add_header_files(svm
INSTALL_HEADERS
ssvm.h
svm_common.h
svmdb.h
svm_fifo.h
svm_fifo_segment.h
queue.h
message_queue.h
svm.h
svmdb.h
LINK_LIBRARIES vppinfra rt pthread
)
##############################################################################
# svmdb shared library
##############################################################################
add_vpp_library(svmdb
SOURCES svmdb.c
LINK_LIBRARIES svm vppinfra rt pthread
)
##############################################################################
# svm tools
##############################################################################
add_executable (svmtool svmtool.c)
target_link_libraries (svmtool vppinfra svm)
add_executable (svmdbtool svmdbtool.c)
target_link_libraries (svmdbtool vppinfra svm svmdb)
install(
TARGETS svmtool svmdbtool
DESTINATION bin
add_vpp_executable(svmtool
SOURCES svmtool.c
LINK_LIBRARIES vppinfra svm
)
add_vpp_executable (svmdbtool
SOURCES svmdbtool.c
LINK_LIBRARIES vppinfra svm svmdb
)
+23 -25
View File
@@ -14,50 +14,48 @@
##############################################################################
# vat plugin shared library
##############################################################################
add_library(vatplugin SHARED plugin_api.c)
target_link_libraries(vatplugin vppinfra)
add_dependencies (vatplugin vppinfra)
install(TARGETS vatplugin DESTINATION lib)
add_vpp_library(vatplugin
SOURCES plugin_api.c
LINK_LIBRARIES vppinfra
)
##############################################################################
# vpp_api_test
##############################################################################
add_executable (vpp_api_test
add_vpp_executable(vpp_api_test ENABLE_EXPORTS
SOURCES
api_format.c
main.c
plugin.c
json_format.c
vat.h
json_format.h
LINK_LIBRARIES
vlibmemoryclient
svm
vatplugin
vppinfra
Threads::Threads
rt m dl crypto
)
target_link_libraries (vpp_api_test vlibmemoryclient svm vatplugin vppinfra
Threads::Threads rt m dl crypto)
set_target_properties(vpp_api_test PROPERTIES ENABLE_EXPORTS 1)
install(TARGETS vpp_api_test DESTINATION bin)
##############################################################################
# vpp_json_test
##############################################################################
add_executable (vpp_json_test
json_format.h
json_format.c
json_test.c)
target_link_libraries(vpp_json_test vppinfra m)
set_target_properties(vpp_json_test PROPERTIES ENABLE_EXPORTS 1)
install(TARGETS vpp_json_test DESTINATION bin)
add_vpp_executable(vpp_json_test ENABLE_EXPORTS
SOURCES json_format.c json_test.c
LINK_LIBRARIES vppinfra m
)
##############################################################################
# vat headers
##############################################################################
vpp_add_header_files(vat
vat.h
json_format.h
)
install(FILES vat.h json_format.h DESTINATION include/vat)
##############################################################################
# restart
##############################################################################
add_executable (vpp_restart restart.c)
target_link_libraries (vpp_restart svmdb svm vppinfra pthread rt)
install(TARGETS vpp_restart DESTINATION bin )
add_vpp_executable(vpp_restart
SOURCES restart.c
LINK_LIBRARIES svm svmdb vppinfra Threads::Threads rt
)
+9 -12
View File
@@ -14,20 +14,19 @@
##############################################################################
# vppcom shared library
##############################################################################
add_library(vppcom SHARED
add_vpp_library(vppcom
SOURCES
vppcom.c
vcl_bapi.c
vcl_cfg.c
vcl_event.c
vcl_private.c
)
target_link_libraries(vppcom vppinfra svm vlibmemoryclient rt pthread)
install(TARGETS vppcom DESTINATION lib)
##############################################################################
# vcl headers
##############################################################################
vpp_add_header_files(vcl
LINK_LIBRARIES
vppinfra svm vlibmemoryclient rt pthread
)
add_vpp_headers(vcl
ldp.h
vcl_event.h
sock_test.h
@@ -43,7 +42,7 @@ vpp_add_header_files(vcl
##############################################################################
option(VPP_BUILD_VCL_TESTS "Build vcl tests." ON)
if(VPP_BUILD_VCL_TESTS)
set(VCL_TESTS
foreach(test
vcl_test_server
vcl_test_client
sock_test_server
@@ -51,9 +50,7 @@ if(VPP_BUILD_VCL_TESTS)
test_vcl_listener_server
test_vcl_listener_client
)
foreach(test ${VCL_TESTS})
add_executable(${test} ${test}.c)
target_link_libraries(${test} vppcom)
add_vpp_executable(${test} SOURCES ${test}.c LINK_LIBRARIES vppcom)
endforeach()
endif(VPP_BUILD_VCL_TESTS)
+5 -11
View File
@@ -24,7 +24,8 @@ install(FILES ${CMAKE_BINARY_DIR}/vlib/config.h DESTINATION include/vlib)
##############################################################################
# vlib shared library
##############################################################################
set(VLIB_SRCS
add_vpp_library(vlib
SOURCES
buffer.c
buffer_serialize.c
cli.c
@@ -53,16 +54,8 @@ set(VLIB_SRCS
unix/mc_socket.c
unix/plugin.c
unix/util.c
)
add_library(vlib SHARED ${VLIB_SRCS})
target_link_libraries(vlib vppinfra svm ${CMAKE_DL_LIBS})
install(TARGETS vlib DESTINATION lib)
##############################################################################
# vlib headers
##############################################################################
vpp_add_header_files(vlib
INSTALL_HEADERS
buffer_funcs.h
buffer.h
buffer_node.h
@@ -94,5 +87,6 @@ vpp_add_header_files(vlib
unix/plugin.h
unix/unix.h
vlib.h
)
LINK_LIBRARIES vppinfra svm ${CMAKE_DL_LIBS}
)
+5 -1
View File
@@ -11,9 +11,13 @@
# See the License for the specific language governing permissions and
# limitations under the License.
vpp_add_header_files(vlibapi
install(
FILES
api_helper_macros.h
api.h
vat_helper_macros.h
api_common.h
DESTINATION
include/vlibapi
)
+14 -15
View File
@@ -11,11 +11,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
vpp_add_api_files(vlibmemory_api_headers
memclnt.api
)
add_library (vlibmemory SHARED
add_vpp_library (vlibmemory
SOURCES
memory_api.c
memory_shared.c
memory_client.c
@@ -24,12 +21,8 @@ add_library (vlibmemory SHARED
vlib_api_cli.c
../vlibapi/api_shared.c
../vlibapi/node_serialize.c
)
target_link_libraries (vlibmemory vppinfra svm vlib)
add_dependencies(vlibmemory vlibmemory_api_headers)
install (TARGETS vlibmemory DESTINATION lib)
vpp_add_header_files(vlibmemory
INSTALL_HEADERS
vl_memory_msg_enum.h
memory_shared.h
vl_memory_api_h.h
@@ -38,16 +31,22 @@ vpp_add_header_files(vlibmemory
api.h
memory_client.h
socket_api.h
)
add_library (vlibmemoryclient SHARED
API_FILES
memclnt.api
LINK_LIBRARIES vppinfra svm vlib
)
add_dependencies(vlibmemory vlibmemory_api_headers)
add_vpp_library (vlibmemoryclient
SOURCES
memory_shared.c
memory_client.c
socket_client.c
../vlibapi/api_shared.c
../vlibapi/node_serialize.c
)
target_link_libraries (vlibmemoryclient vppinfra svm vlib)
LINK_LIBRARIES vppinfra svm vlib
)
add_dependencies(vlibmemoryclient vlibmemory_api_headers)
install (TARGETS vlibmemoryclient DESTINATION lib)
+1229 -626
View File
File diff suppressed because it is too large Load Diff
+7 -6
View File
@@ -15,14 +15,15 @@
# vpp api client library
##############################################################################
add_library (vppapiclient SHARED
add_vpp_library (vppapiclient
SOURCES
client/client.c
client/libvppapiclient.map
)
target_link_libraries(vppapiclient vppinfra vlibmemoryclient svm pthread m rt)
add_dependencies(vppapiclient vpp_version_h api_headers)
install(TARGETS vppapiclient DESTINATION lib)
vpp_add_header_files(vpp-api
LINK_LIBRARIES vppinfra vlibmemoryclient svm pthread m rt
)
add_dependencies(vppapiclient vpp_version_h api_headers)
add_vpp_headers(vpp-api
client/vppapiclient.h
)
+37 -24
View File
@@ -33,12 +33,22 @@ add_custom_target(vpp_version_h
##############################################################################
option(VPP_API_TEST_BUILTIN "Use builtin VPP API test." ON)
vpp_add_api_files(vpp_api_headers
set(VPP_API_FILES
api/vpe.api
stats/stats.api
oam/oam.api
)
vpp_add_api_files(vpp_api_headers ${VPP_API_FILES})
foreach(file ${VPP_API_FILES})
get_filename_component(dir ${file} DIRECTORY)
install(
FILES ${CMAKE_CURRENT_BINARY_DIR}/${file}.h
DESTINATION include/vpp/${dir}
)
endforeach()
set(VPP_SOURCES
vnet/main.c
app/vpe_cli.c
@@ -61,15 +71,14 @@ if(VPP_API_TEST_BUILTIN)
add_definitions(-DVPP_API_TEST_BUILTIN=1)
endif()
add_executable (vpp ${VPP_SOURCES})
add_vpp_executable(vpp
ENABLE_EXPORTS
SOURCES ${VPP_SOURCES}
LINK_LIBRARIES svm vlib vppinfra vlibmemory vnet Threads::Threads ${CMAKE_DL_LIBS}
DEPENDS vpp_version_h api_headers
)
target_link_libraries(vpp svm vlib vppinfra vlibmemory vnet Threads::Threads
${CMAKE_DL_LIBS})
add_dependencies(vpp vpp_version_h api_headers)
set_target_properties(vpp PROPERTIES ENABLE_EXPORTS 1)
install(TARGETS vpp DESTINATION bin)
vpp_add_header_files(vpp
add_vpp_headers(vpp
api/vpe_msg_enum.h
api/vpe_all_api_h.h
)
@@ -77,28 +86,32 @@ vpp_add_header_files(vpp
##############################################################################
# vppctl binary
##############################################################################
add_executable(vppctl app/vppctl.c)
target_link_libraries(vppctl vppinfra)
install(TARGETS vppctl DESTINATION bin)
add_vpp_executable(vppctl
SOURCES app/vppctl.c
LINK_LIBRARIES vppinfra
)
##############################################################################
# vpp_get_metrics binary
##############################################################################
add_executable (vpp_get_metrics api/vpp_get_metrics.c ${VPP_API_HDRS})
target_link_libraries (vpp_get_metrics vppinfra svm svmdb)
install(TARGETS vpp_get_metrics DESTINATION bin)
add_vpp_executable(vpp_get_metrics
SOURCES api/vpp_get_metrics.c
LINK_LIBRARIES vppinfra svm svmdb
DEPENDS api_headers
)
##############################################################################
# stats binaries
##############################################################################
add_executable(summary_stats_client api/summary_stats_client.c)
add_executable(stat_client app/stat_client.c)
add_dependencies(summary_stats_client api_headers)
add_dependencies(stat_client api_headers)
target_link_libraries(summary_stats_client vppinfra svm vlibmemoryclient)
target_link_libraries(stat_client vppinfra svm vlibmemoryclient)
add_vpp_executable(summary_stats_client
SOURCES api/summary_stats_client.c
LINK_LIBRARIES vppinfra svm vlibmemoryclient
DEPENDS api_headers
)
##############################################################################
# install
##############################################################################
add_vpp_executable(stat_client
SOURCES app/stat_client.c
LINK_LIBRARIES vppinfra svm vlibmemoryclient
DEPENDS api_headers
)
+34 -29
View File
@@ -88,26 +88,7 @@ set(VPPINFRA_SRCS
linux/sysfs.c
)
if(VPP_USE_DLMALLOC)
list(APPEND VPPINFRA_SRCS
dlmalloc.c
mem_dlmalloc.c
)
else(VPP_USE_DLMALLOC)
list(APPEND VPPINFRA_SRCS
mheap.c
mem_mheap.c
)
endif(VPP_USE_DLMALLOC)
add_library(vppinfra SHARED ${VPPINFRA_SRCS})
target_link_libraries(vppinfra m)
install(TARGETS vppinfra DESTINATION lib)
##############################################################################
# vppinfra headers
##############################################################################
vpp_add_header_files(vppinfra
set(VPPINFRA_HEADERS
asm_mips.h
asm_x86.h
bihash_16_8.h
@@ -200,12 +181,32 @@ vpp_add_header_files(vppinfra
linux/sysfs.h
)
if(VPP_USE_DLMALLOC)
list(APPEND VPPINFRA_SRCS
dlmalloc.c
mem_dlmalloc.c
)
else(VPP_USE_DLMALLOC)
list(APPEND VPPINFRA_SRCS
mheap.c
mem_mheap.c
)
endif(VPP_USE_DLMALLOC)
add_vpp_library(vppinfra
SOURCES ${VPPINFRA_SRCS}
LINK_LIBRARIES m
INSTALL_HEADERS ${VPPINFRA_HEADERS}
)
##############################################################################
# vppinfra headers
##############################################################################
option(VPP_BUILD_VPPINFRA_TESTS "Build vppinfra tests." OFF)
if(VPP_BUILD_VPPINFRA_TESTS)
set(VPPINFRA_TESTS
bihash_template
foreach(test
bihash_vec88
cuckoo_bihash
cuckoo_template
dlist
elf
@@ -232,14 +233,18 @@ if(VPP_BUILD_VPPINFRA_TESTS)
tw_timer
valloc
vec
vhash
zvec
)
foreach(test ${VPPINFRA_TESTS})
add_executable(test_${test} test_${test}.c)
target_link_libraries(test_${test} vppinfra)
add_vpp_executable(test_${test}
SOURCES test_${test}.c
LINK_LIBRARIES vppinfra
)
endforeach()
target_link_libraries(test_bihash_template Threads::Threads)
target_link_libraries(test_cuckoo_bihash Threads::Threads)
foreach(test bihash_template cuckoo_bihash)
add_vpp_executable(test_${test}
SOURCES test_${test}.c
LINK_LIBRARIES vppinfra Threads::Threads
)
endforeach()
endif(VPP_BUILD_VPPINFRA_TESTS)