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
Project itself contains source files that include headers from Dependency
and when the executable is built it needs to be linked against Dependency
's static library.
So far I can get this to work, but I have to specify the include directories of Dependency
in the CMakeLists.txt
file for Project
manually. I want this to be pulled out automatically, and I have explored the option of using the find_package()
command to do so with limited success and making things much more complicated.
All I want to do is have Dependency
built before Project
and have Project
link against the library and have its include directories. Is there a simple concise way of achieving this?
My current CMake files:
Project
, file CMakeLists.txt
:
cmake_minimum_required (VERSION 2.6)
project (Project)
include_directories ("${PROJECT_SOURCE_DIR}/Project")
add_subdirectory (Dependency)
add_executable (Project main.cpp)
target_link_libraries (Project Dependency)
add_dependencies(Project Dependency)
Dependency
, file CMakeLists.txt
:
project(Dependency)
add_library(Dependency SomethingToCompile.cpp)
target_link_libraries(Dependency)
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…