project(sayonara)

include(FindPkgConfig)
include(compiler.cmake)

if(WIN32)
	pkg_check_modules(GIO gio-windows-2.0 REQUIRED)
endif()

pkg_check_modules(TAGLIB taglib>=1.6 REQUIRED)
pkg_check_modules(GLIB glib-2.0 REQUIRED)
pkg_check_modules(GOBJECT gobject-2.0 REQUIRED)
pkg_check_modules(GSTREAMER gstreamer-1.0 REQUIRED)
pkg_check_modules(GSTREAMER_BASE gstreamer-base-1.0 REQUIRED)
pkg_check_modules(GSTREAMER_BASE_APP gstreamer-app-1.0 REQUIRED)

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)

if( NOT DEFINED CMAKE_BUILD_TYPE OR NOT CMAKE_BUILD_TYPE )
	message("Use standard build type \"Release\"")
	set(CMAKE_BUILD_TYPE "Release")
endif()

find_package(Qt5 COMPONENTS Core Widgets Sql Network DBus Xml REQUIRED)
find_package(Qt5LinguistTools REQUIRED)

set(CMAKE_AUTOMOC ON)
#set(CMAKE_AUTOUIC ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)

include_directories(${Qt5Core_INCLUDE_DIRS})
include_directories(${Qt5Widgets_INCLUDE_DIRS})
include_directories(${Qt5Xml_INCLUDE_DIRS})
include_directories(${Qt5Sql_INCLUDE_DIRS})
include_directories(${Qt5DBus_INCLUDE_DIRS})
include_directories(${Qt5Network_INCLUDE_DIRS})
include_directories(${GSTREAMER_INCLUDE_DIRS})
include_directories(${GLIB_INCLUDE_DIRS})
include_directories(${GOBJECT_INCLUDE_DIRS})
include_directories(${GSTREAMER_INCLUDE_DIRS})
include_directories(${GSTREAMER_BASE_INCLUDE_DIRS})
include_directories(${TAGLIB_INCLUDE_DIRS})

include_directories(${CMAKE_SOURCE_DIR}/src)
include_directories(${CMAKE_BINARY_DIR}/src)

add_definitions(${Qt5Core_DEFINITIONS})
add_definitions(${QT_DEFINITIONS})
add_definitions(-DLIB_INSTALL_DIR="${CMAKE_INSTALL_PREFIX}/lib/sayonara")

if(WIN32)
	message("Windows: host Will compile without dbus and shutdown support")

else()
	message("No Windows: Will compile with dbus and shutdown support")
	add_definitions(-DWITH_DBUS)
	add_definitions(-DWITH_SHUTDOWN)
	set(WIN32 0)
endif()

link_directories(${GSTREAMER_LIBRARY_DIRS})

if(WIN32)
	link_directories(${GIO_LIBRARY_DIRS})
elseif(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
	find_library(execinfo_LIB execinfo)
	if(NOT execinfo_LIB)
		message(FATAL_ERROR "FreeBSD requires execinfo library")
	endif()
	set(OS_LIBRARIES ${execinfo_LIB})
endif()


add_subdirectory(Application)
add_subdirectory(GUI)
add_subdirectory(Utils)
add_subdirectory(Database)
add_subdirectory(Interfaces)
add_subdirectory(Components)
add_subdirectory(Languages)
add_subdirectory(3rdParty)

set(SOURCES
	Main.cpp
)

add_executable(${PROJECT_NAME} ${SOURCES} ${QM_FILES})

#file(GLOB_RECURSE HeaderFiles "${CMAKE_CURRENT_SOURCE_DIR}/*.h")
#add_custom_target(headers SOURCES ${HeaderFiles})

if(WIN32)
	set(OS_LIBRARIES
		api-ms-win-core-winrt-l1-1-0
		api-ms-win-core-winrt-string-l1-1-0
		${GIO_LIBRARIES}
	)
endif()


target_link_libraries(${PROJECT_NAME}
	say_application
	say_gui_resources
	say_lang
	${OS_LIBRARIES}
)


if(WIN32)
	install(TARGETS ${PROJECT_NAME} DESTINATION .)
else()
	install(TARGETS ${PROJECT_NAME} DESTINATION bin)
endif()


