# This file is part of c-evo-evo.
#
# This software is governed by the CeCILL license under French law and
# abiding by the rules of distribution of free software. You can use,
# modify and/or redistribute the software under the terms of the CeCILL
# license as circulated by CEA, CNRS and INRIA at the following URL
# "http://www.cecill.info".
#
# As a counterpart to the access to the source code and rights to copy,
# modify and redistribute granted by the license, users are provided only
# with a limited warranty and the software's author, the holder of the
# economic rights, and the successive licensors have only limited
# liability.
#
# In this respect, the user's attention is drawn to the risks associated
# with loading, using, modifying and/or developing or reproducing the
# software by the user in light of its specific status of free software,
# that may mean that it is complicated to manipulate, and that also
# therefore means that it is reserved for developers and experienced
# professionals having in-depth computer knowledge. Users are therefore
# encouraged to load and test the software's suitability as regards their
# requirements in conditions enabling the security of their systems and/or
# data to be ensured and, more generally, to use and operate it in the
# same conditions as regards security.
#
# The fact that you are presently reading this means that you have had
# knowledge of the CeCILL license and that you accept its terms.

# DpiWidgets: Qt Widgets equivalent of the Lazarus/Delphi "DpiControls"
# package found at ../../cevo/Packages/DpiControls. It provides a Dpi::
# namespace of thin wrappers around Qt widgets, following the same unit
# breakdown (Common, Graphics, PixelPointer, Controls, Forms, StdCtrls,
# ExtCtrls, ComCtrls, Grids, Menus, Spin), to ease porting the C-evo UI code.

find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets)

set(DPI_WIDGETS_HEADERS
    include/Dpi/DpiCommon.h
    include/Dpi/DpiPixelPointer.h
    include/Dpi/DpiGraphics.h
    include/Dpi/DpiControls.h
    include/Dpi/DpiForms.h
    include/Dpi/DpiStdCtrls.h
    include/Dpi/DpiExtCtrls.h
    include/Dpi/DpiComCtrls.h
    include/Dpi/DpiGrids.h
    include/Dpi/DpiMenus.h
    include/Dpi/DpiSpin.h
    include/Dpi/DpiWidgets.h
)

set(DPI_WIDGETS_SOURCES
    src/DpiCommon.cpp
    src/DpiPixelPointer.cpp
    src/DpiGraphics.cpp
    src/DpiControls.cpp
    src/DpiForms.cpp
    src/DpiStdCtrls.cpp
    src/DpiExtCtrls.cpp
    src/DpiComCtrls.cpp
    src/DpiGrids.cpp
    src/DpiMenus.cpp
    src/DpiSpin.cpp
)

add_library(dpiwidgets SHARED ${DPI_WIDGETS_SOURCES} ${DPI_WIDGETS_HEADERS})

target_include_directories(dpiwidgets PUBLIC
    ${CMAKE_CURRENT_SOURCE_DIR}/include
)

target_link_libraries(dpiwidgets PUBLIC Qt${QT_VERSION_MAJOR}::Widgets)

set_target_properties(dpiwidgets PROPERTIES
    AUTOMOC ON
    CXX_STANDARD 17
    CXX_STANDARD_REQUIRED ON
)

# CevoWidgets: Qt equivalent of the C-evo-specific "CevoComponents" package
# (../../cevo/Packages/CevoComponents), built on top of Dpi:: above. Provides
# a Cevo:: namespace (Area, ButtonBase/A/B/C/G/N, EOTButton, ListBoxEx,
# DrawDlg/BaseMessgDlg, BufferedDrawDlg/FramedDlg, GraphicSet, Texture,
# ScreenTools' drawing helpers). Directories, StringTables, AsyncProcess2 and
# Sound are not ported: they are plain platform/data utilities (QProcess
# already covers AsyncProcess2's job; Sound is superseded by ../media).

set(CEVO_WIDGETS_HEADERS
    include/Cevo/CevoArea.h
    include/Cevo/CevoBaseWin.h
    include/Cevo/CevoButtonA.h
    include/Cevo/CevoButtonB.h
    include/Cevo/CevoButtonBase.h
    include/Cevo/CevoButtonC.h
    include/Cevo/CevoButtonG.h
    include/Cevo/CevoButtonN.h
    include/Cevo/CevoDrawDlg.h
    include/Cevo/CevoEOTButton.h
    include/Cevo/CevoGraphicSet.h
    include/Cevo/CevoListBoxEx.h
    include/Cevo/CevoScreenTools.h
    include/Cevo/CevoTexture.h
    include/Cevo/CevoWidgets.h
)

set(CEVO_WIDGETS_SOURCES
    src/CevoArea.cpp
    src/CevoBaseWin.cpp
    src/CevoButtonA.cpp
    src/CevoButtonB.cpp
    src/CevoButtonBase.cpp
    src/CevoButtonC.cpp
    src/CevoButtonG.cpp
    src/CevoButtonN.cpp
    src/CevoDrawDlg.cpp
    src/CevoEOTButton.cpp
    src/CevoGraphicSet.cpp
    src/CevoListBoxEx.cpp
    src/CevoScreenTools.cpp
    src/CevoTexture.cpp
)

add_library(cevowidgets SHARED ${CEVO_WIDGETS_SOURCES} ${CEVO_WIDGETS_HEADERS})

target_include_directories(cevowidgets PUBLIC
    ${CMAKE_CURRENT_SOURCE_DIR}/include
)

target_link_libraries(cevowidgets PUBLIC dpiwidgets Qt${QT_VERSION_MAJOR}::Widgets)

set_target_properties(cevowidgets PROPERTIES
    AUTOMOC ON
    CXX_STANDARD 17
    CXX_STANDARD_REQUIRED ON
)

include(GNUInstallDirs)
install(TARGETS dpiwidgets cevowidgets
    LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}/c-evo-evo
    RUNTIME DESTINATION ${CMAKE_INSTALL_LIBDIR}/c-evo-evo
)
