cmake_minimum_required(VERSION 3.16)

project(ChartKitDemoCode LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_AUTOMOC ON)

find_package(Qt5 REQUIRED COMPONENTS Core Gui Widgets Svg Charts)

add_executable(ChartKitDemo main.cpp)

target_compile_definitions(ChartKitDemo PRIVATE BUILD_STATIC ZIP_STD WIN32_LEAN_AND_MEAN)
target_include_directories(ChartKitDemo PRIVATE
    ${CMAKE_CURRENT_LIST_DIR}/../include
    ${CMAKE_CURRENT_LIST_DIR}/../include/UIGearsQtChartLib
    ${CMAKE_CURRENT_LIST_DIR}/../include/UIGearsQtLib
)
target_link_libraries(ChartKitDemo PRIVATE
    ${CMAKE_CURRENT_LIST_DIR}/../lib/UIGearsQtChartLib.lib
    ${CMAKE_CURRENT_LIST_DIR}/../lib/UIGearsQtLib.lib
    Qt5::Core Qt5::Gui Qt5::Widgets Qt5::Svg Qt5::Charts
)

if(WIN32)
    target_link_libraries(ChartKitDemo PRIVATE opengl32)
endif()

if(MSVC)
    target_compile_options(ChartKitDemo PRIVATE /W3 /MP /utf-8)
endif()

set_target_properties(ChartKitDemo PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)

file(GLOB TRIAL_RUNTIME_DLLS ${CMAKE_CURRENT_LIST_DIR}/../bin/*.dll)
if(TRIAL_RUNTIME_DLLS)
    add_custom_command(TARGET ChartKitDemo POST_BUILD
        COMMAND ${CMAKE_COMMAND} -E copy_if_different ${TRIAL_RUNTIME_DLLS} $<TARGET_FILE_DIR:ChartKitDemo>
    )
endif()

foreach(runtime_dir platforms imageformats iconengines styles)
    if(EXISTS ${CMAKE_CURRENT_LIST_DIR}/../bin/${runtime_dir})
        add_custom_command(TARGET ChartKitDemo POST_BUILD
            COMMAND ${CMAKE_COMMAND} -E copy_directory
                ${CMAKE_CURRENT_LIST_DIR}/../bin/${runtime_dir}
                $<TARGET_FILE_DIR:ChartKitDemo>/${runtime_dir}
        )
    endif()
endforeach()
