From 6cf09108425a512b64b5c1fea8444a7e7d3be04a Mon Sep 17 00:00:00 2001 From: Biswapriyo Nath Date: Mon, 3 Oct 2022 11:07:36 +0530 Subject: [PATCH] Merge pull request #22462 from Biswa96:fix-directx-check * cmake: Fix DirectX detection in mingw The pragma comment directive is valid for MSVC only. So, the DirectX detection fails in mingw. The failure is fixed by adding the required linking library (here d3d11) in the try_compile() function in OpenCVDetectDirectX.cmake file. Also add a message if the first DirectX check fails. * gapi: Fix compilation with mingw These changes remove MSVC specific pragma directive. The compilation fails at linking time due to absence of proper linking library. The required libraries are added in corresponding CMakeLists.txt file. * samples: Fix compilation with mingw These changes remove MSVC specific pragma directive. The compilation fails at linking time due to absence of proper linking library. The required libraries are added in corresponding CMakeLists.txt file. --- cmake/OpenCVDetectDirectX.cmake | 3 +++ cmake/checks/directx.cpp | 1 - modules/gapi/CMakeLists.txt | 9 +++++++++ modules/gapi/samples/onevpl_infer_single_roi.cpp | 2 -- .../onevpl/accelerators/accel_policy_dx11.cpp | 1 - .../onevpl/accelerators/dx11_alloc_resource.hpp | 1 - .../streaming/onevpl/cfg_param_device_selector.cpp | 2 -- .../onevpl/demux/async_mfp_demux_data_provider.cpp | 8 -------- samples/directx/CMakeLists.txt | 12 ++++++++++++ samples/directx/d3d10_interop.cpp | 1 - samples/directx/d3d11_interop.cpp | 1 - samples/directx/d3d9_interop.cpp | 1 - samples/directx/d3d9ex_interop.cpp | 1 - samples/opengl/opengl_interop.cpp | 6 ------ 14 files changed, 24 insertions(+), 25 deletions(-) diff --git a/cmake/OpenCVDetectDirectX.cmake b/cmake/OpenCVDetectDirectX.cmake index fbe4a71185..fa1bac235e 100644 --- a/cmake/OpenCVDetectDirectX.cmake +++ b/cmake/OpenCVDetectDirectX.cmake @@ -2,15 +2,18 @@ if(WIN32) try_compile(__VALID_DIRECTX "${OpenCV_BINARY_DIR}" "${OpenCV_SOURCE_DIR}/cmake/checks/directx.cpp" + LINK_LIBRARIES d3d11 OUTPUT_VARIABLE TRY_OUT ) if(NOT __VALID_DIRECTX) + message(STATUS "No support for DirectX (install Windows 8 SDK)") return() endif() try_compile(__VALID_DIRECTX_NV12 "${OpenCV_BINARY_DIR}" "${OpenCV_SOURCE_DIR}/cmake/checks/directx.cpp" COMPILE_DEFINITIONS "-DCHECK_NV12" + LINK_LIBRARIES d3d11 OUTPUT_VARIABLE TRY_OUT ) if(__VALID_DIRECTX_NV12) diff --git a/cmake/checks/directx.cpp b/cmake/checks/directx.cpp index c617ac341a..be687c24f8 100644 --- a/cmake/checks/directx.cpp +++ b/cmake/checks/directx.cpp @@ -1,7 +1,6 @@ #include #include -#pragma comment (lib, "d3d11.lib") HINSTANCE g_hInst = NULL; D3D_DRIVER_TYPE g_driverType = D3D_DRIVER_TYPE_NULL; diff --git a/modules/gapi/CMakeLists.txt b/modules/gapi/CMakeLists.txt index edf4e588e0..711fdd1933 100644 --- a/modules/gapi/CMakeLists.txt +++ b/modules/gapi/CMakeLists.txt @@ -317,6 +317,12 @@ if(HAVE_GAPI_ONEVPL) ocv_target_compile_definitions(${the_module} PRIVATE -DHAVE_ONEVPL) ocv_target_link_libraries(${the_module} PRIVATE ${VPL_IMPORTED_TARGETS}) + if(HAVE_DIRECTX AND HAVE_D3D11) + ocv_target_link_libraries(${the_module} PRIVATE d3d11 dxgi) + endif() + if(WIN32) + ocv_target_link_libraries(${the_module} PRIVATE mf mfuuid mfplat shlwapi mfreadwrite) + endif() if(HAVE_D3D11 AND HAVE_OPENCL) ocv_target_include_directories(${the_module} SYSTEM PRIVATE ${OPENCL_INCLUDE_DIRS}) endif() @@ -369,6 +375,9 @@ if(TARGET example_gapi_onevpl_infer_single_roi) if(TARGET ocv.3rdparty.openvino AND OPENCV_GAPI_WITH_OPENVINO) ocv_target_link_libraries(example_gapi_onevpl_infer_single_roi PRIVATE ocv.3rdparty.openvino) endif() + if(HAVE_DIRECTX AND HAVE_D3D11) + ocv_target_link_libraries(example_gapi_onevpl_infer_single_roi PRIVATE d3d11 dxgi) + endif() if(HAVE_D3D11 AND HAVE_OPENCL) ocv_target_include_directories(example_gapi_onevpl_infer_single_roi SYSTEM PRIVATE ${OPENCL_INCLUDE_DIRS}) endif() diff --git a/modules/gapi/samples/onevpl_infer_single_roi.cpp b/modules/gapi/samples/onevpl_infer_single_roi.cpp index 811008b168..de1d233ae5 100644 --- a/modules/gapi/samples/onevpl_infer_single_roi.cpp +++ b/modules/gapi/samples/onevpl_infer_single_roi.cpp @@ -20,13 +20,11 @@ #ifdef HAVE_DIRECTX #ifdef HAVE_D3D11 -#pragma comment(lib,"d3d11.lib") // get rid of generate macro max/min/etc from DX side #define D3D11_NO_HELPERS #define NOMINMAX #include -#pragma comment(lib, "dxgi") #undef NOMINMAX #undef D3D11_NO_HELPERS #endif // HAVE_D3D11 diff --git a/modules/gapi/src/streaming/onevpl/accelerators/accel_policy_dx11.cpp b/modules/gapi/src/streaming/onevpl/accelerators/accel_policy_dx11.cpp index dba05f0169..456e01d676 100644 --- a/modules/gapi/src/streaming/onevpl/accelerators/accel_policy_dx11.cpp +++ b/modules/gapi/src/streaming/onevpl/accelerators/accel_policy_dx11.cpp @@ -14,7 +14,6 @@ #include "logger.hpp" #if defined(HAVE_DIRECTX) && defined(HAVE_D3D11) -#pragma comment(lib,"d3d11.lib") #define D3D11_NO_HELPERS #include diff --git a/modules/gapi/src/streaming/onevpl/accelerators/dx11_alloc_resource.hpp b/modules/gapi/src/streaming/onevpl/accelerators/dx11_alloc_resource.hpp index c68a08a3f8..082e3b5291 100644 --- a/modules/gapi/src/streaming/onevpl/accelerators/dx11_alloc_resource.hpp +++ b/modules/gapi/src/streaming/onevpl/accelerators/dx11_alloc_resource.hpp @@ -13,7 +13,6 @@ #ifdef HAVE_DIRECTX #ifdef HAVE_D3D11 -#pragma comment(lib,"d3d11.lib") #define D3D11_NO_HELPERS #define NOMINMAX diff --git a/modules/gapi/src/streaming/onevpl/cfg_param_device_selector.cpp b/modules/gapi/src/streaming/onevpl/cfg_param_device_selector.cpp index 62623b94f4..d43b9068f3 100644 --- a/modules/gapi/src/streaming/onevpl/cfg_param_device_selector.cpp +++ b/modules/gapi/src/streaming/onevpl/cfg_param_device_selector.cpp @@ -17,14 +17,12 @@ #ifdef HAVE_DIRECTX #ifdef HAVE_D3D11 -#pragma comment(lib,"d3d11.lib") // get rid of generate macro max/min/etc from DX side #define D3D11_NO_HELPERS #define NOMINMAX #include #include -#pragma comment(lib, "dxgi") #undef D3D11_NO_HELPERS #undef NOMINMAX #endif // HAVE_D3D11 diff --git a/modules/gapi/src/streaming/onevpl/demux/async_mfp_demux_data_provider.cpp b/modules/gapi/src/streaming/onevpl/demux/async_mfp_demux_data_provider.cpp index 5d139af824..108f8258ab 100644 --- a/modules/gapi/src/streaming/onevpl/demux/async_mfp_demux_data_provider.cpp +++ b/modules/gapi/src/streaming/onevpl/demux/async_mfp_demux_data_provider.cpp @@ -5,14 +5,6 @@ // Copyright (C) 2021 Intel Corporation #ifdef HAVE_ONEVPL #include -#ifdef _WIN32 - -#pragma comment(lib, "Mf.lib") -#pragma comment(lib, "Mfuuid.lib") -#pragma comment(lib, "Mfplat.lib") -#pragma comment(lib, "shlwapi.lib") -#pragma comment(lib, "mfreadwrite.lib") -#endif // _WIN32 #include #include "streaming/onevpl/demux/async_mfp_demux_data_provider.hpp" diff --git a/samples/directx/CMakeLists.txt b/samples/directx/CMakeLists.txt index 3041e27381..c74c7d4b31 100644 --- a/samples/directx/CMakeLists.txt +++ b/samples/directx/CMakeLists.txt @@ -19,4 +19,16 @@ foreach(sample_filename ${all_samples}) ocv_define_sample(tgt ${sample_filename} directx) ocv_target_link_libraries(${tgt} PRIVATE ${OPENCV_LINKER_LIBS} ${OPENCV_DIRECTX_SAMPLES_REQUIRED_DEPS}) ocv_target_link_libraries(${tgt} PRIVATE "gdi32") + if(sample_filename STREQUAL "d3d9_interop.cpp") + ocv_target_link_libraries(${tgt} PRIVATE d3d9) + endif() + if(sample_filename STREQUAL "d3d9ex_interop.cpp") + ocv_target_link_libraries(${tgt} PRIVATE d3d9) + endif() + if(sample_filename STREQUAL "d3d10_interop.cpp") + ocv_target_link_libraries(${tgt} PRIVATE d3d10) + endif() + if(sample_filename STREQUAL "d3d11_interop.cpp") + ocv_target_link_libraries(${tgt} PRIVATE d3d11) + endif() endforeach() diff --git a/samples/directx/d3d10_interop.cpp b/samples/directx/d3d10_interop.cpp index e8be8fac50..442a3f0c53 100644 --- a/samples/directx/d3d10_interop.cpp +++ b/samples/directx/d3d10_interop.cpp @@ -17,7 +17,6 @@ #include "d3dsample.hpp" -#pragma comment (lib, "d3d10.lib") class D3D10WinApp : public D3DSample { diff --git a/samples/directx/d3d11_interop.cpp b/samples/directx/d3d11_interop.cpp index df40dd3e89..6c55a0c48b 100644 --- a/samples/directx/d3d11_interop.cpp +++ b/samples/directx/d3d11_interop.cpp @@ -17,7 +17,6 @@ #include "d3dsample.hpp" -#pragma comment (lib, "d3d11.lib") class D3D11WinApp : public D3DSample { diff --git a/samples/directx/d3d9_interop.cpp b/samples/directx/d3d9_interop.cpp index c46cf8e9e8..8c308721e0 100644 --- a/samples/directx/d3d9_interop.cpp +++ b/samples/directx/d3d9_interop.cpp @@ -17,7 +17,6 @@ #include "d3dsample.hpp" -#pragma comment (lib, "d3d9.lib") class D3D9WinApp : public D3DSample diff --git a/samples/directx/d3d9ex_interop.cpp b/samples/directx/d3d9ex_interop.cpp index 68b864f0eb..39dda84b66 100644 --- a/samples/directx/d3d9ex_interop.cpp +++ b/samples/directx/d3d9ex_interop.cpp @@ -17,7 +17,6 @@ #include "d3dsample.hpp" -#pragma comment (lib, "d3d9.lib") class D3D9ExWinApp : public D3DSample diff --git a/samples/opengl/opengl_interop.cpp b/samples/opengl/opengl_interop.cpp index 7fbf4d6084..8d3e0f8d47 100644 --- a/samples/opengl/opengl_interop.cpp +++ b/samples/opengl/opengl_interop.cpp @@ -27,12 +27,6 @@ #include "winapp.hpp" -#if defined(_WIN32) -# pragma comment(lib, "opengl32.lib") -# pragma comment(lib, "glu32.lib") -#endif - - class GLWinApp : public WinApp { public: