- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我刚开始使用 CMake。我正在尝试创建一个简单的 CMakeList 文件并从 QT5 5.7 添加对 QPrinter 和 QTextDocument 的支持。根据我的发现,必须将以下库添加到我的 CMakeList 文件中:
这是我现在拥有的:
cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
PROJECT (photobooth)
find_package( Qt5Core )
find_package( Qt5PrintSupport )
find_package( Qt5Gui )
find_package( Qt5Widgets )
set( NAME_SRC
src/main.cpp
src/photobooth.cpp
)
set( NAME_HEADERS
include/photobooth.h
)
INCLUDE_DIRECTORIES( ${CMAKE_CURRENT_SOURCE_DIR}/include )
link_directories( ${CMAKE_BINARY_DIR}/bin)
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin)
add_executable( photobooth ${NAME_SRC} ${NAME_HEADERS} )
target_link_libraries( photobooth Qt5::Widgets )
target_link_libraries( photobooth Qt5::Core )
target_link_libraries( photobooth Qt5::Qt5PrintSupport )
target_link_libraries( photobooth Qt5::Qt5Gui )
这是 Cmake 的输出:
Configuring done
CMake Warning (dev) in CMakeLists.txt:
Policy CMP0020 is not set: Automatically link Qt executables to qtmain
target on Windows. Run "cmake --help-policy CMP0020" for policy details.
Use the cmake_policy command to set the policy and suppress this warning.
This warning is for project developers. Use -Wno-dev to suppress it.
CMake Warning (dev) in CMakeLists.txt:
Policy CMP0020 is not set: Automatically link Qt executables to qtmain
target on Windows. Run "cmake --help-policy CMP0020" for policy details.
Use the cmake_policy command to set the policy and suppress this warning.
This warning is for project developers. Use -Wno-dev to suppress it.
CMake Warning (dev) at CMakeLists.txt:24 (add_executable):
Policy CMP0028 is not set: Double colon in target name means ALIAS or
IMPORTED target. Run "cmake --help-policy CMP0028" for policy details.
Use the cmake_policy command to set the policy and suppress this warning.
Target "photobooth" links to target "Qt5::Qt5PrintSupport" but the target
was not found. Perhaps a find_package() call is missing for an IMPORTED
target, or an ALIAS target is missing?
This warning is for project developers. Use -Wno-dev to suppress it.
CMake Warning (dev) at CMakeLists.txt:24 (add_executable):
Policy CMP0028 is not set: Double colon in target name means ALIAS or
IMPORTED target. Run "cmake --help-policy CMP0028" for policy details.
Use the cmake_policy command to set the policy and suppress this warning.
Target "photobooth" links to target "Qt5::Qt5Gui" but the target was not
found. Perhaps a find_package() call is missing for an IMPORTED target, or
an ALIAS target is missing?
This warning is for project developers. Use -Wno-dev to suppress it.
CMake Warning (dev) in CMakeLists.txt:
Policy CMP0020 is not set: Automatically link Qt executables to qtmain
target on Windows. Run "cmake --help-policy CMP0020" for policy details.
Use the cmake_policy command to set the policy and suppress this warning.
This warning is for project developers. Use -Wno-dev to suppress it.
CMake Warning (dev) at CMakeLists.txt:24 (add_executable):
Policy CMP0028 is not set: Double colon in target name means ALIAS or
IMPORTED target. Run "cmake --help-policy CMP0028" for policy details.
Use the cmake_policy command to set the policy and suppress this warning.
Target "photobooth" links to target "Qt5::Qt5PrintSupport" but the target
was not found. Perhaps a find_package() call is missing for an IMPORTED
target, or an ALIAS target is missing?
This warning is for project developers. Use -Wno-dev to suppress it.
CMake Warning (dev) at CMakeLists.txt:24 (add_executable):
Policy CMP0028 is not set: Double colon in target name means ALIAS or
IMPORTED target. Run "cmake --help-policy CMP0028" for policy details.
Use the cmake_policy command to set the policy and suppress this warning.
Target "photobooth" links to target "Qt5::Qt5Gui" but the target was not
found. Perhaps a find_package() call is missing for an IMPORTED target, or
an ALIAS target is missing?
This warning is for project developers. Use -Wno-dev to suppress it.
CMake Warning (dev) in CMakeLists.txt:
Policy CMP0020 is not set: Automatically link Qt executables to qtmain
target on Windows. Run "cmake --help-policy CMP0020" for policy details.
Use the cmake_policy command to set the policy and suppress this warning.
This warning is for project developers. Use -Wno-dev to suppress it.
CMake Warning (dev) at CMakeLists.txt:24 (add_executable):
Policy CMP0028 is not set: Double colon in target name means ALIAS or
IMPORTED target. Run "cmake --help-policy CMP0028" for policy details.
Use the cmake_policy command to set the policy and suppress this warning.
Target "photobooth" links to target "Qt5::Qt5PrintSupport" but the target
was not found. Perhaps a find_package() call is missing for an IMPORTED
target, or an ALIAS target is missing?
This warning is for project developers. Use -Wno-dev to suppress it.
CMake Warning (dev) at CMakeLists.txt:24 (add_executable):
Policy CMP0028 is not set: Double colon in target name means ALIAS or
IMPORTED target. Run "cmake --help-policy CMP0028" for policy details.
Use the cmake_policy command to set the policy and suppress this warning.
Target "photobooth" links to target "Qt5::Qt5Gui" but the target was not
found. Perhaps a find_package() call is missing for an IMPORTED target, or
an ALIAS target is missing?
This warning is for project developers. Use -Wno-dev to suppress it.
CMake Warning (dev) in CMakeLists.txt:
Policy CMP0020 is not set: Automatically link Qt executables to qtmain
target on Windows. Run "cmake --help-policy CMP0020" for policy details.
Use the cmake_policy command to set the policy and suppress this warning.
This warning is for project developers. Use -Wno-dev to suppress it.
CMake Warning (dev) at CMakeLists.txt:24 (add_executable):
Policy CMP0028 is not set: Double colon in target name means ALIAS or
IMPORTED target. Run "cmake --help-policy CMP0028" for policy details.
Use the cmake_policy command to set the policy and suppress this warning.
Target "photobooth" links to target "Qt5::Qt5PrintSupport" but the target
was not found. Perhaps a find_package() call is missing for an IMPORTED
target, or an ALIAS target is missing?
This warning is for project developers. Use -Wno-dev to suppress it.
CMake Warning (dev) at CMakeLists.txt:24 (add_executable):
Policy CMP0028 is not set: Double colon in target name means ALIAS or
IMPORTED target. Run "cmake --help-policy CMP0028" for policy details.
Use the cmake_policy command to set the policy and suppress this warning.
Target "photobooth" links to target "Qt5::Qt5Gui" but the target was not
found. Perhaps a find_package() call is missing for an IMPORTED target, or
an ALIAS target is missing?
This warning is for project developers. Use -Wno-dev to suppress it.
CMake Warning (dev) in CMakeLists.txt:
Policy CMP0020 is not set: Automatically link Qt executables to qtmain
target on Windows. Run "cmake --help-policy CMP0020" for policy details.
Use the cmake_policy command to set the policy and suppress this warning.
This warning is for project developers. Use -Wno-dev to suppress it.
CMake Warning (dev) in CMakeLists.txt:
Policy CMP0020 is not set: Automatically link Qt executables to qtmain
target on Windows. Run "cmake --help-policy CMP0020" for policy details.
Use the cmake_policy command to set the policy and suppress this warning.
This warning is for project developers. Use -Wno-dev to suppress it.
CMake Warning (dev) in CMakeLists.txt:
Policy CMP0020 is not set: Automatically link Qt executables to qtmain
target on Windows. Run "cmake --help-policy CMP0020" for policy details.
Use the cmake_policy command to set the policy and suppress this warning.
This warning is for project developers. Use -Wno-dev to suppress it.
CMake Warning (dev) in CMakeLists.txt:
Policy CMP0020 is not set: Automatically link Qt executables to qtmain
target on Windows. Run "cmake --help-policy CMP0020" for policy details.
Use the cmake_policy command to set the policy and suppress this warning.
This warning is for project developers. Use -Wno-dev to suppress it.
CMake Warning (dev) at CMakeLists.txt:24 (add_executable):
Policy CMP0028 is not set: Double colon in target name means ALIAS or
IMPORTED target. Run "cmake --help-policy CMP0028" for policy details.
Use the cmake_policy command to set the policy and suppress this warning.
Target "photobooth" links to target "Qt5::Qt5PrintSupport" but the target
was not found. Perhaps a find_package() call is missing for an IMPORTED
target, or an ALIAS target is missing?
This warning is for project developers. Use -Wno-dev to suppress it.
CMake Warning (dev) at CMakeLists.txt:24 (add_executable):
Policy CMP0028 is not set: Double colon in target name means ALIAS or
IMPORTED target. Run "cmake --help-policy CMP0028" for policy details.
Use the cmake_policy command to set the policy and suppress this warning.
Target "photobooth" links to target "Qt5::Qt5Gui" but the target was not
found. Perhaps a find_package() call is missing for an IMPORTED target, or
an ALIAS target is missing?
This warning is for project developers. Use -Wno-dev to suppress it.
Generating done
我的项目使用 Visual Studio 14 2015 Win64 作为我的构建生成良好。此外,当我在 main.cpp 中包含 QTextDocument 时,它会找到它,但不会找到 QPrinter。我做错了什么吗?
最佳答案
一些提示:
find_package( Qt5Core )
find_package( Qt5PrintSupport )
find_package( Qt5Gui )
find_package( Qt5Widgets )
您可以将这些调用合并到一个 find_package
中寻找 Qt5:
find_package(Qt5 REQUIRED
Core
PrintSupport
Gui
Widgets
)
请注意关键字 REQUIRED
的使用,如果找不到包,这将导致 CMake 引发错误。查看您的错误日志,这可能是您的问题。您是否在某处设置了Qt5_DIR
?
Core
和 Gui
在这里是可选的,因为 Widgets
依赖于它们,所以它们将被自动添加。
您应该将 CMake 所需的版本更改为 2.8.11
以确保导入的目标嵌入包含目录。
您应该考虑 target_include_directories
而不是 INCLUDE_DIRECTORIES
以避免全局污染,并将参数附加到目标。这不是真正的要点,而是对 future 更大项目的良好实践。
您对 link_directories
的调用在这里没有用。如果您需要链接库,请选择 target_link_libraries
。
EXECUTABLE_OUTPUT_PATH
是一个旧变量,由作为目标属性的 RUNTIME_OUTPUT_DIRECTORY
取代。
清理后,您的 CMake 项目可能如下所示:
cmake_minimum_required(VERSION 2.8.11 FATAL_ERROR)
PROJECT (photobooth)
find_package(Qt5 REQUIRED
Widgets
PrintSupport
)
set( NAME_SRC
src/main.cpp
src/photobooth.cpp
)
set( NAME_HEADERS
include/photobooth.h
)
add_executable( photobooth ${NAME_SRC} ${NAME_HEADERS} )
set_target_properties(photobooth PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin
)
target_include_directories(photobooth PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
target_link_libraries( photobooth Qt5::Widgets Qt5::PrintSupport )
关于c++ - 将 QT5 库添加到 CMake,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40392487/
运行 pip install cmake 时出现上述错误在 alpine linux (WSL) 上。 完整错误: /home/user# pip install cmake Collecting c
我的项目依赖 mariadb-connector-c我正在尝试使用 cmake 自动化下载、构建和链接过程。 我目前将项目下载到一个目录中,然后尝试执行生成忍者文件并运行它们,但我根本无法运行 cma
我正在尝试像这样在 cmake 中执行 execute_process execute_process(COMMAND ${CMAKE_COMMAND} -P myScript.cmake 这仅在文件
我想知道如果我没有给它任何变量告诉它在哪里找到它,cmake 如何找到我的 llvm cmake 配置。 我是 LLVM 新手。我正在构建一个 Hello World LLVM pass。我在 Ubu
我正在开发一个使用 CMake 的项目。顶CMakeLists.txt文件包含以下行: cmake_minimum_required(VERSION 3.7.2) # Kittens will die
我正在使用 Meego 1.2 工具链使用 cmake 运行构建(长话短说)。这个特定的工具链需要使用 --sysroot 选项来查找它需要的任何库。 set (CMAKE_CXX_FLAGS "-f
我们有一些源代码处理工具,可以从多个“片段”生成原始汇编文件等内容。 当使用 make 中的这些工具时,我们可以通过让源处理工具发出“依赖文件”来确保最新的构建,就像 gcc 一样-MD 标志。 例如
如何在 MSYS2 中安装和配置“cmake”?我尝试安装以下 MSYS 包 我在运行任何 cmake 命令时都收到以下错误 '''CMakeLists.txt:5 (cmake_minimum_re
有没有办法在 CMake 中得到一个变量列表?具体来说,我想要做的是调用一个现有函数,该函数接受多个变量并检查它们的计算结果是否为 true。 在某些情况下,其中一些变量将是空列表(计算结果为 fal
我有两组测试(功能测试和单元测试),我希望能够指定通过 cmake 运行哪一组。 一组测试是我想通过“make test”运行的单元测试。 另一组测试是我想通过“制作功能测试”来运行的功能测试。 目前
我的目标是查看有关调用 g++ 的详细信息由 cmake 直接调用从命令行。我不关心 make 的输出就这个问题而言。 根据official FAQ和 the accepted answer on a
我有一个生成库的CMake项目。我已经编写了一个CMake脚本FindXXX.cmake来帮助我的图书馆的用户。这样,他们可以使用find_package(XXX)并获取所需的变量。到现在为止还挺好。
当我看到带有命名空间的 CMake 库时,它们总是在表单中Parent::Component . 如果我有一个足够大的库,那么该库的子部分可能包含组件。我想知道是否可以/适合做 ParentProje
CMake 变量和属性似乎完成了非常相似的事情,我一直无法理解它们之间的区别。 它们每个都有自己的文档部分,但两者都会影响构建系统,两者都是“预先存在的”,并且两者都可以基于其他 CMake 命令动态
我有一个包含多个子目录的 CMake 项目,例如: dir1 subdir11 subdir12 dir2 subdir21 subdir22 根 CMakeLists
如果您想将静态库链接到共享库或可执行文件,同时保持所有符号可见(例如,您可以稍后打开它以找到它们),在 Linux/BSD 上执行此操作的一种非可移植方式是使用标志-Wl,--whole-archiv
CMake 自动创建一个 FooTarget.cmake文件例如添加 install(EXPORT FooTargets FILE FooTargets.cmake NAMESPACE Foo
在CMake中,ELSE和ENDIF控制流函数将表达式作为参数。根据文档,这些是optional。那么这些目的是什么?仅仅是为了维护目的而使原始IF表达式更清晰,还是提供某些功能? 最佳答案 正如您所
我是 cmake 的新手,我发现它非常令人沮丧。我试图在构建运行时评估的文件路径中使用通配符,而不是在生成构建时。 我创建了一个构建,它使用 SWIG 为某些 C++ 代码生成 Java 包装器。我可
我可能在谷歌上搜索错误,但我无法找到 .cmake 文件的用途。 我刚刚偶然发现了一个我必须使用的项目的 CMake 工具,我很难理解它是如何工作的。我明白在包含 CMakeLists.txt 的目录
我是一名优秀的程序员,十分优秀!