PROJECT(BALLPython)

IF(BALL_PYTHON_SUPPORT)
	INCLUDE(SIPMacros)

	REMOVE_DEFINITIONS(-pedantic)

	INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR})

	IF(NOT BALL_HAS_ASIO)
		SET(SIP_DISABLE_FEATURES "BALL_HAS_ASIO")
	ENDIF()
	SET(SIP_EXTRA_OPTIONS "-e")

	FILE(GLOB BALL_SIP_DEPENDS "BALL/*.sip")
	FILE(GLOB VIEW_SIP_DEPENDS "VIEW/*.sip")

	SET(SIP_EXTRA_FILES_DEPEND ${BALL_SIP_DEPENDS} ${VIEW_SIP_DEPENDS})

	# Add the BALLCore python bindings
	SET(SIP_EXTRA_SOURCES 
		BALL/pyBALLSipHelper.C
		BALL/pyIndexList.C
		BALL/pyConstant.C
	)
	ADD_SIP_PYTHON_MODULE(BALLCore BALLCoremodule BALL/BALLCore.sip BALL)
	
	IF(BALL_HAS_VIEW)
		SET(SIP_EXTRA_SOURCES
			VIEW/pyCompositeList.C
			VIEW/pyBALLSipHelper.C
			VIEW/pyColorRGBAVector.C
			VIEW/pyDatasetVector.C
		)
		# Add the VIEW python bindings
		SET(SIP_INCLUDES ${PROJECT_SOURCE_DIR})
		ADD_SIP_PYTHON_MODULE(VIEW VIEWmodule VIEW/VIEW.sip BALL VIEW)
	ENDIF()

	# Install the BALL.py script
	IF(NOT WIN32)
		SET(BALL_PY_LOCATION ${CMAKE_LIBRARY_OUTPUT_DIRECTORY})
	ELSE()
		SET(BALL_PY_LOCATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${CMAKE_CFG_INTDIR})

	ENDIF()

	ADD_CUSTOM_COMMAND(TARGET BALLCoremodule POST_BUILD
		COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_SOURCE_DIR}/BALL.py ${BALL_PY_LOCATION}
	)

	INSTALL(TARGETS BALLCoremodule
		COMPONENT "${COMPONENT_PYTHON_BINDINGS_BALL}"
		RUNTIME DESTINATION ${BALL_RUNTIME_INSTALL_DIRECTORY}
		LIBRARY DESTINATION ${BALL_LIBRARY_INSTALL_DIRECTORY}
	)

	IF(BALL_HAS_VIEW)
		INSTALL(TARGETS VIEWmodule
			COMPONENT "${COMPONENT_PYTHON_BINDINGS_VIEW}"
			RUNTIME DESTINATION ${BALL_RUNTIME_INSTALL_DIRECTORY}
			LIBRARY DESTINATION ${BALL_LIBRARY_INSTALL_DIRECTORY}
		)
	ENDIF()

	INSTALL(FILES ${PROJECT_SOURCE_DIR}/BALL.py 
		COMPONENT "${COMPONENT_PYTHON_BINDINGS_BALL}"
		DESTINATION "${BALL_PYTHON_INSTALL_DIRECTORY}"
	)
	
	IF (WIN32)
		#		INSTALL(FILES ${PYTHON_EXECUTABLE}
		#	COMPONENT "${COMPONENT_PYTHON_BINDINGS_BALL}"
		#	DESTINATION "${BALL_RUNTIME_INSTALL_DIRECTORY}"
		#)
		
		GET_FILENAME_COMPONENT(PYTHON_SITE_PACKAGES_DIR ${PYTHON_EXECUTABLE} PATH) 
		SET(PYTHON_SITE_PACKAGES_DIR "${PYTHON_SITE_PACKAGES_DIR}/lib")
		
		INSTALL(DIRECTORY "${PYTHON_SITE_PACKAGES_DIR}"
			COMPONENT "${COMPONENT_PYTHON_BINDINGS_BALL}"
			DESTINATION "${BALL_RUNTIME_INSTALL_DIRECTORY}"
		)
	ENDIF ()

	IF (APPLE)
		INSTALL(FILES ${SIP_LIBRARIES}
			COMPONENT "${COMPONENT_PYTHON_BINDINGS_BALL}"
			DESTINATION "${BALL_PYTHON_INSTALL_DIRECTORY}"
		)
	ENDIF()

ENDIF()
