开发者

Building Qt Creator projects from command line

开发者 https://www.devze.com 2023-03-08 13:26 出处:网络
I\'m in the process of writing a build script to automate build and release tasks. I have a Qt Creator project which has three configurations, two of which I want to completely rebuild from scratch wi

I'm in the process of writing a build script to automate build and release tasks. I have a Qt Creator project which has three configurations, two of which I want to completely rebuild from scratch without any precompiled headers 开发者_运维问答and existing .o files to skip (release and release_production). The latter is the same except it has the PRODUCTION symbol #defined.

I'm using windows. How can I build these configurations from the command line?

Edit: Some clarification: The Qt Creator custom build steps are not stored in the qmake makefile but in the Qt Creator-specific .pro.user XML file. I would like to perform these from the command line without repeating them in the script.


There are two steps involved here:

  1. Running qmake to generate Makefiles. The usual command is

    c:\qt\4.7.2\bin\qmake.exe" path\to\some\project.pro -r -spec win32-g++ CONFIG+=...
    

    The -spec switch is important. Make sure you supply a valid makespec file. CONFIG needs to be specified in this step.

  2. Running make to compile and link. This is easy

    C:\MinGW32\bin\mingw32-make -f Makefile.Debug
    

    Remember to point make to the correct makefile.


In the project tab of QtCreator you have the exact command, QtCreator runs on build for both debug and release. Just run those lines in a environment your project can be build (Qt console). But basically Qt projects are build with a qmake.exe then a nmake.exe or the Qt multi-thread make-like executable jom.exe.

For your "production" mode your can use CONFIG+=production argument in the qmake command, then in your .pro files :

CONFIG(production){
DEFINES+=PRODUCTION
}else{
}


There are a few practical details that are necessary in order to make this work.

You have to tell where the compiler & resource processor are located. Ex:

:: CL.EXE
PATH=%PATH%;C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\bin\Hostx64\x64
:: RC.EXE
PATH=%PATH%;C:\Program Files (x86)\Windows Kits\10\bin\10.0.17763.0\x64

You have to define Include and Library paths:

SET INCLUDE=C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include;C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\ucrt;C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\um;C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\shared;C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\atlmfc\include
SET LIB=C:\Program Files (x86)\Windows Kits\10\Lib\10.0.17763.0\um\x64;C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\lib\x64;C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\atlmfc\lib\x64;C:\Program Files (x86)\Windows Kits\10\Lib\10.0.17763.0\ucrt\x64

Then you can do it:

CD C:\Foo\build-your-project-Desktop_Qt_5_13_0_MSVC2017_64bit-Release
C:\Qt\Tools\QtCreator\bin\jom.exe /S -f Makefile.Release clean

C:\Qt\5.13.0\msvc2017_64\bin\qmake.exe -o Makefile ..\your-project\your-project-file.pro -spec win32-msvc "CONFIG+=qtquickcompiler"

C:\Qt\Tools\QtCreator\bin\jom.exe /S /X Build.log -f Makefile.Release

If you get errors, search for the path where the header or lib file is located, and add it to the paths. Keep repeating until all errors are gone.

0

精彩评论

暂无评论...
验证码 换一张
取 消