C++ Foundations·Modern C++ without the folklore

Modern builds and tooling

A build system, warnings and sanitizers catch mistakes before users do.

Intermediate 13 min read Lesson 10 of 300 Challenge included
What you will be able to do
  • Use target-based CMake: target_link_libraries and target_compile_options.
  • Compile with -Wall -Wextra -Wpedantic in development.
  • Run tests with sanitizers enabled.

In plain English

CMake describes targets and dependencies across platforms. Turn on warnings and treat them as errors. AddressSanitizer and UndefinedBehaviorSanitizer find bugs that tests miss; do not ship debug builds.

CMakeLists.txtCMake
cmake_minimum_required(VERSION 3.20)
project(edubyte_cpp CXX)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

add_executable(app src/main.cpp)
target_compile_options(app PRIVATE -Wall -Wextra -Wpedantic)
Your turn

Configure a C++ target

Medium

Create a CMake executable named app from src/main.cpp and enable -Wall -Wextra.

CMAKE · starter
add_executable(app src/main.cpp)
Check your understanding before moving on.
Knowledge checkQuestion 1

Which flag reports undefined behaviour at runtime?

Select an answer to continue
Study tools

Make it yours.

Keep a private note for this lesson, then turn the key ideas into flashcards you can revisit.

Sign in to save notes and flashcards.Both are private to your account and stay with your progress.
Sign in
Finished reading?

Lock in what you just learned.

Mark this lesson complete to save your place and move one step closer to the certificate.

Lesson 10 of 300 · 0% of course