class Gdcm < Formula desc "Grassroots DICOM library and utilities for medical files" homepage "http://sourceforge.net/projects/gdcm/" url "https://downloads.sourceforge.net/project/gdcm/gdcm%202.x/GDCM%202.6.1/gdcm-2.6.1.tar.bz2" sha256 "db12ac4322448dbf707e58d76fa0dc1232ed229d46391236a042588cf50b8033" bottle do sha256 "5e480698f28f6a3d7e16eeec541feb9b6e0ec24edfe4f3c5c35c11f80895d28d" => :el_capitan sha256 "1d046333077cc1f5325247a9f23260cabc1fe6152c75ddd0333e1ad14bcbdf46" => :yosemite sha256 "be5cf5f2ffd1d68322a01d22de4f119366fb26cecb9484c801819ec988d804bf" => :mavericks end option "with-check", "Run the GDCM test suite" depends_on :python => :optional depends_on :python3 => :optional depends_on "openssl" => :optional option :cxx11 cxx11dep = (build.cxx11?) ? ["c++11"] : [] depends_on "cmake" => :build depends_on "vtk" => [:optional] + cxx11dep depends_on "swig" => :build if build.with?("python") || build.with?("python3") if build.with?("python") && build.with?("python3") raise "Recipe may only be installed for one python type." end def install sourcedir = "#{pwd}/source_files" builddir = "#{pwd}/build_files" targets = Dir.glob("*") mkdir sourcedir targets.each do |target| mv target, File.join(sourcedir, File.basename(target)) end mkdir builddir do args = std_cmake_args if build.with?("python") || build.with?("python3") python_executable = `which python`.strip if build.with? "python" python_executable = `which python3`.strip if build.with? "python3" python_prefix = `#{python_executable} -c 'import sys;print(sys.prefix)'`.chomp python_include = `#{python_executable} -c 'from distutils import sysconfig;print(sysconfig.get_python_inc(True))'`.chomp python_version = "python" + `#{python_executable} -c 'import sys;print(sys.version[:3])'`.chomp py_site_packages = "#{lib}/#{python_version}/site-packages" args << "-DPYTHON_EXECUTABLE='#{python_executable}'" args << "-DPYTHON_INCLUDE_DIR='#{python_include}'" if File.exist? "#{python_prefix}/Python" args << "-DPYTHON_LIBRARY='#{python_prefix}/Python'" elsif File.exist? "#{python_prefix}/lib/lib#{python_version}.a" args << "-DPYTHON_LIBRARY='#{python_prefix}/lib/lib#{python_version}.a'" else args << "-DPYTHON_LIBRARY='#{python_prefix}/lib/lib#{python_version}.dylib'" end args << "-DGDCM_WRAP_PYTHON=ON" args << "-DGDCM_INSTALL_PYTHONMODULE_DIR='#{py_site_packages}'" end args << "-DGDCM_BUILD_APPLICATIONS=ON" args << "-DGDCM_BUILD_EXAMPLES=ON" args << "-DGDCM_BUILD_SHARED_LIBS=ON" args << "-DGDCM_BUILD_TESTING=ON" if build.with? "check" args << "-DGDCM_USE_VTK=ON" if build.with? "vtk" args << "-DGDCM_USE_SYSTEM_OPENSSL=ON" if build.with? "openssl" args << sourcedir system "cmake", *args system "make" system "make", "test" if build.with? "check" system "make", "install" end end test do system "#{bin}/gdcminfo", "--version" end end