生成qmake项目时如何生成Visual Studio项目文件? [英] How to generate a Visual Studio project file when I build my qmake project?
问题描述
我喜欢使用Qt Creator进行大多数开发,并且构建由qmake和jom驱动.我偶尔想使用Visual Studio进行调试.我想知道在.pro
文件中放入什么魔术,以便在每次.pro
文件更改时在项目构建期间自动生成Visual Studio项目文件.
I like to do most development using Qt Creator, and the builds are driven with qmake and jom. I occasionally want to use Visual Studio for debugging. I'd like to know what magic to put into the .pro
file to automatically generate a Visual Studio project file during the project build, every time the .pro
file changes.
推荐答案
您可以设置qmake项目,以便它在每次构建时自动生成Visual Studio项目文件.
You can have your qmake project set up so that it automatically generates a Visual Studio project file on every build.
以下内容假定.pro
文件的基本名称与TARGET
相同.说,如果您有TARGET = myapp
,则必须在myapp.pro
中拥有它.只需将以下几行添加到您的.pro文件中即可.
The below assumes that the base name of the .pro
file is the same as the TARGET
. Say, if you have TARGET = myapp
, you must have it in myapp.pro
. Simply add the lines below to your .pro file.
有一个副作用:对.pro
文件的每次更改都会强制重新链接可执行文件.
There is a side effect: every change to the .pro
file forces re-linking of the executable.
下面的脚本不管您的目标mkspec是什么,都支持生成Visual Studio项目.因此,无论您是在Windows还是Unix上构建,还是在Windows上是为Visual Studio构建,还是使用其他编译器,都可以生成它.
The script below supports generating your Visual Studio project no matter what your target mkspec is. Thus it can be generated whether you build on Windows or Unix, and whether you build for Visual Studio on Windows, or using some other compiler
win32-msvc* {
# Works when you build for Visual Studio already
vsproj.spec = $$basename(QMAKESPEC)
} else {
# Works when you're not building for Visual Studio (say, using mingw)
# The configuration you want to build the VS project for (win32-msvc[2005|2008|2010|2012])
vsproj.spec = win32-msvc2008
}
# Sets the project file name appropriately to selected Visual Studio version.
contains(vsproj.spec, win32-msvc201): vsproj.target = $${TARGET}.vcxproj
else: vsproj.target = $${TARGET}.vcproj
# The qmake command to make the Visual Studio project file
vsproj.commands = qmake -tp vc $${_PRO_FILE_} -spec $${vsproj.spec}
# The VS project depends on the .pro file
vsproj.depends = $${_PRO_FILE_}
# Set the above as a target in the makefile.
QMAKE_EXTRA_TARGETS += vsproj
# Make the main target (the executable/library) depend on it,
# so that it gets built.
PRE_TARGETDEPS += $${vsproj.target}
这篇关于生成qmake项目时如何生成Visual Studio项目文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!