aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Formula/libplist.rb
blob: ea7ebe7aedaf82e0b910f7d9d572b27758277247 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
require 'formula'

class Libplist < Formula
  homepage 'http://cgit.sukimashita.com/libplist.git/'
  url 'http://cgit.sukimashita.com/libplist.git/snapshot/libplist-1.10.tar.bz2'
  sha1 'a642bb37eaa4bec428d0b2a4fa8399d80ee73a18'

  head 'http://git.sukimashita.com/libplist.git'

  option 'with-python', 'Enable Cython Python bindings'

  depends_on 'cmake' => :build

  if build.include? 'with-python'
    depends_on 'Cython' => :python
    # Needed to find the Cython executable
    env :userpaths
  end

  def install
    ENV.deparallelize # make fails on an 8-core Mac Pro

    args = std_cmake_args

    # Disable Swig Python bindings
    args << "-DENABLE_SWIG='OFF'"

    if build.include? 'with-python'
      ## Taken from opencv.rb
      #
      # The CMake `FindPythonLibs` Module is dumber than a bag of hammers when
      # more than one python installation is available---for example, it clings
      # to the Header folder of the system Python Framework like a drowning
      # sailor.
      #
      # This code was cribbed from the VTK formula and uses the output to
      # `python-config` to do the job FindPythonLibs should be doing in the first
      # place.
      python_prefix = `python-config --prefix`.strip
      # Python is actually a library. The libpythonX.Y.dylib points to this lib, too.
      if File.exist? "#{python_prefix}/Python"
      # Python was compiled with --framework:
        args << "-DPYTHON_LIBRARY='#{python_prefix}/Python'"
        if !MacOS::CLT.installed? and python_prefix.start_with? '/System/Library'
          # For Xcode-only systems, the headers of system's python are inside of Xcode
          args << "-DPYTHON_INCLUDE_DIR='#{MacOS.sdk_path}/System/Library/Frameworks/Python.framework/Versions/2.7/Headers'"
        else
          args << "-DPYTHON_INCLUDE_DIR='#{python_prefix}/Headers'"
        end
      else
        python_lib = "#{python_prefix}/lib/lib#{which_python}"
        if File.exists? "#{python_lib}.a"
          args << "-DPYTHON_LIBRARY='#{python_lib}.a'"
        else
          args << "-DPYTHON_LIBRARY='#{python_lib}.dylib'"
        end
        args << "-DPYTHON_INCLUDE_DIR='#{python_prefix}/include/#{which_python}'"
      end
    else
      # Also disable Cython Python bindings if we're not building with '--python'
      args << "-DENABLE_CYTHON='OFF'"
    end

    system "cmake", ".", "-DCMAKE_INSTALL_NAME_DIR=#{lib}", *args
    system "make install"
  end

  def caveats
    if build.include? 'with-python'
      <<-EOS.undent
        To use the Python bindings with non-homebrew Python, you need to amend your
        PYTHONPATH like so:
          export PYTHONPATH=#{HOMEBREW_PREFIX}/lib/#{which_python}/site-packages:$PYTHONPATH
      EOS
    end
  end

  def which_python
    "python" + `python -c 'import sys;print(sys.version[:3])'`.strip
  end
end