I am Charmie

メモとログ

vcpkg (C++ package manager): install on Mac OSX

Step 0: check gcc and g++

clang might cause compilation error.

% g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/local/Cellar/gcc/9.2.0_3/libexec/gcc/x86_64-apple-darwin19/9.2.0/lto-wrapper
Target: x86_64-apple-darwin19
Configured with: ../configure --build=x86_64-apple-darwin19 --prefix=/usr/local/Cellar/gcc/9.2.0_3 --libdir=/usr/local/Cellar/gcc/9.2.0_3/lib/gcc/9 --disable-nls --enable-checking=release --enable-languages=c,c++,objc,obj-c++,fortran --program-suffix=-9 --with-gmp=/usr/local/opt/gmp --with-mpfr=/usr/local/opt/mpfr --with-mpc=/usr/local/opt/libmpc --with-isl=/usr/local/opt/isl --with-system-zlib --with-pkgversion='Homebrew GCC 9.2.0_3' --with-bugurl=https://github.com/Homebrew/homebrew-core/issues --disable-multilib --with-native-system-header-dir=/usr/include --with-sysroot=/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk
Thread model: posix
gcc version 9.2.0 (Homebrew GCC 9.2.0_3) 
% gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/local/Cellar/gcc/9.2.0_3/libexec/gcc/x86_64-apple-darwin19/9.2.0/lto-wrapper
Target: x86_64-apple-darwin19
Configured with: ../configure --build=x86_64-apple-darwin19 --prefix=/usr/local/Cellar/gcc/9.2.0_3 --libdir=/usr/local/Cellar/gcc/9.2.0_3/lib/gcc/9 --disable-nls --enable-checking=release --enable-languages=c,c++,objc,obj-c++,fortran --program-suffix=-9 --with-gmp=/usr/local/opt/gmp --with-mpfr=/usr/local/opt/mpfr --with-mpc=/usr/local/opt/libmpc --with-isl=/usr/local/opt/isl --with-system-zlib --with-pkgversion='Homebrew GCC 9.2.0_3' --with-bugurl=https://github.com/Homebrew/homebrew-core/issues --disable-multilib --with-native-system-header-dir=/usr/include --with-sysroot=/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk
Thread model: posix
gcc version 9.2.0 (Homebrew GCC 9.2.0_3) 

Step 1: compile vcpkg

Compile vcpkg with the following commands.

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

The system log looks as follwos:

Downloading cmake...
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   640  100   640    0     0   1636      0 --:--:-- --:--:-- --:--:--  1641
100 31.9M  100 31.9M    0     0  5240k      0  0:00:06  0:00:06 --:--:-- 7223k
Downloading cmake... done.
Extracting cmake...
Extracting cmake... done.
Downloading ninja...
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   622  100   622    0     0   1555      0 --:--:-- --:--:-- --:--:--  1555
100  114k  100  114k    0     0  59321      0  0:00:01  0:00:01 --:--:--  108k
Downloading ninja... done.
Extracting ninja...
Extracting ninja... done.
-- The CXX compiler identification is GNU 9.2.0
-- Checking whether CXX compiler has -isysroot
-- Checking whether CXX compiler has -isysroot - yes
-- Checking whether CXX compiler supports OSX deployment target flag
-- Checking whether CXX compiler supports OSX deployment target flag - yes
-- Check for working CXX compiler: /usr/local/bin/g++-9
-- Check for working CXX compiler: /usr/local/bin/g++-9 -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Detecting the C++ standard library
-- Detecting the C++ standard library - libstdc++
-- Detecting how to use the C++ filesystem library
-- Detecting how to use the C++ filesystem library - <filesystem>
-- Looking for C++ include pthread.h
-- Looking for C++ include pthread.h - found
-- Looking for pthread_create
-- Looking for pthread_create - found
-- Found Threads: TRUE  
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/oyamada/Documents/code/cpp/extern/vcpkg/toolsrc/build.rel
[0/2] Re-checking globbed directories...
[75/75] Linking CXX executable vcpkg
Telemetry
---------

