Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to feed CMake with vcpkg information?

Tags:

c++

cmake

vcpkg

Suppose I have installed some library with vcpkg and it's numerous dependencied (say cgal). Now I want to compile some program against these libraries with CMake.

How should I tell CMake about all locations of all libraries I have downloaded? Including main library I have installed? I have only one setting in CMake, called "source directory" which will point to my code. Where are settings for libraries?


D:\Users\ThirdPartyDesign\CGAL-5.0-examples\CGAL-5.0\examples\Triangulation_2
λ env | grep CMAKE
CMAKE_TOOLCHAIN_FILE=D:\Users\ThirdPartyDesign\vcpkg\scripts\buildsystems\vcpkg.cmake



D:\Users\ThirdPartyDesign\CGAL-5.0-examples\CGAL-5.0\examples\Triangulation_2
λ cmake .
CMake Warning at CMakeLists.txt:18 (find_package):
  By not providing "FindCGAL.cmake" in CMAKE_MODULE_PATH this project has
  asked CMake to find a package configuration file provided by "CGAL", but
  CMake did not find one.

  Could not find a package configuration file provided by "CGAL" with any of
  the following names:

    CGALConfig.cmake
    cgal-config.cmake

  Add the installation prefix of "CGAL" to CMAKE_PREFIX_PATH or set
  "CGAL_DIR" to a directory containing one of the above files.  If "CGAL"
  provides a separate development package or SDK, be sure it has been
  installed.


-- This program requires the CGAL library, and will not be compiled.
-- Configuring done
-- Generating done
-- Build files have been written to: D:/Users/ThirdPartyDesign/CGAL-5.0-examples/CGAL-5.0/examples/Triangulation_2
like image 712
Dims Avatar asked Dec 09 '19 14:12

Dims


People also ask

How do I use CMake with Vcpkg?

The best way to use installed libraries with cmake is via the toolchain file scripts\buildsystems\vcpkg. cmake . To use this file, you simply need to add it onto your CMake command line as: -DCMAKE_TOOLCHAIN_FILE=D:\src\vcpkg\scripts\buildsystems\vcpkg.


Video Answer


1 Answers

Normally you need to set; CMAKE_TOOLCHAIN_FILE and VCPKG_TARGET_TRIPLET.

Set VCPKG_TARGET_TRIPLET to the vcpkg triplet that you are using. The default is x86-windows

Set CMAKE_TOOLCHAIN_FILE to point to path_to_vcpkg\scripts\buildsystems\vcpkg.cmake

Then you can use cmake functions such as find_package to find the required package.

see https://github.com/microsoft/vcpkg/blob/master/docs/examples/installing-and-using-packages.md#cmake-toolchain-file for more information.

like image 131
bertubezz Avatar answered Sep 18 '22 01:09

bertubezz