Let us start with the same source code as for the previous recipe. We want to be able to toggle between two behaviors:
- Build Message.hpp and Message.cpp into a library, static or shared, and then link the resulting library into the hello-world executable.
- Build Message.hpp, Message.cpp, and hello-world.cpp into a single executable, without producing the library.
Let us construct CMakeLists.txt to achieve this:
- We start out by defining the minimum CMake version, project name, and supported language:
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)project(recipe-04 LANGUAGES CXX)
- We introduce a new variable, USE_LIBRARY. This is a logical variable and its value will be set to OFF. We also print its value for the user:
set(USE_LIBRARY ...