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 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.