OS X Homebrew 需要为 cmake 创建构建目录

OS X Homebrew needs to create build directory for cmake

我有一个简单的自制脚本,我正在尝试用它来构建库 cmake-basis。但是,它不能用 cmake 在源代码中构建,我需要创建一个单独的构建目录。通常在 bash 我会做以下事情:

git clone https://github.com/schuhschuh/cmake-basis.git -b develop ~/cmake-basis 
cd ~/cmake-basis && mkdir build && cd build 
cmake .. -DCMAKE_INSTALL_PREFIX=/usr/local 
make 
make install

我正在尝试制作一个自制脚本来自动执行此操作:

# Documentation: https://github.com/Homebrew/homebrew/blob/master/share/doc/homebrew/Formula-Cookbook.md
#                /usr/local/Library/Contributions/example-formula.rb
# PLEASE REMOVE ALL GENERATED COMMENTS BEFORE SUBMITTING YOUR PULL REQUEST!

class CmakeBasis < Formula
  desc "cmake build and installer generation tools"
  homepage "https://github.com/schuhschuh/cmake-basis"
  url "https://github.com/schuhschuh/cmake-basis.git", :using => :git, :tag => "v3.1.0"
  version "3.1"
  #sha256 ""

  depends_on "cmake" => :build
  depends_on "doxygen" => :recommended
  depends_on :python => :required
  # todo: add sphinx python dependency
  #depends_on :x11 # if your formula requires any X11/XQuartz components

  # The optional devel block is only executed if the user passes `--devel`.
  # Use this to specify a not-yet-released version of a software.
  devel do

    url "https://github.com/schuhschuh/cmake-basis.git", :using => :git, :branch => "develop"

  end

  head do

    url "https://github.com/schuhschuh/cmake-basis.git", :using => :git, :branch => "master"

  end

  def install
    args = %W[
    ]
    # ENV.deparallelize  # if your formula fails when building in parallel
    system "cmake", "-G", "Unix Makefiles", buildpath, *(std_cmake_args + args)
    system "make"
    system "make", "install"
  end



  test do
    # `test do` will create, run in and delete a temporary directory.
    #
    # This test will fail and we won't accept that! It's enough to just replace
    # "false" with the main program this formula installs, but it'd be nice if you
    # were more thorough. Run the test with `brew test cmake-basis`. Options passed
    # to `brew install` such as `--HEAD` also need to be provided to `brew test`.
    #
    # The installed folder is not in the path, so use the entire path to any
    # executables being tested: `system "#{bin}/program", "do", "something"`.
    system "false"
  end
end

但是报如下错误:

CMake Error at src/cmake/ProjectTools.cmake:666 (message):
  This project should not be configured & build in the source directory:

    /tmp/cmake-basis20150811-955-1b0sqck

  You must run CMake in a separate build directory.
Call Stack (most recent call first):
  src/cmake/ProjectTools.cmake:1952 (basis_buildtree_asserts)
  src/cmake/ProjectTools.cmake:2156 (basis_project_begin)
  CMakeLists.txt:66 (basis_project_impl)


-- Configuring incomplete, errors occurred!

如何使用 homebrew 执行 cd ~/cmake-basis && mkdir build && cd build 的等价操作,以便它会为我创建一个单独的目录以 运行 cmake?

感谢 DomT4 在 homebrew 上的解决方案:

def install
  mkdir "build" do
    system "cmake", "-G", "Unix Makefiles", "..", *std_cmake_args
    system "make"
    system "make", "install"
 end
end