I have two projects PROJ in my workspace ws with corresponding third party libraries TPL as shown below. All depend on opencv 4.4.
ws
├── PROJ1 (opencv 4.4)
| └── TPL1 (opencv 4.4)
└── PROJ2 (opencv 4.4)
└── TPL2 (opencv 4.4)
PROJ1, PROJ2 and TPL1 have following lines in their CMakeLists.txt:
set(OpenCV_DIR $ENV{OPENCV4_DIR})
find_package(OpenCV 4.4 REQUIRED)
Whereas TPL2 only have:
find_package(OpenCV 4.4 REQUIRED)
but does not have
set(OpenCV_DIR $ENV{OPENCV4_DIR})
When I run cmake and make inside PROJ1/build and PROJ2/build they succeessbully get built. However, notice that PROJ2 gets built without TPL2 having set(OpenCV_DIR $ENV{OPENCV4_DIR}) specified in its CMakeLists.txt, but TPL1 needs to have this line for PROJ1 to build successfully. Otherwise it gives following error:
fatal error: opencv/cv.h: No such file or directory
26 | #include <opencv/cv.h>
| ^~~~~~~~~~~~~
Why is it so? Is there some CMakeLists.txt config that lets third party apps to inherit paths from CMakeLists.txt in parent directories or something similar?
PS: I do not do make install in any of these PROJs and TPLs.