view CmakeLists.txt @ 2:177f640940f2

Update exception class and cleanup redifinitions During firmware download and exception caused the application to stop. Rootcause was the defference between QT5 and QT6 exception and string handling which is updated now. In addition some old definitions were removed to avoid compiler warnings.
author Ideenmodellierer
date Fri, 28 Nov 2025 19:57:35 +0100
parents 0b3630a29ad8
children e30f00f760d3
line wrap: on
line source

cmake_minimum_required(VERSION 3.21)

project(OSTCCompanion VERSION 1.0 LANGUAGES CXX)

project(OSTCCompanion LANGUAGES CXX)

# ----------------------------------------
# C++ Standard
# ----------------------------------------
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)

# ----------------------------------------
# Qt6 Modules
# ----------------------------------------
find_package(Qt6 REQUIRED COMPONENTS
    Core
    Gui
    Widgets
    Network
    Svg
    Xml
    SerialPort
    LinguistTools
)


# ----------------------------------------
# Sources, Header, UI and Ressources
# ----------------------------------------
set(SOURCES
    main.cpp
    AES/rijndael.cpp
    editlogdialog.cpp
    Utils/Exception.cpp
    Utils/Log.cpp
    Utils/LogAppender.cpp
    Utils/LogConsole.cpp
    Utils/LogFile.cpp
    Utils/ProgressEvent.cpp
    MainWindow.cpp
    Serial.cpp
    HexFile.cpp
    SettingsDialog.cpp
    HardwareOperations.cpp
    OSTCFrogOperations.cpp
    OSTCSportOperations.cpp
    OSTC2cOperations.cpp
    OSTC2Operations.cpp
    OSTC3Operations.cpp
    OSTC3pOperations.cpp
    OSTC4Operations.cpp
    OSTC_CR_Operations.cpp
)

set(HEADERS
    AES/rijndael.h
    AES/Adler16.h
    Utils/Exception.h
    Utils/Log.h
    Utils/LogAppender.h
    Utils/LogConsole.h
    Utils/LogFile.h
    Utils/ProgressEvent.h
    MainWindow.h
    Serial.h
    HexFile.h
    SettingsDialog.h
    HardwareOperations.h
    OSTCFrogOperations.h
    OSTCSportOperations.h
    OSTC2cOperations.h
    OSTC2Operations.h
    OSTC3Operations.h
    OSTC3pOperations.h
    OSTC4Operations.h
    OSTC_CR_Operations.h
    editlogdialog.h
    ui_LogEditor.h
)

set(UIS
    LogEditor.ui
    MainWindow.ui
    Settings.ui
)

set(RESOURCES
    Resources.qrc
    icon.rc
)

set(TRANSLATIONS
    Translations/companion_DE.ts
    Translations/companion_FR.ts
    Translations/companion_ES.ts
    Translations/companion_IT.ts
    Translations/companion_RU.ts
)

set(app_icon_resource_windows "${CMAKE_CURRENT_SOURCE_DIR}/icon.rc")

# ----------------------------------------
# Executable erstellen
# ----------------------------------------
qt_add_executable(${PROJECT_NAME}
    ${SOURCES}
    ${HEADERS}
    ${UIS}
    ${RESOURCES}
    Utils/Export.h
    ${app_icon_resource_windows}
)

target_include_directories(${PROJECT_NAME} PRIVATE
    ${CMAKE_CURRENT_SOURCE_DIR}       # Root
    ${CMAKE_CURRENT_SOURCE_DIR}/Utils
    ${CMAKE_CURRENT_SOURCE_DIR}/AES
)

# ----------------------------------------
# Qt Libraries verlinken
# ----------------------------------------
target_link_libraries(${PROJECT_NAME}
    PRIVATE Qt6::Core Qt6::Gui Qt6::Widgets Qt6::Network Qt6::Svg Qt6::Xml Qt6::SerialPort
)

# ----------------------------------------
# Plattform-spezifische Anpassungen
# ----------------------------------------
if(WIN32)
    target_compile_definitions(${PROJECT_NAME} PRIVATE _CRT_SECURE_NO_WARNINGS=1 BUILDING_OSTC_COMPANION)
elseif(APPLE)
    target_compile_options(${PROJECT_NAME} PRIVATE -std=c++11 -Wno-inconsistent-missing-override)
