Skip to content

Commit

Permalink
support pack deb
Browse files Browse the repository at this point in the history
  • Loading branch information
lkpworkspace committed Jan 11, 2024
1 parent 122da69 commit 5002680
Show file tree
Hide file tree
Showing 11 changed files with 86 additions and 58 deletions.
63 changes: 10 additions & 53 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ option(MYFRAME_INSTALL_DEPS "Install deps" ON)
option(MYFRAME_GENERATE_EXAMPLE "Generate example library" ON)
option(MYFRAME_GENERATE_TEST "Generate test executable program" ON)

### cmake module
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")

### compile option
set(CMAKE_C_VISIBILITY_PRESET hidden)
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
Expand All @@ -20,20 +23,13 @@ else()
message(STATUS "Set default cxx standard 17")
endif()

### output path
set(MYFRAME_OUTPUT_ROOT "${CMAKE_BINARY_DIR}/output")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${MYFRAME_OUTPUT_ROOT}/lib)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${MYFRAME_OUTPUT_ROOT}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${MYFRAME_OUTPUT_ROOT}/bin)

### install path
if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set(CMAKE_INSTALL_PREFIX "$ENV{HOME}/${CMAKE_PROJECT_NAME}" CACHE PATH "myframe default install prefix" FORCE)
message(STATUS "Set default install prefix $ENV{HOME}/${CMAKE_PROJECT_NAME}")
message(STATUS "Set default install prefix ${CMAKE_INSTALL_PREFIX}")
else()
message(STATUS "Set install prefix ${CMAKE_INSTALL_PREFIX}")
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
endif()
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
set(MYFRAME_BIN_DIR "bin")
set(MYFRAME_INC_DIR "include")
set(MYFRAME_LIB_DIR "lib")
Expand Down Expand Up @@ -72,67 +68,28 @@ install(FILES
PERMISSIONS OWNER_READ GROUP_READ WORLD_READ
DESTINATION .
)
INSTALL(PROGRAMS
install(PROGRAMS
"tools/gen_mod_proj.py"
DESTINATION ${MYFRAME_BIN_DIR}
)
install(DIRECTORY templates DESTINATION .)
install(DIRECTORY conf DESTINATION .)
install(DIRECTORY DESTINATION ${MYFRAME_LOG_DIR})
install(DIRECTORY DESTINATION ${MYFRAME_SERVICE_DIR})
install(CODE "
file(
WRITE ${CMAKE_INSTALL_PREFIX}/version.txt
\"${${PROJECT_NAME}_VERSION_MAJOR}.${${PROJECT_NAME}_VERSION_MINOR}.${${PROJECT_NAME}_VERSION_PATCH}\"
\"${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}\"
)
")
if (MYFRAME_INSTALL_DEPS)
if (${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.21")
install(IMPORTED_RUNTIME_ARTIFACTS jsoncpp_lib)
install(IMPORTED_RUNTIME_ARTIFACTS glog::glog)
install(IMPORTED_RUNTIME_ARTIFACTS gflags)
else()
message(WARNING "Can not install deps lib, cmake version ${CMAKE_VERSION} < 3.21")
endif()
endif()

### package
include(InstallRequiredSystemLibraries)
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE")
set(CPACK_PACKAGE_VERSION_MAJOR "${${PROJECT_NAME}_VERSION_MAJOR}")
set(CPACK_PACKAGE_VERSION_MINOR "${${PROJECT_NAME}_VERSION_MINOR}")
set(CPACK_PACKAGE_VERSION_PATCH "${${PROJECT_NAME}_VERSION_PATCH}")
include(CPack)

### export cmake file
install(EXPORT "${PROJECT_NAME}Targets"
FILE "${PROJECT_NAME}Targets.cmake"
DESTINATION lib/cmake/${PROJECT_NAME}
)

include(CMakePackageConfigHelpers)
# generate the config file that is includes the exports
configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/Config.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
INSTALL_DESTINATION "lib/cmake/${PROJECT_NAME}"
NO_SET_AND_CHECK_MACRO
NO_CHECK_REQUIRED_COMPONENTS_MACRO
)

# generate the version file for the config file
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
VERSION "${PROJECT_VERSION}"
COMPATIBILITY SameMinorVersion
)

# install the configuration file
install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
DESTINATION lib/cmake/${PROJECT_NAME}
)

# generate the export targets for the build tree
# needs to be after the install(TARGETS ) command
export(EXPORT "${PROJECT_NAME}Targets"
FILE "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Targets.cmake"
)
include(Packing)
4 changes: 0 additions & 4 deletions Config.cmake.in

This file was deleted.

34 changes: 34 additions & 0 deletions cmake/InstallingConfigs.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# export cmake file
install(EXPORT "${PROJECT_NAME}Targets"
FILE "${PROJECT_NAME}Targets.cmake"
DESTINATION lib/cmake/${PROJECT_NAME}
)

include(CMakePackageConfigHelpers)
# generate the config file that is includes the exports
configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/Config.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
INSTALL_DESTINATION "lib/cmake/${PROJECT_NAME}"
NO_SET_AND_CHECK_MACRO
NO_CHECK_REQUIRED_COMPONENTS_MACRO
)

