cmake_minimum_required(VERSION 3.3 FATAL_ERROR)

project("QuEyeSdiDemo" LANGUAGES CXX)



option(BUILD_WITH_IMAGE_LOAD_BUTTON "Build with the ability to load images. Note: Images with annotations can not be loaded in every manner" OFF)

option(UEYE_BUILD_WITH_QT6  "Use Qt6 instead of Qt5"  OFF)

option(UEYE_BUILD_FORCE_QT6  "Force Qt6"  OFF)



if("${CMAKE_VERSION}" VERSION_GREATER 3.9)

    cmake_policy(SET CMP0071 NEW)

endif()



if ("${CMAKE_VERSION}" VERSION_GREATER 3.11)

    cmake_policy(SET CMP0074 NEW)

endif()



if (WIN32)

    if(CMAKE_SIZEOF_VOID_P EQUAL 8)

        set(PLATFORM_SUFFIX _64)

    endif(CMAKE_SIZEOF_VOID_P EQUAL 8)

endif()



include(_cmake/finder_release.cmake)

link_libraries(ueye_api${PLATFORM_SUFFIX})



set(TARGET_NAME "ueyedemo")

SET(LANG_SUBDIRECTORY "lang/demo")



# -------------------------------------



# includes



include("_cmake/ccache.cmake")

include("_cmake/default_build_type.cmake")



# -------------------------------------



set(SOURCES

    "src/cameralist.cpp"

    "src/eventthread.cpp"

    "src/histogram.cpp"

    "src/ImageInfoDialog.cpp"

    "src/main.cpp"

    "src/mainview.cpp"

    "src/properties.cpp"

    "src/graphicsview.cpp"

    "src/graphicsscene.cpp"

    "src/widgets/qipedit.cpp"

    "src/queyeimage.cpp"

    "src/utils.cpp"

    "src/display.cpp"

    "src/camera.cpp"

    "src/toolbar_display.cpp"

    "src/properties/tab_base.cpp"

    "src/properties/tab_format.cpp"

    "src/properties/tab_hotpixel.cpp"

    "src/properties/tab_image.cpp"

    "src/properties/tab_focus.cpp"

    "src/properties/tab_io.cpp"

    "src/properties/tab_trigger.cpp"

    "src/properties/tab_misc.cpp"

    "src/properties/tab_size.cpp"

    "src/properties/tab_timing.cpp"

    "src/properties/tab_xs.cpp"

    "src/properties/tab_aes_agc.cpp"

    "src/properties/tab_awb.cpp"

    "src/properties/tab_color.cpp"

    "src/properties/tab_lut.cpp"

    "src/properties/tab_network.cpp"

    "src/properties/tab_sequence_aoi.cpp"

    "src/properties/tab_shutter.cpp"

    "src/properties/tab_linescan.cpp"

    "src/widgets/qpropertyslider.cpp"

    "src/widgets/qlistslider.cpp"

    "src/subwindow.cpp"

    "src/intensity.cpp"

        )



set(HEADERS

    "src/cameralist.h"

    "src/eventthread.h"

    "src/histogram.h"

    "src/intensity.h"

    "src/ImageInfoDialog.h"

    "src/mainview.h"

    "src/properties.h"

    "src/graphicsview.h"

    "src/graphicsscene.h"

    "src/version.h"

    "src/queyeimage.h"

    "src/widgets/qipedit.h"

    "src/widgets/qipdot.h"

    "src/utils.h"

    "src/display.h"

    "src/camera.h"

    "src/toolbar_display.h"

    "src/property_class.h"

    "src/properties/tab_base.h"

    "src/properties/tab_format.h"

    "src/properties/tab_hotpixel.h"

    "src/properties/tab_image.h"

    "src/properties/tab_io.h"

    "src/properties/tab_focus.h"

    "src/properties/tab_trigger.h"

    "src/properties/tab_misc.h"

    "src/properties/tab_size.h"

    "src/properties/tab_timing.h"

    "src/properties/tab_xs.h"

    "src/properties/tab_aes_agc.h"

    "src/properties/tab_awb.h"

    "src/properties/tab_color.h"

    "src/properties/tab_lut.h"

    "src/properties/tab_network.h"

    "src/properties/tab_sequence_aoi.h"

    "src/properties/tab_shutter.h"

    "src/properties/tab_linescan.h"

    "src/widgets/qpropertyslider.h"

    "src/widgets/qlistslider.h"

    "src/subwindow.h"

        )



set(FORMS

    "src/ui/properties_format.ui"

    "src/ui/properties_io.ui"

    "src/ui/properties_trigger.ui"

    "src/ui/properties_format.ui"

    "src/ui/properties_xs_features.ui"

    "src/ui/properties_network.ui"

    "src/ui/properties_sequence_aoi.ui"

)



set(RESOURCES

    "mainview.qrc"

)



set(INCLUDES

    "src"

    "include/"

)



# -- Grouping for Visual Studio

source_group(header REGULAR_EXPRESSION ".*\.h")

source_group(header/widgets REGULAR_EXPRESSION "widgets/.*\.h")

source_group(header/properties REGULAR_EXPRESSION "properties/.*\.h")



source_group(src REGULAR_EXPRESSION ".*\.cpp")

source_group(src/widgets REGULAR_EXPRESSION "widgets/.*\.cpp")

source_group(src/properties REGULAR_EXPRESSION "properties/.*\.cpp")



