Skip to content

Draft: Add tests for KDEInstallDirs DATADIR

Julius Künzel requested to merge work/data-dir-test-win into master

KDEInstallDirs has an issue with Qt6 in case find_package(Qt6 ...) is called before include(KDEInstallDirs).

This is visible on Windows where DATAROOTDIR should be bin/data, but is shared in this case. This is a quite serious bug on Windows as - beside potentially affecting content of individual apps like translations - it breaks breeze and hence the themes for all our apps. However I it might affect not only Windows, but also some not yet discovered other situations as well.

This bug only appears with Qt6 ecause different to Qt5 it uses CMake and with CMake GNUInstallDirs as build system.

Everything fine (case 1):

include(KDEInstallDirs)

message("DATAROOTDIR is ${KDE_INSTALL_DATAROOTDIR}")
# DATAROOTDIR is bin/data [On Windows] CORRECT
# DATAROOTDIR is share [On Linux] CORRECT

Bug gets triggered (case 2):

include(GNUInstallDirs)
include(KDEInstallDirs)

message("DATAROOTDIR is ${KDE_INSTALL_DATAROOTDIR}")
# DATAROOTDIR is share [On Windows] WRONG
# DATAROOTDIR is share [On Linux] CORRECT

Looking at the CMake trace the problem is that in case 2 the CMAKE_INSTALL_* vars like CMAKE_INSTALL_DATAROOT="share" are defined by GNUInstallDirs, while in case 1 they aren't.

This is important for the following code in KDEInstallDirsCommon.cmake:

# The next line is line 149 of KDEInstallDirsCommon.cmake
    elseif(${_cmakename}) # TRUE in case 2, FALSE in case 1
        if(_cmakename_is_deprecated)
            message(DEPRECATION "${_cmakename} is deprecated, use KDE_INSTALL_${varname} instead.")
        endif()
        # The CMAKE_ name was given (probably on the command line): move
        # it to the new name
        set(KDE_INSTALL_${varname} "${${_cmakename}}"
            CACHE PATH
                  "${docstring} (${_docpath})"
                  FORCE)
    else() # Executed only in case 1
        # insert an empty value into the cache, indicating the default
        # should be used (including compatibility vars above)
        set(KDE_INSTALL_${varname} ""
            CACHE PATH "${docstring} (${_docpath})")
        set(KDE_INSTALL_${varname} "${_realpath}")
    endif()

Hence set(KDE_INSTALL_DATAROOTDIR CMAKE_INSTALL_DATAROOTDIR ...) is called which sets KDE_INSTALL_DATAROOTDIR to "share" independent of the platform logic in ECM.

Edited by Julius Künzel

Merge request reports