homebrew-core/Formula/boost-mpi.rb

125 lines
4.4 KiB
Ruby

class BoostMpi < Formula
desc "C++ library for C++/MPI interoperability"
homepage "https://www.boost.org/"
# Please add to synced_versions_formulae.json once version synced with boost
url "https://boostorg.jfrog.io/artifactory/main/release/1.76.0/source/boost_1_76_0.tar.bz2"
sha256 "f0397ba6e982c4450f27bf32a2a83292aba035b827a5623a14636ea583318c41"
license "BSL-1.0"
head "https://github.com/boostorg/boost.git", branch: "master"
livecheck do
formula "boost"
end
bottle do
sha256 arm64_monterey: "416ef0b362beb9bd330074bdf9d0dfc65a306360ee0fc2867eea3f73620381cb"
sha256 arm64_big_sur: "8289fe7bb5a684360ab11462bf4312024a620854714ce02d6553e32274e5bfeb"
sha256 monterey: "4f8cc86632acebee2041d9e03772d4eff34ee3b195fd83b7b83afce577b8029f"
sha256 big_sur: "76544350ace536b0af831854f3ce18a5c101155a132001685bcfa3ea411bbb94"
sha256 catalina: "d3e1dfd88b6d683581efb1c0d732076eaa634d42d6e8d3de05ebec949f512740"
sha256 mojave: "fc0b30274d5d1eaf5f66b7c733e8c516ddfc864beddc0932eb6ee3ddd2457e6c"
sha256 cellar: :any_skip_relocation, x86_64_linux: "925c67fecdd80283070e6483972dfb0b81cdae28f6a404c46e640bb95ee13a54"
end
# Test with cmake to avoid issues like:
# https://github.com/Homebrew/homebrew-core/issues/67285
depends_on "cmake" => :test
depends_on "boost"
depends_on "open-mpi"
def install
# "layout" should be synchronized with boost
args = %W[
-d2
-j#{ENV.make_jobs}
--layout=tagged-1.66
--user-config=user-config.jam
install
threading=multi,single
link=shared,static
]
# Trunk starts using "clang++ -x c" to select C compiler which breaks C++11
# handling using ENV.cxx11. Using "cxxflags" and "linkflags" still works.
args << "cxxflags=-std=c++11"
args << "cxxflags=-stdlib=libc++" << "linkflags=-stdlib=libc++" if ENV.compiler == :clang
open("user-config.jam", "a") do |file|
if OS.mac?
file.write "using darwin : : #{ENV.cxx} ;\n"
else
file.write "using gcc : : #{ENV.cxx} ;\n"
end
file.write "using mpi ;\n"
end
system "./bootstrap.sh", "--prefix=#{prefix}", "--libdir=#{lib}", "--with-libraries=mpi"
system "./b2",
"--prefix=install-mpi",
"--libdir=install-mpi/lib",
*args
lib.install Dir["install-mpi/lib/*mpi*"]
(lib/"cmake").install Dir["install-mpi/lib/cmake/*mpi*"]
if OS.mac?
# libboost_mpi links to libboost_serialization, which comes from the main boost formula
boost = Formula["boost"]
MachO::Tools.change_install_name("#{lib}/libboost_mpi-mt.dylib",
"libboost_serialization-mt.dylib",
"#{boost.lib}/libboost_serialization-mt.dylib")
MachO::Tools.change_install_name("#{lib}/libboost_mpi.dylib",
"libboost_serialization.dylib",
"#{boost.lib}/libboost_serialization.dylib")
end
end
test do
(testpath/"test.cpp").write <<~EOS
#include <boost/mpi.hpp>
#include <iostream>
#include <boost/serialization/string.hpp>
namespace mpi = boost::mpi;
int main(int argc, char* argv[])
{
mpi::environment env(argc, argv);
mpi::communicator world;
if (world.rank() == 0) {
world.send(1, 0, std::string("Hello"));
std::string msg;
world.recv(1, 1, msg);
std::cout << msg << "!" << std::endl;
} else {
std::string msg;
world.recv(0, 0, msg);
std::cout << msg << ", ";
std::cout.flush();
world.send(0, 1, std::string("world"));
}
return 0;
}
EOS
boost = Formula["boost"]
args = ["-L#{lib}",
"-L#{boost.lib}",
"-lboost_mpi-mt",
"-lboost_serialization"]
on_linux do
args << "-Wl,-rpath,#{lib}"
args << "-Wl,-rpath,#{boost.lib}"
end
system "mpic++", "test.cpp", *args, "-o", "test"
system "mpirun", "-np", "2", "./test"
(testpath/"CMakeLists.txt").write "find_package(Boost COMPONENTS mpi REQUIRED)"
system "cmake", ".", "-Wno-dev"
end
end