Skip to content

Commit

Permalink
[HICN-279] Added libmemif packaging.
Browse files Browse the repository at this point in the history
Change-Id: Ie8662059163b7a01211bb18fb8f6b77bbbc07279
Signed-off-by: Mauro Sardara <[email protected]>
  • Loading branch information
msardara committed Sep 24, 2019
1 parent d6bd901 commit a0da41b
Show file tree
Hide file tree
Showing 67 changed files with 311 additions and 78 deletions.
32 changes: 22 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ option(BUILD_APPS "Build the hicn apps" OFF)
option(BUILD_CTRL "Build the hicn control tools" ON)
option(BUILD_HICNPLUGIN "Build the hicn vpp plugin" OFF)
option(BUILD_HICNEXTRAPLUGIN "Build the hicn extra plugin" OFF)
option(BUILD_SYSREPOPLUGIN "Build the sysrepo plugin" OFF)

list(APPEND dir_options
BUILD_LIBHICN
Expand All @@ -36,6 +37,10 @@ list(APPEND dir_options
BUILD_UTILS
BUILD_APPS
BUILD_CTRL
BUILD_HICNPLUGIN
BUILD_HICNEXTRAPLUGIN
BUILD_SYSREPOPLUGIN
BUILD_LIBMEMIF
)

set(BUILD_LIBHICN_DIR lib)
Expand All @@ -45,7 +50,9 @@ set(BUILD_UTILS_DIR utils)
set(BUILD_APPS_DIR apps)
set(BUILD_CTRL_DIR ctrl)
set(BUILD_HICNPLUGIN_DIR hicn-plugin)
set(BUILD_HICNEXTRAPLUGIN_DIR utils/extras/)
set(BUILD_SYSREPOPLUGIN_DIR ctrl/sysrepo-plugins)
set(BUILD_HICNEXTRAPLUGIN_DIR extras/hicn-extra-plugin)
set(BUILD_LIBMEMIF_DIR extras/libmemif)

## Add enabled components
foreach (opt ${dir_options})
Expand All @@ -69,11 +76,20 @@ set(HICN_CTRL hicn-ctrl)
set(LIBHICN_CTRL hicn-ctrl)
set(HICN_APPS hicn-apps)
set(FACE_MGR facemgr)
set(LIBMEMIF memif)

if (BUILD_HICNPLUGIN AND "${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
list(APPEND subdirs
${BUILD_HICNPLUGIN_DIR}
)
find_package(Libmemif)

if (NOT Libmemif_FOUND)
message(STATUS "Libmemif not found in the system. Building it as external project.")
list(INSERT subdirs 0
${BUILD_LIBMEMIF_DIR}
)

unset(LIBMEMIF_INCLUDE_DIRS)
unset(LIBMEMIF_LIBRARIES)
endif()

list(APPEND HICN_BINARY_API_INCLUDE_DIRS
${PROJECT_BINARY_DIR}/hicn-plugin
Expand All @@ -83,20 +99,16 @@ if (BUILD_HICNPLUGIN AND "${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
set(LIBTRANSPORT ${LIBTRANSPORT}-memif)
endif()

if (BUILD_HICNEXTRAPLUGIN AND "${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
list(APPEND subdirs
${BUILD_HICNEXTRAPLUGIN_DIR}
)
endif()

## Libraries targets
set(LIBHICN_SHARED ${LIBHICN}.shared)
set(LIBTRANSPORT_SHARED ${LIBTRANSPORT}.shared)
set(LIBHICN_CTRL_SHARED ${LIBHICN_CTRL}.shared)
set(LIBMEMIF_SHARED ${LIBMEMIF}.shared)

set(LIBHICN_STATIC ${LIBHICN}.static)
set(LIBTRANSPORT_STATIC ${LIBTRANSPORT}.static)
set(LIBHICN_CTRL_STATIC ${LIBHICN_CTRL}.static)
set(LIBMEMIF_STATIC ${LIBMEMIF}.static)

## HEADER FILES
set(HICN_INCLUDE_DIRS "" "" CACHE INTERNAL "" FORCE)
Expand Down
2 changes: 1 addition & 1 deletion apps/higet/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ set(CMAKE_MODULE_PATH
)

if (NOT CMAKE_BUILD_TYPE)
message(STATUS "No build type selected, default to Release")
message(STATUS "${PROJECT_NAME}: No build type selected, default to Release")
set(CMAKE_BUILD_TYPE "Release")
endif ()

Expand Down
2 changes: 1 addition & 1 deletion apps/http-proxy/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ set(CMAKE_MODULE_PATH
)

if (NOT CMAKE_BUILD_TYPE)
message(STATUS "No build type selected, default to Release")
message(STATUS "${PROJECT_NAME}: No build type selected, default to Release")
set(CMAKE_BUILD_TYPE "Release")
endif ()

Expand Down
2 changes: 1 addition & 1 deletion ctrl/facemgr/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ endif()
project(facemgr)

if (NOT CMAKE_BUILD_TYPE)
message(STATUS "No build type selected, default to Release")
message(STATUS "${PROJECT_NAME}: No build type selected, default to Release")
set(CMAKE_BUILD_TYPE "Release")
endif()

Expand Down
2 changes: 1 addition & 1 deletion ctrl/libhicnctrl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
project(libhicnctrl)

if (NOT CMAKE_BUILD_TYPE)
message(STATUS "No build type selected, default to Release")
message(STATUS "${PROJECT_NAME}: No build type selected, default to Release")
set(CMAKE_BUILD_TYPE "Release")
endif()

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,19 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH}
set (CMAKE_CXX_STANDARD 11)
set (CMAKE_C_STANDARD 11)

include (Packaging)

# Check for memfd_create syscall
include(CheckSymbolExists)
CHECK_SYMBOL_EXISTS ( "__NR_memfd_create" "sys/syscall.h" HAVE_MEMFD_CREATE )
if ( HAVE_MEMFD_CREATE )
add_definitions ( -DHAVE_MEMFD_CREATE )
add_definitions ( -DHAVE_MEMFD_CREATE )
endif()

if(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR)
set(HICN_EXTRA_PLUGIN extra-plugin)
set(HICN_EXTRA_PLUGIN extra-plugin)
endif()

include (Packaging)

# Dependencies

find_package(Vpp REQUIRED)
Expand All @@ -60,17 +60,20 @@ set(HICN_EXTRA_PLUGIN_HEADER_FILES
)

if (NOT VPP_HOME)
set(VPP_HOME /usr)
set(VPP_HOME /usr)
endif()

if (NOT CMAKE_BUILD_TYPE)
set (CMAKE_BUILD_TYPE "Release")
endif (NOT CMAKE_BUILD_TYPE)

SET(EXTRA_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR} CACHE STRING "extra_install_prefix")
SET(EXTRA_INSTALL_PREFIX
${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}
CACHE STRING "extra_install_prefix"
)

if (CMAKE_BUILD_TYPE STREQUAL "Release")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -Wall -march=native -O3 -g")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -Wall -march=native -O3 -g")
elseif (CMAKE_BUILD_TYPE STREQUAL "Debug")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -Wall -march=native -O0 -g")
add_definitions(-DCLIB_DEBUG -fPIC -fstack-protector-all)
Expand All @@ -80,25 +83,30 @@ include_directories(SYSTEM)
include_directories(${CMAKE_CURRENT_BINARY_DIR})

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DEXTRA_VPP_PLUGIN=1")

add_library(hicn_extra_plugin SHARED
${HICN_EXTRA_PLUGIN_SOURCE_FILES})
${HICN_EXTRA_PLUGIN_SOURCE_FILES}
)

include_directories(${CMAKE_CURRENT_BINARY_DIR}/vpp_plugins)

set(VPP_INSTALL_PLUGIN ${EXTRA_INSTALL_PREFIX}/vpp_plugins)

set_target_properties(hicn_extra_plugin
PROPERTIES
LINKER_LANGUAGE C
INSTALL_RPATH ${VPP_INSTALL_PLUGIN}
PREFIX ""
LIBRARY_OUTPUT_NAME "hicn_router")
PROPERTIES
LINKER_LANGUAGE C
INSTALL_RPATH ${VPP_INSTALL_PLUGIN}
PREFIX ""
LIBRARY_OUTPUT_NAME "hicn_router"
)

