From bc4d6bf5ac9bfec50233298450c973a5304a062f Mon Sep 17 00:00:00 2001 From: Takanori Suzuki Date: Wed, 1 Feb 2017 13:25:29 +0900 Subject: [PATCH] Change CMakeLists.txt for generating deb and rpm --- CMakeLists.txt | 57 ++++++++++++++++++++++++++++++++++++++++++++++++-- README.md | 23 ++++++++++++++++++++ 2 files changed, 78 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index cba6972..ebb5137 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,8 +1,61 @@ +set(VERSION 1.0.2) cmake_minimum_required(VERSION 2.8.0) project(CrazyDiskInfo CXX) add_executable(CrazyDiskInfo main.cpp) set(CMAKE_CXX_FLAGS "-Wall -std=c++11") -SET_TARGET_PROPERTIES(CrazyDiskInfo PROPERTIES OUTPUT_NAME crazy) +set_target_properties(CrazyDiskInfo PROPERTIES OUTPUT_NAME crazy) target_link_libraries(CrazyDiskInfo atasmart) target_link_libraries(CrazyDiskInfo ncursesw) -INSTALL(TARGETS CrazyDiskInfo RUNTIME DESTINATION /usr/sbin) +set(CMAKE_INSTALL_PREFIX /usr) +install(TARGETS CrazyDiskInfo RUNTIME DESTINATION sbin) +install(FILES LICENSE README.md DESTINATION share/doc/CrazyDiskInfo) +# CPACK +set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README.md") +set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE") +set(CPACK_PACKAGE_VERSION ${VERSION}) +set(CPACK_PACKAGE_RELEASE 1) +set(CPACK_SOURCE_IGNORE_FILES \\\\.git/ \\\\..*\\\\.swp /build/ Changelog.tmp) +set(CPACK_GENERATOR "TGZ") +set(CPACK_PACKAGE_NAME "CrazyDiskInfo") +set(CPACK_PACKAGE_CONTACT "https://github.com/otakuto") +set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "CrazyDiskInfo is an interactive TUI S.M.A.R.T viewer for Unix systems") +set(CPACK_PACKAGE_VENDOR "otakuto") +set(CPACK_PACKAGING_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX}) +# find dpkg or rpm and switch the package name +string(TOLOWER "${CPACK_PACKAGE_NAME}" CPACK_PACKAGE_NAME_LOWERCASE) +find_program(DPKG_PROGRAM dpkg) +if(DPKG_PROGRAM) + execute_process( + COMMAND ${DPKG_PROGRAM} --print-architecture + OUTPUT_VARIABLE CPACK_DEBIAN_PACKAGE_ARCHITECTURE + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + set(CPACK_PACKAGE_FILE_NAME +"${CPACK_PACKAGE_NAME_LOWERCASE}_${CPACK_PACKAGE_VERSION}-${CPACK_PACKAGE_RELEASE}_${CPACK_DEBIAN_PACKAGE_ARCHITECTURE}") + set(CPACK_GENERATOR "DEB" ${CPACK_GENERATOR}) +else(DPKG_PROGRAM) +set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-${CPACK_PACKAGE_RELEASE}.${CMAKE_SYSTEM_PROCESSOR}") +find_program(RPM_PROGRAM rpm) +if(RPM_PROGRAM) + set(CPACK_GENERATOR "RPM" ${CPACK_GENERATOR}) +endif(RPM_PROGRAM) +endif(DPKG_PROGRAM) +# making rpm +set(CPACK_RPM_PACKAGE_LICENSE "MIT") +set(CPACK_RPM_PACKAGE_GROUP "Utilities") +set(CPACK_RPM_PACKAGE_REQUIRES "libatasmart ncurses-libs") +set(CPACK_RPM_PACKAGE_NAME "${CPACK_PACKAGE_NAME}") +set(CPACK_RPM_PACKAGE_DESCRIPTION "${CPACK_PACKAGE_DESCRIPTION_SUMMARY}") +set(CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION /usr/sbin) +execute_process(COMMAND git log --format=*\ %cd\ %aN%n-\ \(%h\)\ %s%d%n --date=local + OUTPUT_FILE ${CMAKE_CURRENT_SOURCE_DIR}/Changelog.tmp) +execute_process(COMMAND sed -r s/[0-9]+:[0-9]+:[0-9]+\ // + INPUT_FILE ${CMAKE_CURRENT_SOURCE_DIR}/Changelog.tmp + OUTPUT_FILE ${CMAKE_CURRENT_SOURCE_DIR}/Changelog) +set(CPACK_RPM_CHANGELOG_FILE "${CMAKE_CURRENT_SOURCE_DIR}/Changelog") +set(CPACK_RESOURCE_FILE_README "${CMAKE_CURRENT_SOURCE_DIR}/README.md") +set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE") +set(CPACK_DEBIAN_PACKAGE_DEPENDS "libatasmart4, libncurses5, libncursesw5") +set(CPACK_DEBIAN_PACKAGE_SECTION "admin") +set(CPACK_DEBIAN_PACKAGE_NAME "${CPACK_PACKAGE_NAME_LOWERCASE}") +include(CPack) diff --git a/README.md b/README.md index ec3cedf..a65f49a 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,29 @@ $ make && make install $ sudo crazy ``` +## Build rpm or deb packge, Install and Run +In rpm environment: +``` +$ sudo yum install ncurses-devel libatasmart-devel gcc-c++ cmake +$ mkdir build +$ cd build +$ cmake .. +$ cpack --config CPackConfig.cmake +$ sudo rpm -ihv CrazyDiskInfo-*.rpm +$ sudo crazy +``` + +In deb environment: +``` +$ sudo apt-get install libatasmart-dev libncurses5-dev libncursesw5-dev cmake g++ +$ mkdir build +$ cd build +$ cmake .. +$ cpack --config CPackConfig.cmake +$ sudo dpkg -i crazydiskinfo_*.deb +$ sudo crazy +``` + ### Binary Package Debian package is available from [OBS(Open Build Service)](https://build.opensuse.org/package/show/home:tsuroot/CrazyDiskInfo) Direct Links: