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 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…