vcpkg collects usage data in order to help us improve your experience. The data collected by Microsoft is anonymous. You can opt-out of telemetry by re-running bootstrap-vcpkg.sh with -disableMetrics
Read more about vcpkg telemetry at docs/about/privacy.md

Step 2: hook up user-wide integration

The following command makes vcpkg ready to manage packages.

% ./vcpkg integrate install 
Applied user-wide integration for this vcpkg root.

CMake projects should use: "-DCMAKE_TOOLCHAIN_FILE=/ROOT_DIRECTORY_OF_VCPKG/scripts/buildsystems/vcpkg.cmake"

Step 3: install packages

vcpkg binary provide following functionality.

% ./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
  vcpkg upgrade                   Rebuild all outdated packages
  vcpkg x-history <pkg>           (Experimental) Shows the history of CONTROL versions of a package
  vcpkg hash <file> [alg]         Hash a file by specific algorithm, default SHA512
  vcpkg help topics               Display the list of help topics
  vcpkg help <topic>              Display help for a specific topic

  vcpkg integrate install         Make installed packages available user-wide.
  vcpkg integrate remove          Remove user-wide integration
  vcpkg integrate bash            Enable bash tab-completion

  vcpkg export <pkg>... [opt]...  Exports a package
  vcpkg edit <pkg>                Open up a port for editing (uses $EDITOR, default 'code')
  vcpkg import <pkg>              Import a pre-built library
  vcpkg create <pkg> <url> [archivename]
                                  Create a new package
  vcpkg owns <pat>                Search for files in installed packages
  vcpkg depend-info <pkg>...      Display a list of dependencies for packages
  vcpkg env                       Creates a clean shell environment for development or compiling.
  vcpkg version                   Display version information
  vcpkg contact                   Display contact information to send feedback

Options:
  --triplet <t>                   Specify the target architecture triplet. See 'vcpkg help triplet'
                                  (default: $VCPKG_DEFAULT_TRIPLET)
  --overlay-ports=<path>          Specify directories to be used when searching for ports
  --overlay-triplets=<path>       Specify directories containing triplets files
  --vcpkg-root <path>             Specify the vcpkg root directory
                                  (default: $VCPKG_ROOT)
  --x-scripts-root=<path>         (Experimental) Specify the scripts root directory

  @response_file                  Specify a response file to provide additional parameters

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

test on ceres

install ceres

% ./vcpkg install ceres
Computing installation plan...
The following packages will be built and installed:
    ceres[core]:x64-osx
  * eigen3[core]:x64-osx
  * gflags[core]:x64-osx
  * glog[core]:x64-osx
