如何在 CMakeLists.txt 中包含非 Vcpkg?

发布于 2025-01-19 09:19:11 字数 863 浏览 1 评论 0原文

所以我有一个依赖opencv的项目,它是用vcpkg安装的。该项目是使用 cmake 构建的。

CMakeLists.txt

cmake_minimum_required(VERSION 3.19.1)

project(mylib)

set (CMAKE_CXX_STANDARD 14)

find_package(OpenCV REQUIRED)

include_directories(${OpenCV_INCLUDE_DIRS})

link_libraries(${OpenCV_LIBS})

set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS TRUE)

add_library(mylib SHARED mylib.cpp another_lib.cpp)

工作正常。

现在,我想使用

https://sourceforge.net/projects/opencvlibrary/files/4.4.0/opencv-4.4.0-vc14_vc15.exe/download

安装在 C:\opencv 我看到有 opencv\build\OpenCVConfig.cmakefind_package 正在寻找,对吗?

但是我如何让 cmake 得到这个而不是 vcpkg 中的那个呢?

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)

project(mylib)

set (CMAKE_CXX_STANDARD 14)

find_package(OpenCV REQUIRED)

include_directories(${OpenCV_INCLUDE_DIRS})

link_libraries(${OpenCV_LIBS})

set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS TRUE)

add_library(mylib SHARED mylib.cpp another_lib.cpp)

That works fine.

Now, instead of vcpkg provided opencv, I want to use opencv from

https://sourceforge.net/projects/opencvlibrary/files/4.4.0/opencv-4.4.0-vc14_vc15.exe/download

After installing it on C:\opencv I see there is opencv\build\OpenCVConfig.cmake, which find_package look for, right?

But how do I make cmake get this one instead of the one from vcpkg?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

糖粟与秋泊 2025-01-26 09:19:11

使用< packagename> _dir变量指向配置文件的位置。它适用于配置文件随附的任何库。
For you it would look like this:

set(OpenCV_DIR "C:/opencv/build")

Since it is incorrect to add hard-coded paths into persistent scripts, you can choose among different methods of providing this variable to your script:

  • Console invocation: cmake OpenCV_DIR="C:/opencv /build"
  • CMake presets ( user)
  • Local config by using some LocalConfig.cmake with the content above (set(...)), which you include in your main script like this: 包括(localconfig.cmake)

Use <PackageName>_DIR variable pointing to where the config file is located. It works for any library which comes with a config file.
For you it would look like this:

set(OpenCV_DIR "C:/opencv/build")

Since it is incorrect to add hard-coded paths into persistent scripts, you can choose among different methods of providing this variable to your script:

  • Console invocation: cmake OpenCV_DIR="C:/opencv/build"
  • CMake presets (user)
  • Local config by using some LocalConfig.cmake with the content above (set(...)), which you include in your main script like this: include(LocalConfig.cmake)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文