# generate the version file for the config file
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
VERSION "${PROJECT_VERSION}"
COMPATIBILITY SameMinorVersion
)

# install the configuration file
install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
DESTINATION lib/cmake/${PROJECT_NAME}
)

# generate the export targets for the build tree
# needs to be after the install(TARGETS ) command
export(EXPORT "${PROJECT_NAME}Targets"
FILE "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Targets.cmake"
)
27 changes: 27 additions & 0 deletions cmake/Packing.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
include(InstallRequiredSystemLibraries)

set(CPACK_PACKAGE_NAME ${PROJECT_NAME} CACHE STRING "The resulting package name")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "C++ application framework"
CACHE STRING "Package description for the package metadata"
)
set(CPACK_STRIP_FILES YES)
set(CPACK_INSTALL_DEFAULT_DIRECTORY_PERMISSIONS
OWNER_READ OWNER_WRITE OWNER_EXECUTE
GROUP_READ GROUP_EXECUTE
WORLD_READ WORLD_EXECUTE
)
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_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE")
set(CPACK_RESOURCE_FILE_README "${CMAKE_CURRENT_SOURCE_DIR}/README.md")

# deb
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "likepeng <${CPACK_PACKAGE_CONTACT}>")
set(CPACK_DEBIAN_FILE_NAME DEB-DEFAULT)
set(CPACK_COMPONENTS_GROUPING ALL_COMPONENTS_IN_ONE)
set(CPACK_DEB_COMPONENT_INSTALL YES)
set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS YES)

include(CPack)
7 changes: 7 additions & 0 deletions docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,16 @@ myframe安装目录:`/usr/local`

## 构建docker镜像
```sh
# eg:
# myframe_version: 0.9.1
bash docker_build.bash <myframe_version>
```

## 构建好的docker镜像
```sh
docker pull docker.io/likepeng0418/myframe:amd64-<myframe_version>
```

## 创建运行docker容器
```sh
docker run -itd \
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion docker/docker_build.bash
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function main {
"${cmd[@]}" \
--build-arg myframe_version=$1 \
--ulimit nofile=102400:102400 \
-f "ubuntu2004.dockerfile" \
-f "dev.dockerfile" \
-t "${IMAGE_NAME}:${tag}" \
"${MYFRAME_ROOT}"
}
Expand Down
1 change: 1 addition & 0 deletions launcher/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ install(TARGETS ${DIR_NAME}
ARCHIVE DESTINATION ${MYFRAME_LIB_DIR}
RUNTIME DESTINATION ${MYFRAME_BIN_DIR}
)
install(DIRECTORY conf DESTINATION .)
File renamed without changes.
2 changes: 2 additions & 0 deletions myframe/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,5 @@ install(TARGETS ${PROJECT_NAME}
ARCHIVE DESTINATION ${MYFRAME_LIB_DIR}
RUNTIME DESTINATION ${MYFRAME_BIN_DIR}
)

include(InstallingConfigs)
4 changes: 4 additions & 0 deletions myframe/Config.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

@PACKAGE_INIT@

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

0 comments on commit 5002680

Please sign in to comment.