# Set CMake policies
CMAKE_MINIMUM_REQUIRED(VERSION 3.3.0)
CMAKE_POLICY(SET CMP0048 NEW)
SET(CMAKE_CXX_STANDARD 17)
add_definitions(-DQT_NO_DEPRECATED_WARNINGS)
ENABLE_TESTING()

# Basic information about our project
PROJECT(scantools VERSION 1.0.8)

# Pull in a few home-written modules
SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/" "${CMAKE_SOURCE_DIR}/src/3rdParty/KDE-extra-cmake-modules/modules/")

# Make Qt5 work
SET(CMAKE_INCLUDE_CURRENT_DIR ON)
SET(CMAKE_AUTOMOC ON)
SET(CMAKE_AUTORCC ON)
find_package(Qt5 5.4 COMPONENTS Concurrent Core Gui Test REQUIRED)
include(GNUInstallDirs)

# Bind in additional packages
FIND_PACKAGE(JPEG REQUIRED)
FIND_PACKAGE(ZLIB REQUIRED)

# Set includes globally
include_directories(${PROJECT_SOURCE_DIR}/src/libscantools)

#
# Find GIT repository data.
#
if (EXISTS ${CMAKE_SOURCE_DIR}/.git)
    # Get the current working branch
    execute_process(
        COMMAND git rev-parse --abbrev-ref HEAD
        WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
        OUTPUT_VARIABLE GIT_BRANCH
        OUTPUT_STRIP_TRAILING_WHITESPACE
        )
    message("Currently working with git branch ${GIT_BRANCH}")

    # Get the latest abbreviated commit hash of the working branch
    execute_process(
        COMMAND git log -1 --format=%H
        WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
        OUTPUT_VARIABLE GIT_COMMIT
        OUTPUT_STRIP_TRAILING_WHITESPACE
        )
    message("Currently working with git Commit ${GIT_COMMIT}")

    # Get the latest commit date of the working branch
    execute_process(
        COMMAND git log -1 --format=%as
        WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
        OUTPUT_VARIABLE GIT_DATE
        OUTPUT_STRIP_TRAILING_WHITESPACE
        )
    message("Currently working with git commit from ${GIT_DATE}")
else()
    message("Not working from a GIT directory")
    set(GIT_BRANCH "")
    set(GIT_COMMIT "")
    set(GIT_DATE "")
endif()

# Subdirectories
add_subdirectory(packaging)
add_subdirectory(src)
