4

I am trying to automate the build process for one of my QT-project. I used the following command in my batch file for non-QT projects

"C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE\devenv.exe" "myproject.sln" /build "Debug|x64" /projectconfig Debug

but it is not working for my QT project. Am I missing something?

Abtin Rasoulian
  • 869
  • 1
  • 8
  • 11

2 Answers2

7

Here is an example on how to do that (command by command):

"C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\vcvarsall.bat" x86
cd <my_project_directory>
qmake
nmake

The first command sets up the environment for using Visual Studio tools. Second command changes the current directory to one where your Qt project file is (you have to have one). Third command runs Qt's qmake.exe utility to generate make files. And finally nmake will build your project.

However, if you don't use Qt project files and have only VisualStudio solution, you can use MSBuild utility, like:

"C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\vcvarsall.bat" x86
MSBuild your_solution.sln /p:Configuration=Debug

You can also set additional environment variables, such as QTDIR if it does not find your Qt installation.

vahancho
  • 20,808
  • 3
  • 47
  • 55
  • Facing similar problem with VS 2017 and Qt 5, you can also add `/p:QTDIR=` to the `msbuild` line instead of setting the environment variable if you prefer – cbuchart Jul 30 '18 at 07:43
0

If somebody finds this question looking for an answer on how to automate the build process of a QT project, and wants to do it using a BATCH file as the original question states, here is the BATCH script that I used to automate my building process:

@echo off
call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvarsall.bat" x86

cd %path_to_your_repo%

nmake /f Makefile.Release clean && qmake.exe %path_to_your_.pro% -spec win32-msvc "CONFIG+=qtquickcompiler"
nmake qmake_all

nmake -f Makefile.Release

It is important to call the vcvarsall.bat the first thing, as this will set the environment for all visual studio tools. Also make sure to launch it with call, if you just start the batch file as in @vahancho's answer it will stop your script after executing vcvarsall.bat.

The clean step is not necessary but it is a good practice to use it before building.

It is important to select the -spec and CONFIG (if any) during the qmake step, as this will allow you to select the compiler and required configuration if you are using some extra QT configuration.

Shunya
  • 2,344
  • 4
  • 16
  • 28