install(DIRECTORY
DESTINATION ${VPP_INSTALL_PLUGIN}
COMPONENT ${HICN_EXTRA_PLUGIN})
DESTINATION ${VPP_INSTALL_PLUGIN}
COMPONENT ${HICN_EXTRA_PLUGIN}
)

install(TARGETS hicn_extra_plugin
DESTINATION
${VPP_INSTALL_PLUGIN}
COMPONENT ${HICN_EXTRA_PLUGIN})
DESTINATION
${VPP_INSTALL_PLUGIN}
COMPONENT ${HICN_EXTRA_PLUGIN}
)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
68 changes: 68 additions & 0 deletions extras/libmemif/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# Copyright (c) 2019 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.

set(CMAKE_MODULE_PATH
${CMAKE_MODULE_PATH}
"${CMAKE_CURRENT_SOURCE_DIR}/../../cmake/Modules"
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules"
)

include(ExternalProject)
include(Packaging)

if(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR)
set(LIBMEMIF memif)
endif()

execute_process(
COMMAND bash -c "if [ ! -d vpp ]; then
git clone https://github.com/FDio/vpp.git -b stable/1908 vpp;
else
pushd vpp && git pull && popd;
fi"
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
)

execute_process(
COMMAND ${CMAKE_COMMAND} -E
remove_directory ${CMAKE_CURRENT_BINARY_DIR}/libmemif
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
)

