How cmake find library packages

 

Introduction

An example will be used to illustrate how cmake find library packages.

Example

## you can install library first ##
$ sudo apt-get install libasound2

## in the CMakeLists.txt ##
# Handle ALSA / ASound libraries
find_package(ALSA)
if (ALSA_FOUND)
  message (STATUS "Info - Found ALSA library: ${ALSA_LIBRARY}")
  message (STATUS "Info - Found ALSA include: ${ALSA_INCLUDE_DIR}")
else (ALSA_FOUND)
  message (FATAL_ERROR "Info - ALSA is not found")
endif (ALSA_FOUND)

Which variable can I use

  • Go to official web site 001 or official web site 002
  • In ubuntu you can go to the installation path and find all the modules
    • /usr/share/cmake-3.16/Modules
    • FindALSA.cmake

Reference

Comments