How to generate a Visual Studio project file when I build my qmake project?

痴心易碎 提交于 2019-12-23 03:21:44

问题


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.


回答1:


You can have your qmake project set up so that it automatically generates a Visual Studio project file on every build.

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.

There is a side effect: every change to the .pro file forces re-linking of the executable.

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}


来源:https://stackoverflow.com/questions/19013696/how-to-generate-a-visual-studio-project-file-when-i-build-my-qmake-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!