Reputation: 23
I have the following build system file which not working.
{
"cmd" : ["qmake", "-project"],
"cmd" : ["qmake"],
"cmd" : ["make"],
"working_dir": "${project_path:${folder}}",
}
No files are generated. Usually following files should be created:
How can I run multiple commands in the build file?
Upvotes: 2
Views: 3734
Reputation: 429
For others looking for examples, here I've created a default 'qmake' build system (debug configuration) and a 'release' variant which goes extra step of cleaning, moving some files and then zipping up the result.
For this all to work, you will need certain paths and environment variables setup, luckily Qt comes with a windows batch file to do such a thing, and so does Visual Studio 2017 (or you can just install the Visual Studio CLI developer tools without the IDE).
I start a cmd.exe (make sure 'where subl' works and if not fix that first by putting path to Sublime executable folder in your PATH environment variable), then I source %QTDIR%\bin\qtenv2.bat
to set the correct qmake toolchain. I'm using msvc2017_64 'toolkit' for this so my path is C:\Qt\5.12.5\msvc2017_64\bin\qtenv2.bat
.
Then if you are using Microsoft's Visual C++ toolchain (cl.exe, nmake, et al.) you will need to also run the batch file to setup correct environment variables for that. I'm using 64-bit Qt toolkit so I need 'vcvars64.bat' file. It's buried deep in the Visual Studio folders, mine is in "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Auxiliary\Build\"
. After sourcing both the qt and ms .bat files we are ready to start sublime text from cmd.exe. Use subl myproject.sublime-project
.
Having said all that here is my example qmake build system for my project:
{
"build_systems": [
{
"name": "qmake",
"shell_cmd": "qmake ${project_path}/foo/foo.pro -spec win32-msvc \"CONFIG+=debug\" && C:/Qt/Tools/QtCreator/bin/jom -f Makefile.Debug && ${project_path}/foo/build/debug/foo.exe",
"selector": "source.c++",
"working_dir": "${project_path}/foo/build",
"variants": [
{
"name": "release",
"shell_cmd": "qmake ${project_path}/foo/foo.pro -spec win32-msvc \"CONFIG+=qtquickcompiler\" \"CONFIG+=release\" && C:/Qt/Tools/QtCreator/bin/jom qmake_all && C:/Qt/Tools/QtCreator/bin/jom install && C:/Qt/Tools/QtCreator/bin/jom clean && C:/Qt/5.12.5/msvc2017_64/bin/windeployqt ${project_path}/foo/build/release/foo.exe && \"C:/Program Files/7-zip/7z.exe\" a foo.zip ./release/*"
}],
}
Upvotes: 0
Reputation: 271
Here is the build system I'm using for my Qt 5 projects in Sublime Text 3:
{
"shell_cmd": "qmake && make",
"working_dir": "${project_path:${folder}}",
"variants":
[
{
"name": "Qmake Project",
"shell_cmd": "qmake -project"
},
{
"name": "Qmake Clean",
"shell_cmd": "make clean"
}
]
}
To expand on dutt's comment, you can run multiple commands in a single line using the same syntax you would if you were writing the commands in the shell. && is nice because it executes the next command only if the previous one succeeded.
See Shell - Multiple commands in one line for more info on shell commands on a single line.
Upvotes: 3
Reputation: 16059
You could make a bash file with all the commands in it, and set the command to that.
{
"cmd" : ["my_build.sh"],
"working_dir": "${project_path:${folder}}",
}
# my_build.sh
qmake -project
qmake
make
Upvotes: 1