From 7292f650d75a2c2fc760bf46c28071cb23d3150b Mon Sep 17 00:00:00 2001 From: Denis Biryukov Date: Fri, 18 Oct 2024 21:27:32 +0000 Subject: [PATCH] fix package generation --- install/CMakeLists.txt | 41 ++++++++++++++++++++++++++---- install/cpack_project_config.cmake | 33 ++++++++++++++++++++++++ 2 files changed, 69 insertions(+), 5 deletions(-) create mode 100644 install/cpack_project_config.cmake diff --git a/install/CMakeLists.txt b/install/CMakeLists.txt index 34980f40c..826634724 100644 --- a/install/CMakeLists.txt +++ b/install/CMakeLists.txt @@ -22,9 +22,9 @@ function(install_zenohc_lib configurations property_postfix package_name) else() set(ZENOHC_INSTALL_DYLIBDIR ${CMAKE_INSTALL_LIBDIR}) endif() - install(FILES ${dylib_path} DESTINATION ${ZENOHC_INSTALL_DYLIBDIR} CONFIGURATIONS ${configurations}) + install(FILES ${dylib_path} DESTINATION ${ZENOHC_INSTALL_DYLIBDIR} CONFIGURATIONS ${configurations} COMPONENT lib) if(DEFINED implib_path) - install(FILES ${implib_path} DESTINATION ${CMAKE_INSTALL_LIBDIR} CONFIGURATIONS ${configurations}) + install(FILES ${implib_path} DESTINATION ${CMAKE_INSTALL_LIBDIR} CONFIGURATIONS ${configurations} COMPONENT lib) endif() if((APPLE OR UNIX)) get_filename_component(LIBNAME ${DYLIB} NAME_WE) @@ -33,13 +33,14 @@ function(install_zenohc_lib configurations property_postfix package_name) DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig" CONFIGURATIONS ${configurations} RENAME ${package_name}.pc - OPTIONAL) + OPTIONAL + COMPONENT dev) endif() else() get_target_property(staticlib_path zenohc::static IMPORTED_LOCATION_${property_postfix}) get_target_property(NATIVE_STATIC_LIBS zenohc::static INTERFACE_LINK_LIBRARIES) get_filename_component(STATICLIB ${staticlib_path} NAME) - install(FILES ${staticlib_path} DESTINATION ${CMAKE_INSTALL_LIBDIR} CONFIGURATIONS ${configurations}) + install(FILES ${staticlib_path} DESTINATION ${CMAKE_INSTALL_LIBDIR} CONFIGURATIONS ${configurations} COMPONENT lib) endif() set(CMAKE_INSTALL_CMAKEDIR "${CMAKE_INSTALL_LIBDIR}/cmake/${package_name}") @@ -79,7 +80,7 @@ endfunction() # get_target_property(include_dirs zenohc::lib INTERFACE_INCLUDE_DIRECTORIES) foreach(dir ${include_dirs}) - install(DIRECTORY "${dir}/" DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) + install(DIRECTORY "${dir}/" DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} COMPONENT headers) endforeach() # @@ -87,3 +88,33 @@ endforeach() # install_zenohc_lib("Release;RelWithDebInfo;MinSizeRel;None" "RELEASE" zenohc) install_zenohc_lib("Debug" "DEBUG" zenohc) + +# +# Configure CPack +# +set(CPACK_PACKAGE_DIRECTORY "${CMAKE_BINARY_DIR}/packages") +set(CPACK_PACKAGE_CHECKSUM MD5) +set(CPACK_PACKAGE_VENDOR "The Eclipse Foundation") +set(CPACK_PACKAGE_VERSION_MAJOR ${PROJECT_VERSION_MAJOR}) +set(CPACK_PACKAGE_VERSION_MINOR ${PROJECT_VERSION_MINOR}) +set(CPACK_PACKAGE_VERSION_PATCH ${PROJECT_VERSION_PATCH}) +set(CPACK_COMPONENT_LIB_DESCRIPTION "The C client library for Eclipse zenoh") +set(CPACK_COMPONENT_DEV_DESCRIPTION "${CPACK_COMPONENT_LIB_DESCRIPTION} - cmake files") +set(CPACK_COMPONENT_HEADERS_DESCRIPTION "${CPACK_COMPONENT_LIB_DESCRIPTION} - header files") +set(CPACK_COMPONENT_LIB_GROUP "lib") +set(CPACK_COMPONENT_HEADERS_GROUP "dev") +set(CPACK_COMPONENT_DEV_GROUP "dev") +set(CPACK_COMPONENT_HEADERS_DEPENDS lib) +set(CPACK_COMPONENT_DEV_DEPENDS lib) + +set(CPACK_GENERATOR ZIP) +# set package name to format -. +# platform name doesn't matter for header-only library +set(CPACK_PACKAGE_NAME zenoh-c) +if(NOT CPACK_PACKAGE_VERSION) + set(CPACK_PACKAGE_VERSION ${PROJECT_VERSION}) +endif() +set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}") +set(CPACK_PROJECT_CONFIG_FILE "${CMAKE_CURRENT_SOURCE_DIR}/cpack_project_config.cmake") + +include(CPack) diff --git a/install/cpack_project_config.cmake b/install/cpack_project_config.cmake new file mode 100644 index 000000000..6de93b128 --- /dev/null +++ b/install/cpack_project_config.cmake @@ -0,0 +1,33 @@ +if(CPACK_GENERATOR MATCHES "DEB") + # DEB package + if(NOT DEBARCH) + execute_process( + COMMAND dpkg --print-architecture + OUTPUT_VARIABLE DEBARCH + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + endif() + message(STATUS "Configure DEB packaging for Linux ${DEBARCH}") + set(CPACK_DEBIAN_PACKAGE_MAINTAINER "ZettaScale Zenoh Team, ") + set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE ${DEBARCH}) + set(CPACK_DEB_COMPONENT_INSTALL ON) + set(CPACK_DEBIAN_FILE_NAME DEB-DEFAULT) + set(CPACK_DEBIAN_LIB_PACKAGE_NAME ${CPACK_PACKAGE_NAME}) # avoid "-lib" suffix for "lib" package + set(CPACK_DEBIAN_LIB_PACKAGE_DEPENDS "libc6 (>=2.12)") + set(CPACK_DEBIAN_DEV_PACKAGE_DEPENDS "${CPACK_DEBIAN_LIB_PACKAGE_NAME} (=${CPACK_PACKAGE_VERSION})") +endif() + +if(CPACK_GENERATOR MATCHES "RPM") + # RPM package + # rpmbuild should be installed + # apt install rpm + if(NOT RPMARCH) + set(RPMARCH ${CMAKE_SYSTEM_PROCESSOR}) + endif() + message(STATUS "Configure RPM packaging for Linux ${RPMARCH}") + set(CPACK_RPM_PACKAGE_ARCHITECTURE ${RPMARCH}) + set(CPACK_RPM_COMPONENT_INSTALL ON) + set(CPACK_RPM_FILE_NAME RPM-DEFAULT) + set(CPACK_RPM_LIB_PACKAGE_NAME ${CPACK_PACKAGE_NAME}) # avoid "-lib" suffix for "lib" package + set(CPACK_RPM_DEV_PACKAGE_REQUIRES "${CPACK_RPM_LIB_PACKAGE_NAME} = ${CPACK_PACKAGE_VERSION}") +endif() \ No newline at end of file