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
- In a new directory, write a
C++programfizzbuzz.cppthat implementsFizzBuzz - The program should prompt the user to enter an integer
N - The program then prints out the integers from
1toNinclusive- 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
- If the number is divisible by 3, print
Extra Challenge (optional)
- Instead of 3 and 5, let the user enter the quotient for
Fizzand the quotient forBuzz
Compiling
- Use
g++to compile your program - Run it and make sure it works.
CMake
- Create a file called
CMakeLists.txt - Using the example provided in CMake Basics
- Make changes needed to get it to compile your
fizzbuzz.cppprogram - Remove lines that are unnecessary for this task.
- Make changes needed to get it to compile your
- Build a
Releaseversion by specifying-DCMAKE_BUILD_TYPE=Releaseon the command line- Do you notice any difference when running the program?