I have the following Structure of my Project:
├── CMakeLists.txt
├── libA
│ ├── CMakeLists.txt
│ ├── include
│ │ └── libA
│ │ └── my_liba.h
│ ├── src
│ │ └── my_liba.cpp
│ └── test
├── libB
│ ├── CMakeLists.txt
│ ├── include
│ │ └── libB
│ │ └── my_libb.h
│ ├── src
│ │ └── my_libb.cpp
│ └── test
└── runner
├── CMakeLists.txt
└── src
└── main.cpp
I would like to achieve the following:
- Be able to build
libA
andlibB
andRunner
seperately - Be able to build all together.
For the dependency: libB
depends on libA
and Runner
needs libB
.
How do i have to configure libB and Runner?
These are the current CMakeLists.txt
Files:
libA/CMakeLists.txt:
cmake_minimum_required(VERSION 3.14)
project (MyLibA)
add_library(${PROJECT_NAME} src/my_liba.cpp)
add_library(Example::LibA ALIAS ${PROJECT_NAME})
target_include_directories( ${PROJECT_NAME}
PUBLIC ${PROJECT_SOURCE_DIR}/include
)
libB/CMakeLists.txt:
cmake_minimum_required(VERSION 3.14)
project (MyLibB)
add_library(${PROJECT_NAME} src/my_libb.cpp)
add_library(Example::LibB ALIAS ${PROJECT_NAME})
target_link_libraries(${PROJECT_NAME} PRIVATE Example::LibA)
target_include_directories( ${PROJECT_NAME}
PUBLIC ${PROJECT_SOURCE_DIR}/include
)
Runner/CMakeLists.txt
project(runner)
add_executable(${PROJECT_NAME} src/main.cpp)
target_link_libraries(${PROJECT_NAME}
Example::LibB
)
CMakeLists.txt:
cmake_minimum_required(VERSION 3.14)
project(Example)
add_subdirectory(libA)
add_subdirectory(libB)
add_subdirectory(runner)
With the current configuration i can build everything out of the lib
directory.
I could also build libA
from inside the libA
Directory. But i could not build libB
or runner
from there folders, which was to be expected, since they do not know where to find the dependencies.
How do i have to change my CMakeFiles
to get this to work?