From f82eb0f79c647d5b64c32e6e4837399705037dc1 Mon Sep 17 00:00:00 2001 From: Roman Donchenko Date: Tue, 22 Oct 2013 18:47:37 +0400 Subject: [PATCH] Add better OpenMP detection and make an option to enable it. Bug report and inspiration: http://code.opencv.org/issues/3328 --- CMakeLists.txt | 1 + cmake/OpenCVFindLibsPerf.cmake | 14 +++++++------- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f0b0e12927..704c51be8c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -151,6 +151,7 @@ OCV_OPTION(WITH_QT "Build with Qt Backend support" OFF OCV_OPTION(WITH_WIN32UI "Build with Win32 UI Backend support" ON IF WIN32 ) OCV_OPTION(WITH_QUICKTIME "Use QuickTime for Video I/O insted of QTKit" OFF IF APPLE ) OCV_OPTION(WITH_TBB "Include Intel TBB support" OFF IF (NOT IOS) ) +OCV_OPTION(WITH_OPENMP "Include OpenMP support" OFF) OCV_OPTION(WITH_CSTRIPES "Include C= support" OFF IF WIN32 ) OCV_OPTION(WITH_TIFF "Include TIFF support" ON IF (NOT IOS) ) OCV_OPTION(WITH_UNICAP "Include Unicap support (GPL)" OFF IF (UNIX AND NOT APPLE AND NOT ANDROID) ) diff --git a/cmake/OpenCVFindLibsPerf.cmake b/cmake/OpenCVFindLibsPerf.cmake index 72b4ba6f7f..33ea36f482 100644 --- a/cmake/OpenCVFindLibsPerf.cmake +++ b/cmake/OpenCVFindLibsPerf.cmake @@ -47,13 +47,13 @@ else() endif() # --- OpenMP --- -if(NOT HAVE_TBB AND NOT HAVE_CSTRIPES) - set(_fname "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/omptest.cpp") - file(WRITE "${_fname}" "#ifndef _OPENMP\n#error\n#endif\nint main() { return 0; }\n") - try_compile(HAVE_OPENMP "${CMAKE_BINARY_DIR}" "${_fname}") - file(REMOVE "${_fname}") -else() - set(HAVE_OPENMP 0) +if(WITH_OPENMP AND NOT HAVE_TBB AND NOT HAVE_CSTRIPES) + find_package(OpenMP) + if(OPENMP_FOUND) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}") + endif() + set(HAVE_OPENMP "${OPENMP_FOUND}") endif() # --- GCD ---