cmake_minimum_required(VERSION 3.14)

project(eismultiplexer-qt)

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/")
include(GitVersion)
get_version_from_git()
message("Building version ${PROJECT_VERSION}")

add_compile_definitions(VERSION_MAJOR=${CMAKE_PROJECT_VERSION_MAJOR})
add_compile_definitions(VERSION_MINOR=${CMAKE_PROJECT_VERSION_MINOR})
add_compile_definitions(VERSION_PATCH=${CMAKE_PROJECT_VERSION_PATCH})

message("Platform " ${CMAKE_SYSTEM_NAME})
if(WIN32 AND NOT CMAKE_HOST_SYSTEM_NAME MATCHES "Windows")
	configure_file(${CMAKE_CURRENT_SOURCE_DIR}/scripts/release-win.sh ${CMAKE_CURRENT_BINARY_DIR}/release.sh @ONLY)
	add_custom_target(package
		COMMAND ${CMAKE_CURRENT_BINARY_DIR}/release.sh
		WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
		COMMENT "Createing release archive"
		VERBATIM)
endif(WIN32 AND NOT CMAKE_HOST_SYSTEM_NAME MATCHES "Windows")

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

find_package(PkgConfig REQUIRED)
pkg_check_modules(EISMULIPLEXER REQUIRED eismuliplexer)
find_package(Qt6 REQUIRED COMPONENTS Widgets)
find_package(Qt6 REQUIRED COMPONENTS Core)
find_package(Python3 COMPONENTS Interpreter Development REQUIRED)

set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)

add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/external/QCodeEditor")

add_executable(${PROJECT_NAME}
    main.cpp
    channelwidget.cpp
    channelwidget.h
    mainwindow.h
    mainwindow.cpp
    mainwindow.ui
    multiplexer.h
    multiplexer.cpp
    triggerwidget.cpp
    triggerwidget.h
    pythonrunner.cpp
    pythonrunner.h
    pythonembed.cpp
)
set_target_properties(${PROJECT_NAME} PROPERTIES WIN32_EXECUTABLE ON)
target_compile_options(${PROJECT_NAME} PUBLIC "-Wall")
target_include_directories(${PROJECT_NAME} PUBLIC QCodeEditor)
target_include_directories(${PROJECT_NAME} PRIVATE ${Python3_INCLUDE_DIRS})
target_link_libraries(${PROJECT_NAME} PRIVATE Qt6::Widgets Qt6::Core ${EISMULIPLEXER_LIBRARIES} QCodeEditor ${Python3_LIBRARIES})
set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/resources/eismultiplexerqt.png PROPERTIES QT_RESOURCE_ALIAS eismultiplexerqt.png)
qt_add_resources(${PROJECT_NAME} "resources" PREFIX "/" FILES ${CMAKE_CURRENT_SOURCE_DIR}/resources/eismultiplexerqt.png )
install(TARGETS ${PROJECT_NAME} DESTINATION bin)
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/resources/eismultiplexerqt.desktop DESTINATION share/applications)
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/resources/eismultiplexerqt.png DESTINATION share/icons/hicolor/256x256/apps)
