I am trying to use CMake to set up some simple dependencies between a C++ project and the libraries that it uses.
The set up is as follows
It is not exactly clear what you want to do, and why Project
and Dependency
have to be build separately.
My first though on your example would be
In PROJECT
's CMakeLists.txt
:
add_dependencies(Project Dependency)
There is no need to specify dependency, target_link_libraries()
already does that.In DEPENDENCY
's CMakeLists.txt
:
project(Dependency)
It builds a library, so why to have own project?target_link_libraries(Dependency)
Because it does nothingSince CMake 2.8.11
you can use target_include_directories
. Just simply add in your DEPENDENCY project this function and fill in include directories you want to see in the main project. CMake will care the rest.
PROJECT, CMakeLists.txt:
cmake_minimum_required (VERSION 2.8.11)
project (Project)
include_directories (Project)
add_subdirectory (Dependency)
add_executable (Project main.cpp)
target_link_libraries (Project Dependency)
DEPENDENCY, CMakeLists.txt
project (Dependency)
add_library (Dependency SomethingToCompile.cpp)
target_include_directories (Dependency PUBLIC include)