From c63d79c5b16fcbbec46f1b8bb871dab2274e2b01 Mon Sep 17 00:00:00 2001 From: Yuantao Feng Date: Mon, 16 Jan 2023 17:44:13 +0800 Subject: [PATCH] Merge pull request #23095 from fengyuentau:fix_omp_macos * fix openmp include and link issue on macos * turn off have_openmp if OpenMP_CXX_INCLUDE_DIRS is empty * test commit * use condition HAVE_OPENMP and OpenMP_CXX_LIBRARIES for linking * remove trailing whitespace * remove notes * update conditions * use OpenMP_CXX_LIBRARIES for linking --- cmake/OpenCVFindFrameworks.cmake | 3 +++ modules/core/CMakeLists.txt | 4 ++++ modules/video/CMakeLists.txt | 4 ++++ 3 files changed, 11 insertions(+) diff --git a/cmake/OpenCVFindFrameworks.cmake b/cmake/OpenCVFindFrameworks.cmake index 19f6d66340..741267d269 100644 --- a/cmake/OpenCVFindFrameworks.cmake +++ b/cmake/OpenCVFindFrameworks.cmake @@ -32,6 +32,9 @@ if(WITH_OPENMP) if(OPENMP_FOUND) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}") + if(DEFINED OpenMP_CXX_INCLUDE_DIRS AND OpenMP_CXX_INCLUDE_DIRS) + ocv_include_directories(${OpenMP_CXX_INCLUDE_DIRS}) + endif() endif() set(HAVE_OPENMP "${OPENMP_FOUND}") endif() diff --git a/modules/core/CMakeLists.txt b/modules/core/CMakeLists.txt index eab909843b..fe747540e8 100644 --- a/modules/core/CMakeLists.txt +++ b/modules/core/CMakeLists.txt @@ -168,6 +168,10 @@ if(HAVE_HPX) ocv_target_link_libraries(${the_module} LINK_PRIVATE "${HPX_LIBRARIES}") endif() +if(HAVE_OPENMP AND DEFINED OpenMP_CXX_LIBRARIES AND OpenMP_CXX_LIBRARIES) + ocv_target_link_libraries(${the_module} LINK_PRIVATE "${OpenMP_CXX_LIBRARIES}") +endif() + ocv_add_accuracy_tests() ocv_add_perf_tests() diff --git a/modules/video/CMakeLists.txt b/modules/video/CMakeLists.txt index 8499de9169..a302e5a5d1 100644 --- a/modules/video/CMakeLists.txt +++ b/modules/video/CMakeLists.txt @@ -10,3 +10,7 @@ ocv_define_module(video python js ) + +if(HAVE_OPENMP AND DEFINED OpenMP_CXX_LIBRARIES AND OpenMP_CXX_LIBRARIES) + ocv_target_link_libraries(${the_module} LINK_PRIVATE "${OpenMP_CXX_LIBRARIES}") +endif()