Skip to content

Commit

Permalink
[C][Client] Use cpack to build deb package (#10935)
Browse files Browse the repository at this point in the history
  • Loading branch information
ityuhui authored Nov 24, 2021
1 parent 962e8c4 commit 375f0a5
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ public void processOpts() {

// root folder
supportingFiles.add(new SupportingFile("CMakeLists.txt.mustache", "", "CMakeLists.txt"));
supportingFiles.add(new SupportingFile("Packing.cmake.mustache", "", "Packing.cmake"));
supportingFiles.add(new SupportingFile("libcurl.licence.mustache", "", "libcurl.licence"));
supportingFiles.add(new SupportingFile("uncrustify-rules.cfg.mustache", "", "uncrustify-rules.cfg"));
supportingFiles.add(new SupportingFile("README.md.mustache", "", "README.md"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ else()
endif()

set(pkgName "{{projectName}}")
set(VERSION 0.0.1) # this default version can be overridden in PreTarget.cmake

# this default version can be overridden in PreTarget.cmake
set(PROJECT_VERSION_MAJOR 0)
set(PROJECT_VERSION_MINOR 0)
set(PROJECT_VERSION_PATCH 1)

find_package(CURL 7.58.0 REQUIRED)
if(CURL_FOUND)
Expand Down Expand Up @@ -84,6 +88,8 @@ set(HDRS

include(PreTarget.cmake OPTIONAL)

set(PROJECT_VERSION_STRING "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}")

# Add library with project file with project name as library name
add_library(${pkgName} ${SRCS} ${HDRS})
# Link dependent libraries
Expand All @@ -100,22 +106,22 @@ include(PostTarget.cmake OPTIONAL)

# installation of libraries, headers, and config files
if (NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/Config.cmake.in)
install(TARGETS ${pkgName} DESTINATION ${CMAKE_INSTALL_PREFIX})
install(TARGETS ${pkgName} DESTINATION lib)
else()
include(GNUInstallDirs)
install(TARGETS ${pkgName} DESTINATION ${CMAKE_INSTALL_PREFIX} EXPORT ${pkgName}Targets)
install(TARGETS ${pkgName} DESTINATION lib EXPORT ${pkgName}Targets)

foreach(HDR_FILE ${HDRS})
get_filename_component(HDR_DIRECTORY ${HDR_FILE} DIRECTORY)
get_filename_component(ABSOLUTE_HDR_DIRECTORY ${HDR_DIRECTORY} ABSOLUTE)
file(RELATIVE_PATH RELATIVE_HDR_PATH ${CMAKE_CURRENT_SOURCE_DIR} ${ABSOLUTE_HDR_DIRECTORY})
install(FILES ${HDR_FILE} DESTINATION include/${RELATIVE_HDR_PATH})
install(FILES ${HDR_FILE} DESTINATION include/${pkgName}/${RELATIVE_HDR_PATH})
endforeach()

include(CMakePackageConfigHelpers)
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/${pkgName}/${pkgName}ConfigVersion.cmake"
VERSION "${VERSION}"
VERSION "${PROJECT_VERSION_STRING}"
COMPATIBILITY AnyNewerVersion
)

Expand Down Expand Up @@ -147,6 +153,9 @@ else()
)
endif()

# make installation packages
include(Packing.cmake OPTIONAL)

# Setting file variables to null
set(SRCS "")
set(HDRS "")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
set(CPACK_PACKAGE_NAME lib${pkgName})

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_PACKAGE_DESCRIPTION_SUMMARY ${PROJECT_PACKAGE_DESCRIPTION_SUMMARY})
set(CPACK_PACKAGE_VENDOR ${PROJECT_PACKAGE_VENDOR})
set(CPACK_PACKAGE_CONTACT ${PROJECT_PACKAGE_CONTACT})
set(CPACK_DEBIAN_PACKAGE_MAINTAINER ${PROJECT_PACKAGE_MAINTAINER})

set(CPACK_VERBATIM_VARIABLES YES)

set(CPACK_PACKAGE_INSTALL_DIRECTORY ${CPACK_PACKAGE_NAME})

set(CPACK_PACKAGING_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX})

set(CPACK_DEBIAN_FILE_NAME DEB-DEFAULT)

set(CPACK_DEB_COMPONENT_INSTALL YES)

set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS TRUE)

include(CPack)

0 comments on commit 375f0a5

Please sign in to comment.