# 3.27.9 is stable as of 2024-02-24
cmake_minimum_required( VERSION 3.27.9 )

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

# 5.15.12 is stable as of 2024-02-24
set (QT_MIN_VERSION "5.15.12")
# 5.100 adds {question,warn}TwoActions and deprecates {question,warn}YesNo
# 5.115 is stable as of 2024-02-24
set (KF5_MIN_VERSION "5.115")

# as of 2024-02-24 5.96 is the newest version referenced in /usr/share/ECM/kde-modules/KDECompilerSettings
find_package( ECM 5.96.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 ${KF5_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)	# TODO write tests
# 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( Qt5 ${QT_MIN_VERSION} CONFIG REQUIRED COMPONENTS
	Core
	Gui
	Widgets
	# These must be deps of KF things, shouldn't be used directly
	#Network
	#Xml
	#DBus
)

find_package( KF5 ${KF5_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
	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 )

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