cmake_minimum_required(VERSION 3.8)
project(sayonara)

include(${CMAKE_SOURCE_DIR}/cmake/UnixEnvironment.cmake)

include_directories(${CMAKE_CURRENT_SOURCE_DIR})
include_directories(${CMAKE_CURRENT_BINARY_DIR})

# absolute linker paths are no longer supoorted in -l parameter
# use -L for path and -l for library itself
if(POLICY CMP0003)
	cmake_policy(SET CMP0003 NEW)
endif()

# no more escaping of preprocessor definitions
if(POLICY CMP0005)
	cmake_policy(SET CMP0005 NEW)
endif()

# Run Automoc/Autouic over autogenerated source files (e.g. from qrc files)
if(POLICY CMP0071)
	cmake_policy(SET CMP0071 NEW)
endif()

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()

# Macros.h.in
set(SAYONARA_WITH_DBUS 1)
set(SAYONARA_WITH_SHUTDOWN 1)

configure_file(Macros.h.in "${CMAKE_CURRENT_BINARY_DIR}/Utils/Macros.h" @ONLY)

set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC OFF)
set(CMAKE_INCLUDE_CURRENT_DIR ON)

add_subdirectory(Application)
add_subdirectory(Components)
add_subdirectory(Database)
add_subdirectory(DBus)
add_subdirectory(Interfaces)
add_subdirectory(Gui)
add_subdirectory(Languages)
add_subdirectory(Utils)

qt5_add_resources(DATABASE_RCC
	${CMAKE_CURRENT_SOURCE_DIR}/../resources/Database.qrc
	${CMAKE_CURRENT_SOURCE_DIR}/../resources/Resources.qrc
)

add_executable(${PROJECT_NAME} Main.cpp ${QM_FILES} ${DATABASE_RCC})

target_link_libraries(${PROJECT_NAME}
	sayonara_application
	sayonara_languages

	${OS_LIBRARIES}
)

add_executable("create-database" CreateDB.cpp ${DATABASE_RCC})
target_link_libraries("create-database"
	sayonara_utils
	sayonara_database
	Qt5::Widgets
)

install(TARGETS ${PROJECT_NAME} DESTINATION bin)
