summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDamjan Marion <damarion@cisco.com>2020-05-07 16:49:45 +0200
committerFlorin Coras <florin.coras@gmail.com>2020-05-08 17:01:32 +0000
commit599efc67e87e89666d44efd34b5d3db7ccf1f4ca (patch)
tree5ced205cb5ff5247e8e9b596295d4ab4d60319c5
parent13f64ce2272539d97b8c499e8e298a053fb3c9e2 (diff)
build: various improvements
- add option to install only host tools - add option to specify lib and runtime dir Type: improvement Change-Id: I6356b52df459120fc9b0127948bae7679fb10e52 Signed-off-by: Damjan Marion <damarion@cisco.com>
-rw-r--r--extras/libmemif/CMakeLists.txt90
-rw-r--r--extras/libmemif/examples/CMakeLists.txt2
-rw-r--r--extras/libmemif/src/CMakeLists.txt21
-rw-r--r--extras/libmemif/test/CMakeLists.txt4
-rw-r--r--src/CMakeLists.txt17
-rw-r--r--src/cmake/VPPConfig.cmake4
-rw-r--r--src/cmake/exec.cmake2
-rw-r--r--src/cmake/library.cmake2
-rw-r--r--src/cmake/plugin.cmake4
-rw-r--r--src/tools/vppapigen/CMakeLists.txt2
-rw-r--r--src/vpp-api/vapi/CMakeLists.txt2
11 files changed, 111 insertions, 39 deletions
diff --git a/extras/libmemif/CMakeLists.txt b/extras/libmemif/CMakeLists.txt
index 263bd18d1df..7f4915b5d70 100644
--- a/extras/libmemif/CMakeLists.txt
+++ b/extras/libmemif/CMakeLists.txt
@@ -19,15 +19,6 @@ set(CMAKE_C_STANDARD 11)
include(CheckCCompilerFlag)
include(CheckFunctionExists)
-set(VPP_SRC "${CMAKE_CURRENT_SOURCE_DIR}/../../src")
-execute_process(
- COMMAND find ${VPP_SRC} -type d -name "cmake"
- OUTPUT_VARIABLE CMAKE_DEPS_FOLDER
- OUTPUT_STRIP_TRAILING_WHITESPACE
-)
-include(${CMAKE_DEPS_FOLDER}/library.cmake)
-include(${CMAKE_DEPS_FOLDER}/pack.cmake)
-
if (NOT CMAKE_BUILD_TYPE)
message(STATUS "No build type selected, default to Release")
set(CMAKE_BUILD_TYPE "Release")
@@ -47,7 +38,6 @@ if(${HAVE_MEMFD_CREATE})
endif()
include_directories(src)
-set(LIBMEMIF memif)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
find_package(Check 0.10.0)
@@ -61,8 +51,80 @@ endif ()
add_subdirectory(src)
add_subdirectory(examples)
-add_vpp_packaging(
- NAME "memif"
- VENDOR "fd.io"
- DESCRIPTION "Shared Memory Interface"
+##############################################################################
+# Packaging
+##############################################################################
+
+# parse /etc/os-release
+file(READ "/etc/os-release" os_version)
+string(REPLACE "\n" ";" os_version ${os_version})
+foreach(_ver ${os_version})
+ string(REPLACE "=" ";" _ver ${_ver})
+ list(GET _ver 0 _name)
+ list(GET _ver 1 _value)
+ set(OS_${_name} ${_value})
+endforeach()
+
+ # extract version from git
+execute_process(
+ COMMAND git describe --long --match v*
+ WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
+ OUTPUT_VARIABLE VER
+ OUTPUT_STRIP_TRAILING_WHITESPACE
)
+string(REGEX REPLACE "v(.*)-([0-9]+)-(g[0-9a-f]+)" "\\1;\\2;\\3" VER ${VER})
+list(GET VER 0 tag)
+list(GET VER 1 commit_num)
+list(GET VER 2 commit_name)
+
+#define DEB and RPM version numbers
+if(${commit_num} EQUAL 0)
+ set(deb_ver "${tag}")
+ set(rpm_ver "${tag}")
+else()
+ if (DEFINED ENV{BUILD_NUMBER})
+ set(deb_ver "${tag}~${commit_num}-${commit_name}~b$ENV{BUILD_NUMBER}")
+ set(rpm_ver "${tag}~${commit_num}_${commit_name}~b$ENV{BUILD_NUMBER}")
+ else()
+ set(deb_ver "${tag}~${commit_num}-${commit_name}")
+ set(rpm_ver "${tag}~${commit_num}_${commit_name}")
+ endif()
+endif()
+
+set(CPACK_PACKAGE_NAME "memif")
+set(CPACK_STRIP_FILES OFF)
+set(CPACK_PACKAGE_VENDOR "fd.io")
+set(CPACK_COMPONENTS_IGNORE_GROUPS 1)
+set(CPACK_${CPACK_GENERATOR}_COMPONENT_INSTALL ON)
+set(CPACK_${type}_PACKAGE_DESCRIPTION "memif Shared Memory Interface")
+set(CPACK_${type}_PACKAGE_RELEASE 1)
+
+if(OS_ID_LIKE MATCHES "debian")
+ set(CPACK_GENERATOR "DEB")
+ set(type "DEBIAN")
+ set(CPACK_PACKAGE_VERSION "${deb_ver}")
+ set(CPACK_DEBIAN_PACKAGE_MAINTAINER "VPP Team")
+ execute_process(
+ COMMAND dpkg --print-architecture
+ OUTPUT_VARIABLE CPACK_DEBIAN_PACKAGE_ARCHITECTURE
+ OUTPUT_STRIP_TRAILING_WHITESPACE
+ )
+ set(CPACK_PACKAGE_FILE_NAME ${CPACK_PACKAGE_NAME}_${CPACK_PACKAGE_VERSION}_${CPACK_DEBIAN_PACKAGE_ARCHITECTURE})
+elseif(OS_ID_LIKE MATCHES "rhel")
+ set(CPACK_GENERATOR "RPM")
+ set(type "RPM")
+ set(CPACK_PACKAGE_VERSION "${rpm_ver}")
+ execute_process(
+ COMMAND uname -m
+ OUTPUT_VARIABLE CPACK_RPM_PACKAGE_ARCHITECTURE
+ OUTPUT_STRIP_TRAILING_WHITESPACE
+ )
+ set(CPACK_PACKAGE_FILE_NAME ${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}.${CPACK_RPM_PACKAGE_ARCHITECTURE})
+endif()
+
+if(CPACK_GENERATOR)
+ include(CPack)
+else()
+ message(ERROR "CPACK_GENERATOR must be set")
+endif()
+
diff --git a/extras/libmemif/examples/CMakeLists.txt b/extras/libmemif/examples/CMakeLists.txt
index 1cf50002b8a..4f120e59f75 100644
--- a/extras/libmemif/examples/CMakeLists.txt
+++ b/extras/libmemif/examples/CMakeLists.txt
@@ -32,5 +32,5 @@ foreach (EXAMPLE_SRC ${EXAMPLES_LIST})
string(SUBSTRING ${EXAMPLE_SRC} 0 ${INDEX} EXECUTABLE)
add_executable(${EXECUTABLE} ${COMMON_SOURCE_FILES} ${EXAMPLE_SRC})
target_include_directories(${EXECUTABLE} PRIVATE $<BUILD_INTERFACE:${HEADERS_DIR}>)
- target_link_libraries(${EXECUTABLE} ${LIBMEMIF} ${CMAKE_THREAD_LIBS_INIT})
+ target_link_libraries(${EXECUTABLE} memif ${CMAKE_THREAD_LIBS_INIT})
endforeach()
diff --git a/extras/libmemif/src/CMakeLists.txt b/extras/libmemif/src/CMakeLists.txt
index 09a2e4e6005..aced550ff5d 100644
--- a/extras/libmemif/src/CMakeLists.txt
+++ b/extras/libmemif/src/CMakeLists.txt
@@ -32,12 +32,15 @@ list(APPEND MEMIF_SOURCES
include_directories(${HEADERS_DIR})
-add_vpp_library(${LIBMEMIF}
- SOURCES ${MEMIF_SOURCES}
-
- INSTALL_HEADERS ${MEMIF_HEADERS}
-
- LINK_LIBRARIES ${CMAKE_THREAD_LIBS_INIT}
-
- COMPONENT libmemif
-)
+add_library(memif SHARED ${MEMIF_SOURCES})
+target_link_libraries(memif ${CMAKE_THREAD_LIBS_INIT})
+foreach(file ${MEMIF_HEADERS})
+ get_filename_component(dir ${file} DIRECTORY)
+ install(
+ FILES ${file}
+ DESTINATION include/${lib}/${dir}
+ COMPONENT libmemif-dev
+ )
+endforeach()
+
+install(TARGETS memif DESTINATION lib COMPONENT libmemif)
diff --git a/extras/libmemif/test/CMakeLists.txt b/extras/libmemif/test/CMakeLists.txt
index 3681fd3e64b..79754a2f8b7 100644
--- a/extras/libmemif/test/CMakeLists.txt
+++ b/extras/libmemif/test/CMakeLists.txt
@@ -30,6 +30,6 @@ set(SOURCE_FILES
add_executable(${TEST_NAME} ${SOURCE_FILES})
target_include_directories(${TEST_NAME} PRIVATE $<BUILD_INTERFACE:${HEADERS_DIR}>)
-target_link_libraries(${TEST_NAME} ${LIBMEMIF} ${CHECK_LIBRARY} ${SUBUNIT_LIBRARY} ${TEST_LIBS} ${CMAKE_THREAD_LIBS_INIT})
+target_link_libraries(${TEST_NAME} memif ${CHECK_LIBRARY} ${SUBUNIT_LIBRARY} ${TEST_LIBS} ${CMAKE_THREAD_LIBS_INIT})
-add_test(unit_test unit-test) \ No newline at end of file
+add_test(unit_test unit-test)
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 2e3cf6b1d68..59c7512a044 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -50,9 +50,11 @@ set(CMAKE_C_COMPILER_TARGET ${CMAKE_SYSTEM_PROCESSOR}-linux-gnu)
##############################################################################
check_c_compiler_flag("-Wno-address-of-packed-member"
compiler_flag_no_address_of_packed_member)
+set(VPP_RUNTIME_DIR "bin" CACHE STRING "Relative runtime directory path")
+set(VPP_LIBRARY_DIR "lib" CACHE STRING "Relative library directory path")
-set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
-set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
+set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${VPP_RUNTIME_DIR})
+set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${VPP_LIBRARY_DIR})
if (CMAKE_BUILD_TYPE)
set(CMAKE_C_FLAGS "-g -fPIC -Werror -Wall ${CMAKE_C_FLAGS}")
@@ -107,12 +109,12 @@ set_property(CACHE CMAKE_BUILD_TYPE PROPERTY
# sanitizers
##############################################################################
-option(ENABLE_SANITIZE_ADDR "Enable Address Sanitizer" OFF)
-if (ENABLE_SANITIZE_ADDR)
+option(VPP_ENABLE_SANITIZE_ADDR "Enable Address Sanitizer" OFF)
+if (VPP_ENABLE_SANITIZE_ADDR)
set(CMAKE_C_FLAGS "-fsanitize=address --param asan-stack=0 -DCLIB_SANITIZE_ADDR ${CMAKE_C_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "-fsanitize=address ${CMAKE_EXE_LINKER_FLAGS}")
set(CMAKE_SHARED_LINKER_FLAGS "-fsanitize=address ${CMAKE_SHARED_LINKER_FLAGS}")
-endif (ENABLE_SANITIZE_ADDR)
+endif (VPP_ENABLE_SANITIZE_ADDR)
##############################################################################
# install config
@@ -139,7 +141,10 @@ include(cmake/plugin.cmake)
##############################################################################
# subdirs - order matters
##############################################################################
-if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
+option(VPP_HOST_TOOLS_ONLY "Build only host tools" OFF)
+if(VPP_HOST_TOOLS_ONLY)
+ set(SUBDIRS tools/vppapigen cmake)
+elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
find_package(OpenSSL REQUIRED)
set(SUBDIRS
vppinfra svm vlib vlibmemory vlibapi vnet vpp vat vcl plugins
diff --git a/src/cmake/VPPConfig.cmake b/src/cmake/VPPConfig.cmake
index 870c2a5b182..21da59d68ba 100644
--- a/src/cmake/VPPConfig.cmake
+++ b/src/cmake/VPPConfig.cmake
@@ -33,7 +33,9 @@ if (compiler_flag_no_address_of_packed_member)
add_definitions(-Wno-address-of-packed-member)
endif()
-include(CheckCCompilerFlag)
+set(VPP_RUNTIME_DIR "bin" CACHE STRING "Relative runtime directory path")
+set(VPP_LIBRARY_DIR "lib" CACHE STRING "Relative library directory path")
+
include(${CMAKE_CURRENT_LIST_DIR}/cpu.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/api.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/library.cmake)
diff --git a/src/cmake/exec.cmake b/src/cmake/exec.cmake
index d5e837084e9..7bfd5751c83 100644
--- a/src/cmake/exec.cmake
+++ b/src/cmake/exec.cmake
@@ -30,7 +30,7 @@ macro(add_vpp_executable exec)
add_dependencies(${exec} ${ARG_DEPENDS})
endif()
if(NOT ARG_NO_INSTALL)
- install(TARGETS ${exec} DESTINATION bin)
+ install(TARGETS ${exec} DESTINATION ${VPP_RUNTIME_DIR})
endif()
endmacro()
diff --git a/src/cmake/library.cmake b/src/cmake/library.cmake
index dc14ae59e46..d6a63d325e9 100644
--- a/src/cmake/library.cmake
+++ b/src/cmake/library.cmake
@@ -34,7 +34,7 @@ macro(add_vpp_library lib)
endif()
install(
TARGETS ${lib}
- DESTINATION lib
+ DESTINATION ${VPP_LIBRARY_DIR}
COMPONENT ${ARG_COMPONENT}
)
diff --git a/src/cmake/plugin.cmake b/src/cmake/plugin.cmake
index 2e2749a440e..bf40aa504a7 100644
--- a/src/cmake/plugin.cmake
+++ b/src/cmake/plugin.cmake
@@ -86,13 +86,13 @@ macro(add_vpp_plugin name)
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/vpp_api_test_plugins)
install(
TARGETS ${test_plugin_name}
- DESTINATION lib/vpp_api_test_plugins
+ DESTINATION ${VPP_LIBRARY_DIR}/vpp_api_test_plugins
COMPONENT ${PLUGIN_COMPONENT}
)
endif()
install(
TARGETS ${plugin_name}
- DESTINATION lib/vpp_plugins
+ DESTINATION ${VPP_LIBRARY_DIR}/vpp_plugins
COMPONENT ${PLUGIN_COMPONENT}
)
endmacro()
diff --git a/src/tools/vppapigen/CMakeLists.txt b/src/tools/vppapigen/CMakeLists.txt
index 9fb00817ea9..bfabc3a670c 100644
--- a/src/tools/vppapigen/CMakeLists.txt
+++ b/src/tools/vppapigen/CMakeLists.txt
@@ -14,7 +14,7 @@
install(
FILES vppapigen.py
RENAME vppapigen
- DESTINATION bin
+ DESTINATION ${VPP_RUNTIME_DIR}
PERMISSIONS
OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE
WORLD_READ WORLD_EXECUTE
diff --git a/src/vpp-api/vapi/CMakeLists.txt b/src/vpp-api/vapi/CMakeLists.txt
index 4c74ae80928..04e7edd5f2a 100644
--- a/src/vpp-api/vapi/CMakeLists.txt
+++ b/src/vpp-api/vapi/CMakeLists.txt
@@ -55,6 +55,6 @@ install(
vapi_cpp_gen.py
vapi_json_parser.py
- DESTINATION bin
+ DESTINATION ${VPP_RUNTIME_DIR}
COMPONENT vpp-dev
)