PROJECT(BALLPython)

IF(BALL_PYTHON_SUPPORT)
	INCLUDE(SIPMacros)

	REMOVE_DEFINITIONS(-pedantic)

	INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR})

	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 Qt5::Core)
	
	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 Qt5::Widgets)
	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}
	)

	IF(NOT APPLE)
		INSTALL(TARGETS BALLCoremodule
			COMPONENT "${COMPONENT_PYTHON_BINDINGS_BALL}"
			RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
			LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
		)

		IF(BALL_HAS_VIEW)
			INSTALL(TARGETS VIEWmodule
				COMPONENT "${COMPONENT_PYTHON_BINDINGS_VIEW}"
				RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
				LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
			)
		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 "${CMAKE_INSTALL_BINDIR}"
			#)


			GET_FILENAME_COMPONENT(PYTHON_SITE_PACKAGES_DIR ${Python3_EXECUTABLE} PATH)
			SET(PYTHON_SITE_PACKAGES_DIR "${PYTHON_SITE_PACKAGES_DIR}/lib")

			INSTALL(DIRECTORY "${PYTHON_SITE_PACKAGES_DIR}"
				COMPONENT "${COMPONENT_PYTHON_BINDINGS_BALL}"
				DESTINATION "${CMAKE_INSTALL_BINDIR}"
			)
		ENDIF ()
	ENDIF()

ENDIF()
