Issue 1:
System information (version)

OpenCV => 4.1.1

Operating System / Platform => Windows 64 Bit

Compiler => MinGW-w64 10.1.0

Detailed description

Building fails

...
[482/1644] Building CXX object modules/core/CMakeFiles/opencv_core_pch_dephelp.dir/opencv_core_pch_dephelp.cxx.obj
FAILED: modules/core/CMakeFiles/opencv_core_pch_dephelp.dir/opencv_core_pch_dephelp.cxx.obj
C:\msys64\mingw64\bin\c++.exe -D_USE_MATH_DEFINES -D__OPENCV_BUILD=1 -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -IC:/dev/repos/opencv/modules/core/src -IC:/dev/repos/opencv/modules/core/include -Imodules/core -IC:/dev/repos/opencv/3rdparty/zlib -I3rdparty/zlib -IC:/dev/repos/opencv/3rdparty/include/opencl/1.2 -isystem . -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -Wno-long-long -fomit-frame-pointer -ffunction-sections -fdata-sections -msse -msse2 -msse3 -fvisibility=hidden -fvisibility-inlines-hidden -g -O0 -DDEBUG -D_DEBUG -std=c++11 -MD -MT modules/core/CMakeFiles/opencv_core_pch_dephelp.dir/opencv_core_pch_dephelp.cxx.obj -MF modules\core\CMakeFiles\opencv_core_pch_dephelp.dir\opencv_core_pch_dephelp.cxx.obj.d -o modules/core/CMakeFiles/opencv_core_pch_dephelp.dir/opencv_core_pch_dephelp.cxx.obj -c modules/core/opencv_core_pch_dephelp.cxx
cc1plus.exe: warning: command-line option '-Wmissing-prototypes' is valid for C/ObjC but not for C++
cc1plus.exe: warning: command-line option '-Wstrict-prototypes' is valid for C/ObjC but not for C++
In file included from C:/dev/repos/opencv/modules/core/src/precomp.hpp:55,
from modules/core/opencv_core_pch_dephelp.cxx:1:
C:/dev/repos/opencv/modules/core/include/opencv2/core/private.hpp:66:12: fatal error: Eigen/Core: No such file or directory
66 | # include <Eigen/Core>
| ^~~~~~~~~~~~
compilation terminated.
[483/1644] Building CXX object modules/CMakeFiles/ade.dir/__/3rdparty/ade/ade-0.1.1d/sources/ade/source/memory_descriptor_view.cpp.obj
cc1plus.exe: warning: command-line option '-Wmissing-prototypes' is valid for C/ObjC but not for C++
cc1plus.exe: warning: command-line option '-Wstrict-prototypes' is valid for C/ObjC but not for C++
[484/1644] Building CXX object modules/core/CMakeFiles/opencv_test_core_pch_dephelp.dir/opencv_test_core_pch_dephelp.cxx.obj
FAILED: modules/core/CMakeFiles/opencv_test_core_pch_dephelp.dir/opencv_test_core_pch_dephelp.cxx.obj
C:\msys64\mingw64\bin\c++.exe -D_USE_MATH_DEFINES -D__OPENCV_BUILD=1 -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -IC:/dev/repos/opencv/modules/ts/include -IC:/dev/repos/opencv/modules/core/include -IC:/dev/repos/opencv/modules/imgcodecs/include -IC:/dev/repos/opencv/modules/videoio/include -IC:/dev/repos/opencv/modules/imgproc/include -IC:/dev/repos/opencv/modules/highgui/include -Imodules/core/test -isystem . -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -Wno-long-long -fomit-frame-pointer -ffunction-sections -fdata-sections -msse -msse2 -msse3 -fvisibility=hidden -fvisibility-inlines-hidden -g -O0 -DDEBUG -D_DEBUG -std=c++11 -MD -MT modules/core/CMakeFiles/opencv_test_core_pch_dephelp.dir/opencv_test_core_pch_dephelp.cxx.obj -MF modules\core\CMakeFiles\opencv_test_core_pch_dephelp.dir\opencv_test_core_pch_dephelp.cxx.obj.d -o modules/core/CMakeFiles/opencv_test_core_pch_dephelp.dir/opencv_test_core_pch_dephelp.cxx.obj -c modules/core/opencv_test_core_pch_dephelp.cxx
cc1plus.exe: warning: command-line option '-Wmissing-prototypes' is valid for C/ObjC but not for C++
cc1plus.exe: warning: command-line option '-Wstrict-prototypes' is valid for C/ObjC but not for C++
In file included from C:/dev/repos/opencv/modules/core/test/test_precomp.hpp:12,
from modules/core/opencv_test_core_pch_dephelp.cxx:1:
C:/dev/repos/opencv/modules/core/include/opencv2/core/private.hpp:66:12: fatal error: Eigen/Core: No such file or directory
66 | # include <Eigen/Core>
| ^~~~~~~~~~~~
compilation terminated.

full log

Steps to reproduce

Generate and build project with cmake (MSYS2 MINGW64 shell launcher)

cmake -G Ninja $opencv_source
cmake --build ..

$opencv_source - path to opencv source

Issue 2:
System information (version)

OpenCV => 3.4.7 / 4.1.1

Operating System / Platform => Ubuntu 18.04 x86_64

Compiler => gcc 8.3 / gcc 9.1

Detailed description

OpenCV fails to build when Eigen is imported as a CMake target and precompiled header are ON.

When Eigen is imported as a CMake target (here https://github.com/opencv/opencv/blob/3.4.7/cmake/OpenCVFindLibsPerf.cmake#L47-L50) I got the following error when compiling :

[321/1436] Building CXX object modules/core/CMakeFiles/opencv_core_pch_dephelp.dir/opencv_core_pch_dephelp.cxx.o
FAILED: modules/core/CMakeFiles/opencv_core_pch_dephelp.dir/opencv_core_pch_dephelp.cxx.o
/usr/bin/c++ -DOPENCV_WITH_ITT=1 -D_USE_MATH_DEFINES -D__OPENCV_BUILD=1 -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I. -I../modules/core/src -I../modules/core/include -Imodules/core -I../3rdparty/include/opencl/1.2 -I../3rdparty/ittnotify/include -fsigned-char -ffast-math -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections -msse -msse2 -msse3 -fvisibility=hidden -fvisibility-inlines-hidden -O3 -DNDEBUG -DNDEBUG -fPIC -std=c++11 -MD -MT modules/core/CMakeFiles/opencv_core_pch_dephelp.dir/opencv_core_pch_dephelp.cxx.o -MF modules/core/CMakeFiles/opencv_core_pch_dephelp.dir/opencv_core_pch_dephelp.cxx.o.d -o modules/core/CMakeFiles/opencv_core_pch_dephelp.dir/opencv_core_pch_dephelp.cxx.o -c modules/core/opencv_core_pch_dephelp.cxx
In file included from /tmp/Genie/External/source/opencv/modules/core/src/precomp.hpp:55,
from modules/core/opencv_core_pch_dephelp.cxx:1:
../modules/core/include/opencv2/core/private.hpp:66:12: fatal error: Eigen/Core: No such file or directory
# include <Eigen/Core>
^~~~~~~~~~~~

Disabling precompiled header with ENABLE_PRECOMPILED_HEADER=OFF when configuring is workaround.