forked from hakimel/reveal.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Chapter 1 Lab
David Zemon edited this page Jul 18, 2018
·
8 revisions
We're going to add a third library to the project which will be an alternative to upper
. The code for
useful
will switch between using upper
and this new library based on a preprocessor definition (#ifdef
). We'll
also take the time to refactor our growing project's build system into smaller and more modular pieces.
- Read about the
add_subdirectory(...)
command and segregate the relevant CMake scripting code into separateCMakeLists.txt
files, one in each of the project's subdirectories.- This is also an opportune time to create a new directory for the main executable, containing
main.cpp
and its ownCMakeLists.txt
file. - Global code, such as the invocation of the
project()
command, can and should be left in the primaryCMakeLists.txt
script at the root of the project.
- This is also an opportune time to create a new directory for the main executable, containing
- Create a new library (in a new child directory) named
lower
, containing a single source file and an appropriate header in the commoninclude
directory. - Implement a
to_lower(...)
function, similar toupper
'sto_upper(...)
function. - Using CMake, set a preprocessor definition,
LOWER
, on thelower
library such that any dependent targets oflower
also inherit that definition. - Use the same CMake/preprocessor technique to define an
UPPER
definition on theupper
library and its dependents - Add a CMake option that allows the user to easily switch between three different implementations for
useless
:- Original case:
useless
is dependent on neitherupper
norlower
. - Uppercase:
useless
is dependent onupper
. - Lowercase:
useless
is dependent onlower
.
- Original case:
- Utilize the preprocessor definition(s) set above in the
useless
code to switch between the three implementations. - Run your code with all three options to ensure it works as expected. You may also wish to check your dependency diagrams as generated by Graphviz.