# Setup automatic generation of the changelog
MESSAGE(STATUS "Generate installation variables..." )
ADD_CUSTOM_TARGET(changelog
	COMMAND ${HGCOMMAND} log > ${PONYPROG_BINARY_DIR}/ChangeLog
	WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
	)


SET( CPACK_SOURCE_PACKAGE_FILE_NAME "ponyprog-${APP_VERSION}" )



# --- Package generation
# SET( CPACK_BUILD_CONFIG "Release_and_Debug" )
# SET( CPACK_PACKAGE_NAME ${CMAKE_PROJECT_NAME})
SET( CPACK_PACKAGE_VENDOR "Lancos" )
SET( CPACK_PACKAGE_INSTALL_DIRECTORY "PONYPROG ${APP_VERSION}" )
SET( CPACK_PACKAGE_INSTALL_REGISTRY_KEY "PONYPROG ${APP_VERSION}" )
SET( CPACK_PACKAGE_HOMEPAGE "http://ponyprog.sourceforge.net/" )


# Setup global packaging parameters ...
SET( PONYPROG_CPACK_INSTALL_CMAKE_PROJECTS "${CURRENT_BUILD_DIR};ponyprog;ALL;/" )
# MESSAGE("PONYPROG_BINARY_DIR ${CURRENT_BUILD_DIR}")
# SET( PONYPROG_CPACK_PACKAGE_DESCRIPTION "Ponyprog free GUI for EEPROM and microcontroller flashing." )
SET( PONYPROG_CPACK_PACKAGE_FILE_NAME "ponyprog-setup-${APP_VERSION}" )
SET( PONYPROG_CPACK_PACKAGE_VERSION "${APP_VERSION}" )
SET( PONYPROG_CPACK_RESOURCE_FILE_LICENSE "${PROJECT_SOURCE_DIR}/LICENSE" )

SET( PONYPROG_CPACK_SOURCE_INSTALLED_DIRECTORIES "${PROJECT_SOURCE_DIR};/" )
SET( PONYPROG_CPACK_SOURCE_PACKAGE_FILE_NAME "ponyprog-source-${APP_VERSION}" )
SET( PONYPROG_CPACK_SOURCE_IGNORE_FILES
    "/\\\\.svn/"
    "/\\\\.kdev4/*"
    "/\\\\.git/*"
    "/pics/"
    "/build*/*"
    "\\\\.deb"
    "\\\\.rpm"
    "\\\\.zip"
    "\\\\.kdev4"
    "/cppreport"
    "/ponyprog$"
#     "~$"
#     "/ponyprog"
#     "TODO.txt"
#     "CMakeLists.txt.user"
#     "/doxygen/"
#     "${CMAKE_BINARY_DIR}"
)

SET( PONYPROG_CPACK_PACKAGE_NAME ${CMAKE_PROJECT_NAME} )
# SET( PONYPROG_CPACK_PACKAGE_VERSION ${APP_VERSION} )
SET( PONYPROG_CPACK_PACKAGE_RELEASE 0 )
SET( PONYPROG_CPACK_PACKAGE_MAINTAINER "${APP_AUTHOR} <${APP_EMAIL}>" )
SET( PONYPROG_CPACK_PACKAGE_MAINTAINER_NAME "${APP_AUTHOR}" )
SET( PONYPROG_CPACK_PACKAGE_MAINTAINER_EMAIL "${APP_EMAIL}" )
SET( PONYPROG_CPACK_PACKAGE_DESCRIPTION "EEPROM and microcontroller flasher" )
SET( PONYPROG_CPACK_PACKAGE_DESCRIPTION_SUMMARY "EEPROM and microcontroller flasher for PIC, Atmega and other chips" )
# SET( PACKAGE_DEPENDS ${hugr_dependencies} )

SET( PONYPROG_CPACK_PACKAGE_DEPENDS "${PONYPROG_CPACK_PACKAGE_SHLIBDEPS}" )
#SET( PONYPROG_CPACK_PACKAGE_DEPENDS "libusb-1.0-0, libftdi1-2, libftdipp1-3, libqt5core5a, libqt5gui5, libqt5widgets5, libqt5multimedia5, libqt5printsupport5" )

