如何在 CMakeLists.txt 中包含非 Vcpkg?
所以我有一个依赖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.cmake
,find_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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用
< packagename> _dir
变量指向配置文件的位置。它适用于配置文件随附的任何库。For you it would look like this:
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:
cmake OpenCV_DIR="C:/opencv /build"
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:
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:
cmake OpenCV_DIR="C:/opencv/build"
LocalConfig.cmake
with the content above (set(...)
), which you include in your main script like this:include(LocalConfig.cmake)