How to do it

This is a C project and we will use the C99 standard. We will build the CMakeLists.txt file step by step:

  1. We declare a C project and enforce compliance with the C99 standard:
cmake_minimum_required(VERSION 3.6 FATAL_ERROR)  project(recipe-09 LANGUAGES C)set(CMAKE_C_STANDARD 99)set(CMAKE_C_EXTENSIONS OFF)set(CMAKE_C_STANDARD_REQUIRED ON)
  1. We look for pkg-config, using its find-module shipped with CMake. Notice the QUIET argument passed to find_package. CMake will print messages only if the required pkg-config is not found:
find_package(PkgConfig REQUIRED QUIET)
  1. When pkg-config is found, we will have access to the pkg_search_module function to search for any library or program that ships a package configuration .pc file. In ...

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.