Brew Cmake

Posted on  by 



Brew

我是编程新手。您能帮我安装cmake吗?我输入brew install cmake。接下来我该怎么办?. If you already use /.local for user-space packages, the following single line command 1 will get CMake for you 2: $ wget -qO- ' tar -strip-components=1 -xz -C /.local. The names changed in 3.20; older releases had names like cmake-3.19.7-Linux-x8664.tar.gz. If you just want a local folder with CMake only.

Your CMake version should be newer than your compiler. It should be newer than the libraries you are using (especially Boost). New versions work better for everyone.

If you have a built in copy of CMake, it isn't special or customized for your system. You can easily install a new one instead, either on the system level or the user level. Feel free to instruct your users here if they complain about a CMake requirement being set too high. Especially if they want 3.1+ support. Maybe even if they want 3.20+ support...

Quick list (more info on each method below)

Ordered by author preference:

  • All
    • Pip (official, sometimes delayed slightly)
    • Anaconda / Conda-Forge
  • Windows
    • Download binary (official)
  • MacOS
    • Download binary (official)
  • Linux
    • Snapcraft (official)
    • APT repository (Ubuntu/Debian only) (official)
    • Download binary (official)

Official package

You can download CMake from KitWare. This is how you will probably get CMake if you are on Windows. It's not a bad way to get it on macOS either (and a Universal2 version is supplied supporting both Intel and Apple Silicon), but using brew install cmake is much nicer if you use Homebrew (and you should; Apple even supports Homebrew such as during the Apple Silicon rollout). You can also get it on most other package managers, such as Chocolatey for Windows or MacPorts for macOS.

On Linux, there are several options. Kitware provides a Debian/Ubunutu apt repository, as well as snap packages. There are universal Linux binaries provided, but you'll need to pick an install location. If you already use ~/.local for user-space packages, the following single line command1 will get CMake for you 2:

The names changed in 3.20; older releases had names like cmake-3.19.7-Linux-x86_64.tar.gz. If you just want a local folder with CMake only:

You'll obviously want to append to the PATH every time you start a new terminal, or add it to your .bashrc or to an LMod system.

And, if you want a system install, install to /usr/local; this is an excellent choice in a Docker container, for example on GitLab CI. Do not try it on a non-containerized system.

If you are on a system without wget, replace wget -qO- with curl -s.

You can also build CMake on any system, it's pretty easy, but binaries are faster.

CMake Default Versions

Brew Cmake

Here are some common build environments and the CMake version you'll find on them. Feel free to install CMake yourself, it's 1-2 lines and there's nothing 'special' about the built in version. It's also very backward compatible.

Windows

Also Scoop is generally up to date. The normal installers from CMake.org are common on Windows, too.

MacOS

Homebrew is quite a bit more popular nowadays on macOS, at least according to Google Trends.

Linux

RHEL/CentOS

Brew Install Clang

The default on 8 is not too bad, but you should not use the default on 7. Use the EPEL package instead.

Ubuntu

You should only use the default CMake on 18.04+; it's an LTS release with a pretty decent minimum version!

Other

General tools

Just pip install cmake on many systems. Add --user if you have to (modern pip does this for you if needed). This does not supply Universal2 wheels yet.

Brew Cmake-gui

CI

Brew install gccBrew
DistributionCMake versionNotes
TravisCI Xenial3.12.4Mid November 2018 this image became ready for widescale use.
TravisCI Bionic3.12.4Same as Xenial at the moment.
Azure DevOps 18.043.17.0
GitHub Actions 18.043.17.0Mostly in sync with Azure DevOps
GitHub Actions 20.043.17.0Mostly in sync with Azure DevOps

If you are using GitHub Actions, also see the jwlawson/actions-setup-cmake action, which can install your selection of CMake, even in a docker action run.

Full list

Versions less than 3.10 are marked by a deeper color of red.

Also see pkgs.org/download/cmake.

Pip

This is also provided as an official package, maintained by the authors of CMake at KitWare. It's a rather new method, and might fail on some systems (Alpine isn't supported last I checked, but that has a recent CMake), but works really well when it works (like on Travis CI). If you have pip (Python's package installer), you can do:

And as long as a binary exists for your system, you'll be up-and-running almost immediately. If a binary doesn't exist, it will try to use KitWare's scikit-build package to build, which currently can't be listed as a dependency in the packaging system, and might even require (an older) copy of CMake to build. So only use this system if binaries exist, which is most of the time.

This has the benefit of respecting your current virtual environment, as well. It really shines when placed in a pyproject.toml file, however - it will only be installed to build your package, and will not remain afterwords! Fantastic.

Personally, on Linux, I put versions of CMake in folders, like /opt/cmake312 or ~/opt/cmake312, and then add them to [LMod][]. See envmodule_setup for help setting up an LMod system on macOS or Linux. It takes a bit to learn, but is a great way to manage package and compiler versions.

1. I assume this is obvious, but you are downloading and running code, which exposes you to a man in the middle attack. If you are in a critical environment, you should download the file and check the checksum. (And, no, simply doing this in two steps does not make you any safer, only a checksum is safer). ↩
2. If you don't have a .local in your home directory, it's easy to start. Just make the folder, then add export PATH='$HOME/.local/bin:$PATH' to your .bashrc or .bash_profile or .profile file in your home directory. Now you can install any packages you build to -DCMAKE_INSTALL_PREFIX=~/.local instead of /usr/local! ↩

There are several ways to install CMake, depending on your platform.

Windows

There are pre-compiled binaries available on the Download page for Windows as MSI packages and ZIP files. One may alternatively download and build CMake from source. The Download page also provides source releases. In order to build CMake from a source tree on Windows, you must first install the latest binary version of CMake because it is used for building the source tree. Once the binary is installed, run it on CMake as you would any other project. Typically this means selecting CMake as the Source directory and then selecting a binary directory for the resulting executables.

Linux, macOS, UNIX

There are pre-compiled binaries available on the Download page for some UNIX platforms. One may alternatively download and build CMake from source. The Download page provides source releases. There are two possible approaches for building CMake from a source tree. If there is no existing CMake installation, a bootstrap script is provided:

(Note: the make install step is optional, cmake will run from the build directory.)

By default bootstrap will build CMake without any debug or optimization flags. To enable optimizations you will need to specify the CMAKE_BUILD_TYPE option to bootstrap like this: ./bootstrap -- -DCMAKE_BUILD_TYPE:STRING=Release

For more options with bootstrap, run ./bootstrap --help .

Brew cmake link

Or, an existing CMake installation can be used to build a new version:

(Note: the make install step is optional, cmake will run from the build directory.) If you are not using the GNU C++ compiler, you need to tell the bootstrap script (or cmake) which compiler you want to use. This is done by setting the environment variables CC and CXX before running it. For example:

Download Verification

Each release on the Download page comes with a file named cmake-$version-SHA-256.txt, where $version is the release version number.
One may use this file to verify other downloads, such as the source tarball. For example:

Brew Install Gcc

The SHA-256 file itself can be verified by GPG signature:

Brew Cmake Update

The GPG key C6C265324BBEBDC350B513D02D2CEF1034921684 is a signing subkey whose expiry is updated yearly.





Coments are closed