tasks.json 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. {
  2. // See https://go.microsoft.com/fwlink/?LinkId=733558
  3. // for the documentation about the tasks.json format
  4. "version": "2.0.0",
  5. "tasks": [
  6. {
  7. //在当前项目目录创建build文件夹
  8. "label": "mkdir", //任务名称
  9. "type": "shell", //任务类型,定义任务是被作为进程运行还是在 shell 中作为命令运行。
  10. "options": {
  11. "cwd": "${workspaceFolder}" //已执行程序或脚本的当前工作目录,设置当前项目文件夹
  12. },
  13. "command": "mkdir", //命令
  14. "args": [ //命令后面跟的参数
  15. "-Force",
  16. "build"
  17. ]
  18. },
  19. {
  20. "label": "qmake-debug",
  21. "type": "shell",
  22. "options": {
  23. "cwd": "${workspaceFolder}/build" //进入build目录
  24. },
  25. "command": "qmake", //qmake命令,这里没用完整路径,是因为配置到环境变量了 C:/Qt/5.15.2/mingw81_64/bin/qmake.exe
  26. "args": [ //跟的参数是不是很熟悉,就是上面分析出来的Qt Creator执行流程
  27. "../${workspaceFolderBasename}.pro", //在build目录上一级哦
  28. "-spec",
  29. "win32-g++",
  30. "\"CONFIG+=debug\"",
  31. "\"CONFIG+=console\""
  32. ],
  33. "dependsOn": [ //这是本条命令依赖的前置条件,就是上面创建build文件夹的task,直接执行本task会自动先调用依赖的task
  34. "mkdir" //其实可以手动执行一次,后面不用每次都执行创建目录的操作
  35. ]
  36. },
  37. {
  38. "label": "make-debug",
  39. "type": "shell",
  40. "options": {
  41. "cwd": "${workspaceFolder}/build"
  42. },
  43. "command": "mingw32-make", //MinGW这个也配置在环境变量了,不用写完整路径了 C:/Qt/Tools/mingw810_64/bin/mingw32-make.exe
  44. "args": [
  45. "-f",
  46. "Makefile.Debug", //-f 选择makefile,这是qmake编译出来的
  47. "-j7" //这个参数都知道吧,编译用的线程数量
  48. ],
  49. "dependsOn": [
  50. "qmake-debug"
  51. ]
  52. },
  53. {
  54. "label": "run-debug",
  55. "type": "process", //运行就不能选择shell执行了,要选择process
  56. "options": {
  57. "cwd": "${workspaceFolder}/build/debug" //没在.pro配置DESTDIR,会生成到build目录下面对应目录
  58. },
  59. //"command": "${workspaceFolderBasename}.exe", //执行的exe名字,一般当前项目文件夹的名称,自定义可以写其他的
  60. "command": "${workspaceFolder}/build/debug/${workspaceFolderBasename}.exe",
  61. "dependsOn": [
  62. "make-debug"
  63. ]
  64. },
  65. {
  66. "label": "qmake-release",
  67. "type": "shell",
  68. "options": {
  69. "cwd": "${workspaceFolder}/build"
  70. },
  71. "command": "qmake",
  72. "args": [ //注意release跟debug参数的差异
  73. "../${workspaceFolderBasename}.pro",
  74. "-spec",
  75. "win32-g++",
  76. "\"CONFIG+=qtquickcompiler\""
  77. ],
  78. "dependsOn": [
  79. // "mkdir" //不用每次都创建吧
  80. ]
  81. },
  82. {
  83. "label": "make-release",
  84. "type": "shell",
  85. "options": {
  86. "cwd": "${workspaceFolder}/build"
  87. },
  88. "command": "mingw32-make",
  89. "args": [
  90. "-f",
  91. "Makefile.Release", //注意release跟debug参数的差异
  92. "-j7"
  93. ],
  94. "dependsOn": [
  95. "qmake-release"
  96. ]
  97. },
  98. {
  99. "label": "run-release",
  100. "type": "process",
  101. "options": {
  102. "cwd": "${workspaceFolder}/build/release"
  103. },
  104. // "command": "${workspaceFolderBasename}.exe",
  105. "command": "${workspaceFolder}/build/release/${workspaceFolderBasename}.exe",
  106. "dependsOn": [
  107. "make-release"
  108. ]
  109. },
  110. {
  111. "label": "clean",
  112. "type": "shell",
  113. "options": {
  114. "cwd": "${workspaceFolder}/build"
  115. },
  116. "command": "mingw32-make",
  117. "args": [
  118. "clean"
  119. ]
  120. }
  121. ]
  122. }