Move the CUDA searching code in OpenCVConfig.cmake.in out of the foreach loop
authorRoman Donchenko <roman.donchenko@itseez.com>
Mon, 30 Mar 2015 12:04:27 +0000 (15:04 +0300)
committerRoman Donchenko <roman.donchenko@itseez.com>
Mon, 30 Mar 2015 12:04:27 +0000 (15:04 +0300)
There's no reason to do it twice.

cmake/templates/OpenCVConfig.cmake.in

index fcf3a23..660e26d 100644 (file)
@@ -234,54 +234,55 @@ endif()
 foreach(__opttype OPT DBG)
   SET(OpenCV_LIBS_${__opttype} "${OpenCV_LIBS}")
   SET(OpenCV_EXTRA_LIBS_${__opttype} "")
+endforeach()
 
-  # CUDA
-  if(OpenCV_CUDA_VERSION)
-    if(NOT CUDA_FOUND)
-      find_host_package(CUDA ${OpenCV_CUDA_VERSION} EXACT REQUIRED)
-    else()
-      if(NOT CUDA_VERSION_STRING VERSION_EQUAL OpenCV_CUDA_VERSION)
-        message(FATAL_ERROR "OpenCV static library was compiled with CUDA ${OpenCV_CUDA_VERSION} support. Please, use the same version or rebuild OpenCV with CUDA ${CUDA_VERSION_STRING}")
-      endif()
+# CUDA
+if(OpenCV_CUDA_VERSION)
+  if(NOT CUDA_FOUND)
+    find_host_package(CUDA ${OpenCV_CUDA_VERSION} EXACT REQUIRED)
+  else()
+    if(NOT CUDA_VERSION_STRING VERSION_EQUAL OpenCV_CUDA_VERSION)
+      message(FATAL_ERROR "OpenCV static library was compiled with CUDA ${OpenCV_CUDA_VERSION} support. Please, use the same version or rebuild OpenCV with CUDA ${CUDA_VERSION_STRING}")
     endif()
+  endif()
 
-    set(OpenCV_CUDA_LIBS_ABSPATH ${CUDA_LIBRARIES})
+  set(OpenCV_CUDA_LIBS_ABSPATH ${CUDA_LIBRARIES})
 
-    if(${CUDA_VERSION} VERSION_LESS "5.5")
-      list(APPEND OpenCV_CUDA_LIBS_ABSPATH ${CUDA_npp_LIBRARY})
-    else()
-      find_cuda_helper_libs(nppc)
-      find_cuda_helper_libs(nppi)
-      find_cuda_helper_libs(npps)
-      list(APPEND OpenCV_CUDA_LIBS_ABSPATH ${CUDA_nppc_LIBRARY} ${CUDA_nppi_LIBRARY} ${CUDA_npps_LIBRARY})
-    endif()
+  if(${CUDA_VERSION} VERSION_LESS "5.5")
+    list(APPEND OpenCV_CUDA_LIBS_ABSPATH ${CUDA_npp_LIBRARY})
+  else()
+    find_cuda_helper_libs(nppc)
+    find_cuda_helper_libs(nppi)
+    find_cuda_helper_libs(npps)
+    list(APPEND OpenCV_CUDA_LIBS_ABSPATH ${CUDA_nppc_LIBRARY} ${CUDA_nppi_LIBRARY} ${CUDA_npps_LIBRARY})
+  endif()
 
-    if(OpenCV_USE_CUBLAS)
-      list(APPEND OpenCV_CUDA_LIBS_ABSPATH ${CUDA_CUBLAS_LIBRARIES})
-    endif()
+  if(OpenCV_USE_CUBLAS)
+    list(APPEND OpenCV_CUDA_LIBS_ABSPATH ${CUDA_CUBLAS_LIBRARIES})
+  endif()
 
-    if(OpenCV_USE_CUFFT)
-      list(APPEND OpenCV_CUDA_LIBS_ABSPATH ${CUDA_CUFFT_LIBRARIES})
-    endif()
+  if(OpenCV_USE_CUFFT)
+    list(APPEND OpenCV_CUDA_LIBS_ABSPATH ${CUDA_CUFFT_LIBRARIES})
+  endif()
 
-    if(OpenCV_USE_NVCUVID)
-      list(APPEND OpenCV_CUDA_LIBS_ABSPATH ${CUDA_nvcuvid_LIBRARIES})
-    endif()
+  if(OpenCV_USE_NVCUVID)
+    list(APPEND OpenCV_CUDA_LIBS_ABSPATH ${CUDA_nvcuvid_LIBRARIES})
+  endif()
 
-    if(WIN32)
-      list(APPEND OpenCV_CUDA_LIBS_ABSPATH ${CUDA_nvcuvenc_LIBRARIES})
-    endif()
+  if(WIN32)
+    list(APPEND OpenCV_CUDA_LIBS_ABSPATH ${CUDA_nvcuvenc_LIBRARIES})
+  endif()
 
-    set(OpenCV_CUDA_LIBS_RELPATH "")
-    foreach(l ${OpenCV_CUDA_LIBS_ABSPATH})
-      get_filename_component(_tmp ${l} PATH)
-      list(APPEND OpenCV_CUDA_LIBS_RELPATH ${_tmp})
-    endforeach()
+  set(OpenCV_CUDA_LIBS_RELPATH "")
+  foreach(l ${OpenCV_CUDA_LIBS_ABSPATH})
+    get_filename_component(_tmp ${l} PATH)
+    list(APPEND OpenCV_CUDA_LIBS_RELPATH ${_tmp})
+  endforeach()
+
+  list(REMOVE_DUPLICATES OpenCV_CUDA_LIBS_RELPATH)
+  link_directories(${OpenCV_CUDA_LIBS_RELPATH})
+endif()
 
-    list(REMOVE_DUPLICATES OpenCV_CUDA_LIBS_RELPATH)
-    link_directories(${OpenCV_CUDA_LIBS_RELPATH})
-  endif()
-endforeach()
 
 # ==============================================================
 #  Android camera helper macro