对具有子/外部项目/依赖项的项目使用cmake [英] Using cmake for a project with sub/external projects/dependencies
问题描述
我实际上正在通过一个使用 PocoProject 作为提供框架的项目来提高我的c ++技能一个简单的rest网络服务器和json解析以及mongodb驱动程序.
I am actually imroving my c++ skills with a project that uses PocoProject as a framework for supplying a simple rest webserver and json parsing as well as a mongodb driver.
我正在使用cmake/make编译项目
I am compiling my project with cmake/make
我的目录结构是:
root
- pocoproject
- helloworld.cpp
- CMakeLists.txt
要测试cmake,我有一个简单的cpp文件(取自poco示例),它启动一个http服务器.包括以下内容:
To test cmake, I have a simple cpp file (taken from the poco examples) that starts a http-server. the includes are the following:
#include "Poco/Net/HTTPServer.h"
#include "Poco/Net/HTTPRequestHandler.h"
...
#include "Poco/Util/HelpFormatter.h"
#include <iostream>
我的CMakeLists.txt如下:
My CMakeLists.txt look like:
cmake_minimum_required (VERSION 2.6)
project (Hello)
add_executable(Hello helloworld.cpp)
问题:
如何将所需的库从pocoproject添加到我的可执行文件中?如何正确引用标题?
Question:
How do I add the needed libraries from pocoproject to to my executable? How do I reference the headers correctly?
推荐答案
您需要让CMake项目知道从哪里查找依赖项,例如Poco.您需要设置变量 CMAKE_PREFIX_PATH
.可以使用 cmake-gui
或在命令行上完成:
You need let your CMake project know where to look for the dependencies, such as Poco. You need to set the variable CMAKE_PREFIX_PATH
. It can be done with cmake-gui
or on the command line:
cmake ... -DCMAKE_PREFIX_PATH=<path> ...
< path>
是您复制或安装Poco库的位置,因此Poco标头中的路径将类似于< path>/include/Poco/AbstractCache.h
等...,像< path>/lib/libPocoFoundation.*
之类的库,最重要的是,必须在< path>/lib/cmake中找到配置模块/Poco/PocoConfig.cmake
.
The <path>
is where you copied or installed the Poco library, so the Poco headers will have paths like <path>/include/Poco/AbstractCache.h
, etc..., libraries like <path>/lib/libPocoFoundation.*
and most importantly, the config-module must be found at <path>/lib/cmake/Poco/PocoConfig.cmake
.
在您的 CMakeLists.txt
中,您需要使用以下内容找到Poco软件包:
In your CMakeLists.txt
you need to find the Poco package with
find_package(Poco REQUIRED Foundation Util Net)
并使用
target_link_libraries(Hello Poco::Foundation Poco::Util Poco::Net)
这篇关于对具有子/外部项目/依赖项的项目使用cmake的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!