在VS2017下使用Conan和CMake项目进行依赖管理 [英] Dependency management using Conan with a CMake project under VS2017

查看:304
本文介绍了在VS2017下使用Conan和CMake项目进行依赖管理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为C ++设置开发环境,以使用CMake与VS2017集成在Linux x64下编译。为了更好地管理依赖项,我选择使用Conan,但是我对该软件还很陌生,我想知道让VS2017识别项目依赖项的最佳方法是什么。

I'm trying to setup a development environment for C++ to compile under Linux x64 using CMake integration with VS2017. To better manage dependencies I choose to use Conan but I'm pretty new to this software and I'm wondering what's the best way to have VS2017 to recognize the dependencies of the project.

例如,我使用柯南安装了用于C ++的POCO库,但是当我打开Main.cpp文件时,它无法识别头文件的位置,我我真的不确定在哪里添加这些路径。

For example, I've used Conan to install the POCO library for C++ but when I open the Main.cpp file it doesn't recognise the header files location and I'm not really sure where to add those paths.

任何人都可以提供一些提示来解决此问题吗?

Can anyone give some hints to solve this?

如果需要,所有源文件都在我的Github存储库中 CppLinuxVS

If needed all the source files are in my Github repo CppLinuxVS.

更新

根据此信息的评论,您可以在下面找到文件内容:

As per comments on this post, below you can find the contents of the files:

CMakeLists.txt

project(CppLinuxVS)
cmake_minimum_required(VERSION 2.8.12)
add_definitions("-std=c++11")

# Download automatically, you can also just copy the conan.cmake file
if(NOT EXISTS "${CMAKE_BINARY_DIR}/conan.cmake")
   message(STATUS "Downloading conan.cmake from https://github.com/conan-io/cmake-conan")
   file(DOWNLOAD "https://raw.githubusercontent.com/conan-io/cmake-conan/v0.8/conan.cmake"
                 "${CMAKE_BINARY_DIR}/conan.cmake")
endif()

include(${CMAKE_BINARY_DIR}/conan.cmake)
conan_cmake_run(CONANFILE conanfile.txt
                BASIC_SETUP CMAKE_TARGETS
                BUILD missing)

add_executable(CppLinuxVS Main.cpp)
target_link_libraries(CppLinuxVS ${CONAN_LIST})

conanfile.txt

[requires]
Poco/1.8.0@pocoproject/stable

[generators]
cmake

更新2

下载conan.cmake后在VS2017中输出CMake文件而不是在CMakeLists.txt中指定下载文件。还根据注释中的建议更新了CMakeLists.txt,以要求CMake 3.1.2。

Output of CMake inside VS2017 after downloading the conan.cmake file into the project instead of having the download specified in CMakeLists.txt. Also updated the CMakeLists.txt to require CMake 3.1.2 as per suggestion in the comments.

