How to do it

Once again, the root CMakeLists.txt file is unchanged with respect to the previous recipe. Moving onto the leaf directory src containing our sources:

  1. We need to find the UUID library and we can re-use the code used in previous recipes:
# Search for pkg-config and UUIDfind_package(PkgConfig QUIET)if(PKG_CONFIG_FOUND)  pkg_search_module(UUID uuid IMPORTED_TARGET)  if(TARGET PkgConfig::UUID)    message(STATUS "Found libuuid")    set(UUID_FOUND TRUE)  endif()endif()
  1. Next, we set up our shared library target and generate the export header, as shown in the previous recipe:
add_library(message-shared SHARED "")include(GenerateExportHeader)generate_export_header(message-shared  BASE_NAME "message"  EXPORT_MACRO_NAME "message_EXPORT" EXPORT_FILE_NAME ...

Get CMake Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.