关于C/C /QT中的条件构建(宏)
Regarding conditional build (Macro) in C/C++/QT
我想知道在我进行有条件构建的常见(推荐)方法以选择要构建的方法。
因此,可以选择两个文件。
条件1:
class Page : QWebPage {
public:
string test1;
}
条件2:
class EnginePage : QWebEnginePage {
public:
string test1;
string test2;
}
我看到的最常见的方法是使用与Makefile相关的文件类似:
与Makefile有关的文件:
Source +=
one.h
two.h
three.h
four.h
#if (one_defined)
Source += Page.h
#else
Source += EnginePage.h
#end
但是(这是问题)我想知道与此相似(使用一个文件而不是两个文件)是可能的,并且建议:
单个文件(条件1 条件2):
#if (one_defined)
class Page : QWebPage
#else
class EnginePage : QWebEnginePage {
#endif
public:
string test1;
#if (one_defined)
string test2;
#endif
}
您可以在.h文件中使用#cmakedefine CMAKE_VAR
。
CONFIGURE_FILE
将自动替换为#define CMAKE_VAR
或/* #undef CMAKE_VAR*/
取决于CMAKE_VAR
是否设置在CMAKE中。
一个具体示例:
假设您有一个CMAKE变量,该变量称为QWebPage_Defined
,如果定义了qwebpage,则等于true。
您将需要创建一个包含:
的文件(例如configure.h.in
) #cmakedefine QWebPage_Defined
在您的cmake脚本中,您将调用CONFIGURE_FILE
函数:
configure_file("configure.h.in", "${CMAKE_BINARY_DIR}/configure.h")
然后在您的标题中:
#include "configure.h" // Include the file
#ifdef QWebPage_Defined // Warning : use #ifdef and not #if
class Page : QWebPage
#else
class EnginePage : QWebEnginePage {
#endif
public:
string test1;
#ifdef QWebPage_Defined // Warning : use #ifdef and not #if
string test2;
#endif
}
相关文章:
- 如何构建Qt + cmake + QGLWidget
- 在Visual Studio 2017中构建Qt可执行文件
- 尝试使用 MSVC 从源代码构建 qt 创建器:无法打开包含文件:"stddef.h":没有这样的文件或目录
- 错误:无法构建 PhantomJS!构建Qt基地失败
- 如何在构建Qt应用程序时运行git命令
- 使用Visual Studio构建QT
- 如何使用MINGW-W64通过链接时间优化构建QT
- 使用Qt多媒体支持构建Qt
- 尝试在树莓派上构建Qt项目,为什么它会抛出有关qmake的错误
- MSVC 编译器在调试模式下构建 Qt 5.10 时崩溃
- 如何使用-REDUCE -RECATIONS构建QT
- 从MACOS上的源代码构建QT时错误
- 如何有效地构建QT应用程序
- 如何正确构建Qt插件
- 从源代码构建Qt 5.8 - 配置:未知命令行选项'-c++11'
- 尝试使用VC++编译器构建Qt应用程序:"type_traits":没有这样的文件或目录
- 如何使用Team Foundation Server 2017构建QT应用程序
- 使用Visual Studio 2013构建QT 5.2.1的静态版本
- 为嵌入式系统构建QT时错误
- 无法在Visual Studio 2005中构建Qt项目