在Qt5.15和Qt6.2都存在的环境下,使用CMake构建下面的CMakeLists.txt报错
已报QTBUG,被关了,说这个CMakeLists.txt有
问题,使用了“Qt5和Qt5”在链接语句里,不过我并没看出来问题出在哪里,也没明白他说的“Qt5和Qt5”是什么意思
https://bugreports.qt.io/browse/QTBUG-97097代码如下
- cmake_minimum_required(VERSION 3.20)
- if ( NOT ( ( CMAKE_GENERATOR MATCHES "Makefiles" ) OR ( CMAKE_GENERATOR MATCHES "Ninja" ) ) )
- message(FATAL_ERROR "We only support makefile and ninja generator.")
- endif()
- project(TestProject
- VERSION 0.10.3
- )
- find_package(Qt5 COMPONENTS Core Multimedia) # Locate the position of Qt5.
- find_package(Qt6 COMPONENTS Core OPTIONAL_COMPONENTS Multimedia) # Locate the position of Qt6.
- if (NOT (Qt5_FOUND OR Qt6_FOUND))
- message(FATAL_ERROR "at least one of Qt 5 and Qt 6 is needed")
- endif()
- if (Qt5_FOUND)
- if (NOT ANDROID)
- add_executable(TestProgram WIN32 MACOSX_BUNDLE main.cpp )
- else()
- add_library(TestProgram MODULE main.cpp )
- endif()
- set_property(TARGET TestProgram PROPERTY AUTOMOC ON)
- set_property(TARGET TestProgram PROPERTY AUTOUIC ON)
- set_property(TARGET TestProgram PROPERTY AUTORCC ON)
- target_compile_definitions(TestProgram PUBLIC QT_DISABLE_DEPRECATED_BEFORE=0x60000)
- target_link_libraries (TestProgram Qt5::Core Qt5::Multimedia)
- if (NOT WIN32)
- target_link_libraries(TestProgram dl)
- endif()
- endif()
- if (Qt6_FOUND)
- add_executable (Test6Program WIN32 MACOSX_BUNDLE main.cpp )
- set_property(TARGET Test6Program PROPERTY AUTOMOC ON)
- set_property(TARGET Test6Program PROPERTY AUTOUIC ON)
- set_property(TARGET Test6Program PROPERTY AUTORCC ON)
- target_compile_definitions(Test6Program PUBLIC QT_DISABLE_DEPRECATED_BEFORE=0x70000)
- target_link_libraries(Test6Program Qt6::Core)
- if (Qt6Multimedia_FOUND)
- target_link_libraries (Test6Program Qt6::Multimedia)
- endif()
-
- if (NOT WIN32)
- target_link_libraries(Test6Program dl)
- endif()
- endif()
- D:\test>cmake -GNinja -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH="D:\qqt\5.15.2\msvc2019_64;D:\qqt\6.2.0\msvc2019_64" .
- – The C compiler identification is MSVC 19.29.30133.0
- – The CXX compiler identification is MSVC 19.29.30133.0
- – Detecting C compiler ABI info
- – Detecting C compiler ABI info - done
- – Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe - skipped
- – Detecting C compile features
- – Detecting C compile features - done
- – Detecting CXX compiler ABI info
- – Detecting CXX compiler ABI info - done
- – Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe - skipped
- – Detecting CXX compile features
- – Detecting CXX compile features - done
- – Looking for pthread.h
- – Looking for pthread.h - not found
- – Found Threads: TRUE
- – Check if linker can resolve circular dependencies - TRUE
- – Performing Test HAVE_STDATOMIC
- – Performing Test HAVE_STDATOMIC - Success
- – Found WrapAtomic: TRUE
- – Could NOT find WrapVulkanHeaders (missing: Vulkan_INCLUDE_DIR)
- – Could NOT find OpenSSL, try to set the path to OpenSSL root folder in the system variable OPENSSL_ROOT_DIR (missing: OPENSSL_CRYPTO_LIBRARY OPENSSL_INCLUDE_DIR)
- – Could NOT find WrapOpenSSLHeaders (missing: OPENSSL_INCLUDE_DIR)
- – Configuring done
- CMake Error: The INTERFACE_QT_MAJOR_VERSION property of "Qt5::Core" does
- not agree with the value of QT_MAJOR_VERSION already determined
- for "Test6Program".
- – Generating done
- CMake Generate step failed. Build files cannot be regenerated correctly.
- D:\test>