Conan: starting at a text book Hello World

Command Lines

  1. to search libraries from conancenter
    # conan search poco --remote=conancenter
  2. to inspect the metadata of a library
    # conan inspect poco/1.9.4
  3. to install the library and the dependency but also the transitive dependencies, and generate the information for the build system
    # conan install

Preparation

Download the project of the example:
# git clone https://github.com/conan-io/examples.git

50105@DESKTOP-2PP2ND2 MINGW64 /e/workplace/Conan/Repository/examples/libraries/poco/md5 (master)
$ ls
CMakeLists.txt  README.md  build/  build.bat  build.sh*  conanfile.txt  md5.cpp
  1. md5.cpp, the source codes
#include "Poco/MD5Engine.h"
#include "Poco/DigestStream.h"

#include 


int main(int argc, char** argv)
{
    Poco::MD5Engine md5;
    Poco::DigestOutputStream ds(md5);
    ds << "abcdefghijklmnopqrstuvwxyz";
    ds.close();
    std::cout << Poco::DigestEngine::digestToHex(md5.digest()) << std::endl;
    return 0;
}

  1. From the source codes of md5.cpp, one can see that this application relies on the Poco libraries, which can be installed from ConanCenter remote:
# conan search poco --remote=conancenter
Existing package recipes:

poco/1.8.1
poco/1.9.3
poco/1.9.4
...
poco/1.13.0
# conan inspect poco/1.9.4
name: poco
version: 1.9.4
url: https://github.com/conan-io/conan-center-index
homepage: https://pocoproject.org
license: BSL-1.0
author: None
description: Modern, powerful open source C++ class libraries for building network- and internet-based applications that run on desktop, server, mobile and embedded systems.
...
...
  1. And the poco/1.9.4 is the interested version. The metadata of the 1.9.4 version are showed above.
  2. conanfile.txt, the crucial recipe that determines the package. In this example CMake is used to build the project, which is why the cmake generator is
    specified.
[requires]
poco/1.9.4

[generators]
cmake

  1. install the required dependencies and generate the information for the build system:
# mkdir build && cd build
# conan install ..
Configuration:
[settings]
arch=x86_64
arch_build=x86_64
build_type=Release
compiler=Visual Studio
compiler.runtime=MD
compiler.version=16
os=Windows
os_build=Windows
[options]
[build_requires]
[env]

pcre/8.45: Not found in local cache, looking in remotes...
pcre/8.45: Trying with 'conancenter'...
Downloading conanmanifest.txt
Downloading conanfile.py
Downloading conan_export.tgz
pcre/8.45: Downloaded recipe revision 0
bzip2/1.0.8: Not found in local cache, looking in remotes...
...
...
poco/1.9.4: Package installed 827d0093fffd24b2cf1576c6515a7f7707d5d2b9
poco/1.9.4: Downloaded package revision 0
conanfile.txt: Generator cmake created conanbuildinfo.cmake
conanfile.txt: Generator txt created conanbuildinfo.txt
conanfile.txt: Aggregating env generators
conanfile.txt: Generated conaninfo.txt
conanfile.txt: Generated graphinfo

  1. cmake, the generator. To inject the Conan information, include the generated conanbuildinfo.cmake

CMakeLists.txt

cmake_minimum_required(VERSION 2.8.12)
project(MD5Encrypter)

if(CMAKE_VERSION VERSION_LESS 3.0.0)
    include(CheckCXXCompilerFlag)
    check_cxx_compiler_flag(-std=c++11 COMPILER_SUPPORTS_CXX11)
    check_cxx_compiler_flag(-std=c++0x COMPILER_SUPPORTS_CXX0X)
    if(COMPILER_SUPPORTS_CXX11)
      set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
    elseif(COMPILER_SUPPORTS_CXX0X)
      set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
    endif()
else()
    SET(CMAKE_CXX_STANDARD 11)
    SET(CMAKE_CXX_STANDARD_REQUIRED ON)
endif()

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()

add_executable(md5 md5.cpp)
target_link_libraries(md5 ${CONAN_LIBS})

  1. build and run MD5 app, in windows system case
> cmake .. -G "Visual Studio 16"
> cmake --build . --config Release

E:\workplace\Conan\Repository\examples\libraries\poco\md5\build\bin>md5.exe
c3fcd3d76192e4007dfb496cca67e13b
Press any key to continue. . .

你可能感兴趣的:(Conan,Learning,python,c++)