CLion加载Qt工程的错误处理

今天心血来潮,想优化一下之前写的日志分析工具。打开CLion,加载工程,准备开干,结果CMake报了这样的错误:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
-- Could NOT find Qt6CoreTools (missing: Qt6CoreTools_DIR)
CMake Warning at /Users/***/Qt/6.2.1/macos/lib/cmake/Qt6/Qt6Config.cmake:176 (find_package):
Found package configuration file:

/Users/***/Qt/6.2.1/macos/lib/cmake/Qt6Core/Qt6CoreConfig.cmake

but it set Qt6Core_FOUND to FALSE so package "Qt6Core" is considered to be NOT FOUND.
Call Stack (most recent call first):
src/CMakeLists.txt:1 (find_package)

-- Could NOT find Qt6GuiTools (missing: Qt6GuiTools_DIR)
CMake Warning at /Users/***/Qt/6.2.1/macos/lib/cmake/Qt6/Qt6Config.cmake:176 (find_package):
Found package configuration file:

/Users/***/Qt/6.2.1/macos/lib/cmake/Qt6Gui/Qt6GuiConfig.cmake

but it set Qt6Gui_FOUND to FALSE so package "Qt6Gui" is considered to be NOT FOUND.
Call Stack (most recent call first):
src/CMakeLists.txt:1 (find_package)

因为很长一段时间都没有动过这个工程,期间本地的CLion还升级了几个版本,本地Qt版本也升级过好几次,一时间无法确定是什么原因导致的加载失败。好在使用Qt Creator加载工程不会出现这个问题。趁着灵感还在,在Qt Creator里把代码写了。
完事之后上网搜了一波,没有找到靠谱的答案,但是找到了jerbrains官方的Qt指导
照着指导修改了一些工程配置,发现在设置CMAKE_PREFIX_PATH后,上述报错就消失了。
有遇到相同报错的同学可以先排查一下,检查CMAKE_PREFIX_PATH是否包含${QTDIR}/lib/cmake