gpui-cc Course handbook
CHAPTER 01 / STAGE 00VERIFIED BASELINE

Build and run the starter

Get from source to a runnable C++ executable.

setup-build

Learn: what gets built?

CMake reads a recipe and generates Makefiles. Make uses those rules to ask the compiler and linker to produce the executable. Running the executable is a separate action: it can print text and return an exit status even if nobody is watching its output.

Run it: build a separate sample

Read the sample’s main.cpp and CMake recipe. The recipe adds one target named build_demo and sets its output directory to bin/ inside the sample build directory. The program reads one argument from argv[1]. argc includes the program name, so one supplied argument means argc == 2.

CMake · starter/cmake-demo/CMakeLists.txt
cmake_minimum_required(VERSION 4.0)
project(course_build_demo LANGUAGES CXX)

add_executable(build_demo main.cpp)
target_compile_features(build_demo PRIVATE cxx_std_20)
set_target_properties(build_demo PROPERTIES
    RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
C++ · starter/cmake-demo/main.cpp
#include <iostream>

int main(int argc, char** argv) {
    if (argc != 2) {
        std::cerr << "usage: build_demo NAME\n";
        return 2;
    }
    std::cout << "Hello, " << argv[1] << '\n';
    return 0;
}
Terminal
cmake -S course/examples/starter/cmake-demo -B build/examples/cmake-demo -G "Unix Makefiles"
cmake --build build/examples/cmake-demo
./build/examples/cmake-demo/bin/build_demo Ada
echo $?

Expect Hello, Ada, then 0. Try it: omit Ada and immediately run echo $? again. Expect the usage message, then 2. In later stages the checker will distinguish what a program prints from the status it returns.

Build it: your project baseline

Your challenge: Make a freshly built C++ executable print gpui-cc ready and exit successfully.

If starting empty, initialize Git with git init -b main, create src/main.cpp, and write a main that prints the line and returns zero. Add your own CMakeLists.txt. Use the sample’s target and compiler settings as a guide, but name yours gpui_cc, compile src/main.cpp, and put the executable under target/debug/ in the source tree, not the sample’s bin/ in the build tree. Accept TARGET_TYPE as a CMake cache value defaulting to debug and use it in the output path. Here debug labels a folder, not compiler flags. Ignore /build/ and /target/ in Git. If the checker is outside the learner repo, pass --project /path/to/project.

Terminal
cmake -S . -B build -G "Unix Makefiles" -DTARGET_TYPE=debug
cmake --build build
./target/debug/gpui_cc
python3 course/check.py setup-build

What the checker does: Configure and compile from a fresh snapshot, run the resulting executable with a timeout, and require exit 0 and the exact greeting on stdout (ignoring leading and trailing whitespace). If you already have commit 4c2a788, this should be green. If the checker reports a build failure, fix the first compiler or CMake error rather than running an old binary.

Hint: which CMake settings affect the executable?

add_executable creates the target. target_compile_features can require cxx_std_20 for that target. RUNTIME_OUTPUT_DIRECTORY is a target property; an explicit directory built from CMAKE_SOURCE_DIR and the chosen label keeps the output separate from Makefiles.