YouTip LogoYouTip

Cmake Install Setup

CMake Supported Operating Systems: * Microsoft Windows * Apple macOS * Linux * FreeBSD * OpenBSD * Solaris * AIX ## Install CMake CMake can be installed on different operating systems. This article will introduce the installation and configuration on Windows, Linux, and macOS systems. CMake Installation Package Download Address: [https://cmake.org/download/](https://cmake.org/download/). The download page contains source packages and binary packages: !(#) We can download the installation package suitable for our operating system from the binary package list above. ### Windows Select the Windows version installation package (usually a .msi file). After downloading, double-click the downloaded .msi file and follow the installation wizard to install. !(#) During installation, you can choose to add CMake to the system's PATH environment variable (it is recommended to select this option so that the cmake command can be used directly in the command line). !(#) **Verify Installation:** Open Command Prompt (CMD) or PowerShell, enter cmake --version, and check if the CMake version information is displayed correctly. ### macOS **Install via Homebrew** Open Terminal and execute the following installation command: ```bash brew install cmake **Install via Official Installer** Visit the CMake official website download page and select the macOS version .dmg file. Download and run the .dmg file, drag the CMake icon to the Applications folder. !(#) After successful installation, all commands are in the /Applications/CMake.app/Contents/bin directory. We need to add the environment variable to the .bash_profile file and edit it using vim: ```bash vim ~/.bash_profile Add the following content to the end of the file: ```bash export PATH="/Applications/CMake.app/Contents/bin":"$PATH" After adding, execute source ~/.bash_profile or restart the terminal. **Verify Installation:** Open Terminal, enter cmake --version, and confirm that CMake is installed correctly. ### Linux **Install via Package Manager (suitable for most distributions):** * For Ubuntu or Debian systems: `sudo apt-get install cmake` * For Fedora systems: `sudo dnf install cmake` * For Arch Linux systems: `sudo pacman -S cmake` **Install from Source Compilation:** Visit the CMake official website to download the source package. Extract the source package and enter the extracted directory. Execute the following commands to compile and install: ```bash ./bootstrap make sudo make install **Verify Installation:** Open Terminal, enter cmake --version, and confirm that CMake is installed successfully. * * * ## Configure CMake Make sure the CMake installation path is added to the system's PATH environment variable so that CMake can be accessed from the command line at any location. ### Windows Environment Variable Settings If you selected to add CMake to PATH during installation, no additional configuration is needed. If not selected, you can add manually: Right-click "Computer" or "This PC", select "Properties" -> "Advanced System Settings" -> "Environment Variables", find Path in "System Variables", click "Edit", and add the CMake installation path. ### macOS and Linux Usually the installer will automatically configure PATH. If not, you can configure it manually. Open Terminal, edit the ~/.bash_profile or ~/.zshrc file and add the following line: ```bash export PATH="/usr/local/bin:$PATH" Run source ~/.bash_profile or source ~/.zshrc to make the changes take effect. * * * ## Using CMake GUI CMake also provides a Graphical User Interface (GUI) for more intuitive project configuration. In Windows, it can usually be launched from the Start menu. !(#) In macOS and Linux, use the terminal command cmake-gui to launch. !(#) **Set Source Code Directory and Build Directory:** * **Source Code Directory:** Points to the directory containing the CMakeLists.txt file. * **Build Directory:** Points to the directory for storing generated build files. It is recommended to use a separate directory to keep the source code clean. **Configure and Generate:** * Click the "Configure" button, select the compiler and build options. CMake will check dependencies and generate the configuration. * Click the "Generate" button, and CMake will generate build files suitable for the current platform. Through the above steps, users can install and configure CMake and make it ready for building and managing projects.
← Cmake Build FlowFlask Deployment β†’