无法制作柯南+ cmake+ QT一起工作。未找到目标的有效QT版本

发布于 2025-02-10 23:15:58 字数 744 浏览 3 评论 0原文

当我设置设置(cmake_automoc on) cmake说

src/projqt/cmakelists.txt中的cmake警告(dev):autogen:否 针对目标ProJQT找到的有效QT版本。汽车禁用。 考虑添加:

  find_package(qt< qtversion>组件核心)
 

到您的cmakelists.txt文件。

如果我添加find_package(qt5组件核心) set> set(cmake_automoc on)

cmake警告在src/projqt/cmakelists.txt:5(find_package):
通过在cmake_module_path中不提供“ findqt5.cmake”,该项目具有
要求Cmake查找“ QT5”提供的软件包配置文件,
但是Cmake找不到一个。
...

我认为柯南提供了一个自定义find_package首先与柯南相关的行为,然后如果失败,则默认情况下,但看起来它并不像vcpkg一样提供它,就像vcpkg一样,

所有这些操作都在inclage($ {$ {cmake_binary_dir}/conanbuildinfo.cmake)

When I set set(CMAKE_AUTOMOC ON) cmake says

CMake Warning (dev) in src/ProjQt/CMakeLists.txt: AUTOGEN: No
valid Qt version found for target ProjQt. AUTOMOC disabled.
Consider adding:

find_package(Qt<QTVERSION> COMPONENTS Core)

to your CMakeLists.txt file.

If I add find_package(Qt5 COMPONENTS Core) before set(CMAKE_AUTOMOC ON)

CMake Warning at src/ProjQt/CMakeLists.txt:5 (find_package):
By not providing "FindQt5.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "Qt5",
but CMake did not find one.
...

I thought conan provides a custom find_package which behaviour is conan-related first, then default if failed but it looks like it doesn't provide it like vcpkg does

All these actions are done after include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

煮茶煮酒煮时光 2025-02-17 23:15:58

我又遇到了同一问题,这就是我设法修复它的方式:

  1. 设置适当的Conan Generator来生成所需的config cmake文件,
  • 我使用generator =“ cmake_find_package_multi”,如这个问题
  1. “ https://github.com/conan-io/conan-center-index/issues/6251#issuecomment-877777303859” rel = 全部&lt; pkg&gt; config/target.cmake files(在我的情况下),我们需要指向cmake在 noreflow noreferrer“> conan docs” “>”
  2. https://cmake.org/cmake/help/v3.0/variable/cmake_prefix_path.html“ rel =” cmake docs中的nofollow noreferrer > autouic 和autorcc应该与此配置一起使用:
find_package(Qt5 CONFIG REQUIRED)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC ON)

稍后我遇到了两种类型的不同问题……


AutoMoc error
-------------
"SRC:/src/<thisfilename>.cpp"
contains a "Q_OBJECT" macro, but does not include "<thisfilename>.moc"!
Consider to
  - add #include "<thisfilename>.moc"
  - enable SKIP_AUTOMOC for this file

这是通过移动q_object class解决的解决方案。进入标题或添加#include&lt; thisfilename.moc&gt;在类下方,cmake会自动填充该文件的直接路径而无需嵌套路径。例如,如果我有一个称为“ test.cpp”的文件,我必须这样做:

#include <QObject>

class TestObject : public QObject
{
    Q_OBJECT
};

#include <test.moc>

链接器错误,未解决的引用对metaObjectqt_metacastqt_metacall,等等……
在这种情况下,这意味着MOC的生成源代码未添加到汇编中。
它可以通过添加标头文件以及.cpp文件在add_executable中解决

file(GLOB SOURCES
    include/*.h
    src/*.cpp
)
add_executable(${PROJECT_NAME} ${SOURCES})

。 生成MOC的

q_object中, 另一种修复方法是修复它的另一种解决方法是在#include&lt; moc_thisfilename.cpp&gt;中。
test.hpp

#include <QObject>

class TestObject : public QObject
{
    Q_OBJECT
};

test.cpp

#include <test.hpp>
#include <moc_test.cpp>

我尚未找到一种方法来忘记这种Moc Generation Magic,并在包含包含q_Object 相关的东西

I've encountered the same issue again and this is how I managed to fix it:

  1. Set an appropriate conan generator to generate needed config CMake files
  • I use generators = "cmake_find_package_multi" as mentioned in this issue (Again my own issue)
  1. Conan now generates a whole lot of <PKG>Config/Target.cmake files (in my case), we need to point CMake to look for configurations in that folder as specified in conan docs and here in CMake docs
  2. At that point AUTOMOC, AUTOUIC and AUTORCC should work with this piece of config:
find_package(Qt5 CONFIG REQUIRED)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC ON)

I've encountered two types of different issues later on …


AutoMoc error
-------------
"SRC:/src/<thisfilename>.cpp"
contains a "Q_OBJECT" macro, but does not include "<thisfilename>.moc"!
Consider to
  - add #include "<thisfilename>.moc"
  - enable SKIP_AUTOMOC for this file

This is resolved either by moving Q_OBJECT class into header or adding #include <thisfilename.moc> below the class, CMake automatically populates direct path to this file without paths nesting. For example if I have a file called "test.cpp" I have to do this:

#include <QObject>

class TestObject : public QObject
{
    Q_OBJECT
};

#include <test.moc>

Linker errors with unresolved references to metaObject, qt_metacast, qt_metacall, etc …
In that case it means that moc's generated source code was not added into compilation.
It can be resolved either with adding header files along with .cpp files in add_executable call:

file(GLOB SOURCES
    include/*.h
    src/*.cpp
)
add_executable(${PROJECT_NAME} ${SOURCES})

the above has an obvious downside, after each newly created header you have to reconfigure CMake to generate moc stuff

The other way to fix it is to include a file #include <moc_thisfilename.cpp> in the Q_OBJECT's cpp implementation file like that:
test.hpp

#include <QObject>

class TestObject : public QObject
{
    Q_OBJECT
};

test.cpp

#include <test.hpp>
#include <moc_test.cpp>

I haven't yet find a way to forget about this moc generation magic and make CMake autoinclude everything in a smart way when including header containing Q_OBJECT related stuff

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文