Additional packages (*) will be modified to complete this operation.
Starting package 1/4: eigen3:x64-osx
Building package eigen3[core]:x64-osx...
-- Downloading https://gitlab.com/libeigen/eigen/-/archive/3.3.7/eigen-3.3.7.tar.gz...
-- Extracting source /Users/oyamada/Documents/code/cpp/extern/vcpkg/downloads/libeigen-eigen-3.3.7.tar.gz
-- Using source at /Users/oyamada/Documents/code/cpp/extern/vcpkg/buildtrees/eigen3/src/3.3.7-c7b55a8243
-- Configuring x64-osx-dbg
-- Configuring x64-osx-rel
-- Building x64-osx-dbg
-- Building x64-osx-rel
-- Fixing pkgconfig
-- Fixing pkgconfig - release
-- Checking file: /Users/oyamada/Documents/code/cpp/extern/vcpkg/packages/eigen3_x64-osx/lib/pkgconfig/eigen3.pc
-- Fixing pkgconfig - debug
-- Checking file: /Users/oyamada/Documents/code/cpp/extern/vcpkg/packages/eigen3_x64-osx/debug/lib/pkgconfig/eigen3.pc
-- REL PATH: ../../
-- Fixing pkgconfig --- finished
-- Performing post-build validation
-- Performing post-build validation done
Building package eigen3[core]:x64-osx... done
Installing package eigen3[core]:x64-osx...
Installing package eigen3[core]:x64-osx... done
Elapsed time for package eigen3:x64-osx: 21.04 s
Starting package 2/4: gflags:x64-osx
Building package gflags[core]:x64-osx...
-- Downloading https://github.com/gflags/gflags/archive/v2.2.2.tar.gz...
-- Extracting source /Users/oyamada/Documents/code/cpp/extern/vcpkg/downloads/gflags-gflags-v2.2.2.tar.gz
-- Applying patch 0001-patch-dir.patch
-- Applying patch fix_cmake_config.patch
-- Using source at /Users/oyamada/Documents/code/cpp/extern/vcpkg/buildtrees/gflags/src/v2.2.2-d9283b9285
-- Configuring x64-osx-dbg
-- Configuring x64-osx-rel
-- Building x64-osx-dbg
-- Building x64-osx-rel
-- Installing: /Users/oyamada/Documents/code/cpp/extern/vcpkg/packages/gflags_x64-osx/share/gflags/copyright
-- Performing post-build validation
-- Performing post-build validation done
Building package gflags[core]:x64-osx... done
Installing package gflags[core]:x64-osx...
Installing package gflags[core]:x64-osx... done
Elapsed time for package gflags:x64-osx: 15.73 s
Starting package 3/4: glog:x64-osx
Building package glog[core]:x64-osx...
-- Downloading https://github.com/google/glog/archive/v0.4.0.tar.gz...
-- Extracting source /Users/oyamada/Documents/code/cpp/extern/vcpkg/downloads/google-glog-v0.4.0.tar.gz
-- Applying patch glog_disable_debug_postfix.patch
-- Using source at /Users/oyamada/Documents/code/cpp/extern/vcpkg/buildtrees/glog/src/v0.4.0-46ccbc49a4
-- Configuring x64-osx-dbg
-- Configuring x64-osx-rel
-- Building x64-osx-dbg
-- Building x64-osx-rel
-- Installing: /Users/oyamada/Documents/code/cpp/extern/vcpkg/packages/glog_x64-osx/share/glog/copyright
-- Performing post-build validation
-- Performing post-build validation done
Building package glog[core]:x64-osx... done
Installing package glog[core]:x64-osx...
Installing package glog[core]:x64-osx... done
Elapsed time for package glog:x64-osx: 21.67 s
Starting package 4/4: ceres:x64-osx
Building package ceres[core]:x64-osx...
-- Downloading https://github.com/ceres-solver/ceres-solver/archive/1.14.0.tar.gz...
-- Extracting source /Users/oyamada/Documents/code/cpp/extern/vcpkg/downloads/ceres-solver-ceres-solver-1.14.0.tar.gz
-- Applying patch 0001_cmakelists_fixes.patch
-- Applying patch 0002_use_glog_target.patch
-- Applying patch 0003_fix_exported_ceres_config.patch
-- Using source at /Users/oyamada/Documents/code/cpp/extern/vcpkg/buildtrees/ceres/src/1.14.0-d660e542f2
-- Configuring x64-osx-dbg
-- Configuring x64-osx-rel
-- Building x64-osx-dbg
-- Building x64-osx-rel
-- Performing post-build validation
-- Performing post-build validation done
Building package ceres[core]:x64-osx... done
Installing package ceres[core]:x64-osx...
Installing package ceres[core]:x64-osx... done
Elapsed time for package ceres:x64-osx: 4.916 min

Total elapsed time: 5.89 min

The package ceres:x64-osx provides CMake targets:

    find_package(Ceres CONFIG REQUIRED)
    target_link_libraries(main PRIVATE ceres)

use hello world

cmake_minimum_required(VERSION 2.8)

project(helloworld)

include(/VCPKG_ROOT_DIRECTORY/scripts/buildsystems/vcpkg.cmake)
find_package(Ceres CONFIG REQUIRED)

include_directories(${CERES_INCLUDE_DIRS})

# helloworld
add_executable(helloworld helloworld.cc)
target_link_libraries(helloworld PRIVATE ${CERES_LIBRARIES})