'How to include Vcpkg on CMakeLists.txt?
So I have a project which depends on opencv, which is installed with vcpkg. The project is build with cmake.
CMakeLists.txt
cmake_minimum_required(VERSION 3.19.1)
set(CMAKE_TOOLCHAIN_FILE ~/vcpkg/scripts/buildsystems/vcpkg.cmake)
project(mylib)
set (CMAKE_CXX_STANDARD 14)
find_package(OpenCV REQUIRED)
include_directories(~/vcpkg/installed/x64-osx/include)
link_libraries(${OpenCV_LIBS})
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS TRUE)
add_library(mylib SHARED mylib another_lib)
As can be seen, I'm trying to use the same CMakeLists.txt to build it on macOS and Windows.
The link_libraries(${OpenCV_LIBS}) translates nicely between different OSs.
But include_directories(~/vcpkg/installed/x64-osx/include) only works on macOS, on Windows it should refer to C:/vcpkg/installed/x64-windows/include instead.
Is there any opecv/vcpkg I can use inlace of these?
Solution 1:[1]
This include_directories(~/vcpkg/installed/x64-osx/include) looks odd. This should be instead that:
include_directories(${OpenCV_INCLUDE_DIRS})
Solution 2:[2]
You can use vcpkg in the manifest mode https://vcpkg.readthedocs.io/en/latest/users/manifests/
This way you create a JSON file listing all of your dependencies and when invoking cmake vcpkg will automatically bootstrap and install all the dependencies.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | 273K |
| Solution 2 | MarekR |
