Repository: opencv
Issue: CMake gapi option WITH_FREETYPE seems to be ignored
Labels: bug,category: build/install,category: g-api / gapi

### System Information

OpenCV version: 4.9.0
Operating System / Platform: Arch Linux x86_64 (kernel: 6.7.8-arch1-1)
Compiler & compiler version: GCC 13.2.1 ; CMake 3.28.3 ; GNU Make 4.4.1

### Detailed description

I have downloaded the latest OpenCV 4.9.0. From the root, I've ran `mkdir build && cd build && cmake .. && make -j12`. During the compilation, I've received the following error:
```
[ 81%] Building CXX object modules/gapi/CMakeFiles/opencv_gapi.dir/src/backends/common/serialization.cpp.o
[ 81%] Building CXX object modules/gapi/CMakeFiles/opencv_gapi.dir/src/backends/streaming/gstreamingbackend.cpp.o
[ 82%] Building CXX object modules/gapi/CMakeFiles/opencv_gapi.dir/src/backends/render/ft_render.cpp.o
[ 82%] Building CXX object modules/gapi/CMakeFiles/opencv_gapi.dir/src/backends/ie/bindings_ie.cpp.o
[ 82%] Building CXX object modules/gapi/CMakeFiles/opencv_gapi.dir/src/api/s11n.cpp.o
[ 82%] Building CXX object modules/gapi/CMakeFiles/opencv_gapi.dir/src/backends/onnx/bindings_onnx.cpp.o
[ 82%] Building CXX object modules/gapi/CMakeFiles/opencv_gapi.dir/src/backends/ov/bindings_ov.cpp.o
[ 82%] Building CXX object modules/gapi/CMakeFiles/opencv_gapi.dir/src/backends/python/gpythonbackend.cpp.o
[ 82%] Building CXX object modules/gapi/CMakeFiles/opencv_gapi.dir/src/streaming/queue_source.cpp.o
In file included from /home/tom/Downloads/opencv-4.9.0/modules/gapi/src/backends/render/ft_render.cpp:12:
/home/tom/Downloads/opencv-4.9.0/modules/gapi/src/backends/render/ft_render_priv.hpp:15:10: fatal error: ft2build.h: No such file or directory
   15 | #include <ft2build.h>
      |          ^~~~~~~~~~~~
compilation terminated.
make[2]: *** [modules/gapi/CMakeFiles/opencv_gapi.dir/build.make:1154: modules/gapi/CMakeFiles/opencv_gapi.dir/src/backends/render/ft_render.cpp.o] Error 1
make[2]: *** Waiting for unfinished jobs....
make[1]: *** [CMakeFiles/Makefile2:2985: modules/gapi/CMakeFiles/opencv_gapi.dir/all] Error 2
make: *** [Makefile:166: all] Error 2
```

I've made sure that I have `libfreetype-dev` (`freetype2` on arch) installed and linked properly.
```
[build] > pkg-config --cflags freetype2
-I/usr/include/freetype2 -I/usr/include/libpng16 -I/usr/include/harfbuzz -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -I/usr/include/sysprof-6 -pthread
```

After poking around, it seems that the default cmake configuration for the `gapi` for the `WITH_FREETYPE` module is set to `OFF` [as seen here](https://github.com/opencv/opencv/blob/0e524ee95a202b9941d76197da490e36445611f4/modules/gapi/cmake/init.cmake#L3). HOWEVER, the file `ft_render_priv.hpp` used `<ft2build.h>` (and was compiled for some reason) regardless of this option, [even tho it shouldn't have](https://github.com/opencv/opencv/blob/f174363f600aa578874b3f0cb7b190c5dad8a07d/modules/gapi/src/backends/render/ft_render_priv.hpp#L8). I do not know why or how to fix it. Also, after successful compilation, I've found out that my `./build/CMakeVars.txt` has the `FREETYPE_FOUND` variable set to `TRUE`, but the `freetype_FOUND` is set to `0` (could help somehow ?).

I believe this is a bug because compilation failure should not be default behaviour (when the environment is setup correctly).

### Steps to reproduce

I've provided those in the paragraph above. TDLR; download latest OpenCV 4.9.0 from the website and run `mkdir build && cd build && cmake .. && make -j12` from the root. Here's a video of me encountering this issue:

https://github.com/opencv/opencv/assets/71404604/bcdcb2ac-06a2-4798-ac74-358790834a8d




### Issue submission checklist

- [X] I report the issue, it's not a question
- [X] I checked the problem with documentation, FAQ, open issues, forum.opencv.org, Stack Overflow, etc and have not found any solution
- [X] I updated to the latest OpenCV version and the issue is still there
- [X] There is reproducer code and related data files (videos, images, onnx, etc)