Vcpkg install freeglut x86 windows

freeglut

3.6.0#1

A free OpenGL utility toolkit, the open-sourced alternative to the GLUT library.

  • Dependencies
  • Features
  • Versions
  • Port Content

Dependencies

opengl

vcpkg-cmake

host:

vcpkg-cmake-config

host:

Features

No Features

Available Versions

  • 3.6.0#1
  • 3.6.0#0
  • 3.4.0#3
  • 3.4.0#2
  • 3.4.0#1
  • 3.4.0#0
  • 3.2.2#0
  • 3.2.1#7
  • 3.2.1#6
  • 3.2.1#5
  • 3.2.1-4#0
  • 3.2.1-2#0
  • 3.2.1-1#0
  • 3.2.1#0
  • 3.0.0-9#0
  • 3.0.0-8#0
  • 3.0.0-7#0
  • 3.0.0-6#0
  • 3.0.0-5#0
  • 3.0.0-4#0
  • 3.0.0-3#0
  • 3.0.0-2#0
  • 3.0.0-1#0
  • 3.0.0#0

Port Content

  • android.patch
  • cmake-version.patch
  • fix-debug-macro.patch
  • portfile.cmake
  • usage
  • vcpkg-cmake-wrapper.cmake
  • vcpkg.json
  • windows-output-name.patch
  • x11-dependencies-export.patch

Metadata

null

2025-03-21

Supports

This package supports the following triplets:

!ios

Documentation

Unavailable

Homepage

https://sourceforge.net/projects/freeglut/

Install

In classic mode, run the following vcpkg command:

 vcpkg install freeglut

In manifest mode, run the following vcpkg command in your project directory:

 vcpkg add port freeglut

1 Package Managers

1.1 Overview

Package Managers

There are several solutions for managing dependencies in C++ projects,
however they are still no widely used or integrated to IDEs and
building systems. A reasonable set of features for selecting a package
manager is CMake support, CMake integration, IDE integration, command
line interface and distributed repositories. Some of them are:

  • Conan [Most mature], [BEST] — Dependency manager written in Python which
    can install source packages from multiple repositories, including
    local network and current machine package cache of pre-compiled
    object code.

    • Creator: Diego Rodriguez Losada
    • CMake Support: YES
    • Implementation Issues: As Conan is written in Python, it requires
      a Python installation.
    • Package authoring: Packages configuration are written in Python.
    • See:
      • C/C++ Binary Package Management for Visual Studio
    • Video:
      • CppCon 2016: Diego Rodriguez-Losada «Conan, a C and C++ package manager for developers»
      • Humor, funny: CppCon 2016: Diego Rodriguez-Losada «Why not Conan?»
      • Diego Rodriguez-Losada: Conan C++ package manager
  • vcpkg [Most mature], [BEST] — open source cross-platform C++ package
    manager created by Microsft Inc.

    • Creator: Microsft Inc. MSFT
    • CMake Support: YES
    • Documentation: https://vcpkg.readthedocs.io/en/latest/
    • Repository: https://github.com/Microsoft/vcpkg
    • FAQ: VCpkg FAQ
    • See:
      • Vcpkg: A tool to build open source libraries on Window
      • Video: Microsft — Vcpkg a tool to build open source C++ libraries
      • Video: Microsft — GoingNative 54: What’s New In Visual Studio 2017 RC and Introduction To Vcpkg
      • Video: C++ Weekly — Ep 118 — Trying Out The vcpkg Package Manager
  • Buckaroo — «A C++ package manager that will take you to your happy place»
    • Creator: LoopPerfect Limited LTD.
    • CMake Support: Backaroo uses Buck build system as its default
      building system, although there is still some limited support to
      CMake. More info. at Buildign CMake projects
    • Repository: https://github.com/LoopPerfect/buckaroo
    • Documentation: https://github.com/LoopPerfect/buckaroo/wiki/
    • Buckaroo-recipes: https://github.com/LoopPerfect/buckaroo-recipes/tree/master/recipes
  • QPM — Pcakge manager for QT.
    • Repository: https://github.com/Cutehacks/qpm
    • CMake Support: ???
    • Package listing: https://www.qpm.io/packages/index.html
  • cget — «Cmake package retrieval. This can be used to download and
    install cmake packages.» Decentralized: Packages can be installed
    from anywhere, from github, urls, or local files. NOTE: It is not a
    package manager.

    • Creator: Paul Fultz
    • CMake Support: YES
    • Repository: https://github.com/pfultz2/cget
  • Hunter — Cross-platform package manager for C/C++ fully integrated
    to CMake, it does not need any external configuration file or run
    any application before editing the project or running cmake from
    command line. All the libraries to be installed are set in the
    file CMakeFiles.txt. If they are not available in the system, they
    are automatically downloaded and installed.

    • Creator: Ruslan Baratov
    • CMake Support: YES
    • Documentation: https://docs.hunter.sh
    • Package list: https://docs.hunter.sh/en/latest/packages.html
    • Note: It is still under development, but it seems promising.
  • Cppan — «CPPPAN is the crossplatform C/C++ dependency manager. It
    is built on top of CMake and also has build system capabilities.»

    • Creator: Egor Pugin
    • CMake Support: ???
    • Repository: https://github.com/cppan/cppan
    • Documentation: https://github.com/cppan/cppan/tree/v1/doc
  • Build2 — «build2 is an open source (MIT), cross-platform build
    toolchain for developing and packaging C++ code. It is a hierarchy
    of tools that includes the build system, package dependency manager
    (for package consumption), and project dependency manager (for
    project development).»

    • Creator: Code Synthesis LTDA, Boris Kolpackov
    • CMake Support: NO
    • Package listing: https://cppget.org/
    • Possible shortcoming: No integration with CMake building-system
      and no integration to IDEs like CMake.
    • See:
      • Video: CppCon 2018: «C++ Dependency Management: from Package Consumption to Project Development»
  • CPM — [NO LONGER MAINTENED] «A C++ Package Manager based on CMake and Git.»
  • Spack — «Spack is a package manager for supercomputers, Linux, and
    macOS. It makes installing scientific software easy. With Spack,
    you can build a package with multiple versions, configurations,
    platforms, and compilers, and all of these builds can coexist on
    the same machine.»

    • Repository: https://github.com/spack/spack
  • Nuget — A pacakge manager used in Visual Studio for C#, VB.NET,
    Javascript and C++.

    • Creator: Microsft Inc. MSFT
    • CMake Support: NO
    • Problem: It seems to work only on Windows and Visual Studio.
    • See:
      • https://blog.nuget.org/20130426/native-support.html
      • Video: Consuming Native NuGet Packages in Visual Studio
      • https://blog.scalyr.com/2018/07/getting-started-quickly-c-logging/
      • Let’s use Nuget in C++ project (Translated from Japanese with Bing Translator.)

Considerations for package manager choice

  • The most mature package managers with CMake integration are Conan
    and Vcpkg. Vcpkg has the largest number of packages available.
    However, it is not possible to install multiple versions of the
    same package or host a local package repository.
  • Conan is more documented and provides more control over package
    versions. It has descentralized repositories and also allows users to
    host local or intranet private repositories. A minor problem
    of Conan is the Python installation requirement, but this issue
    could be quickly solved by turning Conan into a single native
    executable file by packing Conan Python module with the Python
    interpreter with tools like Py2Exe for Windows.

Comparative table:

Feature Conan Vcpkg
Standalone NO YES
Decentralized repositories YES NO
Local Repository YES NO
Multiple versions of same package YES NO
Integration with IDEs NO NO
Most Simple Winner
More packages Winner
User control Winner
Overall Winner

Some reasonable set of features for a package managers

  • CMake integration
  • Default repository, descentralized and local repositories.
  • Cross platform
  • Easier to use from CMake without needing to call any external
    command, the packages to be installed should be defined in the
    CMakeLists.txt file.
  • Command line tools
  • Browse package metadata from command line or IDE like .net’s Nuget
    or Python’s pip.
  • Integration with IDEs
  • Standalone no depending on any interpreter or
    external dependency or fully packed with the interpreter making
    easier to install and deploy.

Low tech approaches for package or dependency management

  • GIT Submodules
  • Use system-specific package manager for instance: Ubuntu: apt-get;
    Fedora Linux: dnf; BSD Ports: …

    • Disadvantage: Hard to reproduce compilation across different
      machines as most Linux distributions only provide a single
      version and may not have all necessary libraries and header-only
      libraries.
  • Add libraries manually
  • Install packages manually in the systems:
    • ./configure && make && make install
  • Copy header-only libraries to project-directory

Interesting discussions:

  • Reddit /r/cpp Is there a C++ package manager? If not, how do you handle dependencies?
  • Reddit /r/cpp — Downsides to Conan.io?
  • Reddit /r/cpp — Hunter — Cross-platform package manager for C++
  • Announcing a single C++ library manager for Linux, macOS and Windows: Vcpkg

1.2 Conan package Manager

1.2.1 Main Web Sites

1.2.2 Benefits and Capabilities

Benefits:

  • Reduce compile-time
  • Reduce library installation effort duplication
  • Increase library discoverability
  • Easier cross-compilation for different architectures
  • Host package recipes in local network or remotely

Capabilities:

  • Cache and reuse compilation binaries (aka object-code) such as intermediate
    object-code (*.o or *.obj), static libraries and shared libraries
    which reduces compile-time and effort duplication for installing
    a libraries since all projects using the same conan recipe can
    reuse the binaries.
  • Package with embedded sources: Sources can be embedded in a
    package.
  • Package with remote sources: Conan packages (aka recipes) can fetch
    source code from remote sources such as Github, Gitlab,
    Sourceforge, FTP or even a Conan Server in local network.
  • Conan Recipes can build package’s sources with a wide variety of tools such as:
    • GNU autotools
    • CMake
    • GNU Makefile
    • BSD Makefile

1.2.3 Videos

1.2.4 Selected Articles

1.2.6 Conan Package Repositories

1.2.7 Libraries in Conan Center

Libraries in Conan Main Repositories

All libraries in Conan Community:

  • https://bintray.com/conan-community/conan

All libraries in Conan Bincrafters:

  • https://bintray.com/bincrafters/public-conan

Selected Conan Libraries

Conan Recipe Description
Fundamental  
Boost Boost Libraries
Poco libraries Poco framework libraries for network, compression, process and database.
Google’s abseil Google’s abseil library — https://abseil.io/
fmt Fast and type-safe and extensible printf library.
ranges-v3 Ranges library derived from Boost that will be added to C++20 stdandard library.
CLI11 Lightweight header-only command line parser.
Cereal Header-only serialization library
   
parallel stl C++ standard library algorithms with support for execution policies
Intel TBB Intel Threading Building Blocks (Intel TBB) for writing parallel C++ programs.
   
PugiXML XML Parser library
IrrXML Simple and fast open source xml parser for C++
   
   
Unit Testing  
Google Test Google unit testing library, aka GTest
Catch2 Single header unit test framework.
Doctest Header-only unit testing library with fast compile-time.
   
Data Compression  
Zlib Zlib compression library
bzip2 bzip2 is a freely available, patent free (see below), high-quality data compressor.
   
Scientific / Math  
Conan Lapack Lapack linear algebra library
Open BLAS OpenBLAS is an optimized BLAS library based on GotoBLAS2 1.13 BSD version.
eigen Eigen is a C++ template library for linear algebra: matrices, vectors, numerical solvers, and related algorithms.
   
   
Computer Graphics  
libpng Portable Network Graphics An Open, Extensible Image Format with Lossless Compression
freetype Render text onto bitmaps, and provides support for other font-related operations.
imgui Bloat-free Immediate Mode Graphical User interface for C++ with minimal dependencies
glm A C++ mathematics library for graphics programming
sdl2 Simple Direct Media Layer
   
