Skip to content

Commit

Permalink
amrex: add package (#5306)
Browse files Browse the repository at this point in the history
* amrex: add package

* limit plat
  • Loading branch information
star-hengxing authored Sep 22, 2024
1 parent 1193b60 commit ef4572e
Show file tree
Hide file tree
Showing 2 changed files with 122 additions and 0 deletions.
33 changes: 33 additions & 0 deletions packages/a/amrex/patches/24.09/remove-symlink.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
diff --git a/Src/CMakeLists.txt b/Src/CMakeLists.txt
index 6e8af043..df5ca007 100644
--- a/Src/CMakeLists.txt
+++ b/Src/CMakeLists.txt
@@ -27,11 +27,7 @@ add_library(amrex ALIAS amrex_${AMReX_SPACEDIM_LAST}d)
add_library(AMReX::amrex ALIAS amrex_${AMReX_SPACEDIM_LAST}d)

# legacy symlink for build directory: libamrex.[so|a] / amrex.[dll.lib]
-add_custom_command(TARGET amrex_${AMReX_SPACEDIM_LAST}d POST_BUILD
- COMMAND ${CMAKE_COMMAND} -E create_symlink
- $<TARGET_FILE_NAME:amrex_${AMReX_SPACEDIM_LAST}d>
- $<TARGET_FILE_DIR:amrex_${AMReX_SPACEDIM_LAST}d>/$<TARGET_FILE_PREFIX:amrex_${AMReX_SPACEDIM_LAST}d>amrex$<TARGET_FILE_SUFFIX:amrex_${AMReX_SPACEDIM_LAST}d>
-)
+


#
diff --git a/Tools/CMake/AMReXInstallHelpers.cmake b/Tools/CMake/AMReXInstallHelpers.cmake
index 7c832d3a..ea5ea535 100644
--- a/Tools/CMake/AMReXInstallHelpers.cmake
+++ b/Tools/CMake/AMReXInstallHelpers.cmake
@@ -72,11 +72,6 @@ function (install_amrex_targets)
# legacy symlink for: libamrex.[so|a] / amrex.[dll.lib]
# escape spaces for generated cmake_install.cmake file
file(TO_CMAKE_PATH "${CMAKE_INSTALL_PREFIX}/lib" ABS_INSTALL_LIB_DIR)
- install(CODE "file(CREATE_LINK
- $<TARGET_FILE_NAME:amrex_${AMReX_SPACEDIM_LAST}d>
- \"${ABS_INSTALL_LIB_DIR}/$<TARGET_FILE_PREFIX:amrex_${AMReX_SPACEDIM_LAST}d>amrex$<TARGET_FILE_SUFFIX:amrex_${AMReX_SPACEDIM_LAST}d>\"
- COPY_ON_ERROR SYMBOLIC)"
- )

# Install fortran modules if Fortran is enabled
get_property(_lang GLOBAL PROPERTY ENABLED_LANGUAGES)
89 changes: 89 additions & 0 deletions packages/a/amrex/xmake.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package("amrex")
set_homepage("https://amrex-codes.github.io/amrex")
set_description("AMReX: Software Framework for Block Structured AMR")

add_urls("https://github.com/AMReX-Codes/amrex/releases/download/$(version)/amrex-$(version).tar.gz",
"https://github.com/AMReX-Codes/amrex.git")

add_versions("24.09", "a1435d16532d04a1facce9a9ae35d68a57f7cd21a5f22a6590bde3c265ea1449")

add_patches("24.09", "patches/24.09/remove-symlink.patch", "d71adb07252e488ee003f6f04fea756864d6af2232b43208c9e138e062eb6e4d")

add_configs("openmp", {description = "Enable OpenMP", default = false, type = "boolean"})
add_configs("mpi", {description = "Enable MPI", default = false, type = "boolean", readonly = true})
add_configs("cuda", {description = "Enable CUDA", default = false, type = "boolean"})
add_configs("hdf5", {description = "Enable HDF5-based I/O", default = false, type = "boolean"})
add_configs("fortran", {description = "Enable fortran", default = false, type = "boolean"})
add_configs("tools", {description = "Build tools", default = false, type = "boolean"})

if is_plat("linux", "bsd") then
add_syslinks("pthread")
end

add_deps("cmake")

if on_check then
on_check("windows", function (package)
import("core.base.semver")

local msvc = package:toolchain("msvc")
if msvc then
local vs_sdkver = msvc:config("vs_sdkver")
assert(vs_sdkver and semver.match(vs_sdkver):gt("10.0.19041"), "package(amrex) require vs_sdkver > 10.0.19041.0")
end
end)
end

on_load(function (package)
if package:config("openmp") then
package:add("deps", "openmp")
end
if package:config("cuda") then
package:add("deps", "cuda")
end
if package:config("hdf5") then
package:add("deps", "hdf5")
end
if package:config("fortran") and package:is_plat("linux", "macosx") then
package:add("deps", "gfortran", {kind = "binary"})
end
end)

on_install("windows", "macosx", "linux", "bsd", "mingw", function (package)
local configs = {"-DAMReX_ENABLE_TESTS=OFF"}
table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
table.insert(configs, "-DAMReX_PIC=" .. (package:config("pic") and "ON" or "OFF"))

local configs_map = {
openmp = "OMP",
tools = "PLOTFILE_TOOLS",
}
for name, enabled in table.orderpairs(package:configs()) do
if not package:extraconf("configs", name, "builtin") then
local real = configs_map[name] or name:upper()
local enabled = (package:config(name) and "ON" or "OFF")
table.insert(configs, format("-DAMReX_%s=%s", real, enabled))
end
end

if package:is_plat("windows") then
os.mkdir(path.join(package:buildir(), "Src/pdb"))
end
import("package.tools.cmake").install(package, configs)
end)

on_test(function (package)
assert(package:check_cxxsnippets({test = [[
#include <AMReX.H>
#include <AMReX_Print.H>
void test(int argc, char* argv[]) {
amrex::Initialize(argc,argv);
{
amrex::Print() << "Hello world from AMReX version " << amrex::Version() << "\n";
}
amrex::Finalize();
}
]]}, {configs = {languages = "c++17"}}))
end)

0 comments on commit ef4572e

Please sign in to comment.