Xmake Windows 安装

windows下载 https://github.com/xmake-io/xmake/releases/download/v2.6.8/xmake-master.win64.exe

Xmake 编译Qt

1. 新工程,可以通过创建一个新的示例的空工程.

  1. $ xmake create -t qt.console test
  2. $ xmake create -t qt.static test
  3. $ xmake create -t qt.shared test
  4. $ xmake create -t qt.quickapp test
  5. $ xmake create -t qt.widgetapp test

创建后的工程,需要手工添加 Qt所需的依赖,否则编译不过,如: add_frameworks("widgets")

2. 修改示例工程,添加自己项目所需要的项

  1. add_rules("mode.debug", "mode.release")
  2. target("appname")
  3. set_kind("binary")
  4. add_rules("qt.application")
  5. set_languages("c++17")
  6. add_files("src/*.ui")
  7. add_files("src/*.cpp")
  8. add_files("src/*.h")
  9. add_files("src/*.qrc")
  10. add_frameworks("widgets")
  11. -- 6. Add some frequently-used compilation flags in xmake.lua
  12. --
  13. -- @code
  14. -- -- add debug and release modes
  15. -- add_rules("mode.debug", "mode.release")
  16. --
  17. -- -- add macro defination
  18. -- add_defines("NDEBUG", "_GNU_SOURCE=1")
  19. --
  20. -- -- set warning all as error
  21. -- set_warnings("all", "error")
  22. --
  23. -- -- set language: c99, c++11
  24. -- set_languages("c99", "c++11")
  25. --
  26. -- -- set optimization: none, faster, fastest, smallest
  27. -- set_optimize("fastest")
  28. --
  29. -- -- add include search directories
  30. -- add_includedirs("/usr/include", "/usr/local/include")
  31. --
  32. -- -- add link libraries and search directories
  33. -- add_links("tbox")
  34. -- add_linkdirs("/usr/local/lib", "/usr/lib")
  35. --
  36. -- -- add system link libraries
  37. -- add_syslinks("z", "pthread")
  38. --
  39. -- -- add compilation and link flags
  40. -- add_cxflags("-stdnolib", "-fno-strict-aliasing")
  41. -- add_ldflags("-L/usr/local/lib", "-lpthread", {force = true})

3. xmake 会自动检测 Qt SDK,也可以手工设置 Qt SDK 目录

xmake f --qt=E:\Qt\5.15.2\msvc2019 设置sdk目录
xmake f -a x86 设置34位还是64位的 (x86|x64)
xmake f -p windows 设置操作系统(win|linux|mac)

  1. $ xmake f -p windows -a x86 --qt=E:\Qt\5.15.2\msvc2019
  1. xmake f -p windows -a x64 --qt=E:\Qt\5.15.2\msvc2019_64

4. 执行 xmake

  1. $ xmake

参考

xmake 安装 https://xmake.io/#/guide/installation
xmake Qt程序示例 https://xmake.io/#/guide/project_examples?id=qt-program
xmake QtCreator 插件 https://github.com/TapzCrew/xmake-project-manager

遇到的错误

  1. 作为初学者,windows下不要用bash去执行xmake,平台会检测成mingw,检测不到编译器导致报错.

image.png