xmake.lua 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. package("emock")
  2. set_homepage("https://github.com/ez8-co/emock")
  3. set_description("Next generation cross-platform mock library for C/C++")
  4. set_license("Apache-2.0")
  5. add_urls("https://github.com/ez8-co/emock/archive/refs/tags/$(version).tar.gz",
  6. "https://github.com/ez8-co/emock.git")
  7. add_versions("v0.9.0", "376b3584e95642b10947da8244c9b592f62ac267c23949d875a0d5ffe5d32cf5")
  8. add_patches("v0.9.0", "patches/v0.9.0/support_multiplat_and_fix_install.diff", "18af7bccff9849958cfc90f3210bfa73259ad2ebf462c41515ccce4478dbdb98")
  9. add_configs("shared", {description = "Build shared library.", default = false, type = "boolean", readonly = true})
  10. add_configs("namespace", {description = "Build with the `emock::` namespace.", default = true, type = "boolean"})
  11. add_configs("test_framework", {description = "Choose the unit test framework for failure reporting", default = "STDEXCEPT", type = "string", values = {"STDEXCEPT", "gtest", "cpputest", "cppunit"}})
  12. if is_plat("mingw", "windows") then
  13. add_syslinks("dbghelp")
  14. end
  15. add_deps("cmake")
  16. on_load(function (package)
  17. local test_framework = package:config("test_framework")
  18. if test_framework == "gtest" then
  19. package:add("deps", "gtest")
  20. elseif test_framework == "cpputest" then
  21. package:add("deps", "cpputest")
  22. elseif test_framework == "cppunit" then
  23. package:add("deps", "cppunit")
  24. end
  25. end)
  26. on_install("!iphoneos", function (package)
  27. io.replace("src/CMakeLists.txt", "-fPIC", "", {plain = true})
  28. io.replace("src/CMakeLists.txt", "IF(MSVC OR MINGW)\nINSTALL", "if(0)\nINSTALL", {plain = true})
  29. -- gtest require c++17
  30. local configs = {"-DCMAKE_CXX_STANDARD=17"}
  31. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
  32. table.insert(configs, "-DEMOCK_NO_NAMESPACE=" .. (package:config("namespace") and "OFF" or "ON"))
  33. local test_framework = package:config("test_framework")
  34. table.insert(configs, "-DEMOCK_XUNIT=" .. test_framework)
  35. if test_framework ~= "STDEXCEPT" then
  36. local dir = package:dep(test_framework):installdir()
  37. table.insert(configs, "-DEMOCK_XUNIT_HOME=" .. dir)
  38. end
  39. import("package.tools.cmake").install(package, configs)
  40. end)
  41. on_test(function (package)
  42. assert(package:check_cxxsnippets({test = [[
  43. int foobar(int x) {
  44. return x;
  45. }
  46. void test() {
  47. EMOCK(foobar)
  48. .stubs()
  49. .with(any())
  50. .will(returnValue(1));
  51. }
  52. ]]}, {configs = {languages = "c++17"}, includes = "emock/emock.hpp"}))
  53. end)