easymodo / qimgv

Image viewer. Fast, easy to use. Optional video support.
GNU General Public License v3.0
2.35k stars 167 forks source link

How to force compile on qt6? #478

Closed Gigas002 closed 1 year ago

Gigas002 commented 1 year ago

I have both qt5 and qt6 installed on my linux, but since qimgv forces build on qt5 no matter I have qt6, I wanted to introduce the cmake option for this. I tried introducing the FORCE_QT6 option for CMakeLists.txt like so:

option(FORCE_QT6 "Force qt6 build" OFF)

# FIND PACKAGES

if(FORCE_QT6)
    find_package(QT NAMES Qt6 REQUIRED COMPONENTS Core Widgets Svg PrintSupport OpenGLWidgets)
    find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core Widgets Svg PrintSupport OpenGLWidgets)
else()
    find_package(Qt5 COMPONENTS Widgets QUIET)
    if(Qt5_FOUND)
        find_package(QT NAMES Qt5 REQUIRED COMPONENTS Core Widgets Svg PrintSupport)
    else()
        find_package(QT NAMES Qt6 REQUIRED COMPONENTS Core Widgets Svg PrintSupport OpenGLWidgets)
    endif()
    if(QT_VERSION_MAJOR GREATER_EQUAL 6)
        find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core Widgets Svg PrintSupport OpenGLWidgets)
    else()
        find_package(Qt${QT_VERSION_MAJOR} 5.12 REQUIRED COMPONENTS Core Widgets Svg PrintSupport)
    endif()
endif()

But trying to make it with:

mkdir build && cd build
cmake .. -DKDE_SUPPORT=ON -DCMAKE_BUILD_TYPE=Release -DFORCE_QT6=ON

Results in error:

-- The CXX compiler identification is GNU 13.1.1
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Build configuration: Release
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
-- Found Threads: TRUE  
-- Performing Test HAVE_STDATOMIC
-- Performing Test HAVE_STDATOMIC - Success
-- Found WrapAtomic: TRUE  
-- Found OpenGL: /usr/lib/libOpenGL.so   
-- Found WrapOpenGL: TRUE  
-- Found XKB: /usr/lib/libxkbcommon.so (found suitable version "1.5.0", minimum required is "0.5.0") 
-- Found WrapVulkanHeaders: /usr/include  
-- Qt Version: 6.5.0
-- Found PkgConfig: /usr/bin/pkg-config (found version "1.8.1") 
-- Checking for module 'exiv2'
--   Found exiv2, version 0.27.6
-- Found X11: /usr/include   
-- Looking for XOpenDisplay in /usr/lib/libX11.so;/usr/lib/libXext.so
-- Looking for XOpenDisplay in /usr/lib/libX11.so;/usr/lib/libXext.so - found
-- Looking for gethostbyname
-- Looking for gethostbyname - found
-- Looking for connect
-- Looking for connect - found
-- Looking for remove
-- Looking for remove - found
-- Looking for shmat
-- Looking for shmat - found
-- Looking for IceConnectionNumber in ICE
-- Looking for IceConnectionNumber in ICE - found
-- Found OpenCV: /usr (found version "4.7.0") found components: core imgproc 
-- Checking for module 'mpv'
--   Found mpv, version 2.1.0
-- Configuring done (1.2s)
CMake Error: The INTERFACE_QT_MAJOR_VERSION property of "Qt5::Core" does
not agree with the value of QT_MAJOR_VERSION already determined
for "qimgv".

-- Generating done (0.0s)
CMake Generate step failed.  Build files cannot be regenerated correctly.
zymelaii commented 1 year ago

there is one more CMakeLists.txt with find_package Qt under plugins/player_mpv, do you forget to modify it at the same time? or maybe you can try to explicitly specify -DQT_MAJOR_VERSION=6.

Gigas002 commented 1 year ago

@zymelaii nah, setting QT_MAJOR_VERSION through cli arguments is ignored by cmake. I also tried a message("Qt Version: " ${QT_VERSION}) in a plugins/player_mpv and it sees the qt6, judging by output, so I don't think it's failing out there.

zymelaii commented 1 year ago

then how about QT_DEFAULT_MAJOR_VERSION? https://doc.qt.io/qt-6/cmake-variable-reference.html#qt-default-major-version

Gigas002 commented 1 year ago

Nope, it still ignores the option, either I'm doing something wrong:

$ cmake .. -DKDE_SUPPORT=ON -DCMAKE_BUILD_TYPE=Release -DQT_DEFAULT_MAJOR_VERSION=6
-- The CXX compiler identification is GNU 13.1.1
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Build configuration: Release
-- Qt Version: 5.15.9
-- Found PkgConfig: /usr/bin/pkg-config (found version "1.8.1") 
-- Checking for module 'exiv2'
--   Found exiv2, version 0.27.6
-- Found X11: /usr/include   
-- Looking for XOpenDisplay in /usr/lib/libX11.so;/usr/lib/libXext.so
-- Looking for XOpenDisplay in /usr/lib/libX11.so;/usr/lib/libXext.so - found
-- Looking for gethostbyname
-- Looking for gethostbyname - found
-- Looking for connect
-- Looking for connect - found
-- Looking for remove
-- Looking for remove - found
-- Looking for shmat
-- Looking for shmat - found
-- Looking for IceConnectionNumber in ICE
-- Looking for IceConnectionNumber in ICE - found
-- Found OpenCV: /usr (found version "4.7.0") found components: core imgproc 
-- Checking for module 'mpv'
--   Found mpv, version 2.1.0
-- Configuring done (0.8s)
-- Generating done (0.0s)
CMake Warning:
  Manually-specified variables were not used by the project:

    QT_DEFAULT_MAJOR_VERSION

-- Build files have been written to: /home/gigas/downloads/qimgv/build
zymelaii commented 1 year ago

uhh, i tried it on my arch and both versions of qt completed the build.

here is my devenv

the key difference may lie on the option "KDE_SUPPORT"

qimgv specifies kf5windowsystem and this is from the repo KDE/kwindowsystem, which is now updating to kf6windowsystem.

i guess that kf5windowsystem is built with qt5 while the kf6 is built with qt6. with cmake interface property written to the library target, the kf... lib can only accept the qt with the desired version.

so simply disable KDE_SUPPORT or replace kf5windowsystem with kf6windowsystem to fit qt6 may help.

Gigas002 commented 1 year ago

So that's where the error came from! That's reasonable. Thanks for noticing this, it builds without issues, when excluding KDE_SUPPORT option