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/"
url "https://boostorg.jfrog.io/artifactory/main/release/1.80.0/source/boost_1_80_0.tar.bz2"
sha256 "1e19565d82e43bc59209a168f5ac899d3ba471d55c7610c677d4ccf2c9c500c0"
license "BSL-1.0"
head "https://github.com/boostorg/boost.git", branch: "master"
livecheck do
formula "boost"
end
bottle do
sha256 arm64_ventura: "ef79f5ee09830e830df2100cad32f1231fbcfae40ba6d4359cdae15b3b5db54f"
sha256 arm64_monterey: "9c1be1173c1e34c1e88220da18605adb756f777f2c6048013eea7e864fef0ae7"
sha256 arm64_big_sur: "0cf455d731681d626f0e080710576d41639492572acba0d61c3edfdffc6b98c1"
sha256 ventura: "898317fb10a613ecf396f6f63ad0e97f4201ecd83c348fd9d61bac67049a3aaa"
sha256 monterey: "c5195f93adc7fe885d7344184f76b709c2e3e99f7bd7c48db8eb78689fb2add2"
sha256 big_sur: "3245f5c5284d901b402b326115f7925c422821f1e5b46a4db337c27a21ce24a8"
sha256 catalina: "d7837d66fce06bff98c00b0f3904ef1729321864aaef63b142a4520ea955bdc2"
sha256 cellar: :any_skip_relocation, x86_64_linux: "4610f966edd12b60607eff47ad6d912b7b4eb6857d21d25b35e93973eee98eba"
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"]
if OS.linux?
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