How it works

In contrast to the previous recipe, we have defined three libraries:

  • conversion (defined in external)
  • automaton (containing all sources except conversion)
  • evolution (defined in src/evolution and linked against by cpp_test)

In this example, we keep all targets available in the parent scope by referencing CMakeLists.txt files using include():

include(src/CMakeLists.txt)include(external/CMakeLists.txt)

We can build a tree of includes, remembering that when stepping into subdirectories (src/CMakeLists.txt), we need to use paths relative to the parent scope:

include(${CMAKE_CURRENT_LIST_DIR}/evolution/CMakeLists.txt)include(${CMAKE_CURRENT_LIST_DIR}/initial/CMakeLists.txt)include(${CMAKE_CURRENT_LIST_DIR}/io/CMakeLists.txt)include(${CMAKE_CURRENT_LIST_DIR}/parser/CMakeLists.txt) ...

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.