Skip to content

ECMGenerateExportHeader: add USE_VERSION_HEADER arg (& related tune args)

Alternative to !337 (closed). Instead of introducing a generic solution with currently only one use-case in KDE software, this MR proposes a specific solution for the desire to integrate the version header with the export header.

It is built on the idea that the header with the export macros and the deprecation macros is about the public interface of a library and the features (i.e. API) is provides. The version info is the related metainfo that is used to query which features/API is available. It is already used during calculations in the deprecation macros for which deprecated API by default gets compiler warnings and which is made invisible, just is not officially exposed by a separate macro.

Tnis MR adds the option to include a version header to implicitly include it also for any consumers of the export header and thus also making the respective version macros available. Additionally, to give this some more meaning, the export header uses the imported version macro instead of own calculated version value. The latter makes the generated code more understandable when humans look at it, but otherwise no real difference.

Example (before):

set(include_version_header_code "#include <kcoreaddons_version.h>\n")
ecm_generate_export_header(KF6CoreAddons
    BASE_NAME KCoreAddons
    GROUP_BASE_NAME KF
    VERSION ${KF_VERSION}
    DEPRECATED_BASE_VERSION 0
    EXCLUDE_DEPRECATED_BEFORE_AND_AT ${EXCLUDE_DEPRECATED_BEFORE_AND_AT}
    CUSTOM_CONTENT_FROM_VARIABLE include_version_header_code
)

Example (with USE_VERSION_HEADER, matching base name):

ecm_generate_export_header(KF6CoreAddons
    BASE_NAME KCoreAddons
    GROUP_BASE_NAME KF
    VERSION ${KF_VERSION}
    USE_VERSION_HEADER
    DEPRECATED_BASE_VERSION 0
    EXCLUDE_DEPRECATED_BEFORE_AND_AT ${EXCLUDE_DEPRECATED_BEFORE_AND_AT}
)

Example (with USE_VERSION_HEADER, not matching base name):

ecm_generate_export_header(KF6KIOCore
    BASE_NAME KIOCore
    GROUP_BASE_NAME KF
    VERSION ${KF_VERSION}
    USE_VERSION_HEADER kio_version.h
    VERSION_MACRO_NAME KIO_VERSION
    DEPRECATED_BASE_VERSION 0
    EXCLUDE_DEPRECATED_BEFORE_AND_AT ${EXCLUDE_DEPRECATED_BEFORE_AND_AT}
)

Example (with USE_VERSION_HEADER & VERSION_BASE_NAME, not matching base name):

ecm_generate_export_header(KF6KIOCore
    BASE_NAME KIOCore
    GROUP_BASE_NAME KF
    VERSION ${KF_VERSION}
    USE_VERSION_HEADER
    VERSION_BASE_NAME KIO
    DEPRECATED_BASE_VERSION 0
    EXCLUDE_DEPRECATED_BEFORE_AND_AT ${EXCLUDE_DEPRECATED_BEFORE_AND_AT}
)

Example (Qt5/KF5 & Qt6/KF6, also older ECM):

if (QT_MAJOR_VERSION STREQUAL "5")
    set(_generate_export_header_version_args)
else()
    # For Qt6/KF6 world transitively include the version header 
    if(ECM_VERSION VERSION_LESS "5.105")
        set(include_version_header_code "#include <kdegames_version.h>\n")
        set(_generate_export_header_version_args CUSTOM_CONTENT_FROM_VARIABLE include_version_header_code)
    else()
        set(_generate_export_header_version_args USE_VERSION_HEADER)
    endif()
endif()
ecm_generate_export_header(KF5KDEGames
    EXPORT_FILE_NAME libkdegames_export.h
    BASE_NAME KDEGAMES
    VERSION ${KDEGAMES_VERSION}
    DEPRECATED_BASE_VERSION 0
    EXCLUDE_DEPRECATED_BEFORE_AND_AT ${EXCLUDE_DEPRECATED_BEFORE_AND_AT}
    ${_generate_export_header_version_args}
)
Edited by Friedrich W. H. Kossebau

Merge request reports

Loading