Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
154 views
in Technique[技术] by (71.8m points)

c++ - cmake: using only headers from opencv for my library

I'm creating a geometry based tool, that uses Vec class from opencv. This class is completely defined in the matx.hpp header. Therefore, I need just that header for my application. My question is in general though, for cases like this, where you are just using some structures or similar from a library, what's the best way to specify them to use in your CMakeLists.txt

Normally, I would do the following:

find_package(OpenCV REQUIRED COMPONENTS core)

add_library(lib1 STATIC
    src/a.cpp
)
target_link_libraries(lib1
    PUBLIC 
    opencv_core
)

But this will link everything from opencv_core, and although the compiler won't actually add all objects, it being a PUBLIC dependency can lead to problems down the line. For instance, future modules might get away with not linking to opencv_core even if they had to because lib1 carries forward that dependency. This seems like an inaccurate way to achieve what I need.

Alternatively, I could use the ${OpenCV_INCLUDE_DIRS} variable, like so:

target_include_directories(lib1
    ${OpenCV_INCLUDE_DIRS}
) 

But as I'm moving to more modern practices, I prefer to not use variables because they contain all of the combined values for the entire library. For this use case, what is the best way?

Thank you

question from:https://stackoverflow.com/questions/66057414/cmake-using-only-headers-from-opencv-for-my-library

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...