Skip to content

Commit

Permalink
[HICN-430] Rework on CMake
Browse files Browse the repository at this point in the history
Change way targets are defined: each project defines targets.
Fix project BUILD flags
Add build-extras bash script
Rework build tree of extras folder, using ExternalProject_Add

Change-Id: I82fa29896e54c8a033490eba013c3f0431bec9d0
Signed-off-by: Mauro Sardara <[email protected]>
  • Loading branch information
msardara committed Dec 10, 2019
1 parent e8eda2c commit 3f21100
Show file tree
Hide file tree
Showing 35 changed files with 281 additions and 302 deletions.
86 changes: 25 additions & 61 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,30 @@ option(BUILD_UTILS "Build the hicn utils" ON)
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)
option(BUILD_SYSREPOP "Build the sysrepo plugin" OFF)
option(BUILD_LIBYANG "Build the sysrepo plugin" OFF)
option(BUILD_EXTRAS "Build external projects." OFF)

if ((BUILD_APPS OR BUILD_UTILS) AND NOT BUILD_LIBTRANSPORT)
message(STATUS "Libhicntransport required. Enabled by default.")
set (BUILD_LIBTRANSPORT ON)
endif()

if (BUILD_SYSREPOPLUGIN AND NOT BUILD_HICNPLUGIN)
message(STATUS "Hicn-plugin required. Enabled by default.")
set (BUILD_HICNPLUGIN ON)
endif()

if ((BUILD_HICNLIGHT OR
BUILD_LIBTRANSPORT OR
BUILD_UTILS OR
BUILD_APPS OR
BUILD_CTRL OR
BUILD_HICNPLUGIN OR
BUILD_SYSREPOPLUGIN)
AND NOT BUILD_LIBHICN)
message(STATUS "Libhicn required. Enabled by default.")
set(BUILD_LIBHICN ON)
endif()

