xmake.lua 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. package("openmp")
  2. set_homepage("https://openmp.org/")
  3. set_description("The OpenMP API specification for parallel programming")
  4. add_configs("runtime", {description = "Set OpenMP runtime for gcc/clang like compilers.", default = "default", type = "string", values = {"default", "custom"}})
  5. add_configs("feature", {description = "Set OpenMP feature for msvc.", default = "default", type = "string", values = {"default", "experimental", "llvm"}})
  6. on_load(function (package)
  7. if package.has_tool then
  8. for _, toolkind in ipairs({"cc", "cxx"}) do
  9. if package:config("runtime") == "default" then
  10. if package:has_tool(toolkind, "clang", "clangxx") then
  11. package:add("deps", "libomp")
  12. end
  13. end
  14. end
  15. end
  16. end)
  17. on_fetch(function (package)
  18. for _, dep in ipairs(package:orderdeps()) do
  19. if not dep:fetch() then
  20. return
  21. end
  22. end
  23. local result = {}
  24. if package.has_tool then
  25. for _, toolkind in ipairs({"cc", "cxx"}) do
  26. local flagname = toolkind == "cxx" and "cxxflags" or "cflags"
  27. if package:has_tool(toolkind, "cl", "clang_cl") then
  28. if package:config("feature") == "default" then
  29. result[flagname] = "/openmp"
  30. else
  31. result[flagname] = "/openmp:" .. package:config("feature")
  32. end
  33. if package:has_tool(toolkind, "clang_cl") then
  34. result.links = "libomp"
  35. end
  36. elseif package:has_tool(toolkind, "clang", "clangxx") then
  37. if package:is_plat("macosx") then
  38. result[flagname] = "-Xpreprocessor -fopenmp"
  39. else
  40. result[flagname] = "-fopenmp"
  41. end
  42. elseif package:has_tool(toolkind, "gcc", "gxx") then
  43. result[flagname] = "-fopenmp"
  44. elseif package:has_tool(toolkind, "icc", "icpc") then
  45. result[flagname] = "-qopenmp"
  46. elseif package:has_tool(toolkind, "icl") then
  47. result[flagname] = "-Qopenmp"
  48. end
  49. if package:config("runtime") == "default" then
  50. if package:has_tool(toolkind, "clang", "clangxx") then
  51. if not package:is_plat("macosx") then
  52. result.ldflags = "-fopenmp"
  53. end
  54. elseif package:has_tool(toolkind, "gcc", "gxx") then
  55. result.ldflags = "-fopenmp"
  56. elseif package:has_tool(toolkind, "icc", "icpc") then
  57. result.ldflags = "-qopenmp"
  58. elseif package:has_tool(toolkind, "icl") then
  59. result.ldflags = "-Qopenmp"
  60. end
  61. end
  62. if package:config("runtime") == "custom" then
  63. if package:has_tool(toolkind, "cl") then
  64. result.ldflags = "/nodefaultlib:vcomp"
  65. end
  66. end
  67. end
  68. else
  69. raise("This package(openmp) requires xmake version 2.6.1 or newer.")
  70. end
  71. return (result.cflags or result.cxxflags) and result
  72. end)
  73. on_install("linux", "macosx", "windows", "mingw@msys", function (package)
  74. -- we need not install anything because we need only compiler flags and deps
  75. end)
  76. on_test(function (package)
  77. assert(package:check_csnippets({test = [[
  78. #include <stdio.h>
  79. #include <omp.h>
  80. #ifndef _OPENMP
  81. # error missing openmp flags
  82. #endif
  83. static void test() {
  84. #pragma omp parallel
  85. {
  86. printf("hello %d\n", omp_get_thread_num());
  87. }
  88. }
  89. ]]}))
  90. end)