glfw GLFW is an Open Source, multi-platform library for OpenGL, OpenGL ES and Vulkan development on the desktop.
  It provides a simple API for creating windows, contexts and surfaces, receiving input and events.
   
Computer Vision and  
AI — Artificial Inteligence  
OpenCV Most well-known Library for computer vision and image processing.
tiny-dnn tiny-dnn is a C++14 implementation of deep learning on systems with limited computational resource.
   
Encryption and TSL/SSL  
OpenSSL Most well-known library TLS/SSL — Transport Layer Security
cryptopp Free C++ class library of cryptographic schemes.
botan Botan is a cryptography library written in C++11
   
Miscellaneous  
ncurses API to write text-based user interfaces, TUIs in a terminal.
LibCurl curl library that provides clients for many network protocols: http, https, ftp, sftp, …
Pybind 11 Library for creating Python native modules / libraries in C++.
pistache C++ REST framework written by Mathieu Stefani at Datacratic. It is written in pure C++11.
stb — single-file public domain stb single-file public domain libraries for C/C++
wiringpi GPIO Interface library for the Raspberry Pi
   

1.2.8 Command Summary

  1. Search Conan Packages

    Search for Poco libraries in Conan Center repository:

    $ conan search Poco* -r=conan-center
    Existing package recipes:
    
    Poco/1.7.8p3@pocoproject/stable
    Poco/1.7.9@pocoproject/stable
    Poco/1.7.9p1@pocoproject/stable
    Poco/1.7.9p2@pocoproject/stable
    Poco/1.8.0.1@pocoproject/stable
    Poco/1.8.0@pocoproject/stable
    Poco/1.8.1@pocoproject/stable
    Poco/1.9.0@pocoproject/stable
    

    Search for Google Test in Conan Center repository:

    $ conan search gtest/* -r=conan-center
    Existing package recipes:
    
    gtest/1.7.0@bincrafters/stable
    gtest/1.8.0@bincrafters/stable
    gtest/1.8.1@bincrafters/stable
    

    Search for libcurl package on BinCrafters repository:

    λ conan search libcurl/* -r=bincrafters
    Existing package recipes:
    
    libcurl/7.50.3@bincrafters/stable
    libcurl/7.52.1@bincrafters/stable
    libcurl/7.56.1@bincrafters/stable
    libcurl/7.60.0@bincrafters/stable
    libcurl/7.61.1@bincrafters/stable
    

    Search for pybind11 on all conan repositories:

    $ conan search pybind* -r=all
    Existing package recipes:
    
    Remote 'conan-center':
    pybind11/2.2.2@conan/stable
    pybind11/2.2.3@conan/stable
    pybind11/2.2.4@conan/stable
    Remote 'conan-transit':
    pybind11/0.1.0@jason2506/testing
    pybind11/1.4@memsharded/stable
    pybind11/any@memsharded/stable
    
    
  2. List libraries in local cache / local repository

    This command lists packages in local cache or local repository.

    $ conan search
    Existing package recipes:
    
    OpenSSL/1.0.2o@conan/stable
    Poco/1.9.0@pocoproject/stable
    gtest/1.8.1@bincrafters/stable
    zlib/1.2.11@conan/stable
    

    List Conan storage directory ~/.conan on Unix-like (Linux, BSD, OSX …)

    $ tree -L 2  ~/.conan/
    /home/archbox/.conan/
    ├── artifacts.properties
    ├── cacert.pem
    ├── conan.conf
    ├── conan.conf.back
    ├── data
    │   ├── gtest
    │   ├── OpenSSL
    │   ├── Poco
    │   └── zlib
    ├── hooks
    │   └── attribute_checker.py
    ├── profiles
    │   └── default
    ├── registry.json
    ├── registry.json.lock
    ├── settings.yml
    └── version.txt
    
    7 directories, 10 files
    
    

    List directory ~/.conan/data

    $ tree -L 3  ~/.conan/data
    /home/archbox/.conan/data
    ├── gtest
    │   └── 1.8.1
    │       └── bincrafters
    ├── OpenSSL
    │   └── 1.0.2o
    │       └── conan
    ├── Poco
    │   └── 1.9.0
    │       └── pocoproject
    └── zlib
        └── 1.2.11
            └── conan
    
    12 directories, 0 files
    
  3. List Remote Repositories:
    $ conan remote list
    
    conan-center: https://conan.bintray.com [Verify SSL: True]
    conan-transit: https://conan-transit.bintray.com [Verify SSL: True]
    
  4. Add more remote repositories

    Add Repositories:

    • Add Conan Center (Repository installed by default)
    $ conan remote add conan-center https://conan.bintray.com
    
    • Add Conan Community:
    $ conan remote add conan-community https://api.bintray.com/conan/conan-community/conan
    
    • Add bincrafters
    $ conan remote add bincrafters https://api.bintray.com/conan/bincrafters/public-conan
    
  5. Install library in local cache

    Example install package libcurl version 7.61.1 from repository BinCrafters:

    • Installation on Windows 64 bits for 64 bits target. The build type
      is Release, however the installation lacks the debug building.
    • Linux, OS or Nix users don’t need to be concerned about
      Debug/Release build type.
    λ conan install libcurl/7.61.1@bincrafters/stable
    
    Configuration:
    [settings]
    arch=x86_64
    arch_build=x86_64
    build_type=Release
    compiler=Visual Studio
    compiler.runtime=MD
    compiler.version=15
    os=Windows
    os_build=Windows
    [options]
    [build_requires]
    [env]
    
    libcurl/7.61.1@bincrafters/stable: Not found in local cache, looking in remotes...
    libcurl/7.61.1@bincrafters/stable: Trying with 'conan-center'...
    Downloading conanmanifest.txt
    [==================================================] 234B/234B
    Downloading conanfile.py
    [==================================================] 19.4KB/19.4KB
    Downloading conan_export.tgz
    [==================================================] 764B/764B
    Decompressing conan_export.tgz: 100%|██████████| 764/764 [00:00<00:00, 46.3kB/s]
    OpenSSL/1.0.2n@conan/stable: Not found in local cache, looking in remotes...
    OpenSSL/1.0.2n@conan/stable: Trying with 'conan-center'...
    Downloading conanmanifest.txt
    [==================================================] 58B/58B
    Downloading conanfile.py
    [==================================================] 20.1KB/20.1KB
    libcurl/7.61.1@bincrafters/stable: Installing package
    Requirements
        OpenSSL/1.0.2n@conan/stable from 'conan-center' - Downloaded
        libcurl/7.61.1@bincrafters/stable from 'conan-center' - Downloaded
        zlib/1.2.11@conan/stable from 'conan-center' - Cache
    Packages
        OpenSSL/1.0.2n@conan/stable:606fdb601e335c2001bdf31d478826b644747077 - Download
        libcurl/7.61.1@bincrafters/stable:ae6191bc1194317ff7cdbc84d4d302ab49975618 - Download
        zlib/1.2.11@conan/stable:6cc50b139b9c3d27b3e9042d5f5372d327b3a9f7 - Cache
    
    zlib/1.2.11@conan/stable: Already installed!
    OpenSSL/1.0.2n@conan/stable: Retrieving package 606fdb601e335c2001bdf31d478826b644747077 from remote 'conan-center'
    Downloading conanmanifest.txt
    [==================================================] 4.6KB/4.6KB
    Downloading conaninfo.txt
    [==================================================] 1.2KB/1.2KB
    Downloading conan_package.tgz
    [==================================================] 5.6MB/5.6MB
    Decompressing conan_package.tgz: 100%|██████████| 5.32M/5.32M [00:00<00:00, 24.0MB/s]
    OpenSSL/1.0.2n@conan/stable: Package installed 606fdb601e335c2001bdf31d478826b644747077
    libcurl/7.61.1@bincrafters/stable: Retrieving package ae6191bc1194317ff7cdbc84d4d302ab49975618 from remote 'conan-center'
    Downloading conanmanifest.txt
    [==================================================] 1.0KB/1.0KB
    Downloading conaninfo.txt
    [==================================================] 1.8KB/1.8KB
    Downloading conan_package.tgz
    [==================================================] 704.7KB/704.7KB
    Decompressing conan_package.tgz: 100%|██████████| 688k/688k [00:00<00:00, 14.9MB/s]
    libcurl/7.61.1@bincrafters/stable: Package installed ae6191bc1194317ff7cdbc84d4d302ab49975618
    

    Install debug build of libcurl package:

    λ conan install libcurl/7.61.1@bincrafters/stable -s build_type=Debug
    Configuration:
    [settings]
    arch=x86_64
    arch_build=x86_64
    build_type=Debug
    compiler=Visual Studio
    compiler.runtime=MDd
    compiler.version=15
    os=Windows
    os_build=Windows
    [options]
    [build_requires]
    [env]
    
     ...  ...  ...  ...  ... 
    
    Decompressing conan_package.tgz: 100%|██████████| 967k/967k [00:00<00:00, 15.0MB/s]
    libcurl/7.61.1@bincrafters/stable: Package installed 8f5289d9807917ac37fa3752916c824d2a8061ad
    

    Install debug and release build of a library compiling it from source:

    λ conan install libcurl/7.61.1@bincrafters/stable -s build_type=None 
    

    Install release builds of libcurl for x86 target (32 bits):

    λ conan install libcurl/7.61.1@bincrafters/stable -s build_type=Release -s arch=x86
    Configuration:
    [settings]
    arch=x86
    arch_build=x86_64
    build_type=Release
    compiler=Visual Studio
    compiler.runtime=MD
    compiler.version=15
    os=Windows
    os_build=Windows
    [options]
    [build_requires]
    [env]
    

    List installed library in local cache:

    λ conan search
    Existing package recipes:
    
    OpenSSL/1.0.2n@conan/stable
    OpenSSL/1.0.2o@conan/stable
    Poco/1.9.0@pocoproject/stable
    gtest/1.8.1@bincrafters/stable
    libcurl/7.61.1@bincrafters/stable
    zlib/1.2.11@conan/stable
    
  6. Show pacakge information
    λ conan info libcurl/7.61.1@bincrafters/stable
    
    OpenSSL/1.0.2n@conan/stable
        ID: 606fdb601e335c2001bdf31d478826b644747077
        BuildID: None
        Remote: conan-center=https://conan.bintray.com
        URL: http://github.com/lasote/conan-openssl
        License: The current OpenSSL licence is an 'Apache style' license: https://www.openssl.org/source/license.html
        Recipe: Cache
        Binary: Cache
        Binary remote: conan-center
        Creation date: 2018-05-10 07:47:33
        Required by:
            libcurl/7.61.1@bincrafters/stable
        Requires:
            zlib/1.2.11@conan/stable
    libcurl/7.61.1@bincrafters/stable
        ID: ae6191bc1194317ff7cdbc84d4d302ab49975618
        BuildID: None
        Remote: conan-center=https://conan.bintray.com
        URL: http://github.com/bincrafters/conan-libcurl
        Homepage: http://curl.haxx.se
        License: MIT
        Author: Bincrafters <bincrafters@gmail.com>
        Recipe: Cache
        Binary: Cache
        Binary remote: conan-center
        Creation date: 2018-11-16 03:42:43
        Required by:
            PROJECT
        Requires:
            OpenSSL/1.0.2n@conan/stable
            zlib/1.2.11@conan/stable
    zlib/1.2.11@conan/stable
        ID: 6cc50b139b9c3d27b3e9042d5f5372d327b3a9f7
        BuildID: None
        Remote: conan-center=https://conan.bintray.com
        URL: http://github.com/conan-community/conan-zlib
        Homepage: https://zlib.net
        License: Zlib
        Author: Conan Community
        Recipe: Cache
        Binary: Cache
        Binary remote: conan-center
        Creation date: 2018-12-21 02:01:48
        Required by:
            OpenSSL/1.0.2n@conan/stable
            libcurl/7.61.1@bincrafters/stable
    

1.2.9 Example CMake/Conan project

  1. Project Files

    Gist: https://gist.github.com/caiorss/5067e2981488aff1b5765b02adbfdffc

    File: conanfile.txt

    • Conan project file.
    • Poco:shared=False => Static link the library.
    [requires]
    Poco/1.9.0@pocoproject/stable
    gtest/1.8.1@bincrafters/stable
    
    [generators]
    cmake
    
    [options]
    Poco:shared=False
    

    File: CMakeLists.txt

    cmake_minimum_required(VERSION 3.9)
    
    
    
    project(ConanTesting CXX)
    set(CMAKE_CXX_STANDARD 17)     
    set(CMAKE_VERBOSE_MAKEFILE ON)
    
    
    
    
    
    
    
    
    
    
    if(NOT EXISTS "${CMAKE_BINARY_DIR}/conanbuildinfo.cmake")
      execute_process(
        COMMAND           conan install . --install-folder "${CMAKE_BINARY_DIR}"
        WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
     )
    endif()
    
    include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
    conan_basic_setup()
    
    
    
    message(" [INFO] =>> CONAN_LIBS = ${CONAN_LIBS} " )
    
    
    add_executable(poco demo-poco.cpp)
    target_link_libraries(poco PRIVATE ${CONAN_LIBS})
    
    
    add_executable(agtest demo-gtest.cpp)
    target_link_libraries(agtest PRIVATE ${CONAN_LIBS})
    
    
    add_custom_target(run-poco
      COMMAND poco 
      DEPENDS poco 
      WORKING_DIRECTORY ${CMAKE_PROJECT_DIR}
      )
    
    add_custom_target(run-gtest
      COMMAND agtest 
      DEPENDS agtest 
      WORKING_DIRECTORY ${CMAKE_PROJECT_DIR}
      )
    
    install(TARGETS poco agtest  DESTINATION ./bin)
    

    File: demo-gtest.cpp

    #include <iostream>
    #include <Poco/Process.h>
    #include <gtest/gtest.h>
    
    auto FunctionObject = [](int n){ return 5 * n + 4; };
    
    TEST(testA, FunctionObject)
    {
        EXPECT_EQ(19, FunctionObject(3));
    }
    
    TEST(testC, FunctionObject)
    {
        EXPECT_EQ(123, FunctionObject(5));
    }
    
    TEST(testB, FunctionObject)
    {
        EXPECT_EQ(24, FunctionObject(4));
    }
    

    File: demo-poco.cpp

    #include <iostream>
    #include <Poco/Process.h>
    
    int main()
    {
        std::cout << "Running POCO Libraries Launch." << std::endl;
        std::cout << "Poco Libraries are AWESOME!" << std::endl;
    
        #if !defined(_WIN32)
          std::cerr << " [INFO] I am running on some Unix-like Operating System." << std::endl;
          Poco::Process::launch("cat", {"/etc/protocols"});
       #else
          std::cerr << " [INFO] I am running on Windows." << std::endl;
          Poco::Process::launch("notepad.exe", {});
       #endif
       return 0;
    }
    
  2. Building on Windows

    Install Conan packages in the current project at directory ./build/ —
    the packages are download from the default remote repository and
    stored at the Conan cache. Once they were downloaded, further usages
    of those packages will use them from the cache.

    $  conan install . --install-folder build 
    
    Configuration:
    [settings]
    arch=x86_64
    arch_build=x86_64
    build_type=Release
    compiler=Visual Studio
    compiler.runtime=MD
    compiler.version=15
    os=Windows
    os_build=Windows
    [options]
    [build_requires]
    [env]
    
    gtest/1.8.1@bincrafters/stable: WARN: Package is corrupted, removing folder: C:\Users\archbox\.conan\data\gtest\1.8.1\bincrafters\stable\package\3f7b6d42d6c995a23d193db1f844ed23ae943226
    PROJECT: Installing C:\Users\archbox\conan-test\conanfile.txt
    Requirements
        OpenSSL/1.0.2o@conan/stable from 'conan-center' - Cache
        Poco/1.9.0@pocoproject/stable from 'conan-center' - Cache
        gtest/1.8.1@bincrafters/stable from 'conan-center' - Cache
        zlib/1.2.11@conan/stable from 'conan-center' - Cache
    Packages
        OpenSSL/1.0.2o@conan/stable:606fdb601e335c2001bdf31d478826b644747077 - Download
        Poco/1.9.0@pocoproject/stable:09378ed7f51185386e9f04b212b79fe2d12d005c - Download
        gtest/1.8.1@bincrafters/stable:3f7b6d42d6c995a23d193db1f844ed23ae943226 - Download
        zlib/1.2.11@conan/stable:6cc50b139b9c3d27b3e9042d5f5372d327b3a9f7 - Download
    
     ... ....    ... ....    ... ....    ... ....    ... ....    ... ....    ... .... 
    
    Poco/1.9.0@pocoproject/stable: Package installed 09378ed7f51185386e9f04b212b79fe2d12d005c
    PROJECT: Generator cmake created conanbuildinfo.cmake
    PROJECT: Generator txt created conanbuildinfo.txt
    PROJECT: Generated conaninfo.txt
    PROJECT: Generated graphinfo
    

    List ./build directory:

    λ ls build\
    conanbuildinfo.cmake  conanbuildinfo.txt  conaninfo.txt  graph_info.json
    

    Check project packages:

    $ conan info .
    
    PROJECT
        ID: 78e985959974aade35877b722f1e41355f5575f4
        BuildID: None
        Requires:
            Poco/1.9.0@pocoproject/stable
    OpenSSL/1.0.2o@conan/stable
        ID: 35ea421ef4c1d32898da44c28e3cc900bc6459dc
        BuildID: None
        Remote: conan-center=https://conan.bintray.com
        URL: http://github.com/lasote/conan-openssl
        License: The current OpenSSL licence is an 'Apache style' license: https://www.openssl.org/source/license.html
        Recipe: Cache
        Binary: Cache
        Binary remote: conan-center
        Creation date: 2018-08-27 04:12:47
        Required by:
            Poco/1.9.0@pocoproject/stable
        Requires:
            zlib/1.2.11@conan/stable
    Poco/1.9.0@pocoproject/stable
        ID: 67516f54281f3227d74b2b66f92537d98ff1103d
        BuildID: None
        Remote: conan-center=https://conan.bintray.com
        URL: http://github.com/pocoproject/conan-poco
        License: The Boost Software License 1.0
        Recipe: Cache
        Binary: Cache
        Binary remote: conan-center
        Creation date: 2018-08-30 08:28:08
        Required by:
            PROJECT
        Requires:
            OpenSSL/1.0.2o@conan/stable
    zlib/1.2.11@conan/stable
        ID: 1d877a3df840030e6a8abb74c5ffb9088d08b47a
        BuildID: None
        Remote: conan-center=https://conan.bintray.com
        URL: http://github.com/conan-community/conan-zlib
        Homepage: https://zlib.net
        License: Zlib
        Author: Conan Community
        Recipe: Cache
        Binary: Cache
        Binary remote: conan-center
        Creation date: 2018-12-21 07:01:48
        Required by:
            OpenSSL/1.0.2o@conan/stable
    

    Configure CMake on Windows for 64 bits target:

    λ cmake -H. -Bbuild -G "Visual Studio 15 2017 Win64" -DCMAKE_INSTALL_PREFIX=.
    

    Compile with release build and install at ./bin:

    λ cmake --build build --target install --config Release
    
      ...  ...  ...  ...  ...  ...  ...  ...  ... 
    PostBuildEvent:
      setlocal
      "C:\Program Files\CMake\bin\cmake.exe" -DBUILD_TYPE=Release -P cmake_install.cmake
      if %errorlevel% neq 0 goto :cmEnd
      :cmEnd
      endlocal & call :cmErrorLevel %errorlevel% & goto :cmDone
      :cmErrorLevel
      exit /b %1
      :cmDone
      if %errorlevel% neq 0 goto :VCEnd
      :VCEnd
      -- Install configuration: "Release"
      -- Installing: C:/Users/archbox/conan-test/./bin/poco.exe
      -- Installing: C:/Users/archbox/conan-test/./bin/agtest.exe
    FinalizeBuildStatus:
      Deleting file "x64\Release\INSTALL\INSTALL.tlog\unsuccessfulbuild".
      Touching "x64\Release\INSTALL\INSTALL.tlog\INSTALL.lastbuildstate".
    Done Building Project "C:\Users\archbox\conan-test\build\install.vcxproj" (default targets).
    
    
    Build succeeded.
        0 Warning(s)
        0 Error(s)
    
    Time Elapsed 00:00:11.72
    

    List directory ./bin

    λ where ls
    C:\Program Files\Git\usr\bin\ls.exe
    
    λ ls bin
    agtest.exe*  poco.exe*
    

    Run application bin/agtest.exe:

    λ bin\agtest.exe
    Running main() from gmock_main.cc
    [==========] Running 3 tests from 3 test cases.
    [----------] Global test environment set-up.
    [----------] 1 test from testA
    [ RUN      ] testA.FunctionObject
    [       OK ] testA.FunctionObject (0 ms)
    [----------] 1 test from testA (0 ms total)
    
    [----------] 1 test from testC
    [ RUN      ] testC.FunctionObject
    C:\Users\archbox\conan-test\demo-gtest.cpp(14): error: Expected equality of these values:
      123
      FunctionObject(5)
        Which is: 29
    [  FAILED  ] testC.FunctionObject (0 ms)
    [----------] 1 test from testC (0 ms total)
    
    [----------] 1 test from testB
    [ RUN      ] testB.FunctionObject
    [       OK ] testB.FunctionObject (0 ms)
    [----------] 1 test from testB (0 ms total)
    
    [----------] Global test environment tear-down
    [==========] 3 tests from 3 test cases ran. (4 ms total)
    [  PASSED  ] 2 tests.
    [  FAILED  ] 1 test, listed below:
    [  FAILED  ] testC.FunctionObject
    
     1 FAILED TEST
    
    

    Note: Due to the following code in CMakeLists.txt, it is not needed to
    run the command conan-install before cmake to install the packages as
    this block will automatically run the conan-install command if the
    packages are not installed in the project ./build directory. It allows
    to configure CMake in a single step with $ cmake -Bbuild … or open the
    project in an IDE which supports CMake without running conan directly.

    • Summary: with this piece of code, it is not necessary to run conan,
      Cmake will run it automatically as a subprocess.
    if(NOT EXISTS "${CMAKE_BINARY_DIR}/conanbuildinfo.cmake")
      execute_process(
        COMMAND           conan install . --install-folder "${CMAKE_BINARY_DIR}"
        WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
     )
    endif()
    
  3. Building on Linux

    Clone gist:

    $ git clone https://gist.github.com/caiorss/5067e2981488aff1b5765b02adbfdffc conan-test2
    Cloning into 'conan-test2'...
    remote: Enumerating objects: 8, done.
    remote: Counting objects: 100% (8/8), done.
    remote: Compressing objects: 100% (7/7), done.
    remote: Total 8 (delta 1), reused 3 (delta 1), pack-reused 0
    Unpacking objects: 100% (8/8), done.
    
    

    List directory:

    $ ls
    CMakeLists.txt  conanfile.txt  demo-gtest.cpp  demo-poco.cpp
    

    CMake configuration step:

    • Note: The CMakeLists.txt file is set to automatically run Conan in the
      build directory.
    • Note: The packages weren’t download because they are already
      cached.
    $ cmake -H. -Bbuild -G Ninja -DCMAKE_INSTALL_PREFIX=.
    -- Current conanbuildinfo.cmake directory: /home/archbox/root-scripts/conan-test2/build
    -- Conan: Compiler GCC>=5, checking major version 8
    -- Conan: Checking correct version: 8
    -- Conan: Using cmake global configuration
    -- Conan: Adjusting default RPATHs Conan policies
    -- Conan: Adjusting language standard
     [INFO] =>> CONAN_LIBS = PocoMongoDB;PocoNet;PocoNetSSL;PocoCrypto;PocoData;PocoDataSQLite;PocoZip;PocoUtil;PocoXML;PocoJSON;PocoFoundation;rt;gmock_main;gmock;gtest;pthread;ssl;crypto;dl;z 
    -- Configuring done
    -- Generating done
    -- Build files have been written to: /home/archbox/root-scripts/conan-test2/build
    
    
    $ ls build/
    bin/         CMakeCache.txt        conanbuildinfo.txt  rules.ninja
    CMakeFiles/  cmake_install.cmake   conaninfo.txt
    build.ninja  conanbuildinfo.cmake  graph_info.json
    

    Run all targets: (build all executables and libraries)

    $ cmake --build build --target
    [4/4] Linking CXX executable bin/agtest
    

    Install:

    $ cmake --build build --target install
    [0/1] Install the project...
    -- Install configuration: ""
    -- Installing: /home/archbox/root-scripts/conan-test2/./bin/poco
    -- Set runtime path of "/home/archbox/root-scripts/conan-test2/./bin/poco" to ""
    -- Installing: /home/archbox/root-scripts/conan-test2/./bin/agtest
    -- Set runtime path of "/home/archbox/root-scripts/conan-test2/./bin/agtest" to ""
    
    $ ls bin/
    agtest*  poco*
    

    Run the executable bin/agtest.

    $ bin/agtest --gtest_list_tests
    Running main() from gmock_main.cc
    testA.
      FunctionObject
    testC.
      FunctionObject
    testB.
      FunctionObject
    
    
    $ bin/agtest 
    Running main() from gmock_main.cc
    [==========] Running 3 tests from 3 test cases.
    [----------] Global test environment set-up.
    [----------] 1 test from testA
    [ RUN      ] testA.FunctionObject
    [       OK ] testA.FunctionObject (0 ms)
    [----------] 1 test from testA (0 ms total)
    
    ... ... .... 
    
     1 FAILED TEST
    

    Run the executable bin/poco

    $ # /etc/protocols:
    # $Id: protocols,v 1.12 2016/07/08 12:27 ovasik Exp $
    #
    # Internet (IP) protocols
    #
    #	from: @(#)protocols	5.1 (Berkeley) 4/17/89
    #
    # Updated for NetBSD based on RFC 1340, Assigned Numbers (July 1992).
    # Last IANA update included dated 2011-05-03
    #
    # See also http://www.iana.org/assignments/protocol-numbers
    
    ip	0	IP		# internet protocol, pseudo protocol number
    hopopt	0	HOPOPT		# hop-by-hop options for ipv6
    
    ... .... ... ... .... ... ... .... ... ... .... ... ... .... ... 
    

1.2.10 Example CMake/Conan project with conan-cmake module

  1. Project Files

    This sample project uses the CMake wrapper cmake-conan for integrating
    Conan and CMake without the file conanfile.txt or running conan from
    command line before using CMake.

    CMake Module cmake-conan:

    • https://github.com/conan-io/cmake-conan

    Project Gist:

    • https://gist.github.com/caiorss/7b0732f5de5ebc40981521e63a122d8e

    Packages used in this sample project: (Conan reference)

    • gtest/1.8.1@bincrafters/stable
    • Poco/1.9.0@pocoproject/stable

    This project can be downloaded with:

    $ git clone https://gist.github.com/caiorss/7b0732f5de5ebc40981521e63a122d8e gist 
    $ cd gist 
    
    
    $ qtcrator CMakeLists.txt 
    

    File: CMakeLists.txt

    cmake_minimum_required(VERSION 3.9)
    
    
    
    project(ConanTesting CXX)
    set(CMAKE_CXX_STANDARD 17)     
    set(CMAKE_VERBOSE_MAKEFILE ON)
    
    
    
    
    if(NOT EXISTS "${CMAKE_BINARY_DIR}/conan.cmake")
       message(STATUS "Downloading conan.cmake from https://github.com/conan-io/cmake-conan")
       file(DOWNLOAD "https://github.com/conan-io/cmake-conan/raw/v0.13/conan.cmake"
                     "${CMAKE_BINARY_DIR}/conan.cmake")
    endif()
    
    include(${CMAKE_BINARY_DIR}/conan.cmake)
    
    conan_cmake_run(REQUIRES
    
                    
                    Poco/1.9.0@pocoproject/stable
                    gtest/1.8.1@bincrafters/stable
    
                    BASIC_SETUP
                    BUILD missing
                    )
    
    
    
    find_package(GTest REQUIRED)
    
    
    
    
    
    
    
    add_executable(poco demo-poco.cpp)
    target_link_libraries(poco PRIVATE ${CONAN_LIBS})
    
    
    add_executable(agtest demo-gtest.cpp)
    target_link_libraries(agtest PRIVATE GTest::GTest GTest::Main)
    add_test(MyGoogleTest agtest)
    
    install(TARGETS poco agtest  DESTINATION ./bin)
    

    File: demog-gtest.cpp

    #include <iostream>
    #include <Poco/Process.h>
    #include <gtest/gtest.h>
    
    auto FunctionObject = [](int n){ return 5 * n + 4; };
    
    TEST(testA, FunctionObject)
    {
            EXPECT_EQ(19, FunctionObject(3));
    }
    
    TEST(testC, FunctionObject)
    {
            EXPECT_EQ(123, FunctionObject(5));
    }
    
    TEST(testB, FunctionObject)
    {
            EXPECT_EQ(24, FunctionObject(4));
    }
    

    File: poco-test.cpp

    #include <iostream>
    #include <Poco/Process.h>
    
    int main()
    {
        std::cout << "Running POCO Libraries Launch." << std::endl;
        std::cout << "Poco Libraries are AWESOME!" << std::endl;
    
        #if !defined(_WIN32)
          std::cerr << " [INFO] I am running on some Unix-like Operating System." << std::endl;
          Poco::Process::launch("cat", {"/etc/protocols"});
       #else
          std::cerr << " [INFO] I am running on Windows." << std::endl;
          Poco::Process::launch("notepad.exe", {});
        #endif
    
       return 0;
    }
    
  2. Building on Linux/Unix

    Clone repository:

    $ git clone https://gist.github.com/caiorss/7b0732f5de5ebc40981521e63a122d8e gist 
    Cloning into 'gist'...
    remote: Enumerating objects: 8, done.
    remote: Counting objects: 100% (8/8), done.
    remote: Compressing objects: 100% (8/8), done.
    remote: Total 8 (delta 1), reused 0 (delta 0), pack-reused 0
    Unpacking objects: 100% (8/8), done.
    

    Show project files:

    $ ls gist/
    CMakeLists.txt  demo-gtest.cpp  demo-poco.cpp
    

    CMake — configuration => Generate project files.

    • $ cmake -Hgist -Bcache -GNinja -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=.
      • -Hgist
        • => Set source code location to directory ./gist
      • -Bcache
        • => Set binary output directory to ./cache
      • -GNinja
        • => Use Ninja build instead of Makefile
      • -DCMAKE_BUILD_TYPE=Debug
        • => Enable debug build which generates debugging symbols and disable optimization.
      • -DCMAKE_INSTALL_PREFIX=.
        • => Set install directory to current directory (PWD)
    $ cmake -Hgist -Bcache -GNinja -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=. 
    
    -- The CXX compiler identification is GNU 8.3.1
    -- Check for working CXX compiler: /usr/lib64/ccache/c++
    -- Check for working CXX compiler: /usr/lib64/ccache/c++ -- works
    -- Detecting CXX compiler ABI info
    -- Detecting CXX compiler ABI info - done
    -- Detecting CXX compile features
    -- Detecting CXX compile features - done
    -- Downloading conan.cmake from https://github.com/conan-io/cmake-conan
    -- Conan: Automatic detection of conan settings from cmake
    -- Conan: Settings= -s;build_type=Debug;-s;compiler=gcc;-s;compiler.version=8;-s;compiler.libcxx=libstdc++11
    -- Conan executing: conan install . -s build_type=Debug -s compiler=gcc -s compiler.version=8 -s compiler.libcxx=libstdc++11 -g=cmake --build=missing
    -- Configuration:
    [settings]
    arch=x86_64
    arch_build=x86_64
    build_type=Debug
    compiler=gcc
    compiler.libcxx=libstdc++11
    compiler.version=8
    os=Linux
    os_build=Linux
    [options]
    [build_requires]
    [env]
    
    conanfile.txt: Installing package
    Requirements
        OpenSSL/1.0.2o@conan/stable from 'conan-center' - Cache
        Poco/1.9.0@pocoproject/stable from 'conan-center' - Cache
        gtest/1.8.1@bincrafters/stable from 'conan-center' - Cache
        zlib/1.2.11@conan/stable from 'conan-center' - Cache
    Packages
        OpenSSL/1.0.2o@conan/stable:9c111a8074926a7147291383e3d366f41bac77b3 - Cache
        Poco/1.9.0@pocoproject/stable:5d73f6d80f86b797938bd4121e0ee66b325e7063 - Cache
        gtest/1.8.1@bincrafters/stable:884a98ecd973519f5d71b74c29f9e7ddcbd902d4 - Cache
        zlib/1.2.11@conan/stable:761432f3453a17c960259b5b2605153e3bcffd7d - Cache
    
    gtest/1.8.1@bincrafters/stable: Already installed!
    zlib/1.2.11@conan/stable: Already installed!
    OpenSSL/1.0.2o@conan/stable: Already installed!
    Poco/1.9.0@pocoproject/stable: Already installed!
    conanfile.txt: Generator cmake created conanbuildinfo.cmake
    conanfile.txt: Generator txt created conanbuildinfo.txt
    conanfile.txt: Generated conaninfo.txt
    conanfile.txt: Generated graphinfo
    
    -- Conan: Loading conanbuildinfo.cmake
    -- Conan: Adjusting output directories
    -- Conan: Using cmake global configuration
    -- Conan: Adjusting default RPATHs Conan policies
    -- Conan: Adjusting language standard
    -- Current conanbuildinfo.cmake directory: /home/archbox/projects/cache
    -- Conan: Compiler GCC>=5, checking major version 8
    -- Conan: Checking correct version: 8
    -- Found GTest: /home/archbox/.conan/data/gtest/1.8.1/bincrafters/stable/package/884a98ecd973519f5d71b74c29f9e7ddcbd902d4/lib/libgtestd.a  
    -- Looking for C++ include pthread.h
    -- Looking for C++ include pthread.h - found
    -- Looking for pthread_create
    -- Looking for pthread_create - not found
    -- Looking for pthread_create in pthreads
    -- Looking for pthread_create in pthreads - not found
    -- Looking for pthread_create in pthread
    -- Looking for pthread_create in pthread - found
    -- Found Threads: TRUE  
    -- Configuring done
    -- Generating done
    -- Build files have been written to: /home/archbox/projects/cache
    
    

    Show cache directory:

    $ tree -L 2 cache
    cache
    ├── bin
    │   ├── agtest
    │   └── poco
    ├── build.ninja
    ├── CMakeCache.txt
    ├── CMakeFiles
    │   ├── 3.14.3
    │   ├── agtest.dir
    │   ├── CheckLibraryExists
    │   ├── cmake.check_cache
    │   ├── CMakeError.log
    │   ├── CMakeOutput.log
    │   ├── CMakeTmp
    │   ├── feature_tests.bin
    │   ├── feature_tests.cxx
    │   ├── poco.dir
    │   └── TargetDirectories.txt
    ├── cmake_install.cmake
    ├── conanbuildinfo.cmake
    ├── conanbuildinfo.txt
    ├── conan.cmake
    ├── conanfile.txt
    ├── conaninfo.txt
    ├── graph_info.json
    └── rules.ninja
    
    7 directories, 18 files
    

    Build all targets:

    $ cmake --build cache --target 
    [4/4] Linking CXX executable bin/agtest
    

    Run executable agtest (GoogleTest)

    Run executable poco

    Install:

     $ cmake --build cache --target install
     [0/1] Install the project...
     -- Install configuration: "Debug"
     -- Installing: /home/archbox/projects/./bin/poco
     -- Set runtime path of "/home/archbox/projects/./bin/poco" to ""
     -- Installing: /home/archbox/projects/./bin/agtest
     -- Set runtime path of "/home/archbox/projects/./bin/agtest" to ""
    
    $ ls bin/
    agtest*  poco*
    
    
    $ bin/agtest 
    
    
    $ bin/poco 
    

1.2.11 Make conan-cmake module globally available

The cmake-conan cmake module can be installed globally in the system
by moving the file conan.cmake to the default location where CMake
built-in modules are stored.

Those locations are:

  • For Linux
    • /usr/share/cmake/Modules
  • For Mac OSX
    • Similar path schema to Linux
  • For Windows NT
    • C:\\Program Files (x86)\CMake\Modules

Installation on Linux:

$ mkdir -p /usr/share/cmake/Modules/custom && cd /usr/share/cmake/Modules/custom
$ curl -O https://github.com/conan-io/cmake-conan/raw/v0.13/conan.cmake

Project Usage:

Listing 1: File — CMakeLists.txt

cmake_minimum_required(VERSION 2.8)
project(test-package)


include(custom/conan)

set(CONAN_PROFILE default)
conan_cmake_run(REQUIRES
                   Poco/1.9.0@pocoproject/stable
                   gtest/1.8.1@bincrafters/stable
                BASIC_SETUP
                BUILD missing)


add_executable(test-package "main.cpp")
target_link_libraries(test-package hello)

1.3 Vcpkg package manager

1.3.1 Documentation

1.3.2 Windows Vcpkg Intallation

Assumption: Visual studio development tools are already installed.

1 Download and install VCPKG

  • Note: Assumes that vcpkg will be installed at C:\vcpkg
$ cd C:\
$ git clone https://github.com/Microsoft/vcpkg
$ cd vcpkg/
$ bootstrap-vcpkg.bat

2 Run the command Windows Key + R or execute from the terminal the
following command. It opens the environment variables Window.

$ rundll32.exe sysdm.cpl,EditEnvironmentVariables

3 Set the following environment variables.

  • Set PATH to %PATH%;C:\vcpkg
  • Add new variable VCPKG_ROOT and set it to: C:\vcpkg

4 Test installation. Open a new terminal and enter:

C:\Users\archbox> where vcpkg
C:\vcpkg\vcpkg.exe


C:\Users\archbox> echo %VCPKG_ROOT%
C:\vcpkg


C:\Users\archbox>vcpkg list
freeglut:x64-windows                               3.0.0-5          Open source implementation of GLUT with source a...
freeglut:x86-windows                               3.0.0-5          Open source implementation of GLUT with source a...
libjpeg-turbo:x86-windows                          1.5.3-1          libjpeg-turbo is a JPEG image codec that uses SI...
libpng:x86-windows                                 1.6.35-1         libpng is a library implementing an interface fo...
opengl:x86-windows                                 0.0-5            Open Graphics Library (OpenGL)[3][4][5] is a cro...
pybind11:x64-windows                               2.2.3-1          pybind11 is a lightweight header-only library th...
python3:x64-windows                                3.6.4-2          The Python programming language as an embeddable...
zlib:x86-windows                                   1.2.11-3         A compression library

1.3.3 Linux Vcpkg Installation

1 Create install directory

  • In this instruction: VCPKG will be installed at directory
    $HOME/opt/vcpkg or /home/<<MY-USER>/opt/vcpkg/
$ mkdir -p ~/opt && cd ~/opt

2 Download and compile VCPKG

$ git clone https://github.com/Microsoft/vcpkg
$ cd vcpkg/
$ sh bootstrap-vcpkg.sh 

3 Run VCPKG:

$ ./vcpkg
Commands:
  vcpkg search [pat]              Search for packages available to be built
  vcpkg install <pkg>...          Install a package
  vcpkg remove <pkg>...           Uninstall a package
  vcpkg remove --outdated         Uninstall all out-of-date packages
  vcpkg list                      List installed packages
  vcpkg update                    Display list of packages for updating

  ... ... ... ... ... ....   ... . .. ... . .. ... .. .... 

For more help (including examples) see the accompanying README.md.

4 Add VCPKG to search $PATH variable in order to be able to call it
from any directory.

  • Edit: ~/.bashrc or ~/.bash_profile and add the following code and
    restart the REPL.
export VCPKG_ROOT=$HOME/opt/vcpkg/


export PATH=$PATH:$VCPKG_ROOT

1.3.4 Show all available packages

  • $ vcpkg search
$ vcpkg search 

3fd                  2.6.2            C++ Framework For Fast Development
abseil               2018-11-08-1     an open-source collection designed to augment the C++ standard library. Abseil...
ace                  6.5.3            The ADAPTIVE Communication Environment
aixlog               1.2.1            Header-only C++ logging library 
alac                 2017-11-03-c3... The Apple Lossless Audio Codec (ALAC) is a lossless audio codec developed by A...
alac-decoder         0.2              ALAC C implementation of a decoder, written from reverse engineering the file ...
alembic              1.7.10           Alembic is an open framework for storing and sharing scene data that includes ...
allegro5             5.2.4.0          Allegro is a cross-platform library mainly aimed at video game and multimedia ...

 ... ...  ... ...  ... ...  ... ...  ... ...  ... ...  ... ... 

aws-sdk-cpp[waf]                      C++ SDK for the AWS waf service
aws-sdk-cpp[waf-regional]             C++ SDK for the AWS waf-regional service
aws-sdk-cpp[workdocs]                 C++ SDK for the AWS workdocs service
aws-sdk-cpp[workmail]                 C++ SDK for the AWS workmail service
aws-sdk-cpp[workspaces]               C++ SDK for the AWS workspaces service
aws-sdk-cpp[xray]                     C++ SDK for the AWS xray service

 ... ...  ... ...  ... ...  ... ...  ... ...  ... ...  ... ... 

boost-polygon        1.68.0           Boost polygon module
boost-pool           1.68.0           Boost pool module
boost-predef         1.68.0           Boost predef module
boost-preprocessor   1.68.0           Boost preprocessor module
boost-process        1.68.0           Boost process module
boost-program-opt... 1.68.0           Boost program_options module
boost-property-map   1.68.0           Boost property_map module
boost-property-tree  1.68.0           Boost property_tree module
boost-proto          1.68.0           Boost proto module
boost-ptr-container  1.68.0           Boost ptr_container module
boost-python         1.68.0-2         Boost python module
boost-qvm            1.68.0           Boost qvm module
boost-random         1.68.0           Boost random module
boost-range          1.68.0           Boost range module

 ... ...  ... ...  ... ...  ... ...  ... ...  ... ...  ... ... 

1.3.5 Removing package

$ vcpkg.exe remove libjpeg-turbo:x86-windows
Your feedback is important to improve Vcpkg! Please take 3 minutes to complete our survey by running: vcpkg contact --survey
The following packages will be removed:
    libjpeg-turbo:x86-windows
Removing package libjpeg-turbo:x86-windows...
Removing package libjpeg-turbo:x86-windows... done
Purging package libjpeg-turbo:x86-windows...
Purging package libjpeg-turbo:x86-windows... done

1.3.6 Example: Project with spdlog and Boost Ublas

File: CMakeLists.txt

cmake_minimum_required(VERSION 3.9)

if(DEFINED ENV{VCPKG_ROOT} AND NOT DEFINED CMAKE_TOOLCHAIN_FILE)
  set(CMAKE_TOOLCHAIN_FILE "$ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake"
    CACHE STRING "")
  message(" [INFO] VCPKG CMAKE_TOOLCHAIN_FILE = ${CMAKE_TOOLCHAIN_FILE}")
endif()



project(SpdLogVCPKGTest)
set(CMAKE_CXX_STANDARD 17)     
set(CMAKE_VERBOSE_MAKEFILE ON)






find_package(spdlog CONFIG REQUIRED)
add_executable(AppDemo1 demo.cpp)
target_link_libraries(AppDemo1 PRIVATE spdlog::spdlog)


add_custom_target(run-app
  COMMAND AppDemo1 
  DEPENDS AppDemo1 
  WORKING_DIRECTORY ${CMAKE_PROJECT_DIR}
  )

install(TARGETS AppDemo1 DESTINATION ./bin)
if(WIN32)
  
  
  
  install(FILES ${CMAKE_CURRENT_BINARY_DIR}/Debug/fmtd.dll
    DESTINATION "bin")
endif()

File: demo.cpp

#include <iostream>
#include <spdlog/spdlog.h>
#include <spdlog/sinks/stdout_sinks.h>


#include <boost/numeric/ublas/vector.hpp>
#include <boost/numeric/ublas/io.hpp>

namespace ub = boost::numeric::ublas;

int main(){
    auto console = spdlog::stdout_logger_mt("stdout-console");
    console->info("Testing logging information to command line");

    console->info("Welcome to spdlog version {}.{}.{} !", SPDLOG_VER_MAJOR, SPDLOG_VER_MINOR, SPDLOG_VER_PATCH);
    console->warn("Easy padding in numbers like {:08d}", 12);
    console->critical("Support for int: {0:d};  hex: {0:x};  oct: {0:o}; bin: {0:b}", 42);
    console->info("Support for floats {:03.2f}", 1.23456);
    console->info("Positional args are {1} {0}..", "too", "supported");
    console->info("{:>8} aligned, {:<8} aligned", "right", "left");

    ub::vector<double> vec1(3, 2.2) ; vec1[2] = -5.1;
    ub::vector<double> vec2(3, -1.2); vec2[2] = 1.1;

    std::cout << "Vec1 = " << vec1 << std::endl;
    std::cout << "3.0 * Vec1 = " << 3.0 * vec1 << std::endl;
    std::cout << "Norm1(Vec1) = " << ub::norm_1(vec1) << std::endl;
    std::cout << "Vec2 - Vec1 = " << vec2 - vec1 << std::endl;

    std::cout << "\n Enter RETURN to exit" << std::endl;
    std::cin.get();
    return 0;
}

Install Vcpkg libraries Boost Ublas and spdlog:

$ vcpkg install spdlog:x64-windows
$ vcpkg install boost-ublas:x64-windows


$ vcpkg install spdlog
$ vcpkg install boost-ublas

Visual Studio

  • The project can be compiled, modified, debugged and managed by
    opening it with Visual Studio as a directory or by invoking Visual
    Studio form command developer command prompt with the following
    command.

All CMake Targets can be viewed from the VS Solution Explorer.

Figure 1: Visual Studio Solution Explorer — CMake Targets

cmake-project-vs-spdlog.png

Figure 2: Running CMake project from Visual Studio.

Manual Compilation — CMake Configuration Step

CMake Configuration on Windows with Visual Studio building tools as backed:

  • In the project directory run:
$ cmake -H. -Bbuild -G "Visual Studio 15 2017 Win64" -DCMAKE_INSTALL_PREFIX=.

CMake Configuration on Linux using Makefiles:

$ cmake -H. -Bbuild -DCMAKE_INSTALL_PREFIX=.


$ cmake -H. -Bbuild -G Ninja -DCMAKE_INSTALL_PREFIX=.

Manual Compilation — CMake Building Step

Building all CMake targets (compilation targets to build executables
and libraries):

$ cmake --build build --target 

Run install target on Windows:

$ cmake --build build --target install 

  ... ... ... ... .... 
PrepareForBuild:
  Creating directory "x64\Debug\INSTALL\".
  Creating directory "x64\Debug\INSTALL\INSTALL.tlog\".
InitializeBuildStatus:
  Creating "x64\Debug\INSTALL\INSTALL.tlog\unsuccessfulbuild" because "AlwaysCreate" was specified.
PostBuildEvent:
  setlocal
  "C:\Program Files\CMake\bin\cmake.exe" -DBUILD_TYPE=Debug -P cmake_install.cmake
  if %errorlevel% neq 0 goto :cmEnd
  :cmEnd
  endlocal & call :cmErrorLevel %errorlevel% & goto :cmDone
  :cmErrorLevel
  exit /b %1
  :cmDone
  if %errorlevel% neq 0 goto :VCEnd
  :VCEnd
  -- Install configuration: "Debug"
  -- Installing: C:/Users/archbox/Desktop/spdlogtest/./bin/AppDemo1.exe
  -- Up-to-date: C:/Users/archbox/Desktop/spdlogtest/bin/fmtd.dll
FinalizeBuildStatus:
  Deleting file "x64\Debug\INSTALL\INSTALL.tlog\unsuccessfulbuild".
  Touching "x64\Debug\INSTALL\INSTALL.tlog\INSTALL.lastbuildstate".
Done Building Project "C:\Users\archbox\Desktop\spdlogtest\build\install.vcxproj" (default targets).
Build succeeded.
 .... ... .... ... .... ... .... ...

Run install target on Linux:

$ cmake --build build --target install
[2/3] Install the project...
-- Install configuration: ""
-- Installing: /home/archbox/root-scripts/spdlog/./bin/AppDemo1

Check install output on Windows:

$ ls bin
AppDemo1.exe*  fmtd.dll*

Check install output on Linux:

Run program:

bin\AppDemo1.exe 

[2019-01-09 16:17:13.360] [stdout-console] [info] Testing logging information to command line
[2019-01-09 16:17:13.361] [stdout-console] [info] Welcome to spdlog version 1.2.0 !
[2019-01-09 16:17:13.361] [stdout-console] [warning] Easy padding in numbers like 00000012
[2019-01-09 16:17:13.361] [stdout-console] [critical] Support for int: 42;  hex: 2a;  oct: 52; bin: 101010
[2019-01-09 16:17:13.361] [stdout-console] [info] Support for floats 1.23
[2019-01-09 16:17:13.362] [stdout-console] [info] Positional args are supported too..
[2019-01-09 16:17:13.362] [stdout-console] [info]    right aligned, left     aligned
Vec1 = [3](2.2,2.2,-5.1)
3.0 * Vec1 = [3](6.6,6.6,-15.3)
Norm1(Vec1) = 9.5
Vec2 - Vec1 = [3](-3.4,-3.4,6.2)

 Enter RETURN to exit

1.3.7 Example: Project with OpenGL + FreeGLUT

GIST: Cmake C++ project with VCPKG package manager and OpengGL/FreeGlut

File: CMakeLists.txt

cmake_minimum_required(VERSION 3.9)

if(DEFINED ENV{VCPKG_ROOT} AND NOT DEFINED CMAKE_TOOLCHAIN_FILE)
  set(CMAKE_TOOLCHAIN_FILE "$ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake"
    CACHE STRING "")
    message(" [INFO] VCPKG CMAKE_TOOLCHAIN_FILE = ${CMAKE_TOOLCHAIN_FILE}")
endif()



project(OpengGL_Widnows)
set(CMAKE_CXX_STANDARD 17)     
set(CMAKE_VERBOSE_MAKEFILE ON)

find_package(OpenGL REQUIRED)
find_package(GLUT REQUIRED)
find_package(GLU  REQUIRED)






add_executable(openglDemo1 opengl1.cpp)
target_link_libraries(openglDemo1 PRIVATE GLUT::GLUT)

if(UNIX)
  target_link_libraries(openglDemo1 PRIVATE GL)
endif()




if(UNIX)
  set_target_properties(openglDemo1 PROPERTIES SUFFIX ".bin")
endif()


add_custom_target(run-ex1
    COMMAND openglDemo1 
    DEPENDS openglDemo1 
    WORKING_DIRECTORY ${CMAKE_PROJECT_DIR}
)


CMAKE_INSTALL_PREFIX
message(" Freeglut DLL = ${GLUT_RUNTIME_LIBRARY} ${FREEGLUT_DYNAMIC}
") install(TARGETS openglDemo1 DESTINATION out) install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/freeglut.dll" DESTINATION out)

File: opengl1.cpp

#include <iostream>
#if defined(_WIN32)
  #include <windows.h>
#endif 
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>

void renderFunction();

int main(int argc, char ** argv){

    std::cerr << "[INFO] Starting OpenGL main loop." << std::endl;

    glutInit(&argc, argv);  
    glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
    glutInitWindowSize(500, 500);
    glutCreateWindow("Window 1");
    
    glutDisplayFunc(&renderFunction);
    
    glutMainLoop();
    std::cerr << "[INFO] Exit OpenGL main loop." << std::endl;
    return 0;
}

void renderFunction(){
        std::cerr << "[INFO] Running loop." << std::endl;
    
    glClear(GL_COLOR_BUFFER_BIT);   

    
    glRotated(10, 0, 0, 1);

    
    glColor3f(0.0, 0.0, 1.0);

    
    glBegin(GL_POLYGON);
    glVertex3f(-0.5, -0.5, 0);
    glVertex3f( 0.5, -0.5, 0);
    glVertex3f( 0.5,  0.5, 0);
    glVertex3f(-0.5,  0.5, 0);
    
    glEnd();

    glFlush();
}

Install FreeGlut library:

Search FreeGlut library:

$ vcpkg search freeglut

freeglut             3.0.0-5          Open source implementation of GLUT with source and binary backwards compatibil...

If your library is not listed, please open an issue at and/or consider making a pull request:
    https://github.com/Microsoft/vcpkg/issues

Install FreeGlut Library:

  • $ vcpkg install freeglut:x64-Windows
    • Install library compiled for 64 bits target.
  • $ vcpkg install freeglut:x86-Windows
    • Install library compiled for x86 bits target.
$ vcpkg install freeglut:x64-Windows

The following packages will be built and installed:
    freeglut[core]:x64-windows
Starting package 1/1: freeglut:x64-windows
Building package freeglut[core]:x64-windows...
A suitable version of git was not found (required v2.20.0). Downloading portable git v2.20.0...
Downloading git...
  https://github.com/git-for-windows/git/releases/download/v2.20.0.windows.1/PortableGit-2.20.0-32-bit.7z.exe -> C:\vcpkg\downloads\PortableGit-2.20.0-32-bit.7z.exe
Extracting git...
A suitable version of 7zip was not found (required v18.1.0). Downloading portable 7zip v18.1.0...
Downloading 7zip...
  https://www.nuget.org/api/v2/package/7-Zip.CommandLine/18.1.0 -> C:\vcpkg\downloads\7-zip.commandline.18.1.0.nupkg
Extracting 7zip...
A suitable version of nuget was not found (required v4.6.2). Downloading portable nuget v4.6.2...
Downloading nuget...
  https://dist.nuget.org/win-x86-commandline/v4.6.2/nuget.exe -> C:\vcpkg\downloads\nuget.exe
-- Downloading http://downloads.sourceforge.net/project/freeglut/freeglut/3.0.0/freeglut-3.0.0.tar.gz...
-- Extracting source C:/vcpkg/downloads/freeglut-3.0.0.tar.gz
-- Configuring x64-windows
-- Building x64-windows-dbg
-- Building x64-windows-rel
-- Performing post-build validation
-- Performing post-build validation done
Building package freeglut[core]:x64-windows... done
Installing package freeglut[core]:x64-windows...
Installing package freeglut[core]:x64-windows... done
Elapsed time for package freeglut:x64-windows: 2.215 min

Total elapsed time: 2.215 min

The package freeglut is compatible with built-in CMake targets:

    find_package(GLUT REQUIRED)
    target_link_libraries(main PRIVATE GLUT::GLUT)

Clone the GIST for avoiding crating the sources manually:

$ git clone https://gist.github.com/caiorss/4e36d7423cfd456f39c26ba476873a3c opengl-cmake-demo
Cloning into 'opengl-cmake-demo'...
remote: Enumerating objects: 4, done.
remote: Counting objects: 100% (4/4), done.
remote: Compressing objects: 100% (4/4), done.
Unpacking objects: 100% (4/4), done.
remote: Total 4 (delta 0), reused 0 (delta 0), pack-reused 0

$ cd opengl-cmake-demo\

$ dir
 Volume in drive C has no label.
 Volume Serial Number is 

 Directory of C:\Users\archbox\Desktop\opengl-cmake-demo

01/08/2019  05:57 PM    <DIR>          .
01/08/2019  05:57 PM    <DIR>          ..
01/08/2019  05:57 PM             1,630 CMakeLists.txt
01/08/2019  05:57 PM             1,188 opengl1.cpp
               2 File(s)          2,818 bytes
               2 Dir(s)   1,157,586,944 bytes free

Perform CMake configuration step generating building scripts:

$ cmake -H. -Bbuild -G "Visual Studio 15 2017 Win64" -DCMAKE_INSTALL_PREFIX=.
 [INFO] VCPKG CMAKE_TOOLCHAIN_FILE = C:\vcpkg/scripts/buildsystems/vcpkg.cmake
-- The C compiler identification is MSVC 19.16.27025.1
-- The CXX compiler identification is MSVC 19.16.27025.1
 ... ...  ... ...  ... ...  ... ...  ... ...  ... ...  ... ... 
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found OpenGL: opengl32
-- Found GLUT: C:/vcpkg/installed/x64-windows/debug/lib/freeglut.lib
-- WARNING: you are using the obsolete 'GLU' package, please use 'OpenGL' instead
 Freeglut DLL =
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Users/archbox/Desktop/opengl-cmake-demo/build

Build all targets:

  • $ cmake –build build –config debug
  • $ cmake –build build –config release
$ cmake --build build --config debug

Microsoft (R) Build Engine version 15.9.21+g9802d43bc3 for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.

Build started 1/8/2019 6:02:01 PM.
Project "C:\Users\archbox\Desktop\opengl-cmake-demo\build\ALL_BUILD.vcxproj" on node 1 (default targets).
Project "C:\Users\archbox\Desktop\opengl-cmake-demo\build\ALL_BUILD.vcxproj" (1) is building "C:\Users\archbox\Desktop\opengl-cmake-demo\buil d\ZERO_CHECK.vcxproj" (2) on node 1 (default targets).

 .. .. .   ... .. .   ... .. .   ... .. .   ... .. .   ... .. .   ... .. .   ... .. .   ... .. . 

ClCompile:
  C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.16.27023\bin\HostX86\x64\CL.exe /c /I"C:\vcpkg\installed\x6
  4-windows\include" /Zi /W3 /WX- /diagnostics:classic /Od /Ob0 /D WIN32 /D _WINDOWS /D "CMAKE_INTDIR=\"Debug\"" /D _MBCS /Gm- /EHsc /RTC1 /M
  Dd /GS /fp:precise /Zc:wchar_t /Zc:forScope /Zc:inline /GR /std:c++17 /Fo"openglDemo1.dir\Debug\\" /Fd"openglDemo1.dir\Debug\vc141.pdb" /Gd
   /TP /errorReport:queue "C:\Users\archbox\Desktop\opengl-cmake-demo\opengl1.cpp"
  Microsoft (R) C/C++ Optimizing Compiler Version 19.16.27025.1 for x64
  opengl1.cpp
  Copyright (C) Microsoft Corporation.  All rights reserved.

  cl /c /I"C:\vcpkg\installed\x64-windows\include" /Zi /W3 /WX- /diagnostics:classic /Od /Ob0 /D WIN32 /D _WINDOWS /D "CMAKE_INTDIR=\"Debug\"
  " /D _MBCS /Gm- /EHsc /RTC1 /MDd /GS /fp:precise /Zc:wchar_t /Zc:forScope /Zc:inline /GR /std:c++17 /Fo"openglDemo1.dir\Debug\\" /Fd"opengl
  Demo1.dir\Debug\vc141.pdb" /Gd /TP /errorReport:queue "C:\Users\archbox\Desktop\opengl-cmake-demo\opengl1.cpp"

Link:
  C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.16.27023\bin\HostX86\x64\link.exe /ERRORREPORT:QUEUE /OUT:"
  C:\Users\archbox\Desktop\opengl-cmake-demo\build\Debug\openglDemo1.exe" /INCREMENTAL /NOLOGO "C:\vcpkg\installed\x64-windows\debug\lib\free
  glut.lib" kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /MANIFEST /M
  ANIFESTUAC:"level='asInvoker' uiAccess='false'" /manifest:embed /DEBUG /PDB:"C:/Users/archbox/Desktop/opengl-cmake-demo/build/Debug/openglD
  emo1.pdb" /SUBSYSTEM:CONSOLE /TLBID:1 /DYNAMICBASE /NXCOMPAT /IMPLIB:"C:/Users/archbox/Desktop/opengl-cmake-demo/build/Debug/openglDemo1.li
  b" /MACHINE:X64  /machine:x64 openglDemo1.dir\Debug\opengl1.obj

....   ....   ....   ....   ....   ....   ....   ....   ....   ....   ....   ....   ....   ....   ....   ....   ....   .... 

Done Building Project "C:\Users\archbox\Desktop\opengl-cmake-demo\build\ALL_BUILD.vcxproj" (default targets).


Build succeeded.
    0 Warning(s)
    0 Error(s)

Time Elapsed 00:00:06.76

Run executable (target run-ex1):

  • This is conveniced target was added for making easier to run the
    executable from the terminal. It is not needed for IDEs like Visual
    Studio, JetBrains — Clion and so on.
$ cmake --build build --target run-ex1

Compile and run on Linux:

$ vcpkg install freeglut   
$ git clone https://gist.github.com/caiorss/4e36d7423cfd456f39c26ba476873a3c opengl
$ cd opengl 
$ cmake -H. -Bbuild 
$ cmake --build build --target run-ex1 

1.3.8 Example: Project with Nana GUI Library

GIST: Nana GUI + VCPKG + CMake project

File: CMakeLists.txt

cmake_minimum_required(VERSION 3.9)

if(DEFINED ENV{VCPKG_ROOT} AND NOT DEFINED CMAKE_TOOLCHAIN_FILE)
  set(CMAKE_TOOLCHAIN_FILE "$ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake"
    CACHE STRING "")
    message(" [INFO] VCPKG CMAKE_TOOLCHAIN_FILE = ${CMAKE_TOOLCHAIN_FILE}")
endif()



project(DummyProject)
set(CMAKE_CXX_STANDARD 17)     





find_package(unofficial-nana CONFIG REQUIRED)
add_executable(gui1 gui1.cpp)
target_link_libraries(gui1 PRIVATE
  unofficial::nana::nana fontconfig stdc++fs)


add_custom_target(run-gui1
    COMMAND gui1
    DEPENDS gui1
    WORKING_DIRECTORY ${CMAKE_PROJECT_DIR}
)

CMAKE_PREFIX_PATH
install(TARGETS gui1 DESTINATION ./bin)

File: gui1.cpp

  • Note: Demo code taken from — http://nanapro.org/en-us/
#include <nana/gui.hpp>
#include <nana/gui/widgets/label.hpp>
#include <nana/gui/widgets/button.hpp>

int main()
{
    using namespace nana;

    
    form fm;
    
    label lab{fm, "Hello, <bold blue size=16>Nana C++ Library</>"};
    lab.format(true);
    
    button btn{fm, "Quit"};
    btn.events().click([&fm]{
        fm.close();
    });
    
    fm.div("vert <><<><weight=80% text><>><><weight=24<><button><>><>");
    fm["text"]<<lab;
    fm["button"] << btn;
    fm.collocate();
    
    fm.show();
    
    exec();
}

Project directory:

$ tree -L 1
.
├── build
├── CMakeLists.txt
└── gui1.cpp

1 directory, 2 files

Install Linux dependency libraries (Tested on Linux Fedora):

  • Note: Sometimes VCPKG cannot install system libraries. In this
    case, it is necessary to use the current distribution package
    manager.
$ sudo dnf install libX11-devel.x86_x64
$ sudo dnf install libXft-devel.x86_64

Clone gist containing the project:

$ git clone https://gist.github.com/caiorss/724942d43cd11c6ee5b3461ac067c846 sample-vcpkg-proj
$ cd sample-vcpkg-proj

Install package Nana with vcpkg:

$ vcpkg install nana

 ...  ...  ...  ... 
-- Using cached /home/archbox/opt/vcpkg/downloads/cnjinhao-nana-v1.6.2.tar.gz
-- Using source at /home/archbox/opt/vcpkg/buildtrees/nana/src/v1.6.2-51b575c248
-- Configuring x64-linux-dbg
-- Configuring x64-linux-rel
-- Building x64-linux-dbg
-- Building x64-linux-rel
-- Performing post-build validation
-- Performing post-build validation done
Building package nana[core]:x64-linux... done
Installing package nana[core]:x64-linux... 
Installing package nana[core]:x64-linux... done
Elapsed time for package nana:x64-linux: 1.825 min

Total elapsed time: 1.825 min

The package nana:x64-linux provides CMake targets:

    find_package(unofficial-nana CONFIG REQUIRED)
    target_link_libraries(main PRIVATE unofficial::nana::nana)

List installed packages:

$ vcpkg list
boost-accumulators:x64-linux                       1.68.0           Boost accumulators module
boost-algorithm:x64-linux                          1.68.0           Boost algorithm module
boost-any:x64-linux                                1.68.0           Boost any module
boost-array:x64-linux                              1.68.0           Boost array module

... ... ...   ... ... ...   ... ... ...   ... ... ...   ... ... ...   ... ... ...   ... ... ...

gsl:x64-linux                                      2.4-3            The GNU Scientific Library is a numerical librar...
gtest:x64-linux                                    1.8.1-1          GoogleTest and GoogleMock testing frameworks.
libiconv:x64-linux                                 1.15-5           GNU Unicode text conversion
libjpeg-turbo:x64-linux                            1.5.3-1          libjpeg-turbo is a JPEG image codec that uses SI...
liblzma:x64-linux                                  5.2.4            Compression library with an API similar to that ...
libpng:x64-linux                                   1.6.35-1         libpng is a library implementing an interface fo...
nana:x64-linux                                     1.6.2            Cross-platform library for GUI programming in mo...
pybind11:x64-linux                                 2.2.3-1          pybind11 is a lightweight header-only library th...
spdlog:x64-linux                                   1.2.1            Very fast, header only, C++ logging library
zlib:x64-linux                                     1.2.11-3         A compression librar

Filter nana package:

$ vcpkg list | grep nana
nana:x64-linux                                     1.6.2            Cross-platform library for GUI programming in mo...

Building with CMake Ninja or Makefile

Cmake configuration step

  • Default system building system
    • $ cmake -H. -Bbuild
  • Ninja building System:
    • $ cmake -H. -Bbuild -G Ninja
$ cmake -H. -Bbuild -G Ninja  -DCMAKE_PREFIX_PATH=.

 [INFO] VCPKG CMAKE_TOOLCHAIN_FILE = /home/archbox/opt/vcpkg/scripts/buildsystems/vcpkg.cmake
-- The C compiler identification is GNU 8.2.1
-- The CXX compiler identification is GNU 8.2.1
-- Check for working C compiler: /usr/lib64/ccache/cc

 ... ... ... ... ... ... 

-- Found Freetype: /home/archbox/build/vcpkg/installed/x64-linux/lib/libfreetype.a (found version "2.8.1") 
-- Found ZLIB: /home/archbox/build/vcpkg/installed/x64-linux/debug/lib/libz.a (found version "1.2.11") 
-- Found PNG: /home/archbox/build/vcpkg/installed/x64-linux/share/png/../../lib/libpng16.a (found version "1.6.35") 
-- Found BZip2: /home/archbox/build/vcpkg/installed/x64-linux/lib/libbz2.a (found version "1.0.6") 
-- Looking for BZ2_bzCompressInit
-- Looking for BZ2_bzCompressInit - found
-- Looking for XOpenDisplay in /usr/lib64/libX11.so;/usr/lib64/libXext.so
-- Looking for XOpenDisplay in /usr/lib64/libX11.so;/usr/lib64/libXext.so - found

 ... ... ... ... ... ... 

-- Looking for shmat - found
-- Found X11: /usr/lib64/libX11.so
-- Found JPEG: /home/archbox/build/vcpkg/installed/x64-linux/debug/lib/libjpeg.a  
-- Configuring done
-- Generating done
-- Build files have been written to: /home/archbox/root-scripts/vcpkg2/build

Build all targets:

$ cmake --build build --target 

Build and run executable target gui1 (target: run-gui1)

$ cmake --build build --target run-gui1
[3/3] cd /home/archbox/root-scripts/vcpkg2/build && /home/archbox/root-scripts/vcpkg2/build/gui1

Install executable:

$ cmake --build build --target install
[2/3] Install the project...
-- Install configuration: ""
-- Installing: /home/archbox/root-scripts/vcpkg2/./bin/gui1

Run installed executable at ./bin

Directory after compilation:

$ tree . -L 2
.
├── bin
│   └── gui1
├── build
│   ├── build.ninja
│   ├── CMakeCache.txt
│   ├── CMakeFiles
│   ├── cmake_install.cmake
│   ├── gui1
│   ├── install_manifest.txt
│   └── rules.ninja
├── CMakeLists.txt
└── gui1.cpp

3 directories, 9 files

Analyse executable:

Check binary format

$ file bin/gui1 

bin/gui1: ELF 64-bit LSB executable, x86-64, version 1 (GNU/Linux),
dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for
GNU/Linux 3.2.0,
BuildID[sha1]=b2273c2b397213af8c8b8e8808da1ebc195d3b4d, with
debug_info, not stripped

Check file size

$ du -h bin/gui1
19M     bin/gui1
19M     total

Remove debugging symbols

Check file size again:

$ du -h bin/gui1
3.3M    bin/gui1
3.3M    total

Check shared libraries dependencies:

$ ldd bin/gui1
        linux-vdso.so.1 (0x00007fff18930000)
        libfontconfig.so.1 => /lib64/libfontconfig.so.1 (0x00007f5f73116000)
        libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f5f72ef7000)
        libX11.so.6 => /lib64/libX11.so.6 (0x00007f5f72bb6000)
        libXext.so.6 => /lib64/libXext.so.6 (0x00007f5f729a4000)
        libXft.so.2 => /lib64/libXft.so.2 (0x00007f5f7278d000)
        libstdc++.so.6 => /lib64/libstdc++.so.6 (0x00007f5f723fa000)
        libm.so.6 => /lib64/libm.so.6 (0x00007f5f72066000)
        libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007f5f71e4e000)
        libc.so.6 => /lib64/libc.so.6 (0x00007f5f71a8f000)
        libfreetype.so.6 => /lib64/libfreetype.so.6 (0x00007f5f717d8000)
        libexpat.so.1 => /lib64/libexpat.so.1 (0x00007f5f7159d000)
        libuuid.so.1 => /lib64/libuuid.so.1 (0x00007f5f71396000)
        /lib64/ld-linux-x86-64.so.2 (0x00007f5f7335a000)
        libxcb.so.1 => /lib64/libxcb.so.1 (0x00007f5f7116d000)
        libdl.so.2 => /lib64/libdl.so.2 (0x00007f5f70f69000)
        libXrender.so.1 => /lib64/libXrender.so.1 (0x00007f5f70d5e000)
        libbz2.so.1 => /lib64/libbz2.so.1 (0x00007f5f70b4d000)
        libpng16.so.16 => /lib64/libpng16.so.16 (0x00007f5f70919000)
        libz.so.1 => /lib64/libz.so.1 (0x00007f5f70702000)
        libXau.so.6 => /lib64/libXau.so.6 (0x00007f5f704fe000)

Created

Updated

A free OpenGL utility toolkit, the open-sourced alternative to the GLUT library.

  • https://sourceforge.net/projects/freeglut/

# Usage

freeglut provides CMake targets:

find_package(FreeGLUT CONFIG REQUIRED)
target_link_libraries(main PRIVATE $<IF:$<TARGET_EXISTS:FreeGLUT::freeglut>,FreeGLUT::freeglut,FreeGLUT::freeglut_static>) 

freeglut is compatible with built-in CMake targets:

find_package(GLUT REQUIRED)
target_link_libraries(main PRIVATE GLUT::GLUT) 

# License

# Supported Platforms

!ios

  • linux
  • osx
  • uwp
  • windows

    # Features

    No features defined.

    # Dependencies

    # Host Dependencies

    # Dependents

    • dartsim (feature gui )
    • glui
    • imgui (feature glut-binding )
    • libwebp (feature vwebp )
    • mathgl (feature glut )
    • morphologica

    # Host Dependents

    No dependents.

    # Contributors

    # Changelog

    • 6db51d8 [vcpkg_replace_string] warn unchanged by call (#34719)

    • 01ea5f6 [freeglut,gl2ps,glui,mdl-sdk] Platform support corrections (#35391)

    • 90fdea2 [freeglut] Update to 3.2.2, fix X11 dependencies (#23807)

    • e7e328c [many ports] call vcpkg_fixup_pkgconfig() (#20953)

    • c91bcb1 [freeglut] Don’t enforce x64 when the compiler is 64 bit (#16911)

    and 25 more commits:

    • 21b56d9 [vcpkg_from_sourceforge] Add retry mirror function (2/2) (#12018)

    • a0e0c57 [vcpkg] Add vcpkg_from_sourceforge (1/2) (#11899)

    • 8bb07e2 [freeglut] check whether debug/release is enabled before moving files (#9745)

    • 726c111 [vcpkg] fatal_error when patch fails to apply (#8087)

    • 18b029a [WIP] Add a Homepage URL entry for vcpkg ports (#2933)

    • 9c33de2 [freeimage,freeglut,giflib,libwebp] port patches from #5169 (#6364)

    • 6cdb36a [freeglut] enable building on non-win32 (#6298)

    • f138ef3 [freeglut] Fix the internal default link name of freeglut. Fixed #4243.

    • 827c893 [sfml] Support Linux

    • 1b2f75b [vcpkg] Support \share\<port>\usage to handle libraries which are found through built-in Find Modules.

    • 68bfea1 rename freeglut_static.lib for compatibility with FindGLUT.cmake

    • 26516fe vcpkg_configure_cmake (and _meson) now embed debug symbols within static libs (/Z7)

    • f8ae609 [freeglut] Remove debug suffix

    • e6ebc03 [freeglut] Extract SOURCE_PATH variable

    • 628420b [freeglut] Enable static building. Fix pdb copying issues

    • cadee66 If portfile is not static-enabled yet, warn and then build dynamic The opposite if portfile is not dynamic enabled

    • 1808d46 triplet is now automatically included before portfiles.

    • 98b270b [freeglut] Mark as not supporting static building yet

    # Source

    In this tutorial, I will show you the way to install Visual Studio as small as minimum as possible.

    Install Visual Studio

    Download Visual Studio Installer

    When in Visual Studio Installer GUI windows, I suggest you tick like this

    image

    It will consume your diskspace at most 4gb.

    Install vcpkg

    vcpkg is a cross-platform C++ libraries manager. It will do the hard work for you such as building, importing, setting up PATHS, ..etc.

    How to install vcpkg

    To install vcpkg

    > git clone https://github.com/microsoft/vcpkg
    > .\vcpkg\bootstrap-vcpkg.bat
    

    Enter fullscreen mode

    Exit fullscreen mode

    To install the libraries for your project, run:

    > .\vcpkg\vcpkg install [packages to install]
    

    Enter fullscreen mode

    Exit fullscreen mode

    You can also search for the libraries you need with the search subcommand:

    > .\vcpkg\vcpkg search [search term]
    

    Enter fullscreen mode

    Exit fullscreen mode

    In order to use vcpkg with Visual Studio,
    run the following command (may require administrator elevation):

    > .\vcpkg\vcpkg integrate install
    

    Enter fullscreen mode

    Exit fullscreen mode

    All installed libraries are immediately ready to be #include‘d and used in your project without additional configuration.

    Example

    I want to setup glut, glew, glm for my Computer Graphics course.

    I go to where my vcpkg is installed. Then I run

    vcpkg.exe install freeglut glew glm
    

    Enter fullscreen mode

    Exit fullscreen mode

    I wait until it is done.

    vcpkg.exe integrate install
    

    Enter fullscreen mode

    Exit fullscreen mode

    2D Computer Graphics Project

    2D Computer Graphics Project using openGL and FreeGLUT

    This project is for KT34303 — Computer Graphics course of Universiti Malaysia Sabah

    Team

    • Lee Kim Hao
    • Tan Mei Jun
    • Nizam Bin Nordin
    • Kennedy Gregory Mojuntin
    • Ahmad Farhan Bin Ahmad Zaki
    • Muhammad Danial Aiman Bin Mohd Hanif

    Setting up the project

    Requirements

    • Build Tools for Visual Studio 2019
    • Visual Studio Code as our coding environment and setup.
    • CMake as our cross-platform configuration tool.
    • git is a must for development.
    • vcpkg as our library manager

    Windows

    Setting up the Build Tools for VS Code

    You can follow this guide on how to install Build Tools(just follow the Prerequisite 1-3) (https://code.visualstudio.com/docs/cpp/config-msvc) on how to install the required C++ compiler.

    Setting up vcpkg library manager to install FreeGLUT and OpenGL libraries

    After you installed cmake and git, open the command prompt and type the following command to install vcpkg

    > cd C:\ 
    > git clone https://github.com/microsoft/vcpkg.git

    The above command should install vcpkg to C:\vcpkg. Then type the following command

    > .\vcpkg\bootstrap-vcpkg.bat

    This will set up the necessary configuration. Finally, install the FreeGLUT and OpenGL library with the following command

    > .\vcpkg\vcpkg install opengl:x64-windows
    > .\vcpkg\vcpkg install freeglut:x64-windows

    This will take a while, you will know the process is finished if the command prompt shows the following:

    ...
    The package freeglut is compatible with built-in CMake targets:
    
        find_package(GLUT REQUIRED)
        target_link_libraries(main PRIVATE GLUT::GLUT)
    ...
    

    Linux

    Setting up the C++ compiler for VS Code and install FreeGLUT

    On Linux, the library installation is straight forward. Make sure you installed build-essential to install the required compilers and development libraries. Use your package manager to install FreeGLUT library freeglut3-dev

    $ sudo apt get update
    $ sudo apt get install build-essential
    $ sudo apt get install freeglut3-dev

    Cloning this repo

    To clone this repo, create a project folder anywhere you want.
    Open command prompt or terminal in that folder and run the following command

    > git clone https://github.com/screamingDanana/cg-project-2d.git

    The above command should clone this repo to your desired directory.

    Or just download this repo as zip and extract it to your desired location.

    Setting up VS Code workspace

    Open up Visual Studio Code and install the following extensions from the marketplace

    • C/C++
    • CMake
    • CMake Tools

    Next, go to File>Open Folder... then select the folder that you have just cloned, e.g <your project directory>/cg-project-2d

    Press Ctrl+Shift+P to open vscode command pallete and type cmake. You should see CMake: Configure in the list, select it.

    Next, it should list all the available compilers on your computer. For Windows, it should show a list like Microsoft Visual Studio Build Tools 2019 x86_64 or something along the lines. Select the one with x86_64 compiler. On Linux, select the latest GCC Compiler. It should automatically detect CMakeList.txt and configure the project.

    Configuring launch task

    Make sure at the bottom it says Cmake: [Release]: Ready. If not, click on it and select "Release" Press F7 to compile the program. This should create the executable opengl_program.exe for Windows or opengl_program for Linux.

    For Windows: Press F5 and select C++ (Windows). A launch.json configuration file should open.
    Change the "program" field to "${workspaceFolder}/build/Release/opengl_program.exe" you can look for the executable inside the build folder (should be in Release)

    Your program field in launch.json should look like this

    ...
    "program": "${workspaceFolder}/build/Release/opengl_program.exe"
    ...

    After that, save the file and press F5, the program should run.

    For Linux: Press F5 and select C++ (GDB/LLDB). A launch.json configuration file should open.
    Change the "program" field to "${workspaceFolder}/build/opengl_program"

    Your program field in launch.json should look like this

    ...
    "program": "${workspaceFolder}/build/opengl_program"
    ...

    After that, save the file and press F5, the program should run.

    License

    This project is licensed under MIT License

    Понравилась статья? Поделить с друзьями:
    0 0 голоса
    Рейтинг статьи
    Подписаться
    Уведомить о
    guest

    0 комментариев
    Старые
    Новые Популярные
    Межтекстовые Отзывы
    Посмотреть все комментарии
  • Почему у меня нет прав администратора на windows 10
  • Создать загрузочный диск windows 10 на флешку с помощью ultraiso
  • Как запустить видеокарту на компьютере windows 10
  • Windows 10 iot core for minnowboard max
  • Софт для windows mobile