# SET( PACKAGE_DEPENDS "libc6 (>= 2.1.3), libqtcore4 (>= 4:4.6.1), libqtgui4 (>= 4:4.5.3), libstdc++6 (>= 4.1.1)" )


# SET( PONYPROG_CPACK_PACKAGE_GROUP "Groupe" )
SET( PONYPROG_CPACK_PACKAGE_LICENSE "GPL2" )

# ADD_CUSTOM_TARGET(changelog
# 	COMMAND ${GITCOMMAND} log > ${PONYPROG_BINARY_DIR}/ChangeLog
# 	WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
# 	)

# Setup convenience targets for tagging and branching
# SET( PONYPROG_VERSION_TAG "ponyprog-${PONYPROG_MAJOR_VERSION}.${PONYPROG_MINOR_VERSION}.${PONYPROG_RELEASE_VERSION}.${PONYPROG_BUILD_VERSION}" )
# SET( PONYPROG_VERSION_TAG "ponyprog-${PONYPROG_VERSION}" )
# ADD_CUSTOM_TARGET(tag-version
# 	COMMAND ${GITCOMMAND} tag ${PONYPROG_VERSION_TAG}
# 	WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
# 	)

#SET( PONYPROG_BRANCH_TAG "ponyprog-release-${PONYPROG_MAJOR_VERSION}.${PONYPROG_MINOR_VERSION}" )
#ADD_CUSTOM_TARGET(tag-branch
#	COMMAND ${SVNCOMMAND} cp ${PONYPROG_SVN_TRUNK}
#	${PONYPROG_SVN_BRANCHES}/${PONYPROG_BRANCH_TAG} -m "COMP: Branched PONYPROG Version ${PONYPROG_MAJOR_VERSION}.${PONYPROG_MINOR_VERSION}"
#	WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
#	)
# MESSAGE("CMAKE_CURRENT_SOURCE_DIR distr ${CMAKE_CURRENT_SOURCE_DIR} : ${PROJECT_SOURCE_DIR}")
# Get a SourceForge username so we can upload distributables to the FRS
# IF(WIN32)
# 	SET( PONYPROG_SOURCEFORGE_USERNAME "$ENV{USERNAME}" CACHE STRING "SourceForge user account name, for uploading distribution files." )
# ELSE(WIN32)
# 	SET( PONYPROG_SOURCEFORGE_USERNAME "$ENV{USER}" CACHE STRING "SourceForge user account name, for uploading distribution files." )
# ENDIF(WIN32)
# MARK_AS_ADVANCED(PONYPROG_SOURCEFORGE_USERNAME)



# Setup some macros that can be used by the platform-specific distribution logic
MACRO(PONYPROG_CHECK_INSTALLED_VERSION FOUND PACKAGE EXPECTED)
	IF(NOT ${FOUND} STREQUAL ${EXPECTED})
		MESSAGE(SEND_ERROR "Found ${PACKAGE} version ${FOUND} - for installation, version ${EXPECTED} is required." )
	ENDIF(NOT ${FOUND} STREQUAL ${EXPECTED})
ENDMACRO(PONYPROG_CHECK_INSTALLED_VERSION)

# IF(UNIX AND NOT APPLE)
#     SET(CPACK_STRIP_FILES TRUE)
# 
#     SET(CPACK_SET_DESTDIR "ON")
#     SET(CPACK_INSTALL_PREFIX "/usr") 
#     SET(CPACK_PACKAGE_INSTALL_DIRECTORY "/usr")
# ENDIF(UNIX AND NOT APPLE)

# Generate source packages
ADD_SUBDIRECTORY(source)

# Generate platform-specific binary packages
IF(APPLE)
	ADD_SUBDIRECTORY(osx)
ENDIF(APPLE)

IF(UNIX AND NOT APPLE)
	ADD_SUBDIRECTORY(posix)
ENDIF(UNIX AND NOT APPLE)

IF(WIN32)
	ADD_SUBDIRECTORY(win32)
ENDIF(WIN32)


# INCLUDE(CPack)

