diff --git a/Formula/med-file@4.1.1.rb b/Formula/med-file@4.1.1.rb index 83677ed2..d203250e 100644 --- a/Formula/med-file@4.1.1.rb +++ b/Formula/med-file@4.1.1.rb @@ -39,6 +39,11 @@ class MedFileAT411 < Formula # end def install + # use gcc, g++, and gfrontran to build formula + ENV["CC"] = Formula["gcc"].opt_bin/"gcc-13" + ENV["CXX"] = Formula["gcc"].opt_bin/"g++-13" + ENV["FC"] = Formula["gcc"].opt_bin/"gfortran" + # ENV.cxx11 hbp = HOMEBREW_PREFIX @@ -48,35 +53,49 @@ def install "-DCMAKE_INSTALL_LIBDIR", ] + ENV["PYTHON"] = Formula["python@3.11"].opt_bin/"python3.11" + + python_exe = ENV["PYTHON"] + # Get the Python includes directory without duplicates + py_inc_dir = `#{python_exe}-config --includes`.scan(/-I([^\s]+)/).flatten.uniq.join(" ") + + py_lib_path = if OS.mac? + `python3.11-config --configdir`.strip + "/libpython3.11.dylib" + else + `python3.11-config --configdir`.strip + "/libpython3.11.a" + end + + puts "--------------------------------------------" + puts "PYTHON=#{ENV["PYTHON"]}" + puts "PYTHON_INCLUDE_DIR=#{py_inc_dir}" + puts "PYTHON_LIBRARY=#{py_lib_path}" + args = std_cmake_args + %W[ -DHOMEBREW_PREFIX=#{hbp} + -DMEDFILE_BUILD_TESTS=ON + -DMEDFILE_INSTALL_DOC=ON + -DMEDFILE_USE_UNICODE=ON -DMEDFILE_BUILD_PYTHON=ON - -DMEDFILE_BUILD_TESTS=OFF - -DMEDFILE_INSTALL_DOC=OFF - -DPYTHON_EXECUTABLE=#{Formula["python@3.11"].opt_bin}/python3.11 + -DPYTHON_EXECUTABLE=#{python_exe} + -DPYTHON_INCLUDE_DIRS=#{py_inc_dir} -DCMAKE_PREFIX_PATH=#{Formula["hdf5"].opt_prefix};#{Formula["gcc"].opt_prefix}; -DCMAKE_INSTALL_RPATH=#{rpath} ] - if OS.mac? - args << "-DPYTHON_LIBRARY=#{hbp}/opt/python@3.11/Frameworks/Python.framework/Versions/Current/lib" \ - "/libpython3.11.dylib" - args << "-DPYTHON_INCLUDE_DIRS=#{Formula["python@3.11"].opt_prefix}/Frameworks/Python.framework/Versions/" \ - "3.11/Headers" - else - # NOTE: specifying the below cmake var still did not help in finding `Python.h` - args << "-DPYTHON_INCLUDE_DIRS=#{hbp}/opt/python@3.11/include/python3.11" - args << "-DPYTHON_LIBRARY=#{hbp}/opt/python@3.11/lib/libpython3.11.so" - end - # Remove unwanted values from args args.reject! { |arg| rm_std_cmake_args.any? { |value| arg.include?(value) } } - mkdir "build" do - system "cmake", "..", *args - system "make" - system "make", "install" - end + system "cmake", "-S", ".", "-B", "build", *args + system "cmake", "--build", "build" + system "cmake", "--install", "build" + + end + + def post_install + # Move installed Python module to the correct directory + site_packages_dir = lib/"python3.11/site-packages" + mkdir_p site_packages_dir + mv Dir["#{lib}/python.*/site-packages/med"], site_packages_dir end test do