Dependency management using Conan with a CMake project under VS2017

送分小仙女□ 提交于 2020-06-12 15:38:37

问题


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.

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.

image

Can anyone give some hints to solve this?

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

UPDATE

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

UPDATE 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 updated

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})

回答1:


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

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

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.

Hope this helps.



来源:https://stackoverflow.com/questions/49150146/dependency-management-using-conan-with-a-cmake-project-under-vs2017

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!