如何让cmake在设置Dir后提升一个级别

我有这个由CLion生成的cmake文本文件用于测试,使用CLion作为编辑器,使用Qt作为小部件集。我有了here的想法。

在我的CMakeLists.txt中,我有:

cmake_minimum_required(VERSION 3.19)
project(Qt_Test)

set(CMAKE_CXX_STANDARD 20)

# Tell cmake where Qt is located
set(Qt6_DIR "/home/fmc/Qt/6.0.0/gcc_64/lib/cmake/Qt6")

# Tell cmake to find the modules Qt6Core and Qt6widgets
find_package(Qt6 COMPONENTS Core Widgets REQUIRED)

add_executable(Qt_Test main.cpp)    

我的问题是Qt安装的CoreWidgets都是安装在/home/fmc/Qt/6.0.0/gcc_64/lib/cmake上的

使用现在的CMake,我得到了以下错误:

CMake Error at CMakeLists.txt:10 (find_package):
  Found package configuration file:

    /home/fmc/Qt/6.0.0/gcc_64/lib/cmake/Qt6/Qt6Config.cmake

  but it set Qt6_FOUND to FALSE so package "Qt6" is considered to be NOT
  FOUND.  Reason given by package:

  Failed to find Qt component "Core" config file at ""

  Failed to find Qt component "Widgets" config file at ""

有没有办法直接设置组件所需的/home/fmc/Qt/6.0.0/gcc_64/lib/cmake,而不影响/home/fmc/Qt/6.0.0/gcc_64/lib/cmake/Qt6的设置?

转载请注明出处:http://www.ahddzj.com/article/20230526/1007596.html