From 3425c90b66584a56b67a5d2cb11ef23e7a41a262 Mon Sep 17 00:00:00 2001 From: Alexander Smorkalov Date: Tue, 13 Jan 2015 14:39:56 +0300 Subject: [PATCH] GPU samples with NVIDIA specific API excluded from build if CUDA disabled. --- samples/gpu/CMakeLists.txt | 33 +++++++++++++++++--- samples/gpu/cascadeclassifier_nvidia_api.cpp | 21 ++----------- samples/gpu/opticalflow_nvidia_api.cpp | 14 --------- 3 files changed, 31 insertions(+), 37 deletions(-) diff --git a/samples/gpu/CMakeLists.txt b/samples/gpu/CMakeLists.txt index 56aaf0c587..030283c8ba 100644 --- a/samples/gpu/CMakeLists.txt +++ b/samples/gpu/CMakeLists.txt @@ -69,11 +69,27 @@ if(BUILD_EXAMPLES AND OCV_DEPENDENCIES_FOUND) endif() ENDMACRO() + # remove all matching elements from the list + MACRO(list_filterout lst regex) + foreach(item ${${lst}}) + if(item MATCHES "${regex}") + list(REMOVE_ITEM ${lst} "${item}") + endif() + endforeach() + ENDMACRO() + file(GLOB all_samples RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp) - if(NOT WITH_OPENGL) + if(NOT HAVE_OPENGL) list(REMOVE_ITEM all_samples "opengl.cpp") - endif(NOT WITH_OPENGL) + endif() + + if(NOT HAVE_CUDA) + list(REMOVE_ITEM all_samples "opticalflow_nvidia_api.cpp") + list(REMOVE_ITEM all_samples "cascadeclassifier_nvidia_api.cpp") + list(REMOVE_ITEM all_samples "driver_api_multi.cpp") + list(REMOVE_ITEM all_samples "driver_api_stereo_multi.cpp") + endif() foreach(sample_filename ${all_samples}) get_filename_component(sample ${sample_filename} NAME_WE) @@ -86,9 +102,16 @@ endif() if (OCV_DEPENDENCIES_FOUND AND INSTALL_C_EXAMPLES AND NOT WIN32) file(GLOB install_list *.c *.cpp *.jpg *.png *.data makefile.* build_all.sh *.dsp *.cmd ) - if(NOT WITH_OPENGL) - list(REMOVE_ITEM all_samples "opengl.cpp") - endif(NOT WITH_OPENGL) + message(" install_list: ${install_list}") + if(NOT HAVE_OPENGL) + list_filterout(install_list ".*opengl.cpp") + endif() + if(NOT HAVE_CUDA) + list_filterout(install_list ".*opticalflow_nvidia_api.cpp") + list_filterout(install_list ".*cascadeclassifier_nvidia_api.cpp") + list_filterout(install_list ".*driver_api_multi.cpp") + list_filterout(install_list ".*driver_api_stereo_multi.cpp") + endif() install(FILES ${install_list} DESTINATION ${OPENCV_SAMPLES_SRC_INSTALL_PATH}/gpu PERMISSIONS OWNER_READ GROUP_READ WORLD_READ COMPONENT samples) diff --git a/samples/gpu/cascadeclassifier_nvidia_api.cpp b/samples/gpu/cascadeclassifier_nvidia_api.cpp index 98195b35c2..87258b9a05 100644 --- a/samples/gpu/cascadeclassifier_nvidia_api.cpp +++ b/samples/gpu/cascadeclassifier_nvidia_api.cpp @@ -2,39 +2,24 @@ #pragma warning( disable : 4201 4408 4127 4100) #endif -#include "cvconfig.h" #include #include #include #include "opencv2/gpu/gpu.hpp" #include "opencv2/highgui/highgui.hpp" - -#ifdef HAVE_CUDA #include "NCVHaarObjectDetection.hpp" -#endif using namespace std; using namespace cv; - -#if !defined(HAVE_CUDA) || defined(__arm__) - -int main( int, const char** ) -{ -#if !defined(HAVE_CUDA) - std::cout << "CUDA support is required (CMake key 'WITH_CUDA' must be true)." << std::endl; -#endif - #if defined(__arm__) +int main() +{ std::cout << "Unsupported for ARM CUDA library." << std::endl; -#endif - return 0; } - #else - const Size2i preferredVideoFrameSize(640, 480); const string wndTitle = "NVIDIA Computer Vision :: Haar Classifiers Cascade"; @@ -386,4 +371,4 @@ int main(int argc, const char** argv) return 0; } -#endif //!defined(HAVE_CUDA) +#endif diff --git a/samples/gpu/opticalflow_nvidia_api.cpp b/samples/gpu/opticalflow_nvidia_api.cpp index 31ee569788..d0b071f64c 100644 --- a/samples/gpu/opticalflow_nvidia_api.cpp +++ b/samples/gpu/opticalflow_nvidia_api.cpp @@ -9,26 +9,14 @@ #include #include -#include "cvconfig.h" #include #include #include "opencv2/gpu/gpu.hpp" #include "opencv2/highgui/highgui.hpp" -#ifdef HAVE_CUDA #include "NPP_staging/NPP_staging.hpp" #include "NCVBroxOpticalFlow.hpp" -#endif - -#if !defined(HAVE_CUDA) -int main( int, const char** ) -{ - std::cout << "Please compile the library with CUDA support" << std::endl; - return -1; -} -#else -//using std::tr1::shared_ptr; using cv::Ptr; #define PARAM_LEFT "--left" @@ -649,5 +637,3 @@ int main(int argc, char **argv) return 0; } - -#endif