Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/tanner-davison/cmake_commands_notes

a markdown file with cmake commands I can reference
https://github.com/tanner-davison/cmake_commands_notes

Last synced: 14 days ago
JSON representation

a markdown file with cmake commands I can reference

Awesome Lists containing this project

README

        

![Static Badge](https://img.shields.io/badge/Contact-tanner.davison95%40gmail.com-highcontrast%2F)

# ๐Ÿ“š CMake Command Reference

A comprehensive reference for essential CMake commands to assist in configuring, building, and managing your C++ projects.

Created by: Tanner Davison

# ๐Ÿ› ๏ธ Basic CMake Commands

### ๐Ÿ”ง Configure the Project
```bash
cmake -S . -B build
# -S .: Specifies the source directory (where CMakeLists.txt is located).
# -B build: Specifies the build directory where CMake will generate build files.
```
### ๐Ÿ—๏ธ Build the Project
```bash
cmake --build build
# Compiles and builds your project using the build system generated by CMake.
```
### ๐Ÿงน Clean the Build
```bash
rm -rf build
# Manually deletes the build directory, allowing you to start fresh.
```
### โš™๏ธ CMake Configuration Options
๐Ÿ› ๏ธ Set Build Type (Debug/Release)
```bash
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release
# CMAKE_BUILD_TYPE can be set to Debug, Release, RelWithDebInfo, or MinSizeRel.
```
### ๐Ÿงฐ Set a Custom Compiler
```bash
cmake -S . -B build -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++
# Allows you to specify a custom compiler for C and C++.
```
### ๐Ÿ“‚ Specify Installation Directory
```bash
cmake -S . -B build -DCMAKE_INSTALL_PREFIX=/path/to/install
# Sets the directory where the project will be installed.
```
# ๐Ÿงช Testing and Packaging
### ๐Ÿงช Run Tests (if configured)
```bash
ctest
# Runs tests defined in your project.
```
### ๐Ÿ“ฆ Create a Package
```bash
cpack
# Packages your project according to the configuration specified in CMakeLists.txt.
```
# ๐Ÿš€ Advanced Commands
### ๐Ÿ› ๏ธ Generate Compilation Database (for IDEs like VSCode)
```bash
cmake -S . -B build -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
# Generates a compile_commands.json file in the build directory, useful for IDEs that support it.
```
### ๐ŸŽ›๏ธ Use Presets (CMake 3.19+)
```bash
cmake --preset debug
# Presets allow predefined configurations (e.g., debug, release) in a CMakePresets.json file.
```
### ๐Ÿ“‚ Install the Project
```bash
cmake --install build
# Installs the project to the directory specified by CMAKE_INSTALL_PREFIX.
```
# ๐Ÿง Diagnostic Commands
### ๐Ÿ“‹ Show Available CMake Variables
```bash
cmake -LAH
# Displays all available CMake cache variables, useful for debugging or configuring the project.
```
### ๐Ÿ“ Check CMake Version
```bash
cmake --version
# Displays the installed version of CMake.
```
### โ“ Display Help
```bash
cmake --help
# Shows a help message with commonly used commands and options.
```
# ๐Ÿ–ฅ๏ธ Interactive Use
### ๐Ÿ–ผ๏ธ CMake GUI
```bash
cmake-gui
# Launches a graphical user interface for configuring CMake projects interactively.
```