Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CPack #35

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 25 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
cmake_minimum_required(VERSION 3.12)
project(pg_grpc_service_template CXX)

set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)

project(pg_grpc_service_template VERSION 0.0.1)

include(Installing)

# Adding userver dependency
find_package(userver COMPONENTS core grpc postgresql QUIET)
Expand All @@ -23,21 +28,29 @@ endif()

userver_setup_environment()

# Create a proto library with userver extensions
include(GrpcTargets)
userver_add_grpc_library(${PROJECT_NAME}_proto PROTOS handlers/hello.proto)

# Create client library
template_add_library(
LIB_NAME ${PROJECT_NAME}_client
LIB_NAMESPACE ${PROJECT_NAME}
PUBLIC_HDRS
src/hello_client.hpp
SRCS
src/hello_client.cpp
PROTOS
proto/handlers/hello.proto
)
target_link_libraries(${PROJECT_NAME}_client PUBLIC $<BUILD_INTERFACE:${PROJECT_NAME}_proto>)

# Common sources
add_library(${PROJECT_NAME}_objs OBJECT
src/hello.hpp
src/hello.cpp
src/hello_client.hpp
src/hello_client.cpp
)
target_link_libraries(${PROJECT_NAME}_objs PUBLIC userver::postgresql userver::grpc)

# Create a proto library with userver extensions
include(GrpcTargets)
userver_add_grpc_library(${PROJECT_NAME}_proto PROTOS handlers/hello.proto)
target_link_libraries(${PROJECT_NAME}_objs PUBLIC ${PROJECT_NAME}_proto)

target_link_libraries(${PROJECT_NAME}_objs PUBLIC userver::postgresql userver::grpc ${PROJECT_NAME}_client)

# The Service
add_executable(${PROJECT_NAME} src/main.cpp)
Expand Down Expand Up @@ -79,3 +92,5 @@ file(GLOB CONFIGS_FILES ${CMAKE_CURRENT_SOURCE_DIR}/configs/*.yaml ${CMAKE_CURRE

install(TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT ${PROJECT_NAME})
install(FILES ${CONFIGS_FILES} DESTINATION ${CMAKE_INSTALL_SYSCONFDIR}/${PROJECT_NAME} COMPONENT ${PROJECT_NAME})

include(Packaging)
Empty file added LICENSE
Empty file.
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@ install-debug install-release: install-%: build-%
.PHONY: install
install: install-release

# CPack
.PHONY: cpack-debug cpack-release
cpack-debug cpack-release: cpack-%: build-%
cd build_$* && cpack -G DEB

.PHONY: cpack
cpack: cpack-release

# Format the sources
.PHONY: format
format:
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ Makefile contains typicaly useful targets for development:
* `make dist-clean` - clean all, including the CMake cached configurations
* `make install` - does a `make build-release` and runs install in directory set in environment `PREFIX`
* `make install-debug` - does a `make build-debug` and runs install in directory set in environment `PREFIX`
* `make cpack` - does a `make build-release` and runs cpack
* `make cpack-debug` - does a `make build-debug` and runs cpack
* `make docker-COMMAND` - run `make COMMAND` in docker environment
* `make docker-build-debug` - debug build of the service with all the assertions and sanitizers enabled in docker environment
* `make docker-test-debug` - does a `make build-debug` and runs all the tests on the result in docker environment
Expand Down
5 changes: 5 additions & 0 deletions cmake/Config.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@PACKAGE_INIT@

include("${CMAKE_CURRENT_LIST_DIR}/@[email protected]")

check_required_components(@TEMPLATE_LIB_NAME@)
58 changes: 58 additions & 0 deletions cmake/Installing.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
include(GNUInstallDirs)
include(CMakePackageConfigHelpers)

function(template_add_library)
set(options)
set(one_value_args LIB_NAME LIB_NAMESPACE)
set(multi_value_args PUBLIC_HDRS SRCS PROTOS)
cmake_parse_arguments(TEMPLATE "${options}" "${one_value_args}" "${multi_value_args}" ${ARGN})

add_library(${TEMPLATE_LIB_NAME})
target_sources(${TEMPLATE_LIB_NAME} PRIVATE "${TEMPLATE_SRCS}")
target_include_directories(${TEMPLATE_LIB_NAME}
PRIVATE
# where the library itself will look for its internal headers
${CMAKE_CURRENT_SOURCE_DIR}/src
PUBLIC
# where top-level project will look for the library's public headers
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>
# where external projects will look for the library's public headers
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)
set_target_properties(${TEMPLATE_LIB_NAME} PROPERTIES DEBUG_POSTFIX "-d")

set_target_properties(${TEMPLATE_LIB_NAME} PROPERTIES PUBLIC_HEADER "${TEMPLATE_PUBLIC_HDRS}")

install(TARGETS ${TEMPLATE_LIB_NAME}
COMPONENT ${TEMPLATE_LIB_NAME}
EXPORT ${TEMPLATE_LIB_NAME}Targets
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${TEMPLATE_LIB_NAME}
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)

install(EXPORT ${TEMPLATE_LIB_NAME}Targets
COMPONENT ${TEMPLATE_LIB_NAME}
FILE ${TEMPLATE_LIB_NAME}Targets.cmake
NAMESPACE ${TEMPLATE_LIB_NAMESPACE}::
DESTINATION cmake
)

write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/${TEMPLATE_LIB_NAME}ConfigVersion.cmake
COMPATIBILITY AnyNewerVersion
)

configure_package_config_file(${PROJECT_SOURCE_DIR}/cmake/Config.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/${TEMPLATE_LIB_NAME}Config.cmake
INSTALL_DESTINATION cmake
)

install(FILES
${CMAKE_CURRENT_BINARY_DIR}/${TEMPLATE_LIB_NAME}Config.cmake
${CMAKE_CURRENT_BINARY_DIR}/${TEMPLATE_LIB_NAME}ConfigVersion.cmake
DESTINATION cmake
COMPONENT ${TEMPLATE_LIB_NAME}
)

install(FILES "${TEMPLATE_PROTOS}" DESTINATION proto/${TEMPLATE_LIB_NAME} COMPONENT ${TEMPLATE_LIB_NAME})
endfunction()
26 changes: 26 additions & 0 deletions cmake/Packaging.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
set(CPACK_PACKAGE_NAME ${PROJECT_NAME})
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY)
set(CPACK_PACKAGE_VENDOR "Template Company")

set(CPACK_VERBATIM_VARIABLES YES)

set(CPACK_PACKAGE_INSTALL_DIRECTORY ${CPACK_PACKAGE_NAME})
SET(CPACK_OUTPUT_FILE_PREFIX ${CMAKE_BINARY_DIR}/_packages)
set(CPACK_PACKAGING_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX})

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_CONTACT "[email protected]")
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Template")

set(CPACK_RESOURCE_FILE_LICENSE ${PROJECT_SOURCE_DIR}/LICENSE)
set(CPACK_RESOURCE_FILE_README ${PROJECT_SOURCE_DIR}/README.md)

set(CPACK_DEBIAN_PACKAGE_DEPENDS "")
set(CPACK_DEBIAN_FILE_NAME DEB-DEFAULT)
set(CPACK_COMPONENTS_GROUPING ONE_PER_GROUP)
set(CPACK_DEB_COMPONENT_INSTALL YES)

include(CPack)