cmake_minimum_required(VERSION 3.8)
project("Sayonara Player")

option(WITH_TESTS "Building with tests" OFF)
option(LINK_GSTREAMER_PLUGINS "Link the most common GStreamer plugins into the binary. Used for the creation of AppImage files")
option(DISABLE_NATIVE_DIR_DIALOGS "Disable native directory dialogs (problem for snap and flatpak)" OFF)
option(GIT_REVISION "Add some git revision to the version string")
option(ENABLE_PCH "enable precompiled headers for stdlib and Qt" ON)

include(cmake/Compiler.cmake)
include(cmake/Packages.cmake)

if(LINK_GSTREAMER_PLUGINS)
	include(cmake/GStreamer.cmake)
endif()

message("PCH enabled? ${ENABLE_PCH}")

get_property(HAS_64_SUFFIX GLOBAL PROPERTY FIND_LIBRARY_USE_LIB64_PATHS)
if(HAS_64_SUFFIX)
	set(LIB_SUFFIX "64")
else()
	set(LIB_SUFFIX "")
endif()

set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}")

set(SAYONARA_VERSION "1.12.0-stable1")
set(SAYONARA_REVISION ${GIT_REVISION})
set(SAYONARA_FULL_VERSION ${SAYONARA_VERSION})
if (SAYONARA_REVISION)
	set(SAYONARA_FULL_VERSION "${SAYONARA_VERSION}-g${SAYONARA_REVISION}")
endif()
set(SAYONARA_INSTALL_PATH "${CMAKE_INSTALL_PREFIX}")
set(SAYONARA_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}")
set(SAYONARA_INSTALL_BIN_PATH "${CMAKE_INSTALL_PREFIX}/bin/")
set(SAYONARA_INSTALL_LIB_PATH "${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}/sayonara/")
set(SAYONARA_INSTALL_SHARE_PATH "${CMAKE_INSTALL_PREFIX}/share/sayonara/")

message("Build Sayonara ${VAR_SAYONARA_VERSION}")
message("Will install to ${CMAKE_INSTALL_PREFIX}")

# used for cmakedefine in Macros.h.in
set(SAYONARA_WITH_TESTS ${WITH_TESTS})
string(TOLOWER "${CMAKE_BUILD_TYPE}" LOWER_CMAKE_BUILD_TYPE)
if("${LOWER_CMAKE_BUILD_TYPE}" MATCHES "debug")
	set(SAYONARA_WITH_TESTS 1)
endif()

add_subdirectory(dist)
add_subdirectory(src)
add_subdirectory(resources)

message("Lower cmake build type ${LOWER_CMAKE_BUILD_TYPE}")

if(SAYONARA_WITH_TESTS)
	message("Compiling with tests...")
	enable_testing()
	add_subdirectory(test)
else()
	message("Compiling without tests...")
	message(" In order to change that, use -DWITH_TESTS=1")
endif()

set(CMAKE_INSTALL_MANIFEST "install_manifest.txt")
