DEV Community

Lena
Lena

Posted on

2

CMake cheat sheet!

Article::Article

This is just a reminder of some commands I often use and why not share it if it can help someone.

The basics

Generate

Generate the project into path_to_build_directory (the base CMakeLists.txt must is in the current path)

cmake -B path_to_build_directory
Enter fullscreen mode Exit fullscreen mode

Build

Build the project in path_to_build_directory

cmake --build path_to_build_directory
Enter fullscreen mode Exit fullscreen mode

Test

Launch the tests with the root in path_to_build_directory

ctest --test-dir path_to_build_directory
Enter fullscreen mode Exit fullscreen mode

Common stuff

Toolchain integration

cmake -DCMAKE_TOOLCHAIN_FILE=path_to_the_toolchain .
Enter fullscreen mode Exit fullscreen mode

Specify the generator

# Example with Ninja
cmake -GNinja .
Enter fullscreen mode Exit fullscreen mode

Override an option/variable

Now MY_VAR will have the value : ON (ON/OFF can be used for boolean value with CMake)

cmake -DMY_VAR=ON
Enter fullscreen mode Exit fullscreen mode

Vcpkg

On all example there is an env variable named VCPKG_ROOT with path where you can find vcpkg.

Simple use of vcpkg

With Powershell

The quotes are meaningful

cmake -DCMAKE_TOOLCHAIN_FILE="$env:VCPKG_ROOT/scripts/buildsystems/vcpkg.cmake" .
Enter fullscreen mode Exit fullscreen mode

With Bash

cmake -DCMAKE_TOOLCHAIN_FILE="$VCPKG_ROOT/scripts/buildsystems/vcpkg.cmake" .
Enter fullscreen mode Exit fullscreen mode

Specify additionnal toolchain

cmake -DCMAKE_TOOLCHAIN_FILE="$VCPKG_ROOT/scripts/buildsystems/vcpkg.cmake" -DVCPKG_CHAINLOAD_TOOLCHAIN_FILE=my_path_to_my_other_toolchain .
Enter fullscreen mode Exit fullscreen mode

Specify the triplet

With the triplet for emscripten

cmake -DCMAKE_TOOLCHAIN_FILE="$VCPKG_ROOT/scripts/buildsystems/vcpkg.cmake" -DVCPKG_TARGET_TRIPLET=wasm32-emscripten .
Enter fullscreen mode Exit fullscreen mode

Use Both

cmake -DCMAKE_TOOLCHAIN_FILE="$VCPKG_ROOT/scripts/buildsystems/vcpkg.cmake" -DVCPKG_CHAINLOAD_TOOLCHAIN_FILE=my_path_to_my_other_toolchain -DVCPKG_TARGET_TRIPLET=wasm32-emscripten .
Enter fullscreen mode Exit fullscreen mode

An example with emscripten for one of my projects

cmake -GNinja -B em_build -DCMAKE_TOOLCHAIN_FILE="$env:HOMEPATH/vcpkg/scripts/buildsystems/vcpkg.cmake" -DVCPKG_CHAINLOAD_TOOLCHAIN_FILE="$env:EMSCRIPTEN_UPSTREAM_ROOT/emscripten/cmake/Modules/Platform:Emscripten.cmake" -DEMSCRIPTEN=ON
Enter fullscreen mode Exit fullscreen mode

Article::~Article

I hope theses commands will improve your daily life with cmake, or you can just use an IDE that launch the build by just pressing ctrl+b.

Sources

Image of AssemblyAI tool

Transforming Interviews into Publishable Stories with AssemblyAI

Insightview is a modern web application that streamlines the interview workflow for journalists. By leveraging AssemblyAI's LeMUR and Universal-2 technology, it transforms raw interview recordings into structured, actionable content, dramatically reducing the time from recording to publication.

Key Features:
🎥 Audio/video file upload with real-time preview
🗣️ Advanced transcription with speaker identification
⭐ Automatic highlight extraction of key moments
✍️ AI-powered article draft generation
📤 Export interview's subtitles in VTT format

Read full post

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay