1

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?

KcFnMi
  • 5,516
  • 10
  • 62
  • 136

3 Answers3

3

This include_directories(~/vcpkg/installed/x64-osx/include) looks odd. This should be instead that:

include_directories(${OpenCV_INCLUDE_DIRS})
273K
  • 29,503
  • 10
  • 41
  • 64
1

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.

MarekR
  • 2,410
  • 1
  • 14
  • 10
0

include_directories and link_libraries is old style cmake and should be avoided. target_link_libraries should be used instead.

Also using paths specific your our system is not recommended. CMAKE_TOOLCHAIN_FILE value should be provided when configuring project.

IMO it should go like this:

cmake_minimum_required(VERSION 3.19.1)

# this way others can override this value form command line
set(CMAKE_TOOLCHAIN_FILE ~/vcpkg/scripts/buildsystems/vcpkg.cmake CACHE FILEPATH "Path to toolchain")

project(mylib)
find_package(OpenCV REQUIRED)

set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS TRUE)

add_library(mylib SHARED mylib another_lib)

# this should resolve problems with include and linking at the same time
# and only yor target will be impacted (and targets linking your target 
# since PUBLIC is used)
target_link_libraries(mylib PUBLIC ${OpenCV_LIBS})
Marek R
  • 32,568
  • 6
  • 55
  • 140