1> 17:52:57: Copying files to remote machine...
1> 17:53:00: Finished copying files (elapsed time 00h:00m:02s:799ms).
1> /usr/local/bin/cmake -G "Unix Makefiles"  -DCMAKE_BUILD_TYPE="Debug" "\var\tmp\src\03967bd6-44be-4e31-b449-a34a45d7109d\Linux-Debug"
1> -- Conan ** WARNING** : This detection of settings from cmake is experimental and incomplete. Please check 'conan.cmake' and contribute
1> -- Conan executing: conan install /var/tmp/src/03967bd6-44be-4e31-b449-a34a45d7109d/Linux-Debug/conanfile.txt -g cmake -s build_type=Debug -s os=Linux -s compiler=gcc -s compiler.version=5 -s compiler.libcxx=libstdc++11 --build=missing
1> PROJECT: Installing /var/tmp/src/03967bd6-44be-4e31-b449-a34a45d7109d/Linux-Debug/conanfile.txt
1> Requirements
1>     OpenSSL/1.0.2l@conan/stable from 'conan-center'
1>     Poco/1.8.0@pocoproject/stable from 'conan-center'
1>     zlib/1.2.11@conan/stable from 'conan-center'
1> Packages
1>     OpenSSL/1.0.2l@conan/stable:f68b4e006611addfaec53a2f3d5c0e6b0406266d
1>     Poco/1.8.0@pocoproject/stable:e3d8f1070a587658375103e87fd35c8b5c372b6e
1>     zlib/1.2.11@conan/stable:15c6f8a55cbf8b39b86ca055629a91be1b2d3cf5
1> 
1> zlib/1.2.11@conan/stable: Already installed!
1> OpenSSL/1.0.2l@conan/stable: Already installed!
1> Poco/1.8.0@pocoproject/stable: Already installed!
1> PROJECT: Generator cmake created conanbuildinfo.cmake
1> PROJECT: Generator txt created conanbuildinfo.txt
1> PROJECT: Generated conaninfo.txt
1> -- Conan: Loading conanbuildinfo.cmake
1> -- Current conanbuildinfo.cmake directory: /var/tmp/build/03967bd6-44be-4e31-b449-a34a45d7109d/build/Linux-Debug
1> -- Conan: Compiler GCC>=5, checking major version 5
1> -- Conan: Checking correct version: 5
1> -- Conan: Using cmake targets configuration
1> -- Library PocoUtild found /root/.conan/data/Poco/1.8.0/pocoproject/stable/package/e3d8f1070a587658375103e87fd35c8b5c372b6e/lib/libPocoUtild.a
1> -- Library PocoMongoDBd found /root/.conan/data/Poco/1.8.0/pocoproject/stable/package/e3d8f1070a587658375103e87fd35c8b5c372b6e/lib/libPocoMongoDBd.a
1> -- Library PocoNetd found /root/.conan/data/Poco/1.8.0/pocoproject/stable/package/e3d8f1070a587658375103e87fd35c8b5c372b6e/lib/libPocoNetd.a
1> -- Library PocoNetSSLd found /root/.conan/data/Poco/1.8.0/pocoproject/stable/package/e3d8f1070a587658375103e87fd35c8b5c372b6e/lib/libPocoNetSSLd.a
1> -- Library PocoCryptod found /root/.conan/data/Poco/1.8.0/pocoproject/stable/package/e3d8f1070a587658375103e87fd35c8b5c372b6e/lib/libPocoCryptod.a
1> -- Library PocoDatad found /root/.conan/data/Poco/1.8.0/pocoproject/stable/package/e3d8f1070a587658375103e87fd35c8b5c372b6e/lib/libPocoDatad.a
1> -- Library PocoDataSQLited found /root/.conan/data/Poco/1.8.0/pocoproject/stable/package/e3d8f1070a587658375103e87fd35c8b5c372b6e/lib/libPocoDataSQLited.a
1> -- Library PocoZipd found /root/.conan/data/Poco/1.8.0/pocoproject/stable/package/e3d8f1070a587658375103e87fd35c8b5c372b6e/lib/libPocoZipd.a
1> -- Library PocoXMLd found /root/.conan/data/Poco/1.8.0/pocoproject/stable/package/e3d8f1070a587658375103e87fd35c8b5c372b6e/lib/libPocoXMLd.a
1> -- Library PocoJSONd found /root/.conan/data/Poco/1.8.0/pocoproject/stable/package/e3d8f1070a587658375103e87fd35c8b5c372b6e/lib/libPocoJSONd.a
1> -- Library PocoFoundationd found /root/.conan/data/Poco/1.8.0/pocoproject/stable/package/e3d8f1070a587658375103e87fd35c8b5c372b6e/lib/libPocoFoundationd.a
1> -- Library pthread not found in package, might be system one
1> -- Library dl not found in package, might be system one
1> -- Library rt not found in package, might be system one
1> -- Library ssl found /root/.conan/data/OpenSSL/1.0.2l/conan/stable/package/f68b4e006611addfaec53a2f3d5c0e6b0406266d/lib/libssl.a
1> -- Library crypto found /root/.conan/data/OpenSSL/1.0.2l/conan/stable/package/f68b4e006611addfaec53a2f3d5c0e6b0406266d/lib/libcrypto.a
1> -- Library dl not found in package, might be system one
1> -- Library z found /root/.conan/data/zlib/1.2.11/conan/stable/package/15c6f8a55cbf8b39b86ca055629a91be1b2d3cf5/lib/libz.a
1> -- Conan: Adjusting default RPATHs Conan policies
1> -- Conan: Adjusting language standard
1> -- Configuring done
1> -- Generating done
1> -- Build files have been written to: /var/tmp/build/03967bd6-44be-4e31-b449-a34a45d7109d/build/Linux-Debug
1> Starting CMake target info extraction ...
1> Extracted source files and headers.
1> Extracted global settings.
1> Extracted code model.
1> Collating data ...
1> Target info extraction done.

CMakeLists.txt已更新

project(CppLinuxVS)
cmake_minimum_required(VERSION 3.1.2)
add_definitions("-std=c++11")

include(conan.cmake)
conan_cmake_run(CONANFILE conanfile.txt
                BASIC_SETUP CMAKE_TARGETS
                BUILD missing)

add_executable(CppLinuxVS Main.cpp)
target_link_libraries(CppLinuxVS ${CONAN_LIBS})


推荐答案

@lusocoding这是我设置的一个项目,用于演示VS-> Cmake-> Conan的有效组合。

@lusocoding here is a project i setup to demonstrate a working combination of VS -> Cmake -> Conan.

https:// github .com / solvingj / vs-cmake-conan-demo

其中一个关键部分(我记得)是CMakeSettings.json,它应该是通常不提交给git的特定于机器的设置。但是,当时有一些自定义项(我认为这是传递给CMake的CLI标志),我必须对其进行添加以使其起作用。因此,我将该文件提交给git进行演示。

One of the critical parts (as I recall) was CMakeSettings.json, which is supposed to be a machine-specific setting that you don't typically commit to git. However, at the time, there were customizations (i think it was the CLI flags passed to CMake) which i had to add to to make it work. So, i committed that file to git for the demonstration.

看看您是否可以按原样克隆和使用该项目,然后慢慢与您的项目进行比较以发现差异。

See if you can clone and use the project as is, and then slowly compare with your project to find differences.

希望这会有所帮助。

这篇关于在VS2017下使用Conan和CMake项目进行依赖管理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