Repository: opencv
Issue: Issues on OpenCV 4.5.5 compiling from scratch on newer macOS (Intel chip, macOS Monterey)
Labels: question (invalid tracker),category: build/install,platform: ios/osx,incomplete,category: 3rdparty

<!--
If you have a question rather than reporting a bug please go to https://forum.opencv.org where you get much faster responses.
If you need further assistance please read [How To Contribute](https://github.com/opencv/opencv/wiki/How_to_contribute).

This is a template helping you to create an issue which can be processed as quickly as possible. This is the bug reporting section for the OpenCV library.
-->

##### System information (version)
- OpenCV => 4.5.5
- Operating System / Platform => macOS Monterey 12.0.1, 64 Bit
- Compiler => gcc-11, local

##### Detailed description

This is an issue I came across when I tried configuring OpenCV for C++ development after using it with Python for few weeks. I tried to install the "cutting-edge" version from GitHub directly and not use the Homebrew binaries. After cloning the repo, I created a build folder inside, and used CMake to configure build files, when this was finished, I used the 'make all' command to compile. This is when the issue happens.

##### Steps to reproduce

I followed the instructions in the book "Building Computer Vision Projects with OpenCV4 and C++" and I'll describe here the steps that led to an error on my machine:
- Install CMake
- Download latest version of OpenCV from GitHub, unzip anywhere (I git cloned it in /usr/local/Cellar)
- Go to OpenCV director (cd /full/path/to/opencv)
- make new directory called 'build' && cd into 'build'
- Now we call CMake with this command: ```cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/full/path/to/opencv/build -D INSTALL_C_EXAMPLES=ON -D BUILD_EXAMPLES=ON ../```
- I tried both CMake via command line and using the actual CMake application, both led to the same result.
- Now to install OpenCV, inside the build folder, I call: ```make -j4```
- The j4 flag indicates that we should use four cores to install (though I've tried calling ```make``` by itself and it still led to the same error, so this can't be it.
- This is where it starts to build targets, here is the error output after running ```make``` second time (because it's cleaner than first, less to copy/paste).
```
sharbel@sharbel-MacBook-Pro build % make all
[  0%] Built target opencv_highgui_plugins
Consolidate compiler generated dependencies of target libopenjp2
[  1%] Built target libopenjp2
[  1%] Built target opencv_videoio_plugins
Consolidate compiler generated dependencies of target ittnotify
[  1%] Built target ittnotify
Consolidate compiler generated dependencies of target zlib
[  2%] Built target zlib
Consolidate compiler generated dependencies of target ippiw
[  3%] Built target ippiw
Consolidate compiler generated dependencies of target opencv_core
[  8%] Built target opencv_core
Consolidate compiler generated dependencies of target opencv_imgproc
[ 12%] Built target opencv_imgproc
Consolidate compiler generated dependencies of target libjpeg-turbo
[ 15%] Built target libjpeg-turbo
Consolidate compiler generated dependencies of target libpng
[ 16%] Built target libpng
Consolidate compiler generated dependencies of target libtiff
[ 18%] Built target libtiff
Consolidate compiler generated dependencies of target libwebp
[ 24%] Built target libwebp
Consolidate compiler generated dependencies of target opencv_imgcodecs
make[2]: *** No rule to make target `zlib', needed by `lib/libopencv_imgcodecs.4.5.5.dylib'.  Stop.
make[1]: *** [modules/imgcodecs/CMakeFiles/opencv_imgcodecs.dir/all] Error 2
make: *** [all] Error 2
```
I've searched through all tutorials, they each have a flaw and most seem to be outdated or not specific. OpenCV4 works just fine when I use Xcode, because apparently Xcode is able to find the dynamic libraries it's looking for because [Apple changed the location of the libraries](https://developer.apple.com/forums/thread/655588) on newer OS's and properly updated Xcode to handle this, but CMakeLists isn't equipped with that ability, therefore builds are failing. (just a hypothesis, collab with [scawful](https://github.com/scawful)).

##### Issue submission checklist

 - [x] I report the issue, it's not a question
   <!--
   OpenCV team works with forum.opencv.org, Stack Overflow and other communities
   to discuss problems. Tickets with question without real issue statement will be
   closed.
   -->
 - [x] I checked the problem with documentation, FAQ, open issues,
       forum.opencv.org, Stack Overflow, etc and have not found solution
   <!--
   Places to check:
   * OpenCV documentation: https://docs.opencv.org
   * FAQ page: https://github.com/opencv/opencv/wiki/FAQ
   * OpenCV forum: https://forum.opencv.org
   * OpenCV issue tracker: https://github.com/opencv/opencv/issues?q=is%3Aissue
   * Stack Overflow branch: https://stackoverflow.com/questions/tagged/opencv
   -->
 - [x] I updated to latest OpenCV version and the issue is still there
   <!--
   master branch for OpenCV 4.x and 3.4 branch for OpenCV 3.x releases.
   OpenCV team supports only latest release for each branch.
   The ticket is closed, if the problem is not reproduced with modern version.
   -->
 - [x] There is reproducer code and related data files: videos, images, onnx, etc
   <!--
   The best reproducer -- test case for OpenCV that we can add to the library.
   Recommendations for media files and binary files:
   * Try to reproduce the issue with images and videos in opencv_extra repository
     to reduce attachment size
   * Use PNG for images, if you report some CV related bug, but not image reader
     issue
   * Attach the image as archive to the ticket, if you report some reader issue.
     Image hosting services compress images and it breaks the repro code.
   * Provide ONNX file for some public model or ONNX file with with random weights,
     if you report ONNX parsing or handling issue. Architecture details diagram
     from netron tool can be very useful too. See https://lutzroeder.github.io/netron/
   -->