include (InstallRequiredSystemLibraries)

set(PROJECT_PACKAGE_DESCRIPTION_SUMMARY "this is ${PROJECT_NAME} package")
FIND_PATH(HAS_DEBIAN_VERSION debian_version /etc /etc/debian_version)
SET (CPACK_RESOURCE_FILE_LICENSE   "${PROJECT_SOURCE_DIR}/LICENSE")
SET (CPACK_RESOURCE_FILE_README    "${PROJECT_SOURCE_DIR}/README.md")
SET (CPACK_PACKAGE_CONTACT "lijippy@163.com")
SET (CPACK_PACKAGE_DESCRIPTION_SUMMARY "${PROJECT_PACKAGE_DESCRIPTION_SUMMARY}" )
SET (CPACK_PACKAGE_DESCRIPTION_FILE "${PROJECT_SOURCE_DIR}/package/package.md" )


#GENERATOR
if(HAS_DEBIAN_VERSION)
    set (CPACK_GENERATOR "DEB")
else()    
    set (CPACK_GENERATOR "RPM")
    set (CPACK_RPM_PACKAGE_DEBUG 0)
endif()

#set (CPACK_SOURCE_GENERATOR ${CPACK_SOURCE_ZIP})
#set (CPACK_SOURCE_PACKAGE_FILE_NAME "${PROJECT_NAME}-source")

#set install prefgix
set (CPACK_PACKAGING_INSTALL_PREFIX /usr/local)

#set scripts
if(HAS_DEBIAN_VERSION)
    SET(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA 
   "${PROJECT_SOURCE_DIR}/package/preinst;
   ${PROJECT_SOURCE_DIR}/package/postinst;
   ${PROJECT_SOURCE_DIR}/package/prerm;
   ${PROJECT_SOURCE_DIR}/package/postrm")
else() 
    SET(CPACK_RPM_PRE_INSTALL_SCRIPT_FILE "${PROJECT_SOURCE_DIR}/package/preinst")
    SET(CPACK_RPM_POST_INSTALL_SCRIPT_FILE "${PROJECT_SOURCE_DIR}/package/postinst")
    SET(CPACK_RPM_PRE_UNINSTALL_SCRIPT_FILE "${PROJECT_SOURCE_DIR}/package/prerm")
    SET(CPACK_RPM_POST_UNINSTALL_SCRIPT_FILE "${PROJECT_SOURCE_DIR}/package/postrm")
endif()
#set package NAME

if(_DEVEL)
	set(CPACK_PACKAGE_NAME "${PROJECT_NAME}-devel")
else()
	set(CPACK_PACKAGE_NAME "${PROJECT_NAME}")
endif()
message(STATUS "package name ${CPACK_PACKAGE_NAME}")
#version
set (CPACK_PACKAGE_VERSION_MAJOR "${PROJECT_VERSION_MAJOR}")  
set (CPACK_PACKAGE_VERSION_MINOR "${PROJECT_VERSION_MINOR}") 
set (CPACK_PACKAGE_VERSION_PATCH "${PROJECT_VERSION_PATCH}")
include (CPack) 