cmake_minimum_required(VERSION 3.16)
project(lomiri-gallery-app VERSION 3.2.0 LANGUAGES CXX)
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")

# Instruct CMake to run moc automatically when needed.
set(CMAKE_AUTOMOC ON)

option(ENABLE_WERROR "Treat all build warnings as errors" OFF)
option(ENABLE_COVERAGE "Build with coverage instrumentation" OFF)
option(CLICK_MODE "Install to a contained location" ON)

include(CoverageReport)
include(CTest)
include(GNUInstallDirs)

find_package(Qt5Core)
find_package(Qt5DBus)
find_package(Qt5Gui)
find_package(Qt5Qml)
find_package(Qt5Quick)
find_package(Qt5Sql)
find_package(Qt5Widgets)
find_package(Qt5Xml)

find_package(exiv2 REQUIRED)
find_package(MediaInfoLib REQUIRED)
find_package(Intl REQUIRED)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

if (ENABLE_WERROR)
    add_compile_options ("-Werror")
endif ()

if(ENABLE_COVERAGE)
    add_compile_options("--coverage")
    add_link_options("--coverage")
endif()

set(GALLERY lomiri-gallery-app)
set(GETTEXT_NAME ${PROJECT_NAME})
set(DESKTOP_FILE ${GALLERY}.desktop)
set(UBUNTU_MANIFEST_PATH "click/manifest.json.in" CACHE INTERNAL "Relative path to the manifest file")

# make non compiled files visible in qtcreator
file(GLOB_RECURSE NON_COMPILED_FILES *.qml *.js *.py *.svg *.png *.in *.json *.desktop *.pot *.apparmor qmldir)
add_custom_target(NON_COMPILED_TARGET ALL SOURCES ${NON_COMPILED_FILES})

if(CLICK_MODE)
    set(CMAKE_INSTALL_PREFIX /)
    set(CMAKE_INSTALL_BINDIR /)
    set(GALLERY_DIR ${CMAKE_INSTALL_PREFIX})
    add_definitions("-DCLICK_MODE=1")
else()
    set(GALLERY_DIR ${CMAKE_INSTALL_FULL_DATADIR}/${GALLERY})
endif()

# for dh_translations to extract the domain
# (regarding syntax consistency, see http://pad.lv/1181187)
set (GETTEXT_PACKAGE "${GALLERY}")

add_subdirectory(click)
add_subdirectory(desktop)
add_subdirectory(po)
add_subdirectory(rc)
add_subdirectory(src)

if(BUILD_TESTING)
    find_package(Qt5Test)
    add_subdirectory(tests)
endif()
