How to feed CMake with vcpkg information?

痴心易碎 提交于 2020-12-13 04:48:40

问题


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

回答1:


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.



来源:https://stackoverflow.com/questions/59250626/how-to-feed-cmake-with-vcpkg-information

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!