if(CMAKE_BUILD_TYPE STREQUAL "Debug")
    set(CPACK_PACKAGE_NAME "tfe-debug")
else()
    set(CPACK_PACKAGE_NAME "tfe")
endif()

message(STATUS "Package: ${CPACK_PACKAGE_NAME}")

set(CPACK_PACKAGE_VENDOR "MESASOFT")
set(CPACK_PACKAGE_VERSION_MAJOR "${TFE_VERSION_MAJOR}")
set(CPACK_PACKAGE_VERSION_MINOR "${TFE_VERSION_MINOR}")
set(CPACK_PACKAGE_VERSION_PATCH "${TFE_VERSION_PATCH}.${TFE_VERSION_BUILD}")
set(CPACK_PACKAGING_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX})

# RPM Build
set(CPACK_GENERATOR "RPM")
set(CPACK_RPM_AUTO_GENERATED_FILE_NAME ON)
set(CPACK_RPM_FILE_NAME "RPM-DEFAULT")
set(CPACK_RPM_PACKAGE_AUTOREQPROV "no")
set(CPACK_RPM_PACKAGE_RELEASE_DIST on)
set(CPACK_RPM_DEBUGINFO_PACKAGE on)
set(CPACK_RPM_POST_INSTALL_SCRIPT_FILE ${CMAKE_SOURCE_DIR}/cmake/PostInstall.in)
set(CPACK_RPM_POST_UNINSTALL_SCRIPT_FILE ${CMAKE_SOURCE_DIR}/cmake/PostUninstall.in)
set(CPACK_RPM_PRE_UNINSTALL_SCRIPT_FILE ${CMAKE_SOURCE_DIR}/cmake/PreUninstall.in)

# Must uninstall the debug package before install release package
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
    set(CPACK_RPM_PACKAGE_CONFLICTS "tfe")
else()
    set(CPACK_RPM_PACKAGE_CONFLICTS "tfe-debug")
endif()

# setup %config(noreplace)
set(CPACK_RPM_USER_FILELIST "/usr/lib/systemd/system/mrenv.service"
                            "/usr/lib/systemd/system/mrzcpd.service"
                            "/usr/lib/systemd/system/mrtunnat.service"
							"/usr/lib/systemd/system/mrmonit.service"
                            "%config(noreplace) ${CMAKE_INSTALL_PREFIX}/etc/mrglobal.conf"
							"%config(noreplace) ${CMAKE_INSTALL_PREFIX}/etc/mrtunnat.conf"
                            "%config(noreplace) /etc/sysconfig/mrzcpd")
include(CPack)
