How to do it

To create the corresponding source code, please follow these steps:

  1. Create a directory and place hello-world.cpp in the newly created directory.
  2. In this directory, create a CMakeLists.txt file which contains the following:
# set minimum cmake versioncmake_minimum_required(VERSION 3.5 FATAL_ERROR)# project name and languageproject(recipe-01 LANGUAGES CXX)set(CMAKE_CXX_STANDARD 11)set(CMAKE_CXX_EXTENSIONS OFF)set(CMAKE_CXX_STANDARD_REQUIRED ON)include(GNUInstallDirs)set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY  ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR})set(CMAKE_LIBRARY_OUTPUT_DIRECTORY  ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR})set(CMAKE_RUNTIME_OUTPUT_DIRECTORY  ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_BINDIR})# define executable and its ...

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.