cmake_minimum_required(VERSION 3.31)
project({{ settings.project_name }} VERSION 0.0.2)

{% if settings.cmake.uses_ecm %}
find_package(ECM NO_MODULE REQUIRED)
list(APPEND CMAKE_MODULE_PATH ${ECM_MODULE_PATH})
include(ECMQtDeclareLoggingCategory)
{% endif %}

{% if settings.cmake.want_feature_summary %}
include(FeatureSummary)
{% endif %}

include(GNUInstallDirs)

{% if settings.cmake.uses_qt %}
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)
{% endif %}

{% if settings.project_type == 'c++' %}
set(CMAKE_CXX_STANDARD {{ settings.cxx_standard }})
set(CMAKE_CXX_STANDARD_REQUIRED ON)
{% endif %}

{% if settings.want_docs %}
option(BUILD_DOCS "Build documentation." OFF)
option(INSTALL_DOCS "Install documentation." OFF)
{% endif %}
{% if settings.want_tests %}
option(BUILD_TESTS "Build tests." OFF)
{% endif %}

{% if settings.want_docs %}
if(BUILD_DOCS)
  # set(DOXYGEN_EXCLUDE_PATTERNS */autotests/*)
  set(DOXYGEN_GENERATE_TAGFILE "${CMAKE_BINARY_DIR}/html/${CMAKE_PROJECT_NAME}.tags")
  set(DOXYGEN_INTERACTIVE_SVG YES)
  set(DOXYGEN_MARKDOWN_ID_STYLE GITHUB)
  set(DOXYGEN_USE_MDFILE_AS_MAINPAGE "${CMAKE_SOURCE_DIR}/README.md")
  # set(DOXYGEN_TAGFILES ./.docs/qtcore.tags=https://doc.qt.io/qt-6/)
  find_package(Doxygen REQUIRED COMPONENTS dot)
  doxygen_add_docs(docs README.md src ALL)
  if(INSTALL_DOCS)
    install(
      DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/docs/html
      DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/doc/${CMAKE_PROJECT_NAME}-${CMAKE_PROJECT_VERSION})
  endif()
endif()
{% endif %}

{% if settings.cmake.uses_qt %}
find_package(Qt6 REQUIRED COMPONENTS DBus Network CONFIG)
set_package_properties(Qt6DBus PROPERTIES TYPE REQUIRED)
set_package_properties(Qt6Network PROPERTIES TYPE REQUIRED)
add_definitions(
  -DQT_NO_CAST_FROM_ASCII
  -DQT_NO_CAST_FROM_BYTEARRAY
  -DQT_NO_CAST_TO_ASCII
  -DQT_NO_SIGNALS_SLOTS_KEYWORDS
  -DQT_NO_URL_CAST_FROM_STRING
  -DQT_STRICT_ITERATORS
  -DQT_USE_FAST_OPERATOR_PLUS
  -DQT_USE_QSTRINGBUILDER
  -DVERSION=\"${CMAKE_PROJECT_VERSION}\")
{% endif %}

{% if settings.cmake.want_feature_summary %}
feature_summary(WHAT ALL FATAL_ON_MISSING_REQUIRED_PACKAGES)
{% endif %}

add_subdirectory(src)

install(TARGETS ${CMAKE_PROJECT_NAME})
{% if settings.cmake.want_cpack %}
include(CPack)
{% endif %}
