cmake_minimum_required(VERSION 3.5)

project(CupsConfigApp LANGUAGES CXX VERSION 1.1.0)

set(CMAKE_INCLUDE_CURRENT_DIR ON)

set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# QtCreator supports the following variables for Android, which are identical to qmake Android variables.
# Check http://doc.qt.io/qt-5/deployment-android.html for more information.
# They need to be set before the find_package(Qt5 ...) call.

#if(ANDROID)
#    set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android")
#    if (ANDROID_ABI STREQUAL "armeabi-v7a")
#        set(ANDROID_EXTRA_LIBS
#            ${CMAKE_CURRENT_SOURCE_DIR}/path/to/libcrypto.so
#            ${CMAKE_CURRENT_SOURCE_DIR}/path/to/libssl.so)
#    endif()
#endif()

find_package(Qt5 COMPONENTS Core Quick QuickControls2 LinguistTools REQUIRED)

include_directories(src)

file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/i18n)
set(TS_FILES i18n/CupsConfigApp_en_US.ts i18n/CupsConfigApp_de_CH.ts)
set_source_files_properties(${TS_FILES} PROPERTIES OUTPUT_LOCATION "i18n")
configure_file(i18n.qrc ${CMAKE_BINARY_DIR} COPYONLY)
#Create new ts files
#Note: This will overwrite the existing files!
#qt5_create_translation(QM_FILES ${CMAKE_SOURCE_DIR} ${TS_FILES})

#Use existing ts files
qt5_add_translation(QM_FILES ${TS_FILES})


string(TIMESTAMP BUILD_TIME "%Y-%m-%d %H:%M")

add_definitions(-DAPPLICATION_VERSION="${CMAKE_PROJECT_VERSION}" -DBUILD_TIME="${BUILD_TIME}")

if(CMAKE_BUILD_TYPE!=RELEASE) 
    find_package(Hg) 
    if(HG_FOUND) 
        message("hg found: ${HG_EXECUTABLE}") 
        HG_WC_INFO(${PROJECT_SOURCE_DIR} Project) 
        message("Current changeset is ${Project_WC_CHANGESET}") 
        add_definitions(-DHG_COMMIT="${Project_WC_CHANGESET}") 
    else() 
        add_definitions(-DHG_COMMIT="") 
    endif() 
else() 
    add_definitions(-DHG_COMMIT="") 
endif() 


if(ANDROID)
    add_library(ethz-cups-config-app SHARED
      main.cpp
      tablemodel.cpp
      qml.qrc
      ${TS_FILES}
    )
else()
    add_executable(ethz-cups-config-app
      src/main.cpp
      src/configutility.cpp
      src/controller.cpp
      src/cupsutility.cpp
      src/printermodel.cpp
      src/printerparser.cpp
      src/smbutility.cpp
      src/stringutils.cpp
      src/tablemodel.cpp
      src/translator.cpp

      ${CMAKE_BINARY_DIR}/i18n.qrc
      qml.qrc
      resources.qrc

      ${TS_FILES}
      ${QM_FILES}
    )
endif()

target_compile_definitions(ethz-cups-config-app
  PRIVATE $<$<OR:$<CONFIG:Debug>,$<CONFIG:RelWithDebInfo>>:QT_QML_DEBUG>)
target_link_libraries(ethz-cups-config-app
  PRIVATE Qt5::Core Qt5::Quick Qt5::QuickControls2)

install(TARGETS ethz-cups-config-app
		RUNTIME DESTINATION bin COMPONENT libraries
		 LIBRARY DESTINATION lib COMPONENT libraries
		 ARCHIVE DESTINATION lib/static COMPONENT libraries)
install(FILES packaging/config DESTINATION /etc/ethz-cups-config-app/)
install(FILES packaging/ethz-cups-config-app.desktop DESTINATION /usr/share/applications/)
install(FILES resources/material/ethz-cups-config-app.png DESTINATION /usr/share/pixmaps)
