include_directories(${CMAKE_CURRENT_BINARY_DIR})
include_directories(${CMAKE_CURRENT_SOURCE_DIR})

#Singletons in common.h depend on lots of things in subdirs
include_directories(
	${CMAKE_SOURCE_DIR}/src
	${CMAKE_SOURCE_DIR}/src/config
	${CMAKE_SOURCE_DIR}/src/core
	${CMAKE_SOURCE_DIR}/src/history
	${CMAKE_SOURCE_DIR}/src/intro
	${CMAKE_SOURCE_DIR}/src/logs
	${CMAKE_SOURCE_DIR}/src/portage
	${CMAKE_SOURCE_DIR}/src/queue
)

#core
set(core_sources
	core/cacheportagejob.cpp
	core/categorieslistview.cpp
	core/dependatom.cpp
	core/dependencyview.cpp
	core/emerge.cpp
	core/etcupdate.cpp
	core/global.cpp
	# After running clazy-fix-missing-qobject-macro it added Q_OBJECT to the classes in these headers.
	# Apparently that combined with not having a separate .cpp for the implementation in this list makes
	# it now required to list them in sources.
	# Hint from: https://stackoverflow.com/questions/3065154/undefined-reference-to-vtable#comment105441153_3065154
	core/LoadPackageHardMaskJob.h
	core/LoadPackageKeywordsJob.h
	core/LoadPackageUseJob.h
	core/LoadPackageUserHardMaskJob.h
	core/LoadPackageUserUnMaskJob.h
	core/packageinspector.cpp
	core/packagelistmodel.cpp
	core/packagelistitem.cpp
	core/packageversion.cpp
	core/portagedb.cpp
	core/portagefiles.cpp
	core/progressjob.cpp
	core/scanhistoryjob.cpp
	core/scanportagejob.cpp
	core/scanupdatesjob.cpp
	core/signalist.cpp
	core/tooltip.cpp
	core/versionview.cpp )
ki18n_wrap_ui( core_sources core/inspectorbase.ui )

#history
set(history_sources
	history/history.cpp
	history/historylistview.cpp
	history/historytab.cpp
	history/mergelistview.cpp
	history/mergetab.cpp )
ki18n_wrap_ui( history_sources history/historybase.ui history/mergebase.ui )

#portage
set(portage_sources
	portage/portage.cpp
	portage/portagetab.cpp
	portage/uninstallinspector.cpp
	portage/portagelistview.cpp )
ki18n_wrap_ui( portage_sources portage/uninstallbase.ui portage/portagebase.ui )

#config
set( config_sources config/configdialog.cpp )
ki18n_wrap_ui(	config_sources
				config/options1.ui
				config/options2.ui
				config/options3.ui
				config/options4.ui )
kconfig_add_kcfg_files( config_sources config/settings.kcfgc )

#queue
set(queue_sources
	queue/queue.cpp
	queue/queuetab.cpp
	queue/queuelistmodel.cpp
	queue/queuelistview.cpp
	queue/queuelistitem.cpp
	queue/queuelistdelegate.cpp )
ki18n_wrap_ui( queue_sources queue/queuebase.ui )

#intro
set( intro_sources intro/introdlg.cpp )
ki18n_wrap_ui( intro_sources intro/intro.ui )

#logs
set( logs_sources logs/log.cpp logs/logstab.cpp )
ki18n_wrap_ui( logs_sources logs/logsbase.ui )

#kuroo
set( kuroo_sources
	kuroo.cpp
	kurooinit.cpp
	kurooview.cpp
	main.cpp
	statusbar.cpp
	systemtray.cpp )

add_executable(kuroo
	${core_sources}
	${history_sources}
	${portage_sources}
	${config_sources}
	${queue_sources}
	${intro_sources}
	${logs_sources}
	${kuroo_sources} )
kde_enable_exceptions()

# KTorrent sets this just before target_link_libraries, but it doesn't seem to work
# to set the window icon, at least when running from build dir
set( KUROO_ICONS_PNG
	../pics/16-apps-kuroo.png
	../pics/22-apps-kuroo.png
	../pics/32-apps-kuroo.png
	../pics/48-apps-kuroo.png
)

ecm_add_app_icon( kuroo ICONS ${KUROO_ICONS_PNG} )

target_link_libraries( kuroo
	# These are all used directly and not provided by any other dependency. It "compiles and works" on the development system with just these
	KF5::Crash
	KF5::KIOCore
	KF5::Notifications
	KF5::ThreadWeaver
	KF5::TextWidgets
	KF5::XmlGui
	sqlite3		# TODO: use some sort of ORM maybe find_package?
	KF5::ItemViews
	# Builds without these specified, but they should be necessary
	Qt5::Core
	Qt5::Gui
	Qt5::Widgets
	KF5::Auth
	KF5::AuthCore
	KF5::ConfigCore
	KF5::ConfigGui
	KF5::ConfigWidgets
	KF5::CoreAddons
	KF5::I18n
	KF5::WidgetsAddons
	# lddtree also shows these as top-level deps but they don't make sense
	#Qt5::Xml
	#KF5::Service
	#KF5::SonnetUi
	#Qt5::Network
	#KF5::Codecs
	#Qt5::DBus
	#libstdc++
	#libm
	#libgcc_s
	#libc
)

add_executable( kuroo_helper auth/kuroohelper.cpp )
target_link_libraries( kuroo_helper
	# These are all used directly and not provided by any other dependency. It "compiles and works" on the development system with just these
	KF5::KIOCore
	KF5::Auth
	# Builds without explicit declaration, but these make sense
	Qt5::Core
	KF5::CoreAddons	# KProcess
	# lddtree shows these as top-level deps but they don't make sense
	#KF5::Service
	#Qt5::Network
	#KF5::ConfigCore
	#KF5::AuthCore
	#KF5::CoreAddons
	#Qt5::DBus
	#libstdc++
	#libm
	#libgcc_s
	#libc
)
install( TARGETS kuroo_helper DESTINATION ${KAUTH_HELPER_INSTALL_DIR} )
kauth_install_helper_files( kuroo_helper org.gentoo.kuroo root )
kauth_install_actions( org.gentoo.kuroo auth/org.gentoo.kuroo.actions )

########### install ###############
install( TARGETS kuroo ${INSTALL_TARGETS_DEFAULT_ARGS} )
#install( FILES  DESTINATION ${DATA_INSTALL_DIR}/autostart )
install( FILES  config/kurooconfig.kcfg DESTINATION ${KDE_INSTALL_KCFGDIR} )
install( FILES  kurooui.rc DESTINATION ${KDE_INSTALL_KXMLGUI5DIR}/kuroo )
# ktorrent uses install( PROGRAMS ) instead of install( FILES ) for the desktop file
install( PROGRAMS org.gentoo.kuroo.desktop DESTINATION ${KDE_INSTALL_APPDIR} )
