CMake未命中Qt5的QT_DEFINITIONS变量

CMake miss QT_DEFINITIONS variable for Qt5

本文关键字:QT DEFINITIONS 变量 Qt5 CMake      更新时间:2023-10-16

CMake为Qt4具有特殊变量${QT_DEFINITIONS},该变量包含QT定义,如QT_NO_DEBUG和QT_DEBUG。Qt5没有这样的选项。

如何在cmake中添加标准Qt5定义?

请检查<component>_DEFINITIONS/<component>_COMPILE_DEFINITIONS

这里有一个使用QtWidgets和CMake的例子。两个重要部分:

# Find the QtWidgets library
find_package(Qt5Widgets)
# Add the include directories for the Qt 5 Widgets module to
# the compile lines.
include_directories(${Qt5Widgets_INCLUDE_DIRS})

调用find_package()将为您设置以下变量:

  • Qt5Widgets_VERSION_STRING
  • Qt5Widgets_LIBRARIES例如,与target_link_libraries命令一起使用的库列表
  • Qt5Widgets_INCLUDE_DIRS例如,与include_directories命令一起使用的库列表
  • Qt5Widgets_DEFINITIONS例如,与add_definitions一起使用的定义列表
  • Qt5Widgets_COMPILE_DEFINITIONS用于COMPILE_DEFINITIONS目标属性的定义列表
  • Qt5Widgets_FOUND描述是否成功找到模块的布尔值
  • Qt5Widgets_EXECUTABLE_COMPILE_FLAGS生成可执行文件时要使用的标志字符串

(引用自上面的链接;名称取决于您在find_package()调用中搜索的内容)