CMake file cannot locate QT Charts module, but installed it

721 Views Asked by At

CMake file will not locate my QtCharts module, but QtCharts is, in theory, installed - here's a proof of it (that's what I get when I open the maintenance tool)

enter image description here

Now, I've been struggling for days to locate them with no success, I will show you my CMakeLists:

cmake_minimum_required(VERSION 3.17)
project(CPP)

set(CMAKE_CXX_STANDARD 14)

include_directories(Console)
include_directories(Domain)
include_directories(Exception)
include_directories(Repository)
include_directories(Service)
include_directories(StartingWidget)
include_directories(Tests)
include_directories(Validator)

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

set(CMAKE_PREFIX_PATH "C:\\Qt\\5.15.2\\mingw81_64\\lib\\cmake")

set(QT_VERSION 5)
set(REQUIRED_LIBS Core Gui Widgets Charts)
set(REQUIRED_LIBS_QUALIFIED Qt5::Core Qt5::Charts Qt5::Gui Qt5::Widgets)



add_executable(CPP main.cpp Domain/Tutorial.cpp Domain/Tutorial.h Repository/Repository.h Service/Service.cpp Service/Service.h Console/Administrator_Console.cpp Console/Administrator_Console.h Validator/Validator.cpp Validator/Validator.h Exception/Exception.cpp Exception/Exception.h Console/User_Console.cpp Console/User_Console.h Tests/RunTests.cpp Tests/RunTests.h Repository/FileRepository.h Repository/CSVRepository.h Repository/CSVRepository.cpp Repository/HTMLRepository.h Repository/HTMLRepository.cpp Console/GUI_Console.cpp Console/GUI_Console.h Console/GUI_User_Console.cpp Console/GUI_User_Console.h StartingWidget/StartingWidget.cpp StartingWidget/StartingWidget.h)
if (NOT CMAKE_PREFIX_PATH)
    message(WARNING "CMAKE_PREFIX_PATH is not defined, you may need to set it "
            "(-DCMAKE_PREFIX_PATH=\"path/to/Qt/lib/cmake\" or -DCMAKE_PREFIX_PATH=/usr/include/{host}/qt{version}/ on Ubuntu)")
endif ()

find_package(Qt${QT_VERSION} COMPONENTS ${REQUIRED_LIBS} REQUIRED)
target_link_libraries(${PROJECT_NAME} ${REQUIRED_LIBS_QUALIFIED})

and the error I get is:

CMake Error at C:/Qt/5.15.2/mingw81_64/lib/cmake/Qt5/Qt5Config.cmake:28 (find_package):
  Could not find a package configuration file provided by "Qt5Charts" with
  any of the following names:

    Qt5ChartsConfig.cmake
    qt5charts-config.cmake

  Add the installation prefix of "Qt5Charts" to CMAKE_PREFIX_PATH or set
  "Qt5Charts_DIR" to a directory containing one of the above files.  If
  "Qt5Charts" provides a separate development package or SDK, be sure it has
  been installed.
Call Stack (most recent call first):
  CMakeLists.txt:33 (find_package)

This is not the first time I get this error, because I had before another CMakeLists which just had include_package(Qt5::Charts) and I would get the same error. I am using Qt 5.15.2, open source (community).

1

There are 1 best solutions below

1
On

I needed to reinstall the QT and use a custom install instead of using the basic 5.12.5 one, because Maintenance tool might be bugged - if someone runs into this, take care and do a reinstall