set (kmm_templates_SOURCES
  templateloader.cpp
  templatewriter.cpp
  kloadtemplatedlg.cpp
  ktemplateexportdlg.cpp
)

set(kmm_templates_UI
  kloadtemplatedlg.ui
  ktemplateexportdlg.ui
)

ki18n_wrap_ui(kmm_templates_SOURCES ${kmm_templates_UI} )

# Generate templates.qrc file:
set(qrcContents "<!-- This file was autogenerated by CMake. Do not modify or check it into the repository -->\n")
string(APPEND qrcContents "<RCC>\n  <qresource")
string(APPEND qrcContents " prefix=\"/templates\"")
string(APPEND qrcContents ">\n")

# the expression "[a-z][a-z]_[A-Z][A-Z]/*" does match directories named de_DE on
# linux but not on windows. Using "[a-z][a-z]\_*/*" works on both.
file(GLOB_RECURSE template_files
        LIST_DIRECTORIES=true
        RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}"
        "C/*" "[a-z][a-z]/*" "[a-z][a-z]\_*/*")

foreach(template_file ${template_files})
    string(APPEND qrcContents "    <file>${template_file}</file>\n")
endforeach()
string(APPEND qrcContents "  </qresource>\n</RCC>\n")

file(WRITE "templates.qrc" "${qrcContents}")

# add generated file to resources
qt_add_resources(kmm_templates_SOURCES templates.qrc)

add_library(kmm_templates ${kmm_templates_SOURCES})

#   kmm_settings
#  KF${QT_MAJOR_VERSION}::KIOWidgets
#  KF${QT_MAJOR_VERSION}::Completion
#  KF${QT_MAJOR_VERSION}::Notifications
#  KF${QT_MAJOR_VERSION}::ItemViews
#  Qt::Gui
#  Qt::Core
#  Alkimia::alkimia
#  kmm_mymoney


target_link_libraries(kmm_templates PUBLIC
  KF${QT_MAJOR_VERSION}::TextWidgets
  KF${QT_MAJOR_VERSION}::I18n
  kmm_models
  kmm_widgets
)

set_target_properties(kmm_templates PROPERTIES
  VERSION ${PROJECT_VERSION} SOVERSION ${PROJECT_VERSION_MAJOR}
)

generate_export_header(kmm_templates)

install(TARGETS kmm_templates ${INSTALL_TARGETS_DEFAULT_ARGS} )

########### test files ###############
#
# A simple testrun could be done like follows with a simple shell command:
#
# find -name \*.kmt -print0 | xargs --null xmllint --noout --dtdvalid kmt.dtd
