From a45c7956d63786f4f3272ca72a09f108c596ed7b Mon Sep 17 00:00:00 2001 From: ruki Date: Tue, 30 Nov 2021 10:46:26 +0800 Subject: [PATCH] add openmp (#722) * add openmp * Update xmake.lua * Update xmake.lua --- packages/l/libomp/xmake.lua | 23 --------------- packages/o/openmp/xmake.lua | 57 +++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 23 deletions(-) create mode 100644 packages/o/openmp/xmake.lua diff --git a/packages/l/libomp/xmake.lua b/packages/l/libomp/xmake.lua index 71e643210..f6a168a27 100644 --- a/packages/l/libomp/xmake.lua +++ b/packages/l/libomp/xmake.lua @@ -15,29 +15,6 @@ package("libomp") add_syslinks("pthread", "dl") end - on_load(function (package) - if package.has_tool then - for _, toolkind in ipairs({"cc", "cxx"}) do - local flagname = toolkind == "cxx" and "cxxflags" or "cflags" - if package:has_tool(toolkind, "cl") then - package:add(flagname, "/openmp") - elseif package:has_tool(toolkind, "clang", "clangxx") then - if package:is_plat("macosx") then - package:add(flagname, "-Xpreprocessor -fopenmp") - else - package:add(flagname, "-fopenmp") - end - elseif package:has_tool(toolkind, "gcc", "gxx") then - package:add(flagname, "-fopenmp") - elseif package:has_tool(toolkind, "icc", "icpc") then - package:add(flagname, "-qopenmp") - elseif package:has_tool(toolkind, "icl") then - package:add(flagname, "-Qopenmp") - end - end - end - end) - on_install("macosx", "linux", "cross", function (package) local configs = {"-DLIBOMP_INSTALL_ALIASES=OFF"} local shared = package:config("shared") diff --git a/packages/o/openmp/xmake.lua b/packages/o/openmp/xmake.lua new file mode 100644 index 000000000..0fa5e7066 --- /dev/null +++ b/packages/o/openmp/xmake.lua @@ -0,0 +1,57 @@ +package("openmp") + + set_homepage("https://openmp.org/") + set_description("The OpenMP API specification for parallel programming") + + on_load(function (package) + if package.has_tool then + for _, toolkind in ipairs({"cc", "cxx"}) do + local flagname = toolkind == "cxx" and "cxxflags" or "cflags" + if package:has_tool(toolkind, "cl") then + package:add(flagname, "/openmp") + elseif package:has_tool(toolkind, "clang", "clangxx") then + if package:is_plat("macosx") then + package:add(flagname, "-Xpreprocessor -fopenmp") + else + package:add(flagname, "-fopenmp") + end + elseif package:has_tool(toolkind, "gcc", "gxx") then + package:add(flagname, "-fopenmp") + elseif package:has_tool(toolkind, "icc", "icpc") then + package:add(flagname, "-qopenmp") + elseif package:has_tool(toolkind, "icl") then + package:add(flagname, "-Qopenmp") + end + end + end + if package:is_plat("macosx", "linux") then + package:add("deps", "libomp") + end + end) + + on_fetch(function (package) + for _, dep in ipairs(package:orderdeps()) do + if not dep:fetch() then + return + end + end + return {} + end) + + on_install("linux", "macosx", "windows", function (package) + -- we need not install anything because we need only compiler flags and deps + end) + + on_test(function (package) + assert(package:check_csnippets({test = [[ + #include + #include + + static void test() { + #pragma omp parallel + { + printf("hello %d\n", omp_get_thread_num()); + } + } + ]]})) + end)