Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/tanner-davison/cmake_commands_notes
- Owner: Tanner-Davison
- Created: 2024-08-28T02:59:48.000Z (4 months ago)
- Default Branch: main
- Last Pushed: 2024-08-28T03:24:50.000Z (4 months ago)
- Last Synced: 2024-10-28T03:16:06.123Z (about 2 months ago)
- Size: 24.4 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
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.
```