From 8393d755f6449527807c728bf3cf817914ec78f8 Mon Sep 17 00:00:00 2001 From: Maksim Shabunin Date: Fri, 9 Feb 2018 13:21:17 +0300 Subject: [PATCH 1/5] Fixed OpenGL-specific compilation warning (unused function) --- modules/core/src/opengl.cpp | 73 ++++++++++++++++--------------------- 1 file changed, 31 insertions(+), 42 deletions(-) diff --git a/modules/core/src/opengl.cpp b/modules/core/src/opengl.cpp index e730261692..111a9737dc 100644 --- a/modules/core/src/opengl.cpp +++ b/modules/core/src/opengl.cpp @@ -56,53 +56,42 @@ using namespace cv::cuda; namespace { - #ifndef HAVE_OPENGL - inline void throw_no_ogl() { CV_Error(cv::Error::OpenGlNotSupported, "The library is compiled without OpenGL support"); } - #else - inline void throw_no_ogl() { CV_Error(cv::Error::OpenGlApiCallError, "OpenGL context doesn't exist"); } - - bool checkError(const char* file, const int line, const char* func = 0) +#ifndef HAVE_OPENGL +inline static void throw_no_ogl() { CV_Error(cv::Error::OpenGlNotSupported, "The library is compiled without OpenGL support"); } +#elif defined _DEBUG +inline static bool checkError(const char* file, const int line, const char* func = 0) +{ + GLenum err = gl::GetError(); + if (err != gl::NO_ERROR_) { - GLenum err = gl::GetError(); - - if (err != gl::NO_ERROR_) + const char* msg; + switch (err) { - const char* msg; - - switch (err) - { - case gl::INVALID_ENUM: - msg = "An unacceptable value is specified for an enumerated argument"; - break; - - case gl::INVALID_VALUE: - msg = "A numeric argument is out of range"; - break; - - case gl::INVALID_OPERATION: - msg = "The specified operation is not allowed in the current state"; - break; - - case gl::OUT_OF_MEMORY: - msg = "There is not enough memory left to execute the command"; - break; - - default: - msg = "Unknown error"; - }; - - cvError(CV_OpenGlApiCallError, func, msg, file, line); - - return false; - } - - return true; + case gl::INVALID_ENUM: + msg = "An unacceptable value is specified for an enumerated argument"; + break; + case gl::INVALID_VALUE: + msg = "A numeric argument is out of range"; + break; + case gl::INVALID_OPERATION: + msg = "The specified operation is not allowed in the current state"; + break; + case gl::OUT_OF_MEMORY: + msg = "There is not enough memory left to execute the command"; + break; + default: + msg = "Unknown error"; + }; + cvError(CV_OpenGlApiCallError, func, msg, file, line); + return false; } - #endif - - #define CV_CheckGlError() CV_DbgAssert( (checkError(__FILE__, __LINE__, CV_Func)) ) + return true; +} +#endif // HAVE_OPENGL } // namespace +#define CV_CheckGlError() CV_DbgAssert( (checkError(__FILE__, __LINE__, CV_Func)) ) + #ifdef HAVE_OPENGL namespace { From 633b0e56a52ebd88910a91ea84d1472c2d0f3cea Mon Sep 17 00:00:00 2001 From: Maksim Shabunin Date: Fri, 9 Feb 2018 13:24:18 +0300 Subject: [PATCH 2/5] Fixed compilation warnings in samples: - use per-module includes instead of "opencv.hpp" - unused function warnings - undefined macro warning --- samples/cpp/application_trace.cpp | 4 ++- samples/cpp/autofocus.cpp | 4 ++- samples/cpp/detect_blob.cpp | 5 ++- samples/cpp/detect_mser.cpp | 6 ++-- samples/cpp/matchmethod_orb_akaze_brisk.cpp | 5 ++- samples/cpp/train_svmsgd.cpp | 7 +++-- samples/cpp/travelsalesman.cpp | 5 ++- .../morph_lines_detection/Morphology_3.cpp | 5 ++- .../ImgTrans/imageSegmentation.cpp | 4 ++- .../camera_calibration/camera_calibration.cpp | 5 --- .../real_time_pose_estimation/src/CsvWriter.h | 2 +- .../src/ModelRegistration.h | 2 +- .../AKAZE_tracking/planar_tracking.cpp | 3 +- .../Homography/decompose_homography.cpp | 5 ++- .../homography_from_camera_displacement.cpp | 5 ++- .../panorama_stitching_rotating_camera.cpp | 5 ++- .../Homography/perspective_correction.cpp | 31 +++---------------- .../Homography/pose_from_homography.cpp | 5 ++- .../tutorial_code/snippets/core_various.cpp | 5 ++- .../snippets/imgcodecs_imwrite.cpp | 2 +- samples/cpp/tutorial_code/viz/histo3D.cpp | 6 +++- .../tutorial_code/xfeatures2D/LATCH_match.cpp | 4 ++- samples/cpp/videocapture_basic.cpp | 6 ++-- samples/cpp/videowriter_basic.cpp | 6 ++-- samples/opencl/opencl-opencv-interop.cpp | 2 +- 25 files changed, 79 insertions(+), 60 deletions(-) diff --git a/samples/cpp/application_trace.cpp b/samples/cpp/application_trace.cpp index ddddd512e8..fa77542dbd 100644 --- a/samples/cpp/application_trace.cpp +++ b/samples/cpp/application_trace.cpp @@ -1,7 +1,9 @@ /* OpenCV Application Tracing support demo. */ #include -#include +#include +#include +#include #include using namespace cv; diff --git a/samples/cpp/autofocus.cpp b/samples/cpp/autofocus.cpp index cef279d6f2..a71a2954f2 100644 --- a/samples/cpp/autofocus.cpp +++ b/samples/cpp/autofocus.cpp @@ -28,7 +28,9 @@ #include #include #include -#include +#include +#include +#include using namespace std; using namespace cv; diff --git a/samples/cpp/detect_blob.cpp b/samples/cpp/detect_blob.cpp index c240be40e2..3acb8fa1fb 100644 --- a/samples/cpp/detect_blob.cpp +++ b/samples/cpp/detect_blob.cpp @@ -1,4 +1,7 @@ -#include +#include +#include +#include +#include #include #include #include diff --git a/samples/cpp/detect_mser.cpp b/samples/cpp/detect_mser.cpp index daa370817e..a3c3856d2a 100644 --- a/samples/cpp/detect_mser.cpp +++ b/samples/cpp/detect_mser.cpp @@ -1,6 +1,8 @@ -#include +#include +#include +#include +#include #include "opencv2/core/opengl.hpp" -#include "opencv2/cvconfig.h" #include #include diff --git a/samples/cpp/matchmethod_orb_akaze_brisk.cpp b/samples/cpp/matchmethod_orb_akaze_brisk.cpp index 3a3320d8df..7d39bae443 100644 --- a/samples/cpp/matchmethod_orb_akaze_brisk.cpp +++ b/samples/cpp/matchmethod_orb_akaze_brisk.cpp @@ -1,4 +1,7 @@ -#include +#include +#include +#include +#include #include #include diff --git a/samples/cpp/train_svmsgd.cpp b/samples/cpp/train_svmsgd.cpp index 810f061467..854be5c28d 100644 --- a/samples/cpp/train_svmsgd.cpp +++ b/samples/cpp/train_svmsgd.cpp @@ -1,7 +1,8 @@ -#include +#include "opencv2/core.hpp" #include "opencv2/video/tracking.hpp" -#include "opencv2/imgproc/imgproc.hpp" -#include "opencv2/highgui/highgui.hpp" +#include "opencv2/imgproc.hpp" +#include "opencv2/highgui.hpp" +#include "opencv2/ml.hpp" using namespace cv; using namespace cv::ml; diff --git a/samples/cpp/travelsalesman.cpp b/samples/cpp/travelsalesman.cpp index 58dc46eb71..256ff55b43 100644 --- a/samples/cpp/travelsalesman.cpp +++ b/samples/cpp/travelsalesman.cpp @@ -1,4 +1,7 @@ -#include +#include +#include +#include +#include using namespace cv; diff --git a/samples/cpp/tutorial_code/ImgProc/morph_lines_detection/Morphology_3.cpp b/samples/cpp/tutorial_code/ImgProc/morph_lines_detection/Morphology_3.cpp index 31b3687fdf..9ab0099282 100644 --- a/samples/cpp/tutorial_code/ImgProc/morph_lines_detection/Morphology_3.cpp +++ b/samples/cpp/tutorial_code/ImgProc/morph_lines_detection/Morphology_3.cpp @@ -4,7 +4,10 @@ * @author OpenCV team */ -#include +#include +#include +#include +#include void show_wait_destroy(const char* winname, cv::Mat img); diff --git a/samples/cpp/tutorial_code/ImgTrans/imageSegmentation.cpp b/samples/cpp/tutorial_code/ImgTrans/imageSegmentation.cpp index bdaed0c1b1..87a5436a6d 100644 --- a/samples/cpp/tutorial_code/ImgTrans/imageSegmentation.cpp +++ b/samples/cpp/tutorial_code/ImgTrans/imageSegmentation.cpp @@ -4,7 +4,9 @@ * @author OpenCV Team */ -#include +#include +#include +#include #include using namespace std; diff --git a/samples/cpp/tutorial_code/calib3d/camera_calibration/camera_calibration.cpp b/samples/cpp/tutorial_code/calib3d/camera_calibration/camera_calibration.cpp index 35247817a2..87fb4604e2 100644 --- a/samples/cpp/tutorial_code/calib3d/camera_calibration/camera_calibration.cpp +++ b/samples/cpp/tutorial_code/calib3d/camera_calibration/camera_calibration.cpp @@ -245,11 +245,6 @@ static inline void read(const FileNode& node, Settings& x, const Settings& defau x.read(node); } -static inline void write(FileStorage& fs, const String&, const Settings& s ) -{ - s.write(fs); -} - enum { DETECTION = 0, CAPTURING = 1, CALIBRATED = 2 }; bool runCalibrationAndSave(Settings& s, Size imageSize, Mat& cameraMatrix, Mat& distCoeffs, diff --git a/samples/cpp/tutorial_code/calib3d/real_time_pose_estimation/src/CsvWriter.h b/samples/cpp/tutorial_code/calib3d/real_time_pose_estimation/src/CsvWriter.h index d8132f5b41..06314bbd89 100644 --- a/samples/cpp/tutorial_code/calib3d/real_time_pose_estimation/src/CsvWriter.h +++ b/samples/cpp/tutorial_code/calib3d/real_time_pose_estimation/src/CsvWriter.h @@ -3,7 +3,7 @@ #include #include -#include +#include #include "Utils.h" using namespace std; diff --git a/samples/cpp/tutorial_code/calib3d/real_time_pose_estimation/src/ModelRegistration.h b/samples/cpp/tutorial_code/calib3d/real_time_pose_estimation/src/ModelRegistration.h index f1e7aca469..7491ede45a 100644 --- a/samples/cpp/tutorial_code/calib3d/real_time_pose_estimation/src/ModelRegistration.h +++ b/samples/cpp/tutorial_code/calib3d/real_time_pose_estimation/src/ModelRegistration.h @@ -9,7 +9,7 @@ #define MODELREGISTRATION_H_ #include -#include +#include class ModelRegistration { diff --git a/samples/cpp/tutorial_code/features2D/AKAZE_tracking/planar_tracking.cpp b/samples/cpp/tutorial_code/features2D/AKAZE_tracking/planar_tracking.cpp index fdf1104336..83c4daad64 100755 --- a/samples/cpp/tutorial_code/features2D/AKAZE_tracking/planar_tracking.cpp +++ b/samples/cpp/tutorial_code/features2D/AKAZE_tracking/planar_tracking.cpp @@ -1,6 +1,7 @@ #include #include -#include +#include +#include #include //for imshow #include #include diff --git a/samples/cpp/tutorial_code/features2D/Homography/decompose_homography.cpp b/samples/cpp/tutorial_code/features2D/Homography/decompose_homography.cpp index 805f8ce0e2..3673c3f632 100644 --- a/samples/cpp/tutorial_code/features2D/Homography/decompose_homography.cpp +++ b/samples/cpp/tutorial_code/features2D/Homography/decompose_homography.cpp @@ -1,7 +1,10 @@ #include #include #ifdef HAVE_OPENCV_ARUCO -#include +#include +#include +#include +#include #include using namespace std; diff --git a/samples/cpp/tutorial_code/features2D/Homography/homography_from_camera_displacement.cpp b/samples/cpp/tutorial_code/features2D/Homography/homography_from_camera_displacement.cpp index 005d122d0d..ce2f76fa38 100644 --- a/samples/cpp/tutorial_code/features2D/Homography/homography_from_camera_displacement.cpp +++ b/samples/cpp/tutorial_code/features2D/Homography/homography_from_camera_displacement.cpp @@ -1,7 +1,10 @@ #include #include #ifdef HAVE_OPENCV_ARUCO -#include +#include +#include +#include +#include #include using namespace std; diff --git a/samples/cpp/tutorial_code/features2D/Homography/panorama_stitching_rotating_camera.cpp b/samples/cpp/tutorial_code/features2D/Homography/panorama_stitching_rotating_camera.cpp index c2eedc5f94..88dcf47477 100755 --- a/samples/cpp/tutorial_code/features2D/Homography/panorama_stitching_rotating_camera.cpp +++ b/samples/cpp/tutorial_code/features2D/Homography/panorama_stitching_rotating_camera.cpp @@ -1,5 +1,8 @@ #include -#include +#include +#include +#include +#include using namespace std; using namespace cv; diff --git a/samples/cpp/tutorial_code/features2D/Homography/perspective_correction.cpp b/samples/cpp/tutorial_code/features2D/Homography/perspective_correction.cpp index c23c515e8d..16476c6830 100644 --- a/samples/cpp/tutorial_code/features2D/Homography/perspective_correction.cpp +++ b/samples/cpp/tutorial_code/features2D/Homography/perspective_correction.cpp @@ -1,7 +1,10 @@ #include #include #ifdef HAVE_OPENCV_ARUCO -#include +#include +#include +#include +#include #include using namespace std; @@ -17,32 +20,6 @@ Scalar randomColor( RNG& rng ) return Scalar( icolor & 255, (icolor >> 8) & 255, (icolor >> 16) & 255 ); } -void calcChessboardCorners(Size boardSize, float squareSize, vector& corners, Pattern patternType = CHESSBOARD) -{ - corners.resize(0); - - switch (patternType) - { - case CHESSBOARD: - case CIRCLES_GRID: - for( int i = 0; i < boardSize.height; i++ ) - for( int j = 0; j < boardSize.width; j++ ) - corners.push_back(Point3f(float(j*squareSize), - float(i*squareSize), 0)); - break; - - case ASYMMETRIC_CIRCLES_GRID: - for( int i = 0; i < boardSize.height; i++ ) - for( int j = 0; j < boardSize.width; j++ ) - corners.push_back(Point3f(float((2*j + i % 2)*squareSize), - float(i*squareSize), 0)); - break; - - default: - CV_Error(Error::StsBadArg, "Unknown pattern type\n"); - } -} - void perspectiveCorrection(const string &img1Path, const string &img2Path, const Size &patternSize, RNG &rng) { Mat img1 = imread(img1Path); diff --git a/samples/cpp/tutorial_code/features2D/Homography/pose_from_homography.cpp b/samples/cpp/tutorial_code/features2D/Homography/pose_from_homography.cpp index 4fc29a7f88..50a16c223e 100644 --- a/samples/cpp/tutorial_code/features2D/Homography/pose_from_homography.cpp +++ b/samples/cpp/tutorial_code/features2D/Homography/pose_from_homography.cpp @@ -1,7 +1,10 @@ #include #include #ifdef HAVE_OPENCV_ARUCO -#include +#include +#include +#include +#include #include using namespace std; diff --git a/samples/cpp/tutorial_code/snippets/core_various.cpp b/samples/cpp/tutorial_code/snippets/core_various.cpp index 01f69496aa..6e220788ed 100644 --- a/samples/cpp/tutorial_code/snippets/core_various.cpp +++ b/samples/cpp/tutorial_code/snippets/core_various.cpp @@ -1,4 +1,7 @@ -#include +#include +#include +#include +#include using namespace std; using namespace cv; diff --git a/samples/cpp/tutorial_code/snippets/imgcodecs_imwrite.cpp b/samples/cpp/tutorial_code/snippets/imgcodecs_imwrite.cpp index a42fce2672..10f4151694 100644 --- a/samples/cpp/tutorial_code/snippets/imgcodecs_imwrite.cpp +++ b/samples/cpp/tutorial_code/snippets/imgcodecs_imwrite.cpp @@ -1,4 +1,4 @@ -#include +#include using namespace cv; using namespace std; diff --git a/samples/cpp/tutorial_code/viz/histo3D.cpp b/samples/cpp/tutorial_code/viz/histo3D.cpp index 0fb3735542..c01d756c2e 100644 --- a/samples/cpp/tutorial_code/viz/histo3D.cpp +++ b/samples/cpp/tutorial_code/viz/histo3D.cpp @@ -1,4 +1,6 @@ -#include +#include +#include +#include #include using namespace std; @@ -6,6 +8,8 @@ using namespace cv; #ifdef HAVE_OPENCV_VIZ +#include + const String keys = "{Aide h usage ? help | | print this message }" "{@arg1 | | Full path to color imag (3 channels)}" diff --git a/samples/cpp/tutorial_code/xfeatures2D/LATCH_match.cpp b/samples/cpp/tutorial_code/xfeatures2D/LATCH_match.cpp index 04f2c3c6fa..2d1282d89d 100644 --- a/samples/cpp/tutorial_code/xfeatures2D/LATCH_match.cpp +++ b/samples/cpp/tutorial_code/xfeatures2D/LATCH_match.cpp @@ -4,10 +4,12 @@ #ifdef HAVE_OPENCV_XFEATURES2D +#include +#include +#include #include #include #include -#include #include // If you find this code useful, please add a reference to the following paper in your work: diff --git a/samples/cpp/videocapture_basic.cpp b/samples/cpp/videocapture_basic.cpp index ae77b05448..6f46715458 100644 --- a/samples/cpp/videocapture_basic.cpp +++ b/samples/cpp/videocapture_basic.cpp @@ -5,7 +5,9 @@ @date Aug 24, 2016 */ -#include +#include +#include +#include #include #include @@ -49,4 +51,4 @@ int main(int, char**) } // the camera will be deinitialized automatically in VideoCapture destructor return 0; -} \ No newline at end of file +} diff --git a/samples/cpp/videowriter_basic.cpp b/samples/cpp/videowriter_basic.cpp index 9ab4efcc90..76f92ec0e0 100644 --- a/samples/cpp/videowriter_basic.cpp +++ b/samples/cpp/videowriter_basic.cpp @@ -5,7 +5,9 @@ @date Aug 24, 2016 */ -#include +#include +#include +#include #include #include @@ -62,4 +64,4 @@ int main(int, char**) } // the videofile will be closed and released automatically in VideoWriter destructor return 0; -} \ No newline at end of file +} diff --git a/samples/opencl/opencl-opencv-interop.cpp b/samples/opencl/opencl-opencv-interop.cpp index 4f96280cb2..c6630ea45b 100644 --- a/samples/opencl/opencl-opencv-interop.cpp +++ b/samples/opencl/opencl-opencv-interop.cpp @@ -16,7 +16,7 @@ #define CL_USE_DEPRECATED_OPENCL_2_0_APIS // eliminate build warning -#if __APPLE__ +#ifdef __APPLE__ #include #else #include From 2200e13c7193e0fe9db4b9f7c4bee3a7ef043909 Mon Sep 17 00:00:00 2001 From: Maksim Shabunin Date: Fri, 9 Feb 2018 13:30:04 +0300 Subject: [PATCH 3/5] cmake: refactored scripts with samples building: - allow installing samples sources on all platforms even if BUILD_EXAMPLES is disabled, fixed minor issues in sources installation process - use 'example__' scheme for target and binary file naming - use single function for sample executable creation --- CMakeLists.txt | 4 +- cmake/OpenCVModule.cmake | 29 +-- samples/CMakeLists.txt | 88 ++++++--- samples/cpp/CMakeLists.txt | 170 ++++++------------ .../real_time_pose_estimation/CMakeLists.txt | 4 +- .../snippets/imgproc_HoughLinesPointSet.cpp | 3 +- samples/directx/CMakeLists.txt | 58 ++---- samples/dnn/CMakeLists.txt | 103 ++++------- samples/gpu/CMakeLists.txt | 141 ++++++--------- samples/gpu/performance/CMakeLists.txt | 8 +- samples/opencl/CMakeLists.txt | 92 +++------- samples/opengl/CMakeLists.txt | 51 ++---- samples/openvx/CMakeLists.txt | 52 +++--- samples/tapi/CMakeLists.txt | 68 +++---- samples/va_intel/CMakeLists.txt | 51 ++---- 15 files changed, 346 insertions(+), 576 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6a49deb854..87b3cfd737 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -420,7 +420,7 @@ else() ocv_update(OPENCV_LIB_INSTALL_PATH "${OpenCV_INSTALL_BINARIES_PREFIX}lib${LIB_SUFFIX}") endif() ocv_update(OPENCV_3P_LIB_INSTALL_PATH "${OpenCV_INSTALL_BINARIES_PREFIX}staticlib${LIB_SUFFIX}") - ocv_update(OPENCV_SAMPLES_SRC_INSTALL_PATH samples/native) + ocv_update(OPENCV_SAMPLES_SRC_INSTALL_PATH samples) ocv_update(OPENCV_JAR_INSTALL_PATH java) ocv_update(OPENCV_OTHER_INSTALL_PATH etc) ocv_update(OPENCV_CONFIG_INSTALL_PATH ".") @@ -804,7 +804,7 @@ if(BUILD_opencv_apps) endif() # examples -if(BUILD_EXAMPLES OR BUILD_ANDROID_EXAMPLES OR INSTALL_PYTHON_EXAMPLES) +if(BUILD_EXAMPLES OR BUILD_ANDROID_EXAMPLES OR INSTALL_PYTHON_EXAMPLES OR INSTALL_C_EXAMPLES) add_subdirectory(samples) endif() diff --git a/cmake/OpenCVModule.cmake b/cmake/OpenCVModule.cmake index bf4102e1ea..e413198aa5 100644 --- a/cmake/OpenCVModule.cmake +++ b/cmake/OpenCVModule.cmake @@ -1221,9 +1221,13 @@ function(ocv_add_samples) ocv_debug_message("ocv_add_samples(" ${ARGN} ")") set(samples_path "${CMAKE_CURRENT_SOURCE_DIR}/samples") + if(NOT EXISTS "${samples_path}") + return() + endif() + string(REGEX REPLACE "^opencv_" "" module_id ${the_module}) - if(BUILD_EXAMPLES AND EXISTS "${samples_path}") + if(BUILD_EXAMPLES) set(samples_deps ${the_module} ${OPENCV_MODULE_${the_module}_DEPS} opencv_imgcodecs opencv_videoio opencv_highgui ${ARGN}) ocv_check_dependencies(${samples_deps}) @@ -1237,15 +1241,14 @@ function(ocv_add_samples) ocv_add_executable(${the_target} "${source}") ocv_target_include_modules(${the_target} ${samples_deps}) ocv_target_link_libraries(${the_target} LINK_PRIVATE ${samples_deps}) - set_target_properties(${the_target} PROPERTIES PROJECT_LABEL "(sample) ${name}") - - set_target_properties(${the_target} PROPERTIES LABELS "${OPENCV_MODULE_${the_module}_LABEL};Sample") - set_source_files_properties("${source}" - PROPERTIES LABELS "${OPENCV_MODULE_${the_module}_LABEL};Sample") + set_target_properties(${the_target} PROPERTIES + PROJECT_LABEL "(sample) ${name}" + LABELS "${OPENCV_MODULE_${the_module}_LABEL};Sample") + set_source_files_properties("${source}" PROPERTIES + LABELS "${OPENCV_MODULE_${the_module}_LABEL};Sample") if(ENABLE_SOLUTION_FOLDERS) set_target_properties(${the_target} PROPERTIES - OUTPUT_NAME "${module_id}-example-${name}" FOLDER "samples/${module_id}") endif() @@ -1256,8 +1259,8 @@ function(ocv_add_samples) endif() endif() - if(INSTALL_C_EXAMPLES AND NOT WIN32 AND EXISTS "${samples_path}") - file(GLOB DEPLOY_FILES_AND_DIRS "${samples_path}/*") + if(INSTALL_C_EXAMPLES) + file(GLOB DEPLOY_FILES_AND_DIRS "${samples_path}/*") foreach(ITEM ${DEPLOY_FILES_AND_DIRS}) IF( IS_DIRECTORY "${ITEM}" ) LIST( APPEND sample_dirs "${ITEM}" ) @@ -1266,10 +1269,10 @@ function(ocv_add_samples) ENDIF() endforeach() install(FILES ${sample_files} - DESTINATION ${OPENCV_SAMPLES_SRC_INSTALL_PATH}/${module_id} - PERMISSIONS OWNER_READ GROUP_READ WORLD_READ COMPONENT samples) + DESTINATION "${OPENCV_SAMPLES_SRC_INSTALL_PATH}/${module_id}" + COMPONENT samples) install(DIRECTORY ${sample_dirs} - DESTINATION ${OPENCV_SAMPLES_SRC_INSTALL_PATH}/${module_id} - USE_SOURCE_PERMISSIONS COMPONENT samples) + DESTINATION "${OPENCV_SAMPLES_SRC_INSTALL_PATH}/${module_id}" + COMPONENT samples) endif() endfunction() diff --git a/samples/CMakeLists.txt b/samples/CMakeLists.txt index 1ce0489f1a..251cca106f 100644 --- a/samples/CMakeLists.txt +++ b/samples/CMakeLists.txt @@ -1,58 +1,95 @@ -# Detect if we want to build samples with library binaries or not +# Utility function: adds sample executable target with name "example__" +# Usage: +# ocv_define_sample( ) +function(ocv_define_sample out_target source sub) + get_filename_component(name "${source}" NAME_WE) + set(the_target "example_${sub}_${name}") + add_executable(${the_target} "${source}") + set_target_properties(${the_target} PROPERTIES PROJECT_LABEL "(sample) ${name}") + if(ENABLE_SOLUTION_FOLDERS) + set_target_properties(${the_target} PROPERTIES FOLDER "samples/${sub}") + endif() + if(WIN32 AND MSVC AND NOT BUILD_SHARED_LIBS) + set_target_properties(${the_target} PROPERTIES LINK_FLAGS "/NODEFAULTLIB:atlthunk.lib /NODEFAULTLIB:atlsd.lib /DEBUG") + endif() + if(WIN32) + install(TARGETS ${the_target} RUNTIME DESTINATION "samples/${sub}" COMPONENT samples) + endif() + set(${out_target} ${the_target} PARENT_SCOPE) +endfunction() + if(NOT CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_LIST_DIR) +#=================================================================================================== # -# BUILD CASE 1: Build samples with library sources +# Build as part of OpenCV # +#=================================================================================================== - -# ---------------------------------------------------------------------------- -# CMake file for samples. See root CMakeLists.txt -# -# ---------------------------------------------------------------------------- +function(ocv_install_example_src relpath) + if(INSTALL_C_EXAMPLES) + file(GLOB files ${ARGN}) + install(FILES ${files} + DESTINATION "${OPENCV_SAMPLES_SRC_INSTALL_PATH}/${relpath}" + COMPONENT samples) + endif() +endfunction() add_subdirectory(cpp) add_subdirectory(java/tutorial_code) add_subdirectory(dnn) add_subdirectory(gpu) add_subdirectory(tapi) - +add_subdirectory(opencl) if(WIN32 AND HAVE_DIRECTX) add_subdirectory(directx) endif() - if((NOT ANDROID) AND HAVE_OPENGL) add_subdirectory(opengl) endif() - if(HAVE_OPENVX) add_subdirectory(openvx) endif() - if(UNIX AND NOT ANDROID AND (HAVE_VA OR HAVE_VA_INTEL)) add_subdirectory(va_intel) endif() - if(ANDROID AND BUILD_ANDROID_EXAMPLES) add_subdirectory(android) endif() - if(INSTALL_PYTHON_EXAMPLES) add_subdirectory(python) endif() -# -# END OF BUILD CASE 1: Build samples with library sources -# +ocv_install_example_src("." CMakeLists.txt) +if(INSTALL_C_EXAMPLES) + install(DIRECTORY data + DESTINATION "${OPENCV_SAMPLES_SRC_INSTALL_PATH}/data" + COMPONENT samples) +endif() + else() +#=================================================================================================== # -# BUILD CASE 2: Build samples with library binaries +# Standalone mode # +#=================================================================================================== cmake_minimum_required(VERSION 2.8) project(samples C CXX) option(BUILD_EXAMPLES "Build samples" ON) -find_package(OpenCV REQUIRED) +# Assuming following installation folder structure (default for UNIX): +# /share/ +# └── OpenCV/ <-- OPENCV_CONFIG_INSTALL_PATH +# ├── OpenCVConfig.cmake <-- file to be found by find_package +# ├── ... +# ├── samples/ <-- OPENCV_SAMPLES_SRC_INSTALL_PATH +# │   ├── CMakeLists.txt <-- this file +# │   ├── cpp/ +find_package(OpenCV REQUIRED PATHS "..") + +function(ocv_install_example_src) + # not used in this branch +endfunction() if(MSVC) if(NOT ENABLE_BUILD_HARDENING) @@ -80,16 +117,15 @@ if(MSVC) endif() add_subdirectory(cpp) -add_subdirectory(dnn) -# FIXIT: can't use cvconfig.h in samples: add_subdirectory(gpu) - -add_subdirectory(opencl) - if(WIN32) add_subdirectory(directx) endif() +add_subdirectory(dnn) +# add_subdirectory(gpu) +add_subdirectory(opencl) +# add_subdirectory(opengl) +# add_subdirectory(openvx) +add_subdirectory(tapi) +# add_subdirectory(va_intel) -# -# END OF BUILD CASE 2: Build samples with library binaries -# endif() diff --git a/samples/cpp/CMakeLists.txt b/samples/cpp/CMakeLists.txt index c75a5c73e2..18fc6f8db4 100644 --- a/samples/cpp/CMakeLists.txt +++ b/samples/cpp/CMakeLists.txt @@ -1,117 +1,65 @@ -# ---------------------------------------------------------------------------- -# CMake file for C samples. See root CMakeLists.txt -# -# ---------------------------------------------------------------------------- - -SET(OPENCV_CPP_SAMPLES_REQUIRED_DEPS opencv_core opencv_imgproc opencv_flann - opencv_imgcodecs opencv_videoio opencv_highgui opencv_ml opencv_video - opencv_objdetect opencv_photo opencv_features2d opencv_calib3d - opencv_stitching opencv_videostab opencv_shape ${OPENCV_MODULES_PUBLIC} ${OpenCV_LIB_COMPONENTS}) +ocv_install_example_src(cpp *.cpp *.hpp CMakeLists.txt) +set(OPENCV_CPP_SAMPLES_REQUIRED_DEPS + opencv_core + opencv_imgproc + opencv_flann + opencv_imgcodecs + opencv_videoio + opencv_highgui + opencv_ml + opencv_video + opencv_objdetect + opencv_photo + opencv_features2d + opencv_calib3d + opencv_stitching + opencv_videostab + opencv_shape + ${OPENCV_MODULES_PUBLIC} + ${OpenCV_LIB_COMPONENTS}) ocv_check_dependencies(${OPENCV_CPP_SAMPLES_REQUIRED_DEPS}) - -if(BUILD_EXAMPLES AND OCV_DEPENDENCIES_FOUND) - project(cpp_samples) - - ocv_include_directories("${OpenCV_SOURCE_DIR}/include")#for opencv.hpp - ocv_include_modules_recurse(${OPENCV_CPP_SAMPLES_REQUIRED_DEPS}) - - if(HAVE_opencv_cudaoptflow) - ocv_include_directories("${OpenCV_SOURCE_DIR}/modules/cudaoptflow/include") - endif() - if(HAVE_opencv_cudaimgproc) - ocv_include_directories("${OpenCV_SOURCE_DIR}/modules/cudaimgproc/include") - endif() - if(HAVE_opencv_cudaarithm) - ocv_include_directories("${OpenCV_SOURCE_DIR}/modules/cudaarithm/include") - endif() - if(HAVE_opencv_cudafilters) - ocv_include_directories("${OpenCV_SOURCE_DIR}/modules/cudafilters/include") - endif() - - if(CMAKE_COMPILER_IS_GNUCXX AND NOT ENABLE_NOISY_WARNINGS) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-unused-function -Wno-missing-declarations") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-function -Wno-missing-declarations") - endif() - - # --------------------------------------------- - # Define executable targets - # --------------------------------------------- - MACRO(OPENCV_DEFINE_CPP_EXAMPLE name srcs) - - if("${srcs}" MATCHES "tutorial_code") - set(sample_kind tutorial) - set(sample_KIND TUTORIAL) - set(sample_subfolder "tutorials") - else() - set(sample_kind example) - set(sample_KIND EXAMPLE) - set(sample_subfolder "cpp") - endif() - - set(the_target "${sample_kind}_${name}") - add_executable(${the_target} ${srcs}) - ocv_target_link_libraries(${the_target} ${OPENCV_LINKER_LIBS} ${OPENCV_CPP_SAMPLES_REQUIRED_DEPS}) - - if("${srcs}" MATCHES "gpu/") - ocv_target_link_libraries(${the_target} opencv_cudaarithm opencv_cudafilters) - endif() - - if("${srcs}" MATCHES "viz/" AND VTK_USE_FILE) - include(${VTK_USE_FILE}) - ocv_target_link_libraries(${the_target} ${VTK_LIBRARIES}) - add_definitions(-DUSE_VTK) - endif() - - set_target_properties(${the_target} PROPERTIES - OUTPUT_NAME "cpp-${sample_kind}-${name}" - PROJECT_LABEL "(${sample_KIND}) ${name}") - - if(ENABLE_SOLUTION_FOLDERS) - set_target_properties(${the_target} PROPERTIES FOLDER "samples/${sample_subfolder}") - endif() - - if(WIN32) - if (MSVC AND NOT BUILD_SHARED_LIBS) - set_target_properties(${the_target} PROPERTIES LINK_FLAGS "/NODEFAULTLIB:atlthunk.lib /NODEFAULTLIB:atlsd.lib /DEBUG") - endif() - install(TARGETS ${the_target} - RUNTIME DESTINATION "${OPENCV_SAMPLES_BIN_INSTALL_PATH}/${sample_subfolder}" COMPONENT samples) - endif() - ENDMACRO() - - file(GLOB_RECURSE cpp_samples RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp) - - if(NOT HAVE_OPENGL) - ocv_list_filterout(cpp_samples Qt_sample) - endif() - - if(NOT HAVE_opencv_cudaarithm OR NOT HAVE_opencv_cudafilters) - ocv_list_filterout(cpp_samples "/gpu/") - endif() - - if(NOT TARGET opencv_viz) - ocv_list_filterout(cpp_samples "/viz/") - endif() - - if(NOT HAVE_IPP_A) - ocv_list_filterout(cpp_samples "/ippasync/") - endif() - - foreach(sample_filename ${cpp_samples}) - if(NOT "${sample_filename}" MATCHES "real_time_pose_estimation/") - get_filename_component(sample ${sample_filename} NAME_WE) - OPENCV_DEFINE_CPP_EXAMPLE(${sample} ${sample_filename}) - endif() - endforeach() - - include("tutorial_code/calib3d/real_time_pose_estimation/CMakeLists.txt") +if(NOT BUILD_EXAMPLES OR NOT OCV_DEPENDENCIES_FOUND) + return() endif() -if(INSTALL_C_EXAMPLES AND NOT WIN32) - file(GLOB C_SAMPLES *.c *.cpp *.jpg *.png *.data makefile.* build_all.sh *.dsp *.cmd ) - install(FILES ${C_SAMPLES} - DESTINATION ${OPENCV_SAMPLES_SRC_INSTALL_PATH}/cpp - PERMISSIONS OWNER_READ GROUP_READ WORLD_READ COMPONENT samples) +project(cpp_samples) +ocv_include_modules_recurse(${OPENCV_CPP_SAMPLES_REQUIRED_DEPS}) +file(GLOB_RECURSE cpp_samples RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp) +if(NOT HAVE_OPENGL) + ocv_list_filterout(cpp_samples Qt_sample) endif() +if(NOT HAVE_opencv_cudaarithm OR NOT HAVE_opencv_cudafilters) + ocv_list_filterout(cpp_samples "/gpu/") +endif() +if(NOT TARGET opencv_viz) + ocv_list_filterout(cpp_samples "/viz/") +endif() +if(NOT HAVE_IPP_A) + ocv_list_filterout(cpp_samples "/ippasync/") +endif() +ocv_list_filterout(cpp_samples "real_time_pose_estimation/") +foreach(sample_filename ${cpp_samples}) + if(sample_filename MATCHES "viz/" AND VTK_USE_FILE) + include(${VTK_USE_FILE}) + endif() + set(package "cpp") + if(sample_filename MATCHES "tutorial_code") + set(package "tutorial") + endif() + ocv_define_sample(tgt ${sample_filename} ${package}) + ocv_target_link_libraries(${tgt} ${OPENCV_LINKER_LIBS} ${OPENCV_CPP_SAMPLES_REQUIRED_DEPS}) + if(sample_filename MATCHES "gpu/" AND HAVE_opencv_cudaarithm AND HAVE_opencv_cuda_filters) + ocv_target_link_libraries(${tgt} opencv_cudaarithm opencv_cudafilters) + endif() + if(sample_filename MATCHES "viz/" AND VTK_USE_FILE) + ocv_target_link_libraries(${tgt} ${VTK_LIBRARIES}) + target_compile_definitions(${tgt} PRIVATE -DUSE_VTK) + endif() + if(HAVE_OPENGL AND sample_filename MATCHES "detect_mser") + target_compile_definitions(${tgt} PRIVATE HAVE_OPENGL) + endif() +endforeach() + +include("tutorial_code/calib3d/real_time_pose_estimation/CMakeLists.txt" OPTIONAL) diff --git a/samples/cpp/tutorial_code/calib3d/real_time_pose_estimation/CMakeLists.txt b/samples/cpp/tutorial_code/calib3d/real_time_pose_estimation/CMakeLists.txt index a3c5cfe4c4..b0ca6c0ff0 100644 --- a/samples/cpp/tutorial_code/calib3d/real_time_pose_estimation/CMakeLists.txt +++ b/samples/cpp/tutorial_code/calib3d/real_time_pose_estimation/CMakeLists.txt @@ -1,5 +1,5 @@ set(sample_dir ${CMAKE_CURRENT_SOURCE_DIR}/tutorial_code/calib3d/real_time_pose_estimation/src/) -set(target cpp-tutorial-) +set(target example_tutorial_) set(sample_pnplib ${sample_dir}CsvReader.cpp @@ -12,6 +12,8 @@ set(sample_pnplib ${sample_dir}RobustMatcher.cpp ) +ocv_include_modules_recurse(${OPENCV_CPP_SAMPLES_REQUIRED_DEPS}) + add_executable( ${target}pnp_registration ${sample_dir}main_registration.cpp ${sample_pnplib} ) add_executable( ${target}pnp_detection ${sample_dir}main_detection.cpp ${sample_pnplib} ) diff --git a/samples/cpp/tutorial_code/snippets/imgproc_HoughLinesPointSet.cpp b/samples/cpp/tutorial_code/snippets/imgproc_HoughLinesPointSet.cpp index e0f9337b87..e5c8ec06ef 100644 --- a/samples/cpp/tutorial_code/snippets/imgproc_HoughLinesPointSet.cpp +++ b/samples/cpp/tutorial_code/snippets/imgproc_HoughLinesPointSet.cpp @@ -1,4 +1,5 @@ -#include +#include +#include using namespace cv; using namespace std; diff --git a/samples/directx/CMakeLists.txt b/samples/directx/CMakeLists.txt index d0e60bdf33..391ea91af0 100644 --- a/samples/directx/CMakeLists.txt +++ b/samples/directx/CMakeLists.txt @@ -1,45 +1,21 @@ -SET(OPENCV_DIRECTX_SAMPLES_REQUIRED_DEPS opencv_core opencv_imgproc opencv_imgcodecs opencv_videoio opencv_highgui) +ocv_install_example_src(directx *.cpp *.hpp CMakeLists.txt) +set(OPENCV_DIRECTX_SAMPLES_REQUIRED_DEPS + opencv_core + opencv_imgproc + opencv_imgcodecs + opencv_videoio + opencv_highgui) ocv_check_dependencies(${OPENCV_DIRECTX_SAMPLES_REQUIRED_DEPS}) -if(BUILD_EXAMPLES AND OCV_DEPENDENCIES_FOUND) - set(project "directx") - string(TOUPPER "${project}" project_upper) - - project("${project}_samples") - - ocv_include_modules_recurse(${OPENCV_DIRECTX_SAMPLES_REQUIRED_DEPS}) - - # --------------------------------------------- - # Define executable targets - # --------------------------------------------- - MACRO(OPENCV_DEFINE_DIRECTX_EXAMPLE name srcs) - set(the_target "example_${project}_${name}") - add_executable(${the_target} ${srcs}) - - ocv_target_link_libraries(${the_target} ${OPENCV_LINKER_LIBS} ${OPENCV_DIRECTX_SAMPLES_REQUIRED_DEPS}) - - set_target_properties(${the_target} PROPERTIES - OUTPUT_NAME "${project}-example-${name}" - PROJECT_LABEL "(EXAMPLE_${project_upper}) ${name}") - - if(ENABLE_SOLUTION_FOLDERS) - set_target_properties(${the_target} PROPERTIES FOLDER "samples//${project}") - endif() - - if(WIN32) - if(MSVC AND NOT BUILD_SHARED_LIBS) - set_target_properties(${the_target} PROPERTIES LINK_FLAGS "/NODEFAULTLIB:atlthunk.lib /NODEFAULTLIB:atlsd.lib /DEBUG") - endif() - install(TARGETS ${the_target} RUNTIME DESTINATION "${OPENCV_SAMPLES_BIN_INSTALL_PATH}/${project}" COMPONENT samples) - endif() - ENDMACRO() - - file(GLOB all_samples RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp) - - foreach(sample_filename ${all_samples}) - get_filename_component(sample ${sample_filename} NAME_WE) - file(GLOB sample_srcs RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${sample}.*) - OPENCV_DEFINE_DIRECTX_EXAMPLE(${sample} ${sample_srcs}) - endforeach() +if(NOT BUILD_EXAMPLES OR NOT OCV_DEPENDENCIES_FOUND) + return() endif() + +project("directx_samples") +ocv_include_modules_recurse(${tgt} ${OPENCV_DIRECTX_SAMPLES_REQUIRED_DEPS}) +file(GLOB all_samples RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp) +foreach(sample_filename ${all_samples}) + ocv_define_sample(tgt ${sample_filename} directx) + ocv_target_link_libraries(${tgt} ${OPENCV_LINKER_LIBS} ${OPENCV_DIRECTX_SAMPLES_REQUIRED_DEPS}) +endforeach() diff --git a/samples/dnn/CMakeLists.txt b/samples/dnn/CMakeLists.txt index 1e7f8fe830..e7d8c5dab2 100644 --- a/samples/dnn/CMakeLists.txt +++ b/samples/dnn/CMakeLists.txt @@ -1,76 +1,39 @@ -SET(OPENCV_DNN_SAMPLES_REQUIRED_DEPS opencv_core opencv_imgproc opencv_dnn - opencv_imgcodecs opencv_videoio opencv_highgui - ${OpenCV_LIB_COMPONENTS}) +ocv_install_example_src(dnn *.cpp *.hpp CMakeLists.txt) +set(OPENCV_DNN_SAMPLES_REQUIRED_DEPS + opencv_core + opencv_imgproc + opencv_dnn + opencv_imgcodecs + opencv_videoio + opencv_highgui) ocv_check_dependencies(${OPENCV_DNN_SAMPLES_REQUIRED_DEPS}) - -if(BUILD_EXAMPLES AND OCV_DEPENDENCIES_FOUND) - project(dnn_samples) - - # Model branch name: dnn_samples_face_detector_20170830 - set(DNN_FACE_DETECTOR_MODEL_COMMIT "b2bfc75f6aea5b1f834ff0f0b865a7c18ff1459f") - set(DNN_FACE_DETECTOR_MODEL_HASH "afbb6037fd180e8d2acb3b58ca737b9e") - - set(DNN_FACE_DETECTOR_MODEL_NAME "res10_300x300_ssd_iter_140000.caffemodel") - - set(DNN_FACE_DETECTOR_MODEL_DOWNLOAD_DIR "${CMAKE_CURRENT_LIST_DIR}/face_detector") - - if(COMMAND ocv_download) - ocv_download(FILENAME ${DNN_FACE_DETECTOR_MODEL_NAME} - HASH ${DNN_FACE_DETECTOR_MODEL_HASH} - URL - "$ENV{OPENCV_DNN_MODELS_URL}" - "${OPENCV_DNN_MODELS_URL}" - "https://raw.githubusercontent.com/opencv/opencv_3rdparty/${DNN_FACE_DETECTOR_MODEL_COMMIT}/" - DESTINATION_DIR ${DNN_FACE_DETECTOR_MODEL_DOWNLOAD_DIR} - ID DNN_FACE_DETECTOR - RELATIVE_URL - STATUS res) - endif() - - ocv_include_directories("${OpenCV_SOURCE_DIR}/include") - ocv_include_modules_recurse(${OPENCV_DNN_SAMPLES_REQUIRED_DEPS}) - - # --------------------------------------------- - # Define executable targets - # --------------------------------------------- - MACRO(OPENCV_DEFINE_DNN_EXAMPLE name srcs) - set(sample_kind example_dnn) - set(sample_subfolder "dnn") - - set(the_target "${sample_kind}_${name}") - add_executable(${the_target} ${srcs}) - ocv_target_link_libraries(${the_target} ${OPENCV_LINKER_LIBS} ${OPENCV_DNN_SAMPLES_REQUIRED_DEPS}) - - set_target_properties(${the_target} PROPERTIES - OUTPUT_NAME "${sample_kind}-${name}" - PROJECT_LABEL "(${sample_KIND}) ${name}") - - if(ENABLE_SOLUTION_FOLDERS) - set_target_properties(${the_target} PROPERTIES FOLDER "samples/${sample_subfolder}") - endif() - - if(WIN32) - if (MSVC AND NOT BUILD_SHARED_LIBS) - set_target_properties(${the_target} PROPERTIES LINK_FLAGS "/NODEFAULTLIB:atlthunk.lib /NODEFAULTLIB:atlsd.lib /DEBUG") - endif() - install(TARGETS ${the_target} - RUNTIME DESTINATION "${OPENCV_SAMPLES_BIN_INSTALL_PATH}/${sample_subfolder}" COMPONENT samples) - endif() - ENDMACRO() - - file(GLOB_RECURSE dnn_samples RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp) - - foreach(sample_filename ${dnn_samples}) - get_filename_component(sample ${sample_filename} NAME_WE) - OPENCV_DEFINE_DNN_EXAMPLE(${sample} ${sample_filename}) - endforeach() +if(NOT BUILD_EXAMPLES OR NOT OCV_DEPENDENCIES_FOUND) + return() endif() -if(INSTALL_C_EXAMPLES AND NOT WIN32) - file(GLOB C_SAMPLES *.c *.cpp *.jpg *.png *.data makefile.* build_all.sh *.dsp *.cmd ) - install(FILES ${C_SAMPLES} - DESTINATION ${OPENCV_SAMPLES_SRC_INSTALL_PATH}/dnn - PERMISSIONS OWNER_READ GROUP_READ WORLD_READ COMPONENT samples) +# Model branch name: dnn_samples_face_detector_20170830 +set(DNN_FACE_DETECTOR_MODEL_COMMIT "b2bfc75f6aea5b1f834ff0f0b865a7c18ff1459f") +set(DNN_FACE_DETECTOR_MODEL_HASH "afbb6037fd180e8d2acb3b58ca737b9e") +set(DNN_FACE_DETECTOR_MODEL_NAME "res10_300x300_ssd_iter_140000.caffemodel") +set(DNN_FACE_DETECTOR_MODEL_DOWNLOAD_DIR "${CMAKE_CURRENT_LIST_DIR}/face_detector") +if(COMMAND ocv_download) + ocv_download(FILENAME ${DNN_FACE_DETECTOR_MODEL_NAME} + HASH ${DNN_FACE_DETECTOR_MODEL_HASH} + URL + "$ENV{OPENCV_DNN_MODELS_URL}" + "${OPENCV_DNN_MODELS_URL}" + "https://raw.githubusercontent.com/opencv/opencv_3rdparty/${DNN_FACE_DETECTOR_MODEL_COMMIT}/" + DESTINATION_DIR ${DNN_FACE_DETECTOR_MODEL_DOWNLOAD_DIR} + ID DNN_FACE_DETECTOR + RELATIVE_URL + STATUS res) endif() +project(dnn_samples) +ocv_include_modules_recurse(${OPENCV_DNN_SAMPLES_REQUIRED_DEPS}) +file(GLOB_RECURSE dnn_samples RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp) +foreach(sample_filename ${dnn_samples}) + ocv_define_sample(tgt ${sample_filename} dnn) + ocv_target_link_libraries(${tgt} ${OPENCV_LINKER_LIBS} ${OPENCV_DNN_SAMPLES_REQUIRED_DEPS}) +endforeach() diff --git a/samples/gpu/CMakeLists.txt b/samples/gpu/CMakeLists.txt index 0f734677be..8b35e7c37e 100644 --- a/samples/gpu/CMakeLists.txt +++ b/samples/gpu/CMakeLists.txt @@ -1,97 +1,60 @@ -SET(OPENCV_CUDA_SAMPLES_REQUIRED_DEPS opencv_core opencv_flann opencv_imgproc opencv_imgcodecs opencv_videoio opencv_highgui - opencv_ml opencv_video opencv_objdetect opencv_features2d - opencv_calib3d opencv_superres - opencv_cudaarithm opencv_cudafilters opencv_cudawarping opencv_cudaimgproc - opencv_cudafeatures2d opencv_cudaoptflow opencv_cudabgsegm - opencv_cudastereo opencv_cudalegacy opencv_cudaobjdetect) +ocv_install_example_src(gpu *.cpp *.hpp CMakeLists.txt) +set(OPENCV_CUDA_SAMPLES_REQUIRED_DEPS + opencv_core + opencv_flann + opencv_imgproc + opencv_imgcodecs + opencv_videoio + opencv_highgui + opencv_ml + opencv_video + opencv_objdetect + opencv_features2d + opencv_calib3d + opencv_superres + opencv_cudaarithm + opencv_cudafilters + opencv_cudawarping + opencv_cudaimgproc + opencv_cudafeatures2d + opencv_cudaoptflow + opencv_cudabgsegm + opencv_cudastereo + opencv_cudalegacy + opencv_cudaobjdetect) ocv_check_dependencies(${OPENCV_CUDA_SAMPLES_REQUIRED_DEPS}) -if(BUILD_EXAMPLES AND OCV_DEPENDENCIES_FOUND) - set(project "gpu") - string(TOUPPER "${project}" project_upper) - - project("${project}_samples") - - ocv_include_modules_recurse(${OPENCV_CUDA_SAMPLES_REQUIRED_DEPS}) +if(NOT BUILD_EXAMPLES OR NOT OCV_DEPENDENCIES_FOUND) + return() +endif() +project(gpu_samples) +ocv_include_modules_recurse(${OPENCV_CUDA_SAMPLES_REQUIRED_DEPS}) +if(HAVE_opencv_xfeatures2d) + ocv_include_modules_recurse(opencv_xfeatures2d) +endif() +if(HAVE_opencv_cudacodec) + ocv_include_modules_recurse(opencv_cudacodec) +endif() +if(HAVE_CUDA) + ocv_include_directories(${CUDA_INCLUDE_DIRS}) +endif() +if(CMAKE_COMPILER_IS_GNUCXX AND NOT ENABLE_NOISY_WARNINGS) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-unused-function") +endif() +file(GLOB all_samples RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp) +if(NOT HAVE_OPENGL) + ocv_list_filterout(all_samples "opengl") +endif() +foreach(sample_filename ${all_samples}) + ocv_define_sample(tgt ${sample_filename} gpu) + ocv_target_link_libraries(${tgt} ${OPENCV_LINKER_LIBS} ${OPENCV_CUDA_SAMPLES_REQUIRED_DEPS}) if(HAVE_opencv_xfeatures2d) - ocv_include_modules_recurse(opencv_xfeatures2d) + ocv_target_link_libraries(${tgt} opencv_xfeatures2d) endif() - if(HAVE_opencv_cudacodec) - ocv_include_modules_recurse(opencv_cudacodec) + ocv_target_link_libraries(${tgt} opencv_cudacodec) endif() - - if(HAVE_CUDA) - ocv_include_directories(${CUDA_INCLUDE_DIRS}) - endif() - - if(CMAKE_COMPILER_IS_GNUCXX AND NOT ENABLE_NOISY_WARNINGS) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-unused-function") - endif() - - # --------------------------------------------- - # Define executable targets - # --------------------------------------------- - MACRO(OPENCV_DEFINE_CUDA_EXAMPLE name srcs) - set(the_target "example_${project}_${name}") - add_executable(${the_target} ${srcs}) - - ocv_target_link_libraries(${the_target} ${OPENCV_LINKER_LIBS} ${OPENCV_CUDA_SAMPLES_REQUIRED_DEPS}) - - if(HAVE_CUDA AND NOT ANDROID) - ocv_target_link_libraries(${the_target} ${CUDA_CUDA_LIBRARY}) - endif() - - if(HAVE_opencv_xfeatures2d) - ocv_target_link_libraries(${the_target} opencv_xfeatures2d) - endif() - if(HAVE_opencv_cudacodec) - ocv_target_link_libraries(${the_target} opencv_cudacodec) - endif() - - if(HAVE_opencv_ocl) - ocv_target_link_libraries(${the_target} opencv_ocl) - endif() - - set_target_properties(${the_target} PROPERTIES - OUTPUT_NAME "${project}-example-${name}" - PROJECT_LABEL "(EXAMPLE_${project_upper}) ${name}") - - if(ENABLE_SOLUTION_FOLDERS) - set_target_properties(${the_target} PROPERTIES FOLDER "samples//${project}") - endif() - - if(WIN32) - if(MSVC AND NOT BUILD_SHARED_LIBS) - set_target_properties(${the_target} PROPERTIES LINK_FLAGS "/NODEFAULTLIB:atlthunk.lib /NODEFAULTLIB:atlsd.lib /DEBUG") - endif() - install(TARGETS ${the_target} RUNTIME DESTINATION "${OPENCV_SAMPLES_BIN_INSTALL_PATH}/${project}" COMPONENT samples) - endif() - ENDMACRO() - - file(GLOB all_samples RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp) - - if(NOT HAVE_OPENGL) - list(REMOVE_ITEM all_samples "opengl.cpp") - endif() - - foreach(sample_filename ${all_samples}) - get_filename_component(sample ${sample_filename} NAME_WE) - file(GLOB sample_srcs RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${sample}.*) - OPENCV_DEFINE_CUDA_EXAMPLE(${sample} ${sample_srcs}) - endforeach() - - include("performance/CMakeLists.txt") -endif() - -if(INSTALL_C_EXAMPLES AND NOT WIN32) - file(GLOB install_list *.c *.cpp *.jpg *.png *.data makefile.* build_all.sh *.dsp *.cmd ) - if(NOT HAVE_OPENGL) - list(REMOVE_ITEM install_list "opengl.cpp") - endif() - install(FILES ${install_list} - DESTINATION ${OPENCV_SAMPLES_SRC_INSTALL_PATH}/gpu - PERMISSIONS OWNER_READ GROUP_READ WORLD_READ COMPONENT samples) -endif() +endforeach() +include("performance/CMakeLists.txt" OPTIONAL) diff --git a/samples/gpu/performance/CMakeLists.txt b/samples/gpu/performance/CMakeLists.txt index 2b1bf0be6b..641ea6e1b1 100644 --- a/samples/gpu/performance/CMakeLists.txt +++ b/samples/gpu/performance/CMakeLists.txt @@ -34,10 +34,4 @@ if(WIN32) install(TARGETS ${the_target} RUNTIME DESTINATION "${OPENCV_SAMPLES_BIN_INSTALL_PATH}/gpu" COMPONENT samples) endif() -if(INSTALL_C_EXAMPLES AND NOT WIN32) - file(GLOB CUDA_FILES performance/*.cpp performance/*.h) - install(FILES ${CUDA_FILES} - DESTINATION ${OPENCV_SAMPLES_SRC_INSTALL_PATH}/gpu/performance - PERMISSIONS OWNER_READ GROUP_READ WORLD_READ - COMPONENT samples) -endif() +ocv_install_example_src("gpu/performance" performance/*.cpp performance/*.h) diff --git a/samples/opencl/CMakeLists.txt b/samples/opencl/CMakeLists.txt index 6b247e3e75..a614bbe9ee 100644 --- a/samples/opencl/CMakeLists.txt +++ b/samples/opencl/CMakeLists.txt @@ -1,72 +1,38 @@ -# cmake 3.1 needed for find_package(OpenCL) +ocv_install_example_src(opencl *.cpp *.hpp CMakeLists.txt) +# cmake 3.1 needed for find_package(OpenCL) if(CMAKE_VERSION VERSION_LESS "3.1") message(STATUS "OpenCL samples require CMakes 3.1+") return() endif() -set( - OPENCV_OPENCL_SAMPLES_REQUIRED_DEPS - opencv_core - opencv_imgproc - opencv_video - opencv_imgcodecs - opencv_videoio - opencv_highgui) - +set(OPENCV_OPENCL_SAMPLES_REQUIRED_DEPS + opencv_core + opencv_imgproc + opencv_video + opencv_imgcodecs + opencv_videoio + opencv_highgui) ocv_check_dependencies(${OPENCV_OPENCL_SAMPLES_REQUIRED_DEPS}) -if(BUILD_EXAMPLES AND OCV_DEPENDENCIES_FOUND) - - find_package(OpenCL 1.2 QUIET) - if(NOT OpenCL_FOUND) - message(STATUS "OpenCL samples are skipped: OpenCL SDK is required") - return() - endif() - - set(project "opencl") - string(TOUPPER "${project}" project_upper) - - project("${project}_samples") - - ocv_include_modules_recurse(${OPENCV_OPENCL_SAMPLES_REQUIRED_DEPS}) - - include_directories(${OpenCL_INCLUDE_DIR}) - - # --------------------------------------------- - # Define executable targets - # --------------------------------------------- - MACRO(OPENCV_DEFINE_OPENCL_EXAMPLE name srcs) - set(the_target "example_${project}_${name}") - add_executable(${the_target} ${srcs}) - - ocv_target_link_libraries( - ${the_target} - ${OPENCV_LINKER_LIBS} - ${OPENCV_OPENCL_SAMPLES_REQUIRED_DEPS} - ${OpenCL_LIBRARY}) - - set_target_properties(${the_target} PROPERTIES - OUTPUT_NAME "${project}-example-${name}" - PROJECT_LABEL "(EXAMPLE_${project_upper}) ${name}") - - if(ENABLE_SOLUTION_FOLDERS) - set_target_properties(${the_target} PROPERTIES FOLDER "samples//${project}") - endif() - - if(WIN32) - if(MSVC AND NOT BUILD_SHARED_LIBS) - set_target_properties(${the_target} PROPERTIES LINK_FLAGS "/NODEFAULTLIB:atlthunk.lib /NODEFAULTLIB:atlsd.lib /DEBUG") - endif() - install(TARGETS ${the_target} RUNTIME DESTINATION "${OPENCV_SAMPLES_BIN_INSTALL_PATH}/${project}" COMPONENT main) - endif() - ENDMACRO() - - file(GLOB all_samples RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp) - - foreach(sample_filename ${all_samples}) - get_filename_component(sample ${sample_filename} NAME_WE) - file(GLOB sample_srcs RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${sample}.*) - OPENCV_DEFINE_OPENCL_EXAMPLE(${sample} ${sample_srcs}) - endforeach() +if(NOT BUILD_EXAMPLES OR NOT OCV_DEPENDENCIES_FOUND) + return() endif() + +find_package(OpenCL 1.2 QUIET) +if(NOT OpenCL_FOUND) + message(STATUS "OpenCL samples are skipped: OpenCL SDK is required") + return() +endif() + +project(opencl_samples) +ocv_include_modules_recurse(${OPENCV_OPENCL_SAMPLES_REQUIRED_DEPS}) +ocv_include_directories(${OpenCL_INCLUDE_DIR}) +file(GLOB all_samples RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp) +foreach(sample_filename ${all_samples}) + ocv_define_sample(tgt ${sample_filename} opencl) + ocv_target_link_libraries(${tgt} + ${OPENCV_LINKER_LIBS} + ${OPENCV_OPENCL_SAMPLES_REQUIRED_DEPS} + ${OpenCL_LIBRARY}) +endforeach() diff --git a/samples/opengl/CMakeLists.txt b/samples/opengl/CMakeLists.txt index 92bd029203..e383abd899 100644 --- a/samples/opengl/CMakeLists.txt +++ b/samples/opengl/CMakeLists.txt @@ -12,50 +12,23 @@ if(UNIX) set(SAMPLE_LINKER_DEPS "${X11_LIBRARIES}") endif() - - -SET(OPENCV_OPENGL_SAMPLES_REQUIRED_DEPS opencv_core opencv_imgproc opencv_imgcodecs opencv_videoio opencv_highgui) - +SET(OPENCV_OPENGL_SAMPLES_REQUIRED_DEPS + opencv_core + opencv_imgproc + opencv_imgcodecs + opencv_videoio + opencv_highgui) ocv_check_dependencies(${OPENCV_OPENGL_SAMPLES_REQUIRED_DEPS}) if(BUILD_EXAMPLES AND OCV_DEPENDENCIES_FOUND) - set(project "opengl") - string(TOUPPER "${project}" project_upper) - - project("${project}_samples") - + project(opengl_samples) ocv_include_modules_recurse(${OPENCV_OPENGL_SAMPLES_REQUIRED_DEPS}) - - # --------------------------------------------- - # Define executable targets - # --------------------------------------------- - MACRO(OPENCV_DEFINE_OPENGL_EXAMPLE name srcs) - set(the_target "example_${project}_${name}") - add_executable(${the_target} ${srcs}) - - ocv_target_link_libraries(${the_target} ${OPENCV_LINKER_LIBS} ${OPENCV_OPENGL_SAMPLES_REQUIRED_DEPS} ${SAMPLE_LINKER_DEPS}) - - set_target_properties(${the_target} PROPERTIES - OUTPUT_NAME "${project}-example-${name}" - PROJECT_LABEL "(EXAMPLE_${project_upper}) ${name}") - - if(ENABLE_SOLUTION_FOLDERS) - set_target_properties(${the_target} PROPERTIES FOLDER "samples//${project}") - endif() - - if(WIN32) - if(MSVC AND NOT BUILD_SHARED_LIBS) - set_target_properties(${the_target} PROPERTIES LINK_FLAGS "/NODEFAULTLIB:atlthunk.lib /NODEFAULTLIB:atlsd.lib /DEBUG") - endif() - install(TARGETS ${the_target} RUNTIME DESTINATION "${OPENCV_SAMPLES_BIN_INSTALL_PATH}/${project}" COMPONENT samples) - endif() - ENDMACRO() - file(GLOB all_samples RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp) - foreach(sample_filename ${all_samples}) - get_filename_component(sample ${sample_filename} NAME_WE) - file(GLOB sample_srcs RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${sample}.*) - OPENCV_DEFINE_OPENGL_EXAMPLE(${sample} ${sample_srcs}) + ocv_define_sample(tgt ${sample_filename} opengl) + ocv_target_link_libraries(${tgt} + ${OPENCV_LINKER_LIBS} ${OPENCV_OPENGL_SAMPLES_REQUIRED_DEPS} ${SAMPLE_LINKER_DEPS}) endforeach() endif() + +ocv_install_example_src(opengl *.cpp *.hpp CMakeLists.txt) diff --git a/samples/openvx/CMakeLists.txt b/samples/openvx/CMakeLists.txt index f2a5680f43..fd9165bec9 100644 --- a/samples/openvx/CMakeLists.txt +++ b/samples/openvx/CMakeLists.txt @@ -1,37 +1,25 @@ +ocv_install_example_src(cpp *.cpp *.hpp CMakeLists.txt) + cmake_minimum_required(VERSION 2.8.9) -set(OPENCV_OPENVX_SAMPLE_REQUIRED_DEPS opencv_core opencv_imgproc opencv_imgcodecs opencv_videoio opencv_highgui) - +set(OPENCV_OPENVX_SAMPLE_REQUIRED_DEPS + opencv_core + opencv_imgproc + opencv_imgcodecs + opencv_videoio + opencv_highgui) ocv_check_dependencies(${OPENCV_OPENVX_SAMPLE_REQUIRED_DEPS}) -if(BUILD_EXAMPLES AND OCV_DEPENDENCIES_FOUND) - set(group "openvx") - set(name_wrapped "interop") - set(name_orig "interop_orig") - set(name_video "interop_video") - - project("${group}_sample") - - ocv_include_modules_recurse(${OPENCV_OPENVX_SAMPLE_REQUIRED_DEPS}) - - add_definitions(-DIVX_USE_OPENCV) - add_definitions(-DIVX_HIDE_INFO_WARNINGS) - - file(GLOB srcs_wrapped wrappers.cpp *.hpp) - file(GLOB srcs_orig no_wrappers.cpp *.hpp) - file(GLOB srcs_video wrappers_video.cpp *.hpp) - - MACRO(OPENVX_DEFINE_SAMPLE name srcs) - set(target "example_${group}_${name}") - add_executable(${target} ${srcs}) - ocv_target_link_libraries(${target} ${OPENCV_LINKER_LIBS} ${OPENCV_OPENVX_SAMPLE_REQUIRED_DEPS} ${OPENVX_LIBRARIES}) - if(ENABLE_SOLUTION_FOLDERS) - set_target_properties(${target} PROPERTIES FOLDER "samples//${group}") - endif() - ENDMACRO() - - OPENVX_DEFINE_SAMPLE(${name_wrapped} ${srcs_wrapped}) - OPENVX_DEFINE_SAMPLE(${name_orig} ${srcs_orig}) - OPENVX_DEFINE_SAMPLE(${name_video} ${srcs_video}) - +if(NOT BUILD_EXAMPLES OR NOT OCV_DEPENDENCIES_FOUND) + return() endif() + +project(openvx_samples) +ocv_include_modules_recurse(${OPENCV_OPENVX_SAMPLE_REQUIRED_DEPS}) +add_definitions(-DIVX_USE_OPENCV) +add_definitions(-DIVX_HIDE_INFO_WARNINGS) +file(GLOB_RECURSE cpp_samples RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp) +foreach(sample_filename ${cpp_samples}) + ocv_define_sample(tgt ${sample_filename} openvx) + ocv_target_link_libraries(${tgt} ${OPENCV_LINKER_LIBS} ${OPENCV_OPENVX_SAMPLE_REQUIRED_DEPS}) +endforeach() diff --git a/samples/tapi/CMakeLists.txt b/samples/tapi/CMakeLists.txt index 74f51339dd..ba0ac69f9d 100644 --- a/samples/tapi/CMakeLists.txt +++ b/samples/tapi/CMakeLists.txt @@ -1,52 +1,26 @@ -SET(OPENCV_TAPI_SAMPLES_REQUIRED_DEPS opencv_core opencv_imgproc opencv_video opencv_imgcodecs opencv_videoio opencv_highgui opencv_objdetect opencv_features2d opencv_calib3d opencv_flann) +ocv_install_example_src(tapi *.cpp *.hpp CMakeLists.txt) +set(OPENCV_TAPI_SAMPLES_REQUIRED_DEPS + opencv_core + opencv_imgproc + opencv_video + opencv_imgcodecs + opencv_videoio + opencv_highgui + opencv_objdetect + opencv_features2d + opencv_calib3d + opencv_flann) ocv_check_dependencies(${OPENCV_TAPI_SAMPLES_REQUIRED_DEPS}) -if(BUILD_EXAMPLES AND OCV_DEPENDENCIES_FOUND) - set(project "tapi") - string(TOUPPER "${project}" project_upper) - - project("${project}_samples") - - ocv_include_modules_recurse(${OPENCV_TAPI_SAMPLES_REQUIRED_DEPS}) - - # --------------------------------------------- - # Define executable targets - # --------------------------------------------- - MACRO(OPENCV_DEFINE_TAPI_EXAMPLE name srcs) - set(the_target "example_${project}_${name}") - add_executable(${the_target} ${srcs}) - - ocv_target_link_libraries(${the_target} ${OPENCV_LINKER_LIBS} ${OPENCV_TAPI_SAMPLES_REQUIRED_DEPS}) - - set_target_properties(${the_target} PROPERTIES - OUTPUT_NAME "${project}-example-${name}" - PROJECT_LABEL "(EXAMPLE_${project_upper}) ${name}") - - if(ENABLE_SOLUTION_FOLDERS) - set_target_properties(${the_target} PROPERTIES FOLDER "samples//${project}") - endif() - - if(WIN32) - if(MSVC AND NOT BUILD_SHARED_LIBS) - set_target_properties(${the_target} PROPERTIES LINK_FLAGS "/NODEFAULTLIB:atlthunk.lib /NODEFAULTLIB:atlsd.lib /DEBUG") - endif() - install(TARGETS ${the_target} RUNTIME DESTINATION "${OPENCV_SAMPLES_BIN_INSTALL_PATH}/${project}" COMPONENT samples) - endif() - ENDMACRO() - - file(GLOB all_samples RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp) - - foreach(sample_filename ${all_samples}) - get_filename_component(sample ${sample_filename} NAME_WE) - file(GLOB sample_srcs RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${sample}.*) - OPENCV_DEFINE_TAPI_EXAMPLE(${sample} ${sample_srcs}) - endforeach() +if(NOT BUILD_EXAMPLES OR NOT OCV_DEPENDENCIES_FOUND) + return() endif() -if(INSTALL_C_EXAMPLES AND NOT WIN32) - file(GLOB install_list *.c *.cpp *.jpg *.png *.data makefile.* build_all.sh *.dsp *.cmd ) - install(FILES ${install_list} - DESTINATION ${OPENCV_SAMPLES_SRC_INSTALL_PATH}/tapi - PERMISSIONS OWNER_READ GROUP_READ WORLD_READ COMPONENT samples) -endif() +project(tapi_samples) +ocv_include_modules_recurse(${OPENCV_TAPI_SAMPLES_REQUIRED_DEPS}) +file(GLOB all_samples RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp) +foreach(sample_filename ${all_samples}) + ocv_define_sample(tgt ${sample_filename} tapi) + ocv_target_link_libraries(${tgt} ${OPENCV_LINKER_LIBS} ${OPENCV_TAPI_SAMPLES_REQUIRED_DEPS}) +endforeach() diff --git a/samples/va_intel/CMakeLists.txt b/samples/va_intel/CMakeLists.txt index ddf63edb43..af51dd3206 100644 --- a/samples/va_intel/CMakeLists.txt +++ b/samples/va_intel/CMakeLists.txt @@ -1,38 +1,21 @@ -SET(OPENCV_VA_INTEL_SAMPLES_REQUIRED_DEPS opencv_core opencv_imgproc opencv_imgcodecs opencv_videoio opencv_highgui) +ocv_install_example_src(opencl *.cpp *.inc CMakeLists.txt) +set(OPENCV_VA_INTEL_SAMPLES_REQUIRED_DEPS + opencv_core + opencv_imgproc + opencv_imgcodecs + opencv_videoio + opencv_highgui) ocv_check_dependencies(${OPENCV_VA_INTEL_SAMPLES_REQUIRED_DEPS}) -if(BUILD_EXAMPLES AND OCV_DEPENDENCIES_FOUND) - set(project "va_intel") - string(TOUPPER "${project}" project_upper) - - project("${project}_samples") - - ocv_include_modules_recurse(${OPENCV_VA_INTEL_SAMPLES_REQUIRED_DEPS}) - - # --------------------------------------------- - # Define executable targets - # --------------------------------------------- - MACRO(OPENCV_DEFINE_VA_INTEL_EXAMPLE name srcs) - set(the_target "example_${project}_${name}") - add_executable(${the_target} ${srcs}) - - ocv_target_link_libraries(${the_target} ${OPENCV_LINKER_LIBS} ${OPENCV_VA_INTEL_SAMPLES_REQUIRED_DEPS} ${VA_LIBRARIES} ${VA_INTEL_LIBRARIES}) - - set_target_properties(${the_target} PROPERTIES - OUTPUT_NAME "${project}-example-${name}" - PROJECT_LABEL "(EXAMPLE_${project_upper}) ${name}") - - if(ENABLE_SOLUTION_FOLDERS) - set_target_properties(${the_target} PROPERTIES FOLDER "samples//${project}") - endif() - ENDMACRO() - - file(GLOB all_samples RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp) - - foreach(sample_filename ${all_samples}) - get_filename_component(sample ${sample_filename} NAME_WE) - file(GLOB sample_srcs RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${sample}.*) - OPENCV_DEFINE_VA_INTEL_EXAMPLE(${sample} ${sample_srcs}) - endforeach() +if(NOT BUILD_EXAMPLES OR NOT OCV_DEPENDENCIES_FOUND) + return() endif() + +project(va_intel_samples) +ocv_include_modules_recurse(${OPENCV_VA_INTEL_SAMPLES_REQUIRED_DEPS}) +file(GLOB all_samples RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp) +foreach(sample_filename ${all_samples}) + ocv_define_sample(tgt ${sample_filename} va_intel) + ocv_target_link_libraries(${tgt} ${OPENCV_LINKER_LIBS} ${OPENCV_VA_INTEL_SAMPLES_REQUIRED_DEPS}) +endforeach() From 2d1350a9d6d83f207a3181caa512afe378f3206f Mon Sep 17 00:00:00 2001 From: Maksim Shabunin Date: Fri, 9 Feb 2018 16:17:01 +0300 Subject: [PATCH 4/5] Added group targets for samples (opencv_samples, opencv_samples_), install samples/data inseparate component 'samples_data' --- cmake/OpenCVExtraTargets.cmake | 8 ++++++++ cmake/OpenCVModule.cmake | 7 +++++++ samples/CMakeLists.txt | 11 ++++++++++- 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/cmake/OpenCVExtraTargets.cmake b/cmake/OpenCVExtraTargets.cmake index 8dd8a970b6..e766f7a603 100644 --- a/cmake/OpenCVExtraTargets.cmake +++ b/cmake/OpenCVExtraTargets.cmake @@ -43,3 +43,11 @@ if(BUILD_DOCS) add_custom_target(install_docs DEPENDS opencv_docs COMMAND "${CMAKE_COMMAND}" -DCMAKE_INSTALL_COMPONENT=docs -P "${CMAKE_BINARY_DIR}/cmake_install.cmake") endif() + +# Samples +if(BUILD_EXAMPLES) + add_custom_target(opencv_samples) + if(ENABLE_SOLUTION_FOLDERS) + set_target_properties(opencv_samples PROPERTIES FOLDER "extra") + endif() +endif() diff --git a/cmake/OpenCVModule.cmake b/cmake/OpenCVModule.cmake index e413198aa5..fe3978613d 100644 --- a/cmake/OpenCVModule.cmake +++ b/cmake/OpenCVModule.cmake @@ -1251,6 +1251,13 @@ function(ocv_add_samples) set_target_properties(${the_target} PROPERTIES FOLDER "samples/${module_id}") endif() + # Add single target to build all samples for the module: 'make opencv_samples_bioinspired' + set(parent_target opencv_samples_${module_id}) + if(NOT TARGET ${parent_target}) + add_custom_target(${parent_target}) + add_dependencies(opencv_samples ${parent_target}) + endif() + add_dependencies(${parent_target} ${the_target}) if(WIN32) install(TARGETS ${the_target} RUNTIME DESTINATION "samples/${module_id}" COMPONENT samples) diff --git a/samples/CMakeLists.txt b/samples/CMakeLists.txt index 251cca106f..e6ecdf826a 100644 --- a/samples/CMakeLists.txt +++ b/samples/CMakeLists.txt @@ -15,6 +15,15 @@ function(ocv_define_sample out_target source sub) if(WIN32) install(TARGETS ${the_target} RUNTIME DESTINATION "samples/${sub}" COMPONENT samples) endif() + # Add single target to build all samples in the group: 'make opencv_samples_cpp' + set(parent_target opencv_samples_${sub}) + if(NOT TARGET ${parent_target}) + add_custom_target(${parent_target}) + if(TARGET opencv_samples) + add_dependencies(opencv_samples ${parent_target}) + endif() + endif() + add_dependencies(${parent_target} ${the_target}) set(${out_target} ${the_target} PARENT_SCOPE) endfunction() @@ -63,7 +72,7 @@ ocv_install_example_src("." CMakeLists.txt) if(INSTALL_C_EXAMPLES) install(DIRECTORY data DESTINATION "${OPENCV_SAMPLES_SRC_INSTALL_PATH}/data" - COMPONENT samples) + COMPONENT samples_data) endif() else() From c63092781ad46e9d6c7ed9889c6c844d654611c2 Mon Sep 17 00:00:00 2001 From: Maksim Shabunin Date: Mon, 12 Feb 2018 18:39:32 +0300 Subject: [PATCH 5/5] Samples: fixed viz tutorials building with enabled opencv_world --- samples/cpp/CMakeLists.txt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/samples/cpp/CMakeLists.txt b/samples/cpp/CMakeLists.txt index 18fc6f8db4..7de6c1c278 100644 --- a/samples/cpp/CMakeLists.txt +++ b/samples/cpp/CMakeLists.txt @@ -33,7 +33,7 @@ endif() if(NOT HAVE_opencv_cudaarithm OR NOT HAVE_opencv_cudafilters) ocv_list_filterout(cpp_samples "/gpu/") endif() -if(NOT TARGET opencv_viz) +if(NOT VTK_USE_FILE) ocv_list_filterout(cpp_samples "/viz/") endif() if(NOT HAVE_IPP_A) @@ -41,7 +41,7 @@ if(NOT HAVE_IPP_A) endif() ocv_list_filterout(cpp_samples "real_time_pose_estimation/") foreach(sample_filename ${cpp_samples}) - if(sample_filename MATCHES "viz/" AND VTK_USE_FILE) + if(sample_filename MATCHES "/viz/") include(${VTK_USE_FILE}) endif() set(package "cpp") @@ -50,10 +50,10 @@ foreach(sample_filename ${cpp_samples}) endif() ocv_define_sample(tgt ${sample_filename} ${package}) ocv_target_link_libraries(${tgt} ${OPENCV_LINKER_LIBS} ${OPENCV_CPP_SAMPLES_REQUIRED_DEPS}) - if(sample_filename MATCHES "gpu/" AND HAVE_opencv_cudaarithm AND HAVE_opencv_cuda_filters) + if(sample_filename MATCHES "/gpu/" AND HAVE_opencv_cudaarithm AND HAVE_opencv_cuda_filters) ocv_target_link_libraries(${tgt} opencv_cudaarithm opencv_cudafilters) endif() - if(sample_filename MATCHES "viz/" AND VTK_USE_FILE) + if(sample_filename MATCHES "/viz/") ocv_target_link_libraries(${tgt} ${VTK_LIBRARIES}) target_compile_definitions(${tgt} PRIVATE -DUSE_VTK) endif()