我有一个 qmake 批处理文件,它使用 .pri 和 .pro 创建一个用于创建 dll 的 Visual Studio C++ 项目。但是我想自动设置这个项目的属性,特别是调试命令和命令行参数,这在 qmake 中可能吗?
最佳答案
有可能,创建一个
add_qt_path.pri
在某处归档,内容如下:
# test if windows
win32 {
# test if already exists
VCXPROJ_USER_FILE = "$${OUT_PWD}/$${TARGET}.vcxproj.user"
!exists( $${VCXPROJ_USER_FILE}) {
# generate file contents
TEMPNAME = $${QMAKE_QMAKE} # contains full dir of qmake used
QTDIR = $$dirname(TEMPNAME) # gets only the path
# vcxproj.user template
VCXPROJ_USER = "<?xml version=\"1.0\" encoding=\"utf-8\"?>$$escape_expand(\\n)\
<Project xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">$$escape_expand(\\n)\
<PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug|Win32'\">$$escape_expand(\\n)\
<LocalDebuggerEnvironment>PATH=$${QTDIR};%PATH%</LocalDebuggerEnvironment>$$escape_expand(\\n)\
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>$$escape_expand(\\n)\
</PropertyGroup>$$escape_expand(\\n)\
<PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|Win32'\">$$escape_expand(\\n)\
<LocalDebuggerEnvironment>PATH=$${QTDIR};%PATH%</LocalDebuggerEnvironment>$$escape_expand(\\n)\
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>$$escape_expand(\\n)\
</PropertyGroup>$$escape_expand(\\n)\
<PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug|x64'\">$$escape_expand(\\n)\
<LocalDebuggerEnvironment>PATH=$${QTDIR};%PATH%</LocalDebuggerEnvironment>$$escape_expand(\\n)\
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>$$escape_expand(\\n)\
</PropertyGroup>$$escape_expand(\\n)\
<PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|x64'\">$$escape_expand(\\n)\
<LocalDebuggerEnvironment>PATH=$${QTDIR};%PATH%</LocalDebuggerEnvironment>$$escape_expand(\\n)\
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>$$escape_expand(\\n)\
</PropertyGroup>$$escape_expand(\\n)\
</Project>$$escape_expand(\\n)\
"
# write file
write_file($${VCXPROJ_USER_FILE}, VCXPROJ_USER)
}
}
然后将其包含到您的qmake项目(*.pro)文件中,在目标定义之后:
QT += core
QT -= gui
TARGET = test3
CONFIG += console
CONFIG -= app_bundle
include(./../../add_qt_path.pri) # add qt path to vs project
# other qmake stuff
您还可以向 *.vcxproj.user 添加任何其他条目,例如调试命令和命令行参数,只需看看 Visual Studio 如何在您设置它们时自动在 *.vcxproj.user 文件中生成手动。
关于c++ - 是否可以在 qmake .pro 文件中设置 visual studio 项目属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12848974/