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)
With this, we can define and link to the targets anywhere within the file tree accessed via include() statements. However, we should choose to define them at a place that is most intuitive for maintainers and code contributors.