elseif(UNIX)
    target_compile_options(${PROJECT_NAME} PRIVATE -std=c++11)
    set_target_properties(${PROJECT_NAME} PROPERTIES
        BUILD_RPATH "\$ORIGIN/lib"
    )
endif()

# ----------------------------------------
# Debug/Release-Builds
# ----------------------------------------
if(CMAKE_BUILD_TYPE MATCHES Debug)
    target_compile_definitions(${PROJECT_NAME} PRIVATE DEBUG=1)
endif()

# ----------------------------------------
# Version aus Datei einlesen (optional)
# ----------------------------------------
file(STRINGS "${CMAKE_SOURCE_DIR}/VERSION.txt" VERSION_CONTENT)
string(REGEX MATCH "MAJOR=([0-9]+)" _ ${VERSION_CONTENT})
set(MAJOR_VERSION ${CMAKE_MATCH_1})
string(REGEX MATCH "MINOR=([0-9]+)" _ ${VERSION_CONTENT})
set(MINOR_VERSION ${CMAKE_MATCH_1})
string(REGEX MATCH "PATCH=([0-9]+)" _ ${VERSION_CONTENT})
set(PATCH_VERSION ${CMAKE_MATCH_1})
string(REGEX MATCH "BETA=([0-9]+)" _ ${VERSION_CONTENT})
set(BETA_VERSION ${CMAKE_MATCH_1})


message("MAJOR_VERSION = '${MAJOR_VERSION}'")

target_compile_definitions(${PROJECT_NAME} PRIVATE
    MAJOR_VERSION=${MAJOR_VERSION}
    MINOR_VERSION=${MINOR_VERSION}
    PATCH_VERSION=${PATCH_VERSION}
    BETA_VERSION=${BETA_VERSION}
)

# Show folder in Qt Creator
file(GLOB ICON_FILES "${CMAKE_SOURCE_DIR}/Images/*")
add_custom_target(Resources ALL SOURCES ${ICON_FILES})


qt6_add_translation(QM_FILES ${TRANSLATIONS})

if(CMAKE_BUILD_TYPE MATCHES Release)
    target_compile_definitions(${PROJECT_NAME} PRIVATE DEBUG=1)

    message("Build release and installer")

    set(CPACK_IFW_PACKAGE_ICON "${CMAKE_SOURCE_DIR}/Images/inst_OSTC_Companion.ico")

    install(FILES ${CMAKE_SOURCE_DIR}/Images/app_OSTC_Companion.ico
            DESTINATION .          # relativ zum Package root
            COMPONENT Core)

    install(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION bin COMPONENT Core)

    qt_generate_deploy_app_script(
        TARGET ${PROJECT_NAME}
        OUTPUT_SCRIPT deploy_script
        NO_UNSUPPORTED_PLATFORM_ERROR
    )

    install(SCRIPT ${deploy_script}
        COMPONENT Core)

    # CPack IFW Konfiguration
    set(CPACK_GENERATOR "IFW")
    set(CPACK_IFW_ROOT "D:/Programme/QT/Tools/QtInstallerFramework/4.10")
    set(CPACK_PACKAGE_VERSION_MAJOR "3")
    set(CPACK_PACKAGE_VERSION_MINOR "3")
    set(CPACK_PACKAGE_NAME "${PROJECT_NAME}")
    set(CPACK_PACKAGE_VENDOR "Heinrichs Weikamp")
    set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "OSTC Companion Application")
    set (CPACK_IFW_PACKAGE_NAME "${PROJECT_NAME} 3.3.1")
    set (CPACK_IFW_PACKAGE_TITLE "${PROJECT_NAME} Installer")
    set (CPACK_IFW_PACKAGE_PUBLISHER "Heinrichs Weikamp")
    set (CPACK_IFW_PACKAGE_WIZARD_STYLE "Modern")
    set (CPACK_IFW_PACKAGE_WIZARD_SHOW_PAGE_LIST OFF)

    set (CPACK_IFW_PACKAGE_START_MENU_DIRECTORY "OSTC-Tools")

    include(CPack)
    include(CPackIFW)

    # Hauptkomponente
    cpack_add_component(Core
        DISPLAY_NAME "OSTC Companion"
        DESCRIPTION "OSTC maintenance application"
        REQUIRED
    )

    cpack_ifw_configure_component(Core ESSENTIAL FORCED_INSTALLATION)
endif()