execute_process(
COMMAND ${CMAKE_COMMAND} -E
copy_directory vpp/extras/libmemif ${CMAKE_CURRENT_BINARY_DIR}/libmemif
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
)

execute_process(
COMMAND ${CMAKE_COMMAND} -E rename ${CMAKE_CURRENT_BINARY_DIR}/libmemif/src
${CMAKE_CURRENT_BINARY_DIR}/libmemif/memif
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
)

execute_process(
COMMAND
${CMAKE_COMMAND} -E
copy ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists1.patch libmemif/CMakeLists.txt
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
)

execute_process(
COMMAND ${CMAKE_COMMAND} -E
copy ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists2.patch libmemif/memif/CMakeLists.txt
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
)

include(Packaging)
add_subdirectory(${CMAKE_CURRENT_BINARY_DIR}/libmemif ${CMAKE_CURRENT_BINARY_DIR}/libmemif)
58 changes: 58 additions & 0 deletions extras/libmemif/CMakeLists1.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Copyright (c) 2017 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.

cmake_minimum_required(VERSION 3.5 FATAL_ERROR)

project(memif)
set(CMAKE_C_STANDARD 11)

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake")

include(CheckCCompilerFlag)
include(CheckFunctionExists)

execute_process(
COMMAND find ${VPP_SRC} -type d -name "cmake"
OUTPUT_VARIABLE CMAKE_DEPS_FOLDER
OUTPUT_STRIP_TRAILING_WHITESPACE
)
include(BuildMacros)

if (NOT CMAKE_BUILD_TYPE)
message(STATUS "${PROJECT_NAME}: No build type selected, default to Release")
set(CMAKE_BUILD_TYPE "Release")
endif ()

set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -g -DMEMIF_DBG -DICMP_DBG")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_PREFIX}/lib)
set(CMAKE_INSTALL_MESSAGE NEVER)

find_package(Threads REQUIRED)
include_directories(${CMAKE_THREADS_INCLUDE_DIRS})

check_function_exists(memfd_create HAVE_MEMFD_CREATE)
if(${HAVE_MEMFD_CREATE})
add_definitions(-DHAVE_MEMFD_CREATE)
endif()

include_directories(src)
set(LIBMEMIF memif)

set(LIBMEMIF_INCLUDE_DIRS
${CMAKE_CURRENT_SOURCE_DIR}
"" CACHE INTERNAL
"" FORCE
)

add_subdirectory(memif)
42 changes: 42 additions & 0 deletions extras/libmemif/CMakeLists2.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Copyright (c) 2017 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.

cmake_minimum_required(VERSION 3.5 FATAL_ERROR)

set(HEADERS_DIR ${CMAKE_CURRENT_SOURCE_DIR})

list(APPEND MEMIF_HEADERS
libmemif.h
memif.h
)

list(APPEND MEMIF_PRIVATE_HEADERS
memif_private.h
socket.h
)

list(APPEND MEMIF_SOURCES
main.c
socket.c
)

include_directories(${HEADERS_DIR})

build_library(${LIBMEMIF}
SHARED
SOURCES ${MEMIF_SOURCES}
INSTALL_HEADERS ${MEMIF_HEADERS}
LINK_LIBRARIES ${CMAKE_THREAD_LIBS_INIT}
INSTALL_ROOT_DIR memif
COMPONENT libmemif
)
Loading

0 comments on commit a0da41b

Please sign in to comment.