list(APPEND dir_options
BUILD_LIBHICN
Expand All @@ -40,11 +60,8 @@ list(APPEND dir_options
BUILD_UTILS
BUILD_APPS
BUILD_CTRL
BUILD_HICNEXTRAPLUGIN
BUILD_SYSREPOPLUGIN
BUILD_SYSREPO
BUILD_LIBYANG
BUILD_LIBMEMIF
BUILD_EXTRAS
)

set(BUILD_LIBHICN_DIR lib)
Expand All @@ -55,11 +72,7 @@ set(BUILD_APPS_DIR apps)
set(BUILD_CTRL_DIR ctrl)
set(BUILD_HICNPLUGIN_DIR hicn-plugin)
set(BUILD_SYSREPOPLUGIN_DIR ctrl/sysrepo-plugins)
set(BUILD_SYSREPO_DIR extras/sysrepo)
set(BUILD_LIBYANG_DIR extras/libyang)
set(BUILD_HICNEXTRAPLUGIN_DIR extras/hicn-extra-plugin)
set(BUILD_LIBMEMIF_DIR extras/libmemif)

set(BUILD_EXTRAS_DIR extras/)

## Add enabled components
foreach (opt ${dir_options})
Expand All @@ -70,55 +83,6 @@ foreach (opt ${dir_options})
endif()
endforeach()

## Static targets
set(LIBHICN hicn)
set(HICN_LIGHT hicn-light)
set(HICN_LIGHT_CONTROL hicn-light-control)
set(HICN_LIGHT_DAEMON hicn-light-daemon)
set(HICN_PLUGIN hicn-plugin)
set(HICN_EXTRA_PLUGIN hicn-extra-plugin)
set(LIBTRANSPORT hicntransport)
set(HICN_UTILS hicn-utils)
set(HICNCTRL hicnctrl)
set(LIBHICNCTRL hicnctrl)
set(HICN_APPS hicn-apps)
set(LIBFACEMGR facemgr)
set(FACEMGR facemgr)
set(LIBMEMIF memif)

if (BUILD_HICNPLUGIN AND "${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
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()

set(LIBTRANSPORT ${LIBTRANSPORT}-memif)
set(LIBHICNCTRL ${LIBHICNCTRL}-memif)
endif()

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

set(LIBHICN_STATIC ${LIBHICN}.static)
set(LIBTRANSPORT_STATIC ${LIBTRANSPORT}.static)
set(LIBHICNCTRL_STATIC ${LIBHICNCTRL}.static)
set(LIBMEMIF_STATIC ${LIBMEMIF}.static)

## HEADER FILES
set(HICN_INCLUDE_DIRS "" "" CACHE INTERNAL "" FORCE)
set(LIBTRANSPORT_INCLUDE_DIRS "" "" CACHE INTERNAL "" FORCE)
set(LIBHICNCTRL_INCLUDE_DIRS "" "" CACHE INTERNAL "" FORCE)

if (NOT WIN32)
add_compile_options(-Wall -Werror)
endif ()
Expand Down
4 changes: 3 additions & 1 deletion apps/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@ set(CMAKE_MODULE_PATH
include(BuildMacros)
include(WindowsMacros)

set(HICN_APPS hicn-apps CACHE INTERNAL "" FORCE)

if(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR)
find_package(Libtransport REQUIRED)
find_package(Threads REQUIRED)
include_directories(${LIBTRANSPORT_INCLUDE_DIRS})
set(HICN_APPS hicn-apps)
else()
if (${CMAKE_SYSTEM_NAME} STREQUAL "Android")
find_package(OpenSSL REQUIRED)
Expand All @@ -38,6 +39,7 @@ else()
else ()
set(LIBTRANSPORT_LIBRARIES ${LIBTRANSPORT_SHARED})
endif ()

list(APPEND DEPENDENCIES
${LIBTRANSPORT_LIBRARIES}
)
Expand Down
2 changes: 1 addition & 1 deletion cmake/Modules/Packager.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ macro(extract_version)

message(STATUS "Git describe output: ${VER}")

string(REGEX REPLACE "v([0-9]+).([0-9]+)-([0-9]+)-(g[0-9a-f]+)" "\\1;\\2;\\3;\\4" VER ${VER})
string(REGEX REPLACE "v([0-9]+).([0-9]+).*-([0-9]+)-(g[0-9a-f]+)" "\\1;\\2;\\3;\\4" VER ${VER})
list(GET VER 0 VERSION_MAJOR)
list(GET VER 1 VERSION_MINOR)
list(GET VER 2 VERSION_REVISION)
Expand Down
5 changes: 3 additions & 2 deletions ctrl/facemgr/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,12 @@ set(CMAKE_INSTALL_RPATH_USE_LINK_PATH ON)
find_package_wrapper(Config REQUIRED)
find_package_wrapper(LibEvent REQUIRED)

set(FACEMGR facemgr CACHE INTERNAL "" FORCE)
set(LIBFACEMGR facemgr CACHE INTERNAL "" FORCE)

if(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR)
find_package_wrapper(Libhicn REQUIRED)
find_package_wrapper(Libhicnctrl REQUIRED)
set(FACEMGR facemgr)
set(LIBFACEMGR facemgr)
else()
if (${CMAKE_SYSTEM_NAME} STREQUAL "Android")
set(HICN_LIBRARIES ${LIBHICN_STATIC} log)
Expand Down
34 changes: 20 additions & 14 deletions ctrl/libhicnctrl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,29 @@ set(CMAKE_C_STANDARD_REQUIRED ON)

set(CMAKE_MACOSX_RPATH ON)


set(LIBHICNCTRL hicnctrl)

if (BUILD_HICNPLUGIN AND "${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
set(LIBHICNCTRL ${LIBHICNCTRL}-memif PARENT_SCOPE)
set(LINK_FLAGS "-Wl,-unresolved-symbols=ignore-in-shared-libs")
list(APPEND HICN_LIBRARIES ${HICNPLUGIN_LIBRARIES})
endif()

set(LIBHICNCTRL ${LIBHICNCTRL} CACHE INTERNAL "" FORCE)
set(LIBHICNCTRL_SHARED ${LIBHICNCTRL}.shared CACHE INTERNAL "" FORCE)
set(LIBHICNCTRL_STATIC ${LIBHICNCTRL}.static CACHE INTERNAL "" FORCE)
set(HICNCTRL hicnctrl CACHE INTERNAL "" FORCE)
set(LIBHICNCTRL_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/includes CACHE INTERNAL "" FORCE)

if(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR)
set(HICNCTRL hicnctrl)
set(LIBHICNCTRL hicnctrl)
if (BUILD_HICNPLUGIN AND "${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
set(LIBHICNCTRL ${LIBHICNCTRL}-memif)
find_package_wrapper(HicnPlugin REQUIRED)
list(APPEND HICN_LIBRARIES ${HICNPLUGIN_LIBRARIES})
set(LINK_FLAGS "-Wl,-unresolved-symbols=ignore-in-shared-libs")
endif()

find_package_wrapper(Libhicn REQUIRED)
list(APPEND HICN_LIBRARIES ${LIBHICN_SHARED})

set(LIBHICNCTRL_SHARED ${LIBHICNCTRL}.shared)
set(LIBHICNCTRL_STATIC ${LIBHICNCTRL}.static)

set(HICN_INCLUDE_DIRS
${HICN_INCLUDE_DIRS}
${HICNPLUGIN_INCLUDE_DIRS})
Expand All @@ -60,12 +67,11 @@ else()
${LIBHICN_STATIC}
)
elseif (BUILD_HICNPLUGIN AND "${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
set(HICN_INCLUDE_DIRS
${HICN_INCLUDE_DIRS}
${HICNPLUGIN_INCLUDE_DIRS})

set(HICN_LIBRARIES ${HICNPLUGIN_LIBRARIES})
set(LINK_FLAGS "-Wl,-unresolved-symbols=ignore-in-shared-libs")
set(
HICN_INCLUDE_DIRS
${HICN_INCLUDE_DIRS}
${HICNPLUGIN_INCLUDE_DIRS}
)

list(APPEND DEPENDENCIES
hicn_plugin
Expand Down
34 changes: 19 additions & 15 deletions ctrl/sysrepo-plugins/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,30 +26,34 @@ include(BuildMacros)
find_package(PkgConfig REQUIRED)
find_package(Sysrepo REQUIRED)

if (NOT "${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
message(FATAL_ERROR "Sysrepo plugin supported only on Linux systems")
endif()

if (NOT SRPD_PLUGINS_PATH)
if (PKG_CONFIG_FOUND)
execute_process(COMMAND ${PKG_CONFIG_EXECUTABLE} "--variable=SRPD_PLUGINS_PATH" "libsysrepo" OUTPUT_VARIABLE SRPD_PLUGINS_PATH)
string(STRIP ${SRPD_PLUGINS_PATH} SRPD_PLUGINS_PATH)
endif()
if (PKG_CONFIG_FOUND)
execute_process(COMMAND ${PKG_CONFIG_EXECUTABLE} "--variable=SRPD_PLUGINS_PATH" "libsysrepo" OUTPUT_VARIABLE SRPD_PLUGINS_PATH)
string(STRIP ${SRPD_PLUGINS_PATH} SRPD_PLUGINS_PATH)
endif()
endif()

if (NOT SRPD_PLUGINS_PATH)
message(FATAL_ERROR "Cannot get sysrepo plugins directory due to missing pkg-config, set SRPD_PLUGINS_PATH manually.")
message(FATAL_ERROR "Cannot get sysrepo plugins directory due to missing pkg-config, set SRPD_PLUGINS_PATH manually.")
endif()

if(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR)
find_package(Vpp REQUIRED)
find_package(HicnPlugin REQUIRED)
find_package(Libhicn REQUIRED)
add_subdirectory(hicn-plugin)
find_package(Vpp REQUIRED)
find_package(HicnPlugin REQUIRED)
find_package(Libhicn REQUIRED)
else()
if (BUILD_HICNPLUGIN AND "${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
list(APPEND DEPENDENCIES
hicn_plugin)
add_subdirectory(hicn-plugin)
endif ()
list(APPEND DEPENDENCIES
${LIBHICN_SHARED}
${LIBHICN_STATIC}
hicn_plugin
)
endif()

# add subdirectories
add_subdirectory(hicn-plugin)

include(Packaging)
if(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR)
Expand Down
33 changes: 33 additions & 0 deletions extras/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Copyright (c) 2017-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.

cmake_minimum_required(VERSION 3.5 FATAL_ERROR)

project(extras)

list(APPEND CMAKE_MODULE_PATH
${CMAKE_CURRENT_SOURCE_DIR}/../cmake/Modules
)

set (DESTDIR ${CMAKE_BINARY_DIR}/extras-root)

add_subdirectory(router-plugin)
add_subdirectory(libmemif)
add_subdirectory(libyang)
add_subdirectory(sysrepo)


if(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR)
include(Packager)
make_packages()
endif()
72 changes: 24 additions & 48 deletions extras/libmemif/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,58 +11,34 @@
# 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 --depth 1 vpp;
else
pushd vpp && git pull && popd;
fi"
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
)
cmake_minimum_required(VERSION 3.5)
project(libmemif)

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}
list(APPEND MODULE_PATH
${CMAKE_MODULE_PATH}
${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules
)

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}
)
string(REPLACE ";" "|" MODULE_PATH "${MODULE_PATH}")

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

execute_process(
COMMAND ${CMAKE_COMMAND} -E
copy ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists2.patch libmemif/memif/CMakeLists.txt
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
ExternalProject_Add(libmemif
GIT_REPOSITORY https://github.com/FDio/vpp.git
GIT_TAG v19.08.1
GIT_SHALLOW TRUE
PREFIX ${CMAKE_CURRENT_BINARY_DIR}/libmemif
PATCH_COMMAND bash -c "cp ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists1.patch ./extras/libmemif/CMakeLists.txt && cp ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists2.patch ./extras/libmemif/src/CMakeLists.txt"
# Use the alternate list separator
# (https://cmake.org/cmake/help/latest/manual/cmake-language.7.html#lists)
LIST_SEPARATOR |
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_MODULE_PATH=${MODULE_PATH}
SOURCE_SUBDIR ./extras/libmemif
BUILD_COMMAND make package
INSTALL_COMMAND make DESTDIR=${DESTDIR} install
)

include(Packaging)
add_subdirectory(${CMAKE_CURRENT_BINARY_DIR}/libmemif ${CMAKE_CURRENT_BINARY_DIR}/libmemif)
if(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR)
include(Packager)
make_packages()
endif()
Loading

0 comments on commit 3f21100

Please sign in to comment.