CMt错过了Qt5的QT_DEFINITIONS变量

时间:2013-12-04 09:37:36

标签: c++ qt cmake

CMake为Qt4提供了特殊变量$ {QT_DEFINITIONS},其中包含qt定义,如QT_NO_DEBUG和QT_DEBUG。 Qt5没有这样的选择。

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

1 个答案:

答案 0 :(得分:1)

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

有一个使用Qt Widgets和CMake here的例子。两个基本部分:

# 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()电话中搜索的内容)