How to do it

Now that we have the sources in place, our goal will be to configure the project and experiment with compiler flags:

  1. We set the minimum required version of CMake:
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
  1. We declare the name of the project and the language:
project(recipe-08 LANGUAGES CXX)
  1. Then, we print the current set of compiler flags. CMake will use these for all C++ targets:
message("C++ compiler flags: ${CMAKE_CXX_FLAGS}")
  1. We prepare a list of flags for our targets. Some of these will not be available on Windows and we make sure to account for that case:
list(APPEND flags "-fPIC" "-Wall")if(NOT WIN32)  list(APPEND flags "-Wextra" "-Wpedantic")endif()
  1. We add a new target, the geometry library and list its source ...

Get CMake Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.