How to do it

Apart from the name of the project, the root CMakeLists.txt file is unchanged. Let us first look at the CMakeLists.txt file in the src subdirectory, where all the additional work actually happens. We will highlight the changes with respect to the file in the previous recipe:

  1. We declare our SHARED library target and its sources for the messaging library. Note that compile definitions and link libraries are unchanged:
add_library(message-shared SHARED "")target_sources(message-shared  PRIVATE    ${CMAKE_CURRENT_LIST_DIR}/Message.cpp  )target_compile_definitions(message-shared  PUBLIC    $<$<BOOL:${UUID_FOUND}>:HAVE_UUID>  )target_link_libraries(message-shared  PUBLIC    $<$<BOOL:${UUID_FOUND}>:PkgConfig::UUID>  )
  1. We also set target properties. ...

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.