UP | HOME

Exploring CMake

Overview

  • This activity provides an interactive introduction to CMake
  • The CMake Basics provides a conceptual overview and more information

The Program

We will implement the classic FizzBuzz challenge to provide code for our CMake project to compile.

Game Description

  1. In a new directory, write a C++ program fizzbuzz.cpp that implements FizzBuzz
  2. The program should prompt the user to enter an integer N
  3. The program then prints out the integers from 1 to N inclusive
    • If the number is divisible by 3, print Fizz
    • If the number is divisible by 5, print Buzz
    • If the number is divisible by both 3 and 5 print FizzBuzz
    • Otherwise, print the number

Extra Challenge (optional)

  1. Instead of 3 and 5, let the user enter the quotient for Fizz and the quotient for Buzz

Compiling

  1. Use g++ to compile your program
  2. Run it and make sure it works.

CMake

  1. Create a file called CMakeLists.txt
  2. Using the example provided in CMake Basics
    • Make changes needed to get it to compile your fizzbuzz.cpp program
    • Remove lines that are unnecessary for this task.
  3. Build a Release version by specifying -DCMAKE_BUILD_TYPE=Release on the command line
    • Do you notice any difference when running the program?

Author: Matthew Elwin.