+add_custom_target(archive DEPENDS ${ARCHIVE_OUTPUT})
+
+#Get the os type
+if(EXISTS "/etc/os-release")
+ execute_process(COMMAND grep ID_LIKE /etc/os-release
+ OUTPUT_VARIABLE TMP_OSRELEASE
+ )
+ if (NOT TMP_OSRELEASE STREQUAL "")
+ string(REGEX REPLACE ".*=" "" OSRELEASE ${TMP_OSRELEASE})
+ else()
+ set(OSRELEASE "NOT DEBIAN OS")
+ endif()
+ message(STATUS "OSRELEASE = ${OSRELEASE}")
+else()
+ set(OSRELEASE "NOT DEBIAN OS")
+endif()
+
+#Format Build require package
+foreach (PKG_CONFIG ${PKG_REQUIRED_LIST})
+ #Unset TMP variable
+ unset(XPREFIX)
+ unset(XRULE)
+ unset(RPM_EXTRA_DEP)
+ unset(DEB_EXTRA_DEP)
+ #For deb package,add EOL format only for a new line
+ if(DEB_PKG_DEPS)
+ set(DEB_PKG_DEPS "${DEB_PKG_DEPS},\n")
+ endif()
+ #Get pkg-config rule on version
+ string(REGEX REPLACE "[<>]?=.*$" "" XPREFIX ${PKG_CONFIG})
+ string(REGEX MATCH "[<>]?=" XRULE ${PKG_CONFIG})
+ #Only if pkg-config has rule on version
+ if(XRULE)
+ string(REGEX REPLACE ".*[<>]?=" "" XVERS ${PKG_CONFIG})
+ set(RPM_EXTRA_DEP " ${XRULE} ${XVERS}")
+ set(DEB_EXTRA_DEP " (${XRULE} ${XVERS})")
+ endif()
+ #Format for rpm package
+ set(RPM_PKG_DEPS "${RPM_PKG_DEPS}BuildRequires: pkgconfig(${XPREFIX})${RPM_EXTRA_DEP}\n")
+ #Format for deb package
+ #Because the tool "dpkg" is used on the packages db to find the
+ #package providing the pkg-cong file ${XPREFIX}.pc, we need
+ #to test the OS release package type
+ if( OSRELEASE MATCHES "debian" )
+ execute_process(
+ COMMAND dpkg -S *${XPREFIX}.pc
+ OUTPUT_VARIABLE TMP_PKG_BIN
+ )
+ #Need to be harden check
+ string(REGEX REPLACE ":.*$" "" PKG_BIN ${TMP_PKG_BIN})
+ set(DEB_PKG_DEPS "${DEB_PKG_DEPS} ${PKG_BIN} ${DEB_EXTRA_DEP}")
+ endif()
+endforeach()
+
+if(NOT EXISTS ${RPM_TEMPLATE_DIR}/rpm-config.spec.in)
+ MESSAGE(FATAL_ERROR "${Red}Missing mandatory files: you need rpm-config.spec.in in ${RPM_TEMPLATE_DIR} folder.${ColourReset}")
+endif()
+set(PACKAGING_SPEC_OUTPUT ${PROJECT_PKG_ENTRY_POINT}/${NPKG_PROJECT_NAME}.spec)
+# build rpm spec file from template
+configure_file(${RPM_TEMPLATE_DIR}/rpm-config.spec.in ${PACKAGING_SPEC_OUTPUT})
+
+#Because the tool "dpkg" is used on the packages db to find the
+#package providing the pkg-cong file ${XPREFIX}.pc, we need
+#to test the OS release package type
+if( OSRELEASE MATCHES "debian" )
+ # build deb spec file from template
+ set(PACKAGING_DEB_OUTPUT_DSC ${PROJECT_PKG_ENTRY_POINT}/${NPKG_PROJECT_NAME}.dsc)
+ configure_file(${DEB_TEMPLATE_DIR}/deb-config.dsc.in ${PACKAGING_DEB_OUTPUT_DSC})
+ set(PACKAGING_DEB_OUTPUT_INSTALL ${PROJECT_PKG_ENTRY_POINT}/debian.${NPKG_PROJECT_NAME}.install)
+ configure_file(${DEB_TEMPLATE_DIR}/deb-config.install.in ${PACKAGING_DEB_OUTPUT_INSTALL})
+ set(PACKAGING_DEB_OUTPUT_CHANGELOG ${PROJECT_PKG_ENTRY_POINT}/debian.changelog)
+ configure_file(${DEB_TEMPLATE_DIR}/debian.changelog.in ${PACKAGING_DEB_OUTPUT_CHANGELOG})
+ set(PACKAGING_DEB_OUTPUT_COMPAT ${PROJECT_PKG_ENTRY_POINT}/debian.compat)
+ configure_file(${DEB_TEMPLATE_DIR}/debian.compat.in ${PACKAGING_DEB_OUTPUT_COMPAT})
+ set(PACKAGING_DEB_OUTPUT_CONTROL ${PROJECT_PKG_ENTRY_POINT}/debian.control)
+ configure_file(${DEB_TEMPLATE_DIR}/debian.control.in ${PACKAGING_DEB_OUTPUT_CONTROL})
+ set(PACKAGING_DEB_OUTPUT_RULES ${PROJECT_PKG_ENTRY_POINT}/debian.rules)
+ configure_file(${DEB_TEMPLATE_DIR}/debian.rules.in ${PACKAGING_DEB_OUTPUT_RULES})
+endif()
+
+add_custom_target( packaging DEPENDS ${PACKAGING_SPEC_OUTPUT}
+ ${PACKAGING_DEB_OUTPUT_DSC}
+ ${PACKAGING_DEB_OUTPUT_INSTALL}
+ ${PACKAGING_DEB_OUTPUT_CHANGELOG}
+ ${PACKAGING_DEB_OUTPUT_COMPAT}
+ ${PACKAGING_DEB_OUTPUT_CONTROL}
+ ${PACKAGING_DEB_OUTPUT_CONTROL}
+ ${PACKAGING_DEB_OUTPUT_RULES})