Integration of Conan 2 and Qt6

123 views Asked by At

I'm trying to integrate Conan 2 and Qt6 into a study project, but I'm getting an error when starting the build.

Conan file:

[requires]
qt/6.6.1

[generators]
CMakeDeps
CMakeToolchain

[layout]
cmake_layout

Conan profile:

[settings]
arch=x86_64
build_type=Release
compiler=msvc
compiler.cppstd=17
compiler.runtime=dynamic
compiler.version=193
os=Windows

CmakeLists.txt:

cmake_minimum_required(VERSION 3.5)

set(TARGET_NAME test)
set(QT_VERSION_MAJOR 6)

project(${TARGET_NAME} VERSION 0.1 DESCRIPTION "test qt")

set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets)

add_executable(${TARGET_NAME}
    main.cpp
)

if(MSVC)
    target_compile_options(${TARGET_NAME} PRIVATE /W4 /WX)
else()
    target_compile_options(${TARGET_NAME} PRIVATE -Wall -Wextra -pedantic -Werror)
endif()

target_link_libraries(${TARGET_NAME} PRIVATE Qt${QT_VERSION_MAJOR}::Widgets)

My commands sequence:

conan install . --build=missing
cd build
cmake ..

And I got this error:

CMake Error at CMakeLists.txt:15 (find_package):
  By not providing "FindQt6.cmake" in CMAKE_MODULE_PATH this project has
  asked CMake to find a package configuration file provided by "Qt6", but
  CMake did not find one.

  Could not find a package configuration file provided by "Qt6" with any of
  the following names:

    Qt6Config.cmake
    qt6-config.cmake

  Add the installation prefix of "Qt6" to CMAKE_PREFIX_PATH or set "Qt6_DIR"
  to a directory containing one of the above files.  If "Qt6" provides a
  separate development package or SDK, be sure it has been installed.


-- Configuring incomplete, errors occurred!

How do I fix this?

1

There are 1 answers

0
Piotr Gaczkowski On

With Conan 2, there's a different invocation that you need to use as I learned the hard way.

In the source directory, run conan install . --output-folder=build --build=missing and then cd build and invoke CMake,