-
Notifications
You must be signed in to change notification settings - Fork 0
Chapter 2 Lab
It's time to get a bit more in-depth with CMake's scripting syntax. It isn't complex, but there are some intricacies as well as many special functions. We'll explore many of them in this lab.
- Replace the four separate invocations of
add_subdirectory(...)with a for-loop that iterates over a list of subdirectories. (Note that I do not necessarily recommend doing this in practice - it simply works as a good way to practice CMake's for-loops). - Using a generator expression, add a preprocessor definition that will enable a new log statement if and only if the CMake build type is
Debug:- Add a log statement such as
std::cout << "[Upper] Finished for-loop" << std::endl;after the for-loop in the definition ofupper::to_upper(...). - CMake build type ==
Debug - Preprocessor macro ==
TRACE=1 - Only the source code for the
upperlibrary should use this macro (it should not be inherited by any other targets)
- Add a log statement such as
- Confirm with
VERBOSE=1that your new preprocessor macro is only utilized in the debug build and only inupper.cpp, not in release or any other files.
In this section you're going to build a special Make target to generate a complete package for your customer using your own custom CMake function and a few built-in functions.
- Shared libraries are good, right? Switch all of the libraries in this project to be dynamically rather than statically linked.
- Using any combination(s) of
add_custom_targetoradd_custom_commandthat you like, "install" the necessary files into a staging directory within the project's binary directory. Those files should include:- The
HelloWorldexecutable - All three shared libraries
- Headers from the project's
includedirectory
- The
- Create a new target named
my_install(you'll see thatinstallis a reserved target name, and we'll learn about it later) via theadd_custom_targetfunction.
Note that this is a very open-ended lab. You'll want to familiarize yourself with CMake's -E argument and its various options (hint: see this help page). You'll also need to become familiar with various CMake functions that may or may not have been explicitly taught in the slides. Use of the install() function is FORBIDDEN for this lab. The install() function will be taught next and this lab will help familiarize yourself with CMake syntax, docs, and miscellaneous functions. Remember that you want your app to be cross-platform, so do not use system utilities like cp or install and be sure to make use of generator expressions rather than relying on hard-coded filenames for the executable and libraries.