This repo was created to go with the question asked here. Intended to use target_* cmake commands for describing a modular build structure.
.
βββ CMakeLists.txt
βββ main.cpp
βββ ModA
βΒ Β βββ a.cc
βΒ Β βββ CMakeLists.txt
βΒ Β βββ public_includes
βΒ Β βββ a.h
βββ ModB
βΒ Β βββ b.cc
βΒ Β βββ CMakeLists.txt
βΒ Β βββ public_includes
βΒ Β βββ b.h
βββ ModC
βΒ Β βββ c.cc
βΒ Β βββ CMakeLists.txt
βΒ Β βββ public_includes
βΒ Β βββ c.h
βββ README.md
+--------+
+->+main.cpp+<-+
| +--------+ |
| |
| |
| |
+----+ +----+
|ModA| |ModB|
+----+ +----+
^ ^
| |
| +----+ |
+----+ModC+----+
+----+
ModA <- ModC: Module A
depends on Module C
------------------------------------
CMakeLists.txt
------------------------------------
cmake_minimum_required(VERSION 3.0)
project(test_project)
add_subdirectory(ModA)
add_subdirectory(ModB)
add_subdirectory(ModC)
add_executable(main main.cpp)
target_link_libraries(main
PRIVATE
ModA ModB)
------------------------------------
ModA/CMakeLists.txt
------------------------------------
add_library(ModA a.cc)
target_include_directories(ModA
PUBLIC
public_includes)
target_link_libraries(ModA PRIVATE ModC)
------------------------------------
ModB/CMakeLists.txt
------------------------------------
add_library(ModB b.cc)
target_include_directories(ModB
PUBLIC
public_includes)
target_link_libraries(ModB PRIVATE ModC)
------------------------------------
ModC/CMakeLists.txt
------------------------------------
add_library(ModC c.cc)
target_include_directories(ModC
PUBLIC
public_includes)