title: Compile gRPC C++ Examples with vcpkg
body: <p>I am trying to build and run the grpc examples with grpc that was installed with vcpkg manager.</p>
  <p>I installed vcpkg manager by cloning and finding grpc like so:</p>
  <pre class="lang-sh prettyprint-override"><code>sudo apt-get install -y unzip build-essential
  git clone https://github.com/microsoft/vcpkg
  cd vcpkg/
  ./bootstrap-vcpkg.sh -disableMetrics
  ./vcpkg search grpc
  ./vcpkg install grpc
  export PATH=$PATH:$HOME/vcpkg/downloads/tools/cmake-3.14.0-linux/cmake-3.14.0-Linux-x86_64/bin 
  </code></pre>
  <p>Great! So I think I have grpc. I also needed protobuf but it came installed with vcpkg's grpc. If I try to install protobuf I get the following output:</p>
  <pre class="lang-sh prettyprint-override"><code>an@ubuntu:~/vcpkg$ ./vcpkg install protobuf
  Computing installation plan...
  The following packages are already installed:
      protobuf[core]:x64-linux
  Package protobuf:x64-linux is already installed
  
  Total elapsed time: 205.3 us
  
  The package protobuf:x64-linux provides CMake targets:
  
      find_package(protobuf CONFIG REQUIRED)
      target_link_libraries(main PRIVATE protobuf::libprotoc protobuf::libprotobuf protobuf::libprotobuf-lite
  </code></pre>
  <p>To double check I use <code>./vcpkg list</code> to show all the packages I have installed. Heres what it looks like. Note: protobuf and grpc</p>
  <pre><code>adrian@ubuntu:~/vcpkg$ ./vcpkg list
  abseil:x64-linux                                   2020-03-03#8     an open-source collection designed to augment th...
  c-ares:x64-linux                                   2019-5-2-1       A C library for asynchronous DNS requests
  grpc:x64-linux                                     1.31.1           An RPC library and framework
  openssl-unix:x64-linux                             1.1.1h           OpenSSL is an open source project that provides ...
  openssl:x64-linux                                  1.1.1g#1         OpenSSL is an open source project that provides ...
  protobuf:x64-linux                                 3.13.0#2         Protocol Buffers - Google's data interchange format
  re2:x64-linux                                      2020-10-01       RE2 is a fast, safe, thread-friendly alternative...
  upb:x64-linux                                      2020-08-19       μpb (often written 'upb') is a small protobuf i...
  zlib:x64-linux                                     1.2.11#9         A compression library
  </code></pre>
  <p>We can also see grpc and protobuf's binarys in the <code>/vcpkg/installed/x64-linux/libs</code> directory highlighted below:
  <a href="https://i.stack.imgur.com/DPHES.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/DPHES.png" alt="enter image description here" /></a></p>
  <p>Ok great! So now I want to try and compile grpc's hello world examples with the vcpkg manager plugins. In the official grpc website they have a quick instructions for building then compiling. (by default they install grpc natively but its a mess uninstall which is why I went with vcpkg instead).So lets try to compile with these <a href="https://grpc.io/docs/languages/cpp/quickstart/#build-the-example" rel="nofollow noreferrer">instructions from grpc's quick start guide</a>:</p>
  <pre class="lang-sh prettyprint-override"><code>mkdir -p cmake/build
  pushd cmake/build
  cmake -DCMAKE_PREFIX_PATH=$MY_INSTALL_DIR ../..
  make -j
  </code></pre>
  <p>Its important to note that at the beginning they installed grpc natively (which is messy to remove unliked vcpkg). Their instructions indicate to set <code>MY_INSTALL_DIR</code> like so:</p>
  <pre class="lang-sh prettyprint-override"><code>export MY_INSTALL_DIR=$HOME/.local
  export PATH=&quot;$PATH:$MY_INSTALL_DIR/bin&quot;
  </code></pre>
  <p>But this is for installing and compiling grpc's binaries natively. Unfortunately I dont know where the binaries are for vckpkg manager. I see that cmake installs and has a binary located at: <code>vcpkg/downloads/tools</code> but I do not see grpc or protobuf folder for their respecive binaries (see image below). Where would the binaries be located for vcpkg? Per grpc's official instructions I am supposed to use cmake and define these below.</p>
  <pre class="lang-sh prettyprint-override"><code>find_package(gRPC CONFIG REQUIRED)
  find_package(Protobuf CONFIG REQUIRED)
  </code></pre>
  <p>Unfortunately I am relatively new to vcpkg and dependencies with a little experience using Makefiles (which i believe are much different than cmake/cmakelists. I never made cmake files from scratch as I primarily use Makefiles). Could someone please point me in the right direction how to compile and run these examples with vcpkg (or suggest a better approach?) My goal is to learn how to use vcpkg and integrate it into an existing project like gRPC's example files.</p>
  <p><a href="https://i.stack.imgur.com/FzgG8.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/FzgG8.png" alt="vcpkg's installed package directory location" /></a></p>
  <p><strong>Update 1:</strong></p>
  <p>I cd to the example hellow world folder and ran the following as suggested:</p>
  <pre class="lang-sh prettyprint-override"><code>mkdir build-dir
  cd build-dir
  cmake ..
  make
  </code></pre>
  <p>When I ran <code>cmake ..</code> I got the following error:</p>
  <pre class="lang-sh prettyprint-override"><code>grpc/examples/cpp/helloworld/build$ cmake ..
  CMake Error at /usr/share/cmake-3.16/Modules/CMakeDetermineSystem.cmake:99 (message):
    Could not find toolchain file: /usr/vcpkg/scripts/buildsystems/vcpkg.cmake
  Call Stack (most recent call first):
    CMakeLists.txt:24 (project)
  
  
  CMake Error: CMake was unable to find a build program corresponding to &quot;Unix Makefiles&quot;.  CMAKE_MAKE_PROGRAM is not set.  You probably need to select a different build tool.
  CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage
  CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage
  -- Configuring incomplete, errors occurred!
  
  </code></pre>
  <p>This was an indicator that I am not using the correct cmake (the one used by vcpkg. So i did a little digging and according to this <a href="https://vcpkg.readthedocs.io/en/latest/examples/installing-and-using-packages/" rel="nofollow noreferrer">vcpkg documentation</a> I need to integrate vcpkg packages with <code>./vcpkg integrate install</code> which exposes all my packages on my system as long as I point it to the cmake within. It then says I should seed a path:</p>
  <pre class="lang-sh prettyprint-override"><code>~/vcpkg$ ./vcpkg integrate install
  Applied user-wide integration for this vcpkg root.
  
  CMake projects should use: &quot;-DCMAKE_TOOLCHAIN_FILE=/home/adrian/vcpkg/scripts/buildsystems/vcpkg.cmake&quot;
  </code></pre>
  <p>So I try to build with <code>cmake ..</code> but instead I provide the <code>DCMAKE_TOOL_CHAIN</code> argument like so but I am back to the original problem as before.</p>
  <pre class="lang-sh prettyprint-override"><code>/grpc/examples/cpp/helloworld/build$ cmake .. &quot;-DCMAKE_TOOLCHAIN_FILE=/home/adrian/vcpkg/scripts/buildsystems/vcpkg.cmake&quot;
  CMake Error at /usr/share/cmake-3.16/Modules/CMakeDetermineSystem.cmake:99 (message):
    Could not find toolchain file: /usr/vcpkg/scripts/buildsystems/vcpkg.cmake
  Call Stack (most recent call first):
    CMakeLists.txt:24 (project)
  
  
  CMake Error: CMake was unable to find a build program corresponding to &quot;Unix Makefiles&quot;.  CMAKE_MAKE_PROGRAM is not set.  You probably need to select a different build tool.
  CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage
  CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage
  -- Configuring incomplete, errors occurred!
  </code></pre>