# Setup automatic generation of the changelog
ADD_CUSTOM_TARGET(changelog
	COMMAND ${HGCOMMAND} log > ${k3d_BINARY_DIR}/ChangeLog
	WORKING_DIRECTORY ${k3d_SOURCE_DIR}
	)

# Setup convenience targets for tagging and branching
SET(K3D_VERSION_TAG "k3d-${K3D_MAJOR_VERSION}.${K3D_MINOR_VERSION}.${K3D_RELEASE_VERSION}.${K3D_BUILD_VERSION}")
ADD_CUSTOM_TARGET(tag-version
	COMMAND ${HGCOMMAND} tag ${K3D_VERSION_TAG}
	WORKING_DIRECTORY ${k3d_SOURCE_DIR}
	)

#SET(K3D_BRANCH_TAG "k3d-release-${K3D_MAJOR_VERSION}.${K3D_MINOR_VERSION}")
#ADD_CUSTOM_TARGET(tag-branch
#	COMMAND ${SVNCOMMAND} cp ${K3D_SVN_TRUNK}
#	${K3D_SVN_BRANCHES}/${K3D_BRANCH_TAG} -m "COMP: Branched K-3D Version ${K3D_MAJOR_VERSION}.${K3D_MINOR_VERSION}"
#	WORKING_DIRECTORY ${k3d_SOURCE_DIR}
#	)

# Get a SourceForge username so we can upload distributables to the FRS
IF(WIN32)
	SET(K3D_SOURCEFORGE_USERNAME "$ENV{USERNAME}" CACHE STRING "SourceForge user account name, for uploading distribution files.")
ELSE(WIN32)
	SET(K3D_SOURCEFORGE_USERNAME "$ENV{USER}" CACHE STRING "SourceForge user account name, for uploading distribution files.")
ENDIF(WIN32)

# Setup default packaging parameters (deprecated) ...
SET(CPACK_PACKAGE_DESCRIPTION "K-3D free-as-in-freedom modeling, animation and rendering system")
SET(CPACK_PACKAGE_FILE_NAME "k3d-setup-${K3D_VERSION}")
SET(CPACK_PACKAGE_INSTALL_DIRECTORY "K-3D ${K3D_VERSION}")
SET(CPACK_PACKAGE_INSTALL_REGISTRY_KEY "K-3D ${K3D_VERSION}")
SET(CPACK_PACKAGE_NAME "k3d")
SET(CPACK_PACKAGE_VENDOR "www.k-3d.org")
SET(CPACK_PACKAGE_VERSION ${K3D_VERSION})
SET(CPACK_PACKAGE_VERSION_MAJOR ${K3D_MAJOR_VERSION})
SET(CPACK_PACKAGE_VERSION_MINOR ${K3D_MINOR_VERSION})
SET(CPACK_PACKAGE_VERSION_PATCH ${K3D_RELEASE_VERSION})
SET(CPACK_RESOURCE_FILE_LICENSE "${k3d_SOURCE_DIR}/COPYING")

# Setup global packaging parameters ...
SET(K3D_CPACK_INSTALL_CMAKE_PROJECTS "${k3d_BINARY_DIR};k3d;ALL;/")
SET(K3D_CPACK_PACKAGE_DESCRIPTION "K-3D free-as-in-freedom modeling, animation, and rendering system.")
SET(K3D_CPACK_PACKAGE_FILE_NAME "k3d-setup-${K3D_VERSION}")
SET(K3D_CPACK_PACKAGE_NAME "k3d")
SET(K3D_CPACK_PACKAGE_VERSION "${K3D_VERSION}")
SET(K3D_CPACK_RESOURCE_FILE_LICENSE "${k3d_SOURCE_DIR}/COPYING")
SET(K3D_CPACK_SOURCE_IGNORE_FILES "/CVS/;/.svn/;/.hg/")
SET(K3D_CPACK_SOURCE_INSTALLED_DIRECTORIES "${k3d_SOURCE_DIR};/")
SET(K3D_CPACK_SOURCE_PACKAGE_FILE_NAME "k3d-source-${K3D_VERSION}")

# Setup some macros that can be used by the platform-specific distribution logic
MACRO(K3D_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(K3D_CHECK_INSTALLED_VERSION)

MACRO(K3D_CHECK_INSTALLED_PYTHON_DEPENDENCY CONFIG)
	IF(${CONFIG} AND NOT K3D_INSTALL_PYTHON)
		MESSAGE(SEND_ERROR "K3D_INSTALL_PYTHON is required by ${CONFIG}.")
	ENDIF(${CONFIG} AND NOT K3D_INSTALL_PYTHON)
ENDMACRO(K3D_CHECK_INSTALLED_PYTHON_DEPENDENCY)

# 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)