source_group(forms REGULAR_EXPRESSION ".*\.ui")

source_group(forms/props REGULAR_EXPRESSION "properties_.*\.ui")

# -------------------------------------



if(WIN32)

    list(APPEND DEFINITIONS

        "-DNOMINMAX"

    )

    list(APPEND RESOURCES

            "${CMAKE_CURRENT_LIST_DIR}/ueyedemo.rc"

    )

else()

    if (CMAKE_SYSTEM_PROCESSOR MATCHES "^arm")

        message(STATUS "Compiling for arm. Limit signal frame rate to 100/s")

        list(APPEND DEFINITIONS

                -DFRAME_SIGNAL_LIMIT_RATE=100)

    endif()

endif()



if (BUILD_WITH_IMAGE_LOAD_BUTTON)

    list(APPEND DEFINITIONS

            -DWITH_IMAGE_LOAD_BUTTON)

endif()



# -------------------------------------



list(APPEND DEFINITIONS

        -DLANG_INPUT_DIR="${LANG_SUBDIRECTORY}")



set(DEFINITIONS_BUILDTYPE_RELEASE

    "-DNDEBUG"

    "-DQT_NO_DEBUG_OUTPUT"

)



set(DEFINITIONS_BUILDTYPE_DEBUG

    # nil

)



set(DEFINITIONS_BUILDTYPE_RELEASEWITHDEBUG

    "-DQT_NO_DEBUG_OUTPUT"

)



# -------------------------------------



if(CMAKE_BUILD_TYPE MATCHES Debug)

    message(STATUS "[${PROJECT_NAME}] Build Type: Debug")

    list(APPEND DEFINITIONS ${DEFINITIONS_BUILDTYPE_DEBUG})

elseif(CMAKE_BUILD_TYPE MATCHES Release)

    message(STATUS "[${PROJECT_NAME}] Build Type: Release")

    list(APPEND DEFINITIONS ${DEFINITIONS_BUILDTYPE_RELEASE})

elseif(CMAKE_BUILD_TYPE MATCHES RelWithDebInfo)

    message(STATUS "[${PROJECT_NAME}] Build Type: ReleaseWithDebug")

    list(APPEND DEFINITIONS ${DEFINITIONS_BUILDTYPE_RELEASEWITHDEBUG})

else()

    message(STATUS "[${PROJECT_NAME}] Build Type: Default (Release)")

    list(APPEND DEFINITIONS ${DEFINITIONS_BUILDTYPE_RELEASE})

endif()



# -------------------------------------



set(CMAKE_AUTOMOC ON)

set(CMAKE_AUTORCC ON)

set(CMAKE_INCLUDE_CURRENT_DIR ON)



# if Qt is not found on Windows, add -DQt5_ROOT=C:\Qt\5.13.2\msvc2017_64 to your cmake options

# of course you have to adjust the path to your installation

if(UEYE_BUILD_WITH_QT6)

    if(UEYE_BUILD_FORCE_QT6)

        find_package(Qt6 COMPONENTS Widgets REQUIRED)

    else()

        find_package(Qt6 COMPONENTS Widgets)

    endif()

    if(NOT Qt6_FOUND)

        message(STATUS "Can't find Qt6, falling back")

    else()

        set(QT_VERSION_MAJOR 6)

    endif()

endif()



if(NOT Qt6_FOUND)

    find_package(Qt5 COMPONENTS Widgets REQUIRED)

    set(QT_VERSION_MAJOR 5)

endif()



message(STATUS "Found Qt Version ${QT_VERSION_MAJOR}")





find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core Widgets Gui Concurrent REQUIRED)

find_package(Qt${QT_VERSION_MAJOR} COMPONENTS OpenGL LinguistTools QUIET)



if(${QT_VERSION_MAJOR} EQUAL 6)

    qt6_wrap_ui(UI_HEADERS ${FORMS})

else()

    qt5_wrap_ui(UI_HEADERS ${FORMS})

    add_definitions(${Qt5Widgets_DEFINITIONS})

endif()



# -------------------------------------



# Set some Win32 Specific Settings

if(WIN32)

    set(GUI_TYPE WIN32)

endif(WIN32)



add_executable(${TARGET_NAME} ${GUI_TYPE} ${SOURCES} ${RESOURCES} ${HEADERS} ${UI_HEADERS})

target_include_directories(${TARGET_NAME} PRIVATE ${INCLUDES})

target_compile_definitions(${TARGET_NAME} PRIVATE ${DEFINITIONS})

set_target_properties(${TARGET_NAME} PROPERTIES

    C_STANDARD 11

    CXX_STANDARD 11

    C_VISIBILITY_PRESET hidden

    CXX_VISIBILITY_PRESET hidden

)



# -------------------------------------



target_link_libraries(${TARGET_NAME}

        Qt${QT_VERSION_MAJOR}::Widgets

        Qt${QT_VERSION_MAJOR}::Gui

        Qt${QT_VERSION_MAJOR}::Concurrent)



if(${Qt${QT_VERSION_MAJOR}OpenGL_FOUND})

    target_link_libraries(${TARGET_NAME} Qt${QT_VERSION_MAJOR}::OpenGL)

endif()



if(UNIX)

    include("_cmake/post_build_step_strip.cmake")

    POST_BUILD_STEP_TARGET_NAME_STRIP(${TARGET_NAME})

endif()



include(_cmake/install.cmake)

include(_cmake/language.cmake)
