# 3.30.2 is stable as of 2024-10-30
cmake_minimum_required( VERSION 3.30.2 )

#Warned by dev build, apparently having mixed full path and search references
#causes different behavior depending on this policy, we should be fine with NEW
if( COMMAND cmake_policy)
	cmake_policy( SET CMP0003 NEW )
endif( COMMAND cmake_policy )

project( kuroo CXX )

# 6.7.2 is stable as of 2024-10-30
set (QT_MIN_VERSION "6.7.2")
# 6.660 is stable as of 2024-10-30
set (KF_MIN_VERSION "6.6.0")

# as of 2024-10-30 5.96 is the newest version referenced in /usr/share/ECM/kde-modules/KDECompilerSettings
# technically it references 5.240 but only for Win32
find_package( ECM 6.6.0 REQUIRED NO_MODULE )	# increase this to get more strict compiler settings
set( CMAKE_MODULE_PATH ${ECM_MODULE_PATH} ${CMAKE_MODULE_PATH} )

#set(KDE_COMPILERSETTINGS_LEVEL 5.85.0)		# allow to override to a lower version than ECM
include(KDECompilerSettings NO_POLICY_SCOPE)	#Must be first include after find_package ECM because implicitly depends on min ECM version which could be overwritten by other find_package calls
# KDECompilerSettings also includes ECMEnableSanitizers which adds an empty cache variable ECM_ENABLE_SANITIZERS
# which can take semicolon-delimited values of address, leak, thread, memory, undefined, fuzzer
# but it doesn't set these deprecation settings, so do that by hand
include(ECMDeprecationSettings)
ecm_set_disabled_deprecation_versions(
	QT ${QT_MIN_VERSION}
	KF ${KF_MIN_VERSION}
)

# these things are described at https://api.kde.org/ecm/index.html
include(ECMAddAppIcon)	# for ecm_add_app_icon in src/CMakeLists.txt
include(ECMInstallIcons)	# used in pics/CMakeLists.txt
include(ECMAddTests)
# ECMQtDeclareLoggingCategory?

include(FeatureSummary)		# used at the end of this file

# KDECMakeSettings _doesn't_ set this, so do it separately
set( KDE_INSTALL_DIRS_NO_DEPRECATED TRUE )
include(KDEInstallDirs)	#Should be before KDECMakeSettings
include(KDECMakeSettings NO_POLICY_SCOPE)	#https://api.kde.org/ecm/kde-module/KDECMakeSettings.html

# these are set by having >5.85 ECM version when including KDECompilerSettings
# set(CMAKE_CXX_STANDARD 17)
# set(CMAKE_CXX_STANDARD_REQUIRED ON)
# set(CMAKE_CXX_EXTENSIONS OFF)

#set(CLAZY_CHECKS qt6-qlatin1stringchar-to-u)

# Works without this explicit declaration but it ought to be here for correctness
find_package( SQLite3 REQUIRED )

# These are actually all deps of other things
find_package( Qt6 ${QT_MIN_VERSION} CONFIG REQUIRED COMPONENTS
	Core
	Gui
	Widgets
	Core5Compat	# for QRegExp
	Test
	# These must be deps of KF things, shouldn't be used directly
	#Network
	#Xml
	#DBus
)

find_package( KF6 ${KF_MIN_VERSION} REQUIRED COMPONENTS
	# These are all required directly and not provided by any dependencies. It "compiles and works" on the development system with just these
	KIO
	Notifications
	StatusNotifierItem	#separate from Notifications in KF6?
	ThreadWeaver
	TextWidgets
	Crash
	# Required in link step
	XmlGui		# MainWindow is XmlGuiWindow
	ItemViews	# TreeWidgetSearchLine
	# These seem to be provided by deps, but should be direct deps too
	ConfigWidgets
	I18n		# i18n(QStr)
	Config		# Config dialogs
	Auth		# KAuthExecuteJob &c.
	CoreAddons	# AboutData? Job Process User?
	WidgetsAddons	# Font(Chooser|Requester)? PageWidget? MessageBox ...
	# Also shown as toplevel deps in lddtree kuroo but don't make sense
	#Sonnet
	#Service
	#Codecs
)

add_subdirectory( src )
add_subdirectory( po )
add_subdirectory( pics )

if(BUILD_TESTING)
	enable_testing()
	add_subdirectory( autotests )
endif()

# prints the nice summary "The following (OPTIONAL|REQUIRED|...) packages have been found
feature_summary(WHAT ALL INCLUDE_QUIET_PACKAGES FATAL_ON_MISSING_REQUIRED_PACKAGES)

# Adds (make|ninja) clang_format command
#include(KDEClangFormat)
#file(GLOB_RECURSE ALL_CLANG_FORMAT_SOURCE_FILES *.cpp *.h)
#kde_clang_format(${ALL_CLANG_FORMAT_SOURCE_FILES})
