1、下载
去cmake官网下载对应版本的binaries or source code archives。
我电脑:Apple M1 Pro
、macOS:版本13.0.1 (22A400)
,下载的cmake-3.26.0-rc2-macos-universal.dmg
版本
2、安装
点击dmg拖拽安装后实验失败
cmake ..
zsh: command not found: cmake
于是在电脑Launchpad(启动台)
找到CMake
图标,点击启动
点击Tools
,选择How to Install For Command Line Use
给了三种安装方式:
文字版本:
One may add CMake to the PATH:
PATH="/Applications/CMake.app/Contents/bin":"$PATH"
Or, to install symlinks to '/usr/local/bin', run:
sudo "/Applications/CMake.app/Contents/bin/cmake-gui" --install
Or, to install symlinks to another directory, run:
sudo "/Applications/CMake.app/Contents/bin/cmake-gui" --install=/path/to/bin
于是在终端执行了
sudo "/Applications/CMake.app/Contents/bin/cmake-gui" --install
完成安装
3、验证
命令行验证版本号:
~ % cmake --version
cmake version 3.26.0-rc2
CMake suite maintained and supported by Kitware (kitware.com/cmake).
写一个helloworld.cpp
#include <iostream>
using namespace std;
int main()
{
cout << "Hello, World!";
return 0;
}
CMakeList.txt
cmake_minimum_required(VERSION 3.0)
project(HelloWord)
add_executable(hello_world helloword.cpp)
终端运行:
% mkdir build && cd build
build % cmake .. && make -j8
build % ./hello_